Added quick roll

This commit is contained in:
Auxilor
2022-03-18 13:38:55 +00:00
parent 197380dd84
commit e82d88467a
6 changed files with 109 additions and 27 deletions

View File

@@ -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))

View File

@@ -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<RollFlash>("flash") {

View File

@@ -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<RollQuick>("quick") {
override fun create(options: RollOptions): RollQuick =
RollQuick(
options.reward,
options.crate,
options.plugin,
options.player,
options.location,
options.isReroll
)
}
}

View File

@@ -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.

View File

@@ -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
reveal-velocity: 0.2
quick:
height: 1.5
rise-velocity: 0.05
suspend: 10

View File

@@ -39,7 +39,7 @@ crates:
placed:
random-reward:
enabled: true
height: 2
height: 1.5
delay: 30
name: "&fYou could win:"
particles: