From e82d88467a2504dcff93bcfc610252a2dc32614e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 18 Mar 2022 13:38:55 +0000 Subject: [PATCH] Added quick roll --- .../ecocrates/crate/roll/RollEncircle.kt | 2 + .../willfp/ecocrates/crate/roll/RollFlash.kt | 43 +++++----- .../willfp/ecocrates/crate/roll/RollQuick.kt | 79 +++++++++++++++++++ .../com/willfp/ecocrates/crate/roll/Rolls.kt | 1 + .../core-plugin/src/main/resources/config.yml | 9 ++- .../core-plugin/src/main/resources/crates.yml | 2 +- 6 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollQuick.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollEncircle.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollEncircle.kt index 1177899..de9ab7a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollEncircle.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollEncircle.kt @@ -52,6 +52,8 @@ class RollEncircle private constructor( itemsToDisplay.add(reward) itemsToDisplay.shuffle() + player.closeInventory() + for (item in itemsToDisplay) { val entity = world.dropItem(location, item.getDisplay(player, crate)) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollFlash.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollFlash.kt index 2b488ec..1aa83ff 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollFlash.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollFlash.kt @@ -19,6 +19,7 @@ class RollFlash private constructor( override val location: Location, override val isReroll: Boolean ) : Roll { + private val duration = plugin.configYml.getInt("rolls.flash.duration") private val wait = plugin.configYml.getInt("rolls.flash.wait") private val display = crate.getRandomRewards(player, 100, displayWeight = true) @@ -32,10 +33,12 @@ class RollFlash private constructor( item.setGravity(false) item.isCustomNameVisible = true + player.closeInventory() + player.addPotionEffect( PotionEffect( PotionEffectType.BLINDNESS, - wait * 2, + (wait + duration) * 2, 1, false, false, @@ -46,14 +49,20 @@ class RollFlash private constructor( override fun tick(tick: Int) { if (tick % 5 == 0) { - item.velocity = player.eyeLocation.toVector() - .add(player.eyeLocation.direction.normalize().multiply(1.5)) // Make it stop in front of the player - .subtract(item.location.toVector()) - .multiply(tick.toDouble() / wait) - .multiply(0.5) + if (tick < duration) { + item.velocity = player.eyeLocation.toVector() + .add(player.eyeLocation.direction.normalize().multiply(1.5)) // Make it stop in front of the player + .subtract(item.location.toVector()) + .multiply(tick.toDouble() / duration) + .multiply(0.5) - item.itemStack = display[tick.floorDiv(5)].getDisplay(player, crate) - item.customName = display[tick.floorDiv(5)].displayName + item.itemStack = display[tick.floorDiv(5)].getDisplay(player, crate) + item.customName = display[tick.floorDiv(5)].displayName + } else { + item.itemStack = reward.getDisplay(player, crate) + item.customName = reward.displayName + item.velocity = Vector(0, 0, 0) + } } if (tick % 4 == 0) { @@ -67,26 +76,12 @@ class RollFlash private constructor( } override fun shouldContinueTicking(tick: Int): Boolean { - return tick < wait + return tick < wait + duration } override fun onFinish() { player.removePotionEffect(PotionEffectType.BLINDNESS) - - player.playSound( - player.location, - Sound.ENTITY_FIREWORK_ROCKET_TWINKLE, - 1f, - 1f - ) - - item.itemStack = reward.getDisplay(player, crate) - item.customName = reward.displayName - item.velocity = Vector(0, 0, 0) - - plugin.scheduler.runLater(80) { - item.remove() - } + item.remove() } object Factory : RollFactory("flash") { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollQuick.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollQuick.kt new file mode 100644 index 0000000..6b0a812 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/RollQuick.kt @@ -0,0 +1,79 @@ +package com.willfp.ecocrates.crate.roll + +import com.willfp.eco.core.EcoPlugin +import com.willfp.ecocrates.crate.Crate +import com.willfp.ecocrates.reward.Reward +import org.bukkit.Location +import org.bukkit.entity.Item +import org.bukkit.entity.Player +import org.bukkit.util.Vector + +class RollQuick private constructor( + override val reward: Reward, + override val crate: Crate, + override val plugin: EcoPlugin, + override val player: Player, + override val location: Location, + override val isReroll: Boolean +) : Roll { + private val riseVelocity = plugin.configYml.getDouble("rolls.quick.rise-velocity") + private val height = plugin.configYml.getDouble("rolls.quick.height") + private val suspend = plugin.configYml.getInt("rolls.quick.suspend") + private lateinit var item: Item + private var done = false + private var suspendTicks = 0 + + private val end = location.toVector() + .add(Vector(0.0, height, 0.0)) + + override fun roll() { + val world = location.world!! + + item = world.dropItem(location, reward.getDisplay(player, crate)) + item.pickupDelay = Int.MAX_VALUE + item.setGravity(false) + item.isCustomNameVisible = true + item.customName = reward.displayName + + player.closeInventory() + } + + override fun tick(tick: Int) { + if (item.location.toVector().distance(end) < 0.1) { + item.teleport(end.toLocation(item.world)) + item.velocity = Vector(0, 0, 0) + suspendTicks++ + + if (suspendTicks >= suspend) { + done = true + } + } else { + val velocity = end.clone() + .subtract(item.location.toVector()) + .normalize() + .multiply(riseVelocity) + + item.velocity = velocity + } + } + + override fun shouldContinueTicking(tick: Int): Boolean { + return !done + } + + override fun onFinish() { + item.remove() + } + + object Factory : RollFactory("quick") { + override fun create(options: RollOptions): RollQuick = + RollQuick( + options.reward, + options.crate, + options.plugin, + options.player, + options.location, + options.isReroll + ) + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/Rolls.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/Rolls.kt index 042a467..975a28b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/Rolls.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecocrates/crate/roll/Rolls.kt @@ -10,6 +10,7 @@ object Rolls { val CSGO: RollFactory<*> = RollCSGO.Factory val FLASH: RollFactory<*> = RollFlash.Factory val ENCIRCLE: RollFactory<*> = RollEncircle.Factory + val QUICK: RollFactory<*> = RollQuick.Factory /** * Get roll factory matching id. diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 3a43888..505f0d2 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -73,7 +73,8 @@ rolls: scrolls: 35 max-delay: 25 flash: - wait: 80 + duration: 80 + wait: 20 encircle: spin-time: 100 reveal-time: 80 @@ -83,4 +84,8 @@ rolls: spins-per-second: 0.5 rise-velocity: 0.05 spin-velocity: 0.4 - reveal-velocity: 0.2 \ No newline at end of file + reveal-velocity: 0.2 + quick: + height: 1.5 + rise-velocity: 0.05 + suspend: 10 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/crates.yml b/eco-core/core-plugin/src/main/resources/crates.yml index bfafab9..6ad736b 100644 --- a/eco-core/core-plugin/src/main/resources/crates.yml +++ b/eco-core/core-plugin/src/main/resources/crates.yml @@ -39,7 +39,7 @@ crates: placed: random-reward: enabled: true - height: 2 + height: 1.5 delay: 30 name: "&fYou could win:" particles: