Added level numerals and increasing prices

This commit is contained in:
Auxilor
2024-07-05 19:32:06 +01:00
parent 9749f0a4dc
commit 529795286b
4 changed files with 48 additions and 10 deletions

View File

@@ -17,6 +17,7 @@ import com.willfp.eco.core.gui.slot.MaskItems
import com.willfp.eco.core.gui.slot.Slot
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.builder.modify
import com.willfp.eco.core.recipe.parts.EmptyTestableItem
import com.willfp.eco.util.formatEco
import com.willfp.ecomponent.CaptiveItem
import com.willfp.ecomponent.addComponent
@@ -261,12 +262,12 @@ private abstract class MenuSlot(
}
private fun String.injectPlaceholders(player: Player, menu: Menu): String {
val price = menu.scroll[player]?.getOrNull()?.inscriptionPrice?.getDisplay(player)
val scroll = menu.scroll[player]?.getOrNull()?.name
val scroll = menu.scroll[player]?.getOrNull()
val price = scroll?.getInscriptionPriceDisplay(player, capturedItem[player])
return this
.replaceNullable("%price%", price)
.replaceNullable("%scroll%", scroll)
.replaceNullable("%scroll%", scroll?.name)
.formatEco(player = player, formatPlaceholders = true)
}

View File

@@ -13,7 +13,10 @@ import com.willfp.eco.core.placeholder.templates.DynamicInjectablePlaceholder
import com.willfp.eco.core.price.ConfiguredPrice
import com.willfp.eco.core.recipe.Recipes
import com.willfp.eco.core.registry.KRegistrable
import com.willfp.eco.util.evaluateExpression
import com.willfp.eco.util.evaluateExpressionOrNull
import com.willfp.eco.util.formatEco
import com.willfp.eco.util.toNumeral
import com.willfp.ecoscrolls.EcoScrollsPlugin
import com.willfp.ecoscrolls.plugin
import com.willfp.ecoscrolls.target.Targets
@@ -88,22 +91,24 @@ class Scroll(
)
}
val removeRequirements = config.getBool("remove-requirements")
private val removeRequirements = config.getBool("remove-requirements")
val inscriptionConditions = Conditions.compile(
private val inscriptionConditions = Conditions.compile(
config.getSubsections("inscription.conditions"),
context.with("inscription conditions")
)
val inscriptionEffects = Effects.compile(
private val inscriptionEffects = Effects.compile(
config.getSubsections("inscription.effects"),
context.with("inscription effects")
)
val inscriptionPrice = ConfiguredPrice.createOrFree(
private val inscriptionPrice = ConfiguredPrice.createOrFree(
config.getSubsection("inscription.price"),
)
private val priceLevelMultiplier = config.getStringOrNull("inscription.price-level-multiplier")
val isDragAndDropEnabled = config.getBool("inscription.drag-and-drop")
val isInscriptionTableEnabled = config.getBool("inscription.inscription-table")
@@ -117,6 +122,12 @@ class Scroll(
}
}
private val levelNumeralPlaceholder = object : DynamicInjectablePlaceholder(Pattern.compile("level_numeral")) {
override fun getValue(p0: String, p1: PlaceholderContext): String? {
return p1.itemStack?.getScrollLevel(this@Scroll)?.level?.toNumeral()
}
}
private val usesLeftPlaceholder = object : DynamicInjectablePlaceholder(Pattern.compile("uses_left")) {
override fun getValue(p0: String, p1: PlaceholderContext): String? {
val item = p1.itemStack ?: return null
@@ -143,6 +154,7 @@ class Scroll(
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
return listOf(
levelPlaceholder,
levelNumeralPlaceholder,
usesLeftPlaceholder,
usesPlaceholder,
maxUsesPlaceholder
@@ -211,11 +223,11 @@ class Scroll(
return false
}
if (!inscriptionPrice.canAfford(player)) {
if (!inscriptionPrice.canAfford(player, getPriceMultiplier(itemStack))) {
return false
}
inscriptionPrice.pay(player)
inscriptionPrice.pay(player, getPriceMultiplier(itemStack))
inscribe(itemStack)
@@ -280,6 +292,27 @@ class Scroll(
other.conflicts.contains(this.id)
}
fun getPriceMultiplier(itemStack: ItemStack?): Double {
if (itemStack == null || priceLevelMultiplier == null) {
return 1.0
}
val level = itemStack.getScrollLevel(this)?.level ?: 0
return evaluateExpressionOrNull(
// Less elegant than actually using placeholders, but it avoids a bunch
// of extra code.
priceLevelMultiplier.replace("%level%", level.toString()),
placeholderContext(
item = itemStack
)
) ?: 1.0
}
fun getInscriptionPriceDisplay(player: Player, itemStack: ItemStack?): String {
return inscriptionPrice.getDisplay(player, getPriceMultiplier(itemStack))
}
override fun equals(other: Any?): Boolean {
if (other !is Scroll) {
return false

View File

@@ -12,7 +12,7 @@ import org.bukkit.event.inventory.InventoryClickEvent
class DragAndDropListener(private val plugin: EcoScrollsPlugin) : Listener {
@EventHandler
fun onDrag(event: InventoryClickEvent) {
fun handle(event: InventoryClickEvent) {
val player = event.whoClicked as? Player ?: return
if (player.gameMode == GameMode.CREATIVE) {

View File

@@ -41,6 +41,10 @@ inscription:
type: coins
display: "&e%value% coins"
# The formula to multiply the price depending on the level.
# The %level% placeholder is the *current* level of the scroll
price-level-multiplier: "1 + %level% * 0.5"
# If the scroll can be applied to items via drag-and-drop
drag-and-drop: true