Added player placeholders to weights

This commit is contained in:
Auxilor
2022-03-17 10:57:43 +00:00
parent b530075284
commit 29b4c200f1
3 changed files with 11 additions and 11 deletions

View File

@@ -115,7 +115,7 @@ class Crate(
// Add three to the scroll times so that it lines up
for (i in 0..(35 + 3)) {
display.add(getRandomReward(displayWeight = true)) // Fill roll with display weight items
display.add(getRandomReward(player, displayWeight = true)) // Fill roll with display weight items
}
return rollFactory.create(
@@ -129,14 +129,14 @@ class Crate(
)
}
private fun getRandomReward(displayWeight: Boolean = false): Reward {
private fun getRandomReward(player: Player, displayWeight: Boolean = false): Reward {
var weight = 100.0
val selection = rewards.toList().shuffled()
lateinit var current: Reward
for (i in 0..Int.MAX_VALUE) {
current = selection[i % selection.size]
weight -= if (displayWeight) current.displayWeight else current.weight
weight -= if (displayWeight) current.getDisplayWeight(player) else current.getWeight(player)
if (weight <= 0) {
break
}
@@ -197,8 +197,8 @@ class Crate(
)
}
fun getRandomRewards(amount: Int, displayWeight: Boolean = false): List<Reward> {
return (0..amount).map { getRandomReward(displayWeight) }
fun getRandomRewards(player: Player, amount: Int, displayWeight: Boolean = false): List<Reward> {
return (0..amount).map { getRandomReward(player, displayWeight) }
}
fun openPhysical(player: Player, location: Location, physicalKey: Boolean) {
@@ -234,7 +234,7 @@ class Crate(
}
fun open(player: Player, location: Location? = null, physicalKey: Boolean = false) {
val event = CrateOpenEvent(player, this, physicalKey, getRandomReward())
val event = CrateOpenEvent(player, this, physicalKey, getRandomReward(player))
Bukkit.getPluginManager().callEvent(event)
val roll = makeRoll(player, location ?: player.location, event.reward)

View File

@@ -43,10 +43,10 @@ class RollCSGO private constructor(
.toList()
// Add three so it lines up
private val display = crate.getRandomRewards(scrollTimes + 3, displayWeight = true)
private val display = crate.getRandomRewards(player, scrollTimes + 3, displayWeight = true)
.toMutableList().apply {
add(reward)
addAll(crate.getRandomRewards(5, displayWeight = true))
addAll(crate.getRandomRewards(player, 5, displayWeight = true))
}
private var scroll = 0

View File

@@ -12,7 +12,7 @@ import org.bukkit.inventory.ItemStack
class Reward(
private val plugin: EcoPlugin,
config: Config
private val config: Config
) {
private val commands = config.getStrings("commands")
@@ -24,9 +24,9 @@ class Reward(
.addLoreLines(config.getStrings("display.lore"))
.build()
val weight = config.getDouble("weight.actual")
fun getWeight(player: Player) = config.getDoubleFromExpression("weight.actual", player)
val displayWeight = config.getDouble("weight.display")
fun getDisplayWeight(player: Player) = config.getDoubleFromExpression("weight.display", player)
val displayRow = config.getInt("display.row")