Added %chance% and %actual_chance% placeholders to display
This commit is contained in:
@@ -115,8 +115,8 @@ class Crate(
|
||||
setSlot(
|
||||
reward.displayRow,
|
||||
reward.displayColumn,
|
||||
slot(reward.display) {
|
||||
|
||||
slot(reward.getDisplay()) {
|
||||
setUpdater { player, _, _ -> reward.getDisplay(player, this@Crate) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class PlacedCrate(
|
||||
if ((item == null || item?.isDead == true) && crate.isShowingRandomReward) {
|
||||
val entity = world.dropItem(
|
||||
location.clone().add(0.0, crate.randomRewardHeight, 0.0),
|
||||
crate.rewards.first().display
|
||||
crate.rewards.first().getDisplay()
|
||||
)
|
||||
entity.velocity = Vector(0.0, 0.0, 0.0)
|
||||
entity.pickupDelay = Int.MAX_VALUE
|
||||
@@ -75,7 +75,7 @@ class PlacedCrate(
|
||||
private fun tickRandomReward(tick: Int) {
|
||||
if (tick % crate.randomRewardDelay == 0) {
|
||||
spawnRandomReward()
|
||||
item?.itemStack = crate.rewards.random().display
|
||||
item?.itemStack = crate.rewards.random().getDisplay()
|
||||
item?.teleport(location.clone().add(0.0, crate.randomRewardHeight, 0.0))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class RollCSGO private constructor(
|
||||
ItemStack(Material.AIR)
|
||||
) {
|
||||
setUpdater { _, _, _ ->
|
||||
display[(9 - i) + scroll].display
|
||||
display[(9 - i) + scroll].getDisplay(player, crate)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -52,7 +52,7 @@ class RollEncircle private constructor(
|
||||
itemsToDisplay.shuffle()
|
||||
|
||||
for (item in itemsToDisplay) {
|
||||
val entity = world.dropItem(location, item.display)
|
||||
val entity = world.dropItem(location, item.getDisplay(player, crate))
|
||||
|
||||
entity.pickupDelay = Int.MAX_VALUE
|
||||
entity.setGravity(false)
|
||||
@@ -114,7 +114,7 @@ class RollEncircle private constructor(
|
||||
}
|
||||
EncircleState.REVEAL -> {
|
||||
for (item in display.toSet()) {
|
||||
if (item.itemStack != reward.display) {
|
||||
if (item.itemStack != reward.getDisplay(player, crate)) {
|
||||
item.remove()
|
||||
display.remove(item)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class RollFlash private constructor(
|
||||
override fun roll() {
|
||||
val world = location.world!!
|
||||
|
||||
item = world.dropItem(location, display[0].display)
|
||||
item = world.dropItem(location, display[0].getDisplay(player, crate))
|
||||
item.pickupDelay = Int.MAX_VALUE
|
||||
item.setGravity(false)
|
||||
item.isCustomNameVisible = true
|
||||
@@ -51,7 +51,7 @@ class RollFlash private constructor(
|
||||
.multiply(tick.toDouble() / wait)
|
||||
.multiply(0.5)
|
||||
|
||||
item.itemStack = display[tick.floorDiv(5)].display
|
||||
item.itemStack = display[tick.floorDiv(5)].getDisplay(player, crate)
|
||||
item.customName = display[tick.floorDiv(5)].displayName
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class RollFlash private constructor(
|
||||
1f
|
||||
)
|
||||
|
||||
item.itemStack = reward.display
|
||||
item.itemStack = reward.getDisplay(player, crate)
|
||||
item.customName = reward.displayName
|
||||
item.velocity = Vector(0, 0, 0)
|
||||
|
||||
|
||||
@@ -6,10 +6,14 @@ import com.willfp.eco.core.data.keys.PersistentDataKey
|
||||
import com.willfp.eco.core.data.keys.PersistentDataKeyType
|
||||
import com.willfp.eco.core.data.profile
|
||||
import com.willfp.eco.core.drops.DropQueue
|
||||
import com.willfp.eco.core.fast.FastItemStack
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.items.builder.ItemStackBuilder
|
||||
import com.willfp.eco.core.placeholder.PlayerPlaceholder
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
|
||||
import com.willfp.eco.util.formatEco
|
||||
import com.willfp.eco.util.toNiceString
|
||||
import com.willfp.ecocrates.crate.Crate
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.entity.Player
|
||||
@@ -39,11 +43,24 @@ class Reward(
|
||||
if (maxWins > 0) player()
|
||||
}
|
||||
|
||||
val display: ItemStack = ItemStackBuilder(Items.lookup(config.getString("display.item")))
|
||||
.addLoreLines(config.getStrings("display.lore"))
|
||||
private val baseDisplay = ItemStackBuilder(Items.lookup(config.getString("display.item")))
|
||||
.setDisplayName(config.getString("display.name"))
|
||||
.build()
|
||||
|
||||
fun getDisplay(player: Player, crate: Crate): ItemStack {
|
||||
val item = baseDisplay.clone()
|
||||
val fis = FastItemStack.wrap(item)
|
||||
fis.lore = config.getStrings("display.lore").map {
|
||||
it.replace("%chance%", getPercentageChance(player, crate.rewards, displayWeight = true).toNiceString().formatEco(player))
|
||||
.replace("%actual_chance%", getPercentageChance(player, crate.rewards, displayWeight = false).toNiceString()).formatEco(player)
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
fun getDisplay(): ItemStack {
|
||||
return baseDisplay.clone()
|
||||
}
|
||||
|
||||
fun getWeight(player: Player): Double {
|
||||
val weight = config.getDoubleFromExpression("weight.actual", player)
|
||||
if (maxWins > 0) {
|
||||
@@ -64,6 +81,20 @@ class Reward(
|
||||
return weight
|
||||
}
|
||||
|
||||
fun getPercentageChance(player: Player, among: Collection<Reward>, displayWeight: Boolean = false): Double {
|
||||
val others = among.toMutableList()
|
||||
others.remove(this)
|
||||
|
||||
val weight = if (displayWeight) this.getDisplayWeight(player) else this.getWeight(player)
|
||||
|
||||
var totalWeight = weight
|
||||
for (other in others) {
|
||||
totalWeight += if (displayWeight) other.getDisplayWeight(player) else other.getWeight(player)
|
||||
}
|
||||
|
||||
return (weight / totalWeight) * 100
|
||||
}
|
||||
|
||||
val displayRow = config.getInt("display.row")
|
||||
|
||||
val displayColumn = config.getInt("display.column")
|
||||
|
||||
Reference in New Issue
Block a user