Added rerolls
This commit is contained in:
@@ -21,6 +21,7 @@ import com.willfp.eco.util.savedDisplayName
|
||||
import com.willfp.ecocrates.crate.placed.HologramFrame
|
||||
import com.willfp.ecocrates.crate.placed.particle.ParticleAnimations
|
||||
import com.willfp.ecocrates.crate.placed.particle.ParticleData
|
||||
import com.willfp.ecocrates.crate.reroll.ReRollGUI
|
||||
import com.willfp.ecocrates.crate.roll.Roll
|
||||
import com.willfp.ecocrates.crate.roll.RollOptions
|
||||
import com.willfp.ecocrates.crate.roll.Rolls
|
||||
@@ -88,6 +89,8 @@ class Crate(
|
||||
Bukkit.getPluginManager().addPermission(this)
|
||||
}
|
||||
|
||||
val canReroll = config.getBool("can-reroll")
|
||||
|
||||
private val keysKey: PersistentDataKey<Int> = PersistentDataKey(
|
||||
plugin.namespacedKeyFactory.create("${id}_keys"),
|
||||
PersistentDataKeyType.INT,
|
||||
@@ -160,7 +163,7 @@ class Crate(
|
||||
) { getOpens(it).toString() }.register()
|
||||
}
|
||||
|
||||
private fun makeRoll(player: Player, location: Location, reward: Reward): Roll {
|
||||
private fun makeRoll(player: Player, location: Location, reward: Reward, isReroll: Boolean = false): Roll {
|
||||
val display = mutableListOf<Reward>()
|
||||
|
||||
// Add three to the scroll times so that it lines up
|
||||
@@ -174,7 +177,8 @@ class Crate(
|
||||
this,
|
||||
this.plugin,
|
||||
player,
|
||||
location
|
||||
location,
|
||||
isReroll
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -317,7 +321,7 @@ class Crate(
|
||||
}
|
||||
}
|
||||
|
||||
fun open(player: Player, location: Location? = null, physicalKey: Boolean = false): Boolean {
|
||||
fun open(player: Player, location: Location? = null, physicalKey: Boolean = false, isReroll: Boolean = false): Boolean {
|
||||
/* Prevent server crashes */
|
||||
if (hasRanOutOfRewardsAndNotify(player)) {
|
||||
return false
|
||||
@@ -346,7 +350,7 @@ class Crate(
|
||||
.map { plugin.langYml.prefix + StringUtils.format(it, player) }
|
||||
.forEach { Bukkit.broadcastMessage(it) }
|
||||
|
||||
val roll = makeRoll(player, loc, event.reward)
|
||||
val roll = makeRoll(player, loc, event.reward, isReroll = isReroll)
|
||||
var tick = 0
|
||||
|
||||
plugin.runnableFactory.create {
|
||||
@@ -357,7 +361,7 @@ class Crate(
|
||||
it.cancel()
|
||||
roll.onFinish()
|
||||
player.isOpeningCrate = false
|
||||
this.handleFinish(player, roll, loc)
|
||||
if (!canReroll || roll.isReroll) handleFinish(roll) else ReRollGUI.open(roll)
|
||||
}
|
||||
}.runTaskTimer(1, 1)
|
||||
|
||||
@@ -372,7 +376,10 @@ class Crate(
|
||||
previewGUI.open(player)
|
||||
}
|
||||
|
||||
fun handleFinish(player: Player, roll: Roll, location: Location) {
|
||||
fun handleFinish(roll: Roll) {
|
||||
val player = roll.player
|
||||
val location = roll.location
|
||||
|
||||
val event = CrateRewardEvent(player, this, roll.reward)
|
||||
Bukkit.getPluginManager().callEvent(event)
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.willfp.ecocrates.crate.reroll
|
||||
|
||||
import com.willfp.eco.core.gui.menu
|
||||
import com.willfp.eco.core.gui.slot
|
||||
import com.willfp.eco.core.gui.slot.FillerMask
|
||||
import com.willfp.eco.core.gui.slot.MaskItems
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||
import com.willfp.ecocrates.crate.Crates
|
||||
import com.willfp.ecocrates.crate.roll.Roll
|
||||
|
||||
object ReRollGUI {
|
||||
fun open(roll: Roll) {
|
||||
val plugin = roll.plugin
|
||||
|
||||
val menu = menu(plugin.configYml.getInt("reroll.rows")) {
|
||||
setMask(
|
||||
FillerMask(
|
||||
MaskItems.fromItemNames(plugin.configYml.getStrings("reroll.mask.items")),
|
||||
*plugin.configYml.getStrings("reroll.mask.pattern").toTypedArray()
|
||||
)
|
||||
)
|
||||
|
||||
setTitle(plugin.configYml.getFormattedString("reroll.title"))
|
||||
|
||||
for (crate in Crates.values()) {
|
||||
crate.addToKeyGUI(this)
|
||||
}
|
||||
|
||||
setSlot(
|
||||
plugin.configYml.getInt("reroll.accept.row"),
|
||||
plugin.configYml.getInt("reroll.accept.column"),
|
||||
slot(roll.reward.getDisplay(roll.player, roll.crate)) {
|
||||
onLeftClick { _, _, _ ->
|
||||
roll.player.closeInventory() // Will automatically call finish
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
setSlot(
|
||||
plugin.configYml.getInt("reroll.reroll.row"),
|
||||
plugin.configYml.getInt("reroll.reroll.column"),
|
||||
slot(
|
||||
ItemStackBuilder(Items.lookup(plugin.configYml.getString("reroll.reroll.item")))
|
||||
.addLoreLines(plugin.configYml.getStrings("reroll.reroll.lore"))
|
||||
.setDisplayName(plugin.configYml.getString("reroll.reroll.name"))
|
||||
.build()
|
||||
) {
|
||||
onLeftClick { _, _, _ ->
|
||||
roll.crate.open(roll.player, roll.location, isReroll = true)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
onClose { _, _ -> roll.crate.handleFinish(roll) }
|
||||
}
|
||||
|
||||
menu.open(roll.player)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
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.Player
|
||||
|
||||
interface Roll {
|
||||
/**
|
||||
@@ -8,6 +12,31 @@ interface Roll {
|
||||
*/
|
||||
val reward: Reward
|
||||
|
||||
/**
|
||||
* The player.
|
||||
*/
|
||||
val player: Player
|
||||
|
||||
/**
|
||||
* The crate.
|
||||
*/
|
||||
val crate: Crate
|
||||
|
||||
/**
|
||||
* The plugin.
|
||||
*/
|
||||
val plugin: EcoPlugin
|
||||
|
||||
/**
|
||||
* The location.
|
||||
*/
|
||||
val location: Location
|
||||
|
||||
/**
|
||||
* If the roll is a reroll.
|
||||
*/
|
||||
val isReroll: Boolean
|
||||
|
||||
/**
|
||||
* Called on start - once the player begins opening the crate.
|
||||
*/
|
||||
|
||||
@@ -18,10 +18,11 @@ import org.bukkit.inventory.ItemStack
|
||||
|
||||
class RollCSGO private constructor(
|
||||
override val reward: Reward,
|
||||
private val crate: Crate,
|
||||
private val plugin: EcoPlugin,
|
||||
private val player: Player,
|
||||
private val location: Location
|
||||
override val crate: Crate,
|
||||
override val plugin: EcoPlugin,
|
||||
override val player: Player,
|
||||
override val location: Location,
|
||||
override val isReroll: Boolean
|
||||
) : Roll {
|
||||
private val scrollTimes = plugin.configYml.getInt("rolls.csgo.scrolls")
|
||||
private val bias = plugin.configYml.getDouble("rolls.csgo.bias")
|
||||
@@ -126,7 +127,8 @@ class RollCSGO private constructor(
|
||||
options.crate,
|
||||
options.plugin,
|
||||
options.player,
|
||||
options.location
|
||||
options.location,
|
||||
options.isReroll
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,11 @@ import kotlin.math.PI
|
||||
|
||||
class RollEncircle private constructor(
|
||||
override val reward: Reward,
|
||||
private val crate: Crate,
|
||||
private val plugin: EcoPlugin,
|
||||
private val player: Player,
|
||||
private val location: Location
|
||||
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.encircle.rise-velocity")
|
||||
private val spinVelocity = plugin.configYml.getDouble("rolls.encircle.spin-velocity")
|
||||
@@ -172,7 +173,8 @@ class RollEncircle private constructor(
|
||||
options.crate,
|
||||
options.plugin,
|
||||
options.player,
|
||||
options.location
|
||||
options.location,
|
||||
options.isReroll
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,11 @@ import org.bukkit.util.Vector
|
||||
|
||||
class RollFlash private constructor(
|
||||
override val reward: Reward,
|
||||
private val crate: Crate,
|
||||
private val plugin: EcoPlugin,
|
||||
private val player: Player,
|
||||
private val location: Location
|
||||
override val crate: Crate,
|
||||
override val plugin: EcoPlugin,
|
||||
override val player: Player,
|
||||
override val location: Location,
|
||||
override val isReroll: Boolean
|
||||
) : Roll {
|
||||
private val wait = plugin.configYml.getInt("rolls.flash.wait")
|
||||
private val display = crate.getRandomRewards(player, 100, displayWeight = true)
|
||||
@@ -95,7 +96,8 @@ class RollFlash private constructor(
|
||||
options.crate,
|
||||
options.plugin,
|
||||
options.player,
|
||||
options.location
|
||||
options.location,
|
||||
options.isReroll
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ data class RollOptions(
|
||||
val crate: Crate,
|
||||
val plugin: EcoPlugin,
|
||||
val player: Player,
|
||||
val location: Location
|
||||
val location: Location,
|
||||
val isReroll: Boolean
|
||||
)
|
||||
@@ -5,6 +5,32 @@
|
||||
|
||||
no-key-velocity: 1.5 # The speed at which a player should be launched away from a crate if they try to open it without a key. Set to 0 to disable.
|
||||
|
||||
reroll:
|
||||
rows: 3
|
||||
mask:
|
||||
items:
|
||||
- black_stained_glass_pane
|
||||
- green_stained_glass_pane
|
||||
pattern:
|
||||
- "122211111"
|
||||
- "120211011"
|
||||
- "122211111"
|
||||
title: "Accept your reward?"
|
||||
accept:
|
||||
row: 2
|
||||
column: 3
|
||||
reroll:
|
||||
row: 2
|
||||
column: 7
|
||||
item: orange_stained_glass_pane
|
||||
name: "&6Reroll"
|
||||
lore:
|
||||
- "&fNot happy with your item?"
|
||||
- "&fClick to try again for"
|
||||
- "&fa chance at something else!"
|
||||
- ""
|
||||
- "&cYou can only reroll once!"
|
||||
|
||||
keygui:
|
||||
rows: 3
|
||||
mask:
|
||||
|
||||
@@ -2,6 +2,7 @@ crates:
|
||||
- id: demo
|
||||
name: "Demo Crate"
|
||||
roll: csgo
|
||||
can-reroll: true
|
||||
|
||||
preview:
|
||||
title: Demo Crate
|
||||
|
||||
Reference in New Issue
Block a user