Description / balance improvements

This commit is contained in:
Auxilor
2022-09-05 16:37:20 +01:00
parent 54b5f9b6af
commit 2b75fab8a4
8 changed files with 129 additions and 88 deletions

View File

@@ -44,7 +44,7 @@ abstract class EcoEnchant(
configProvider: (EcoEnchant) -> Config,
protected val plugin: EcoEnchantsPlugin
) : Enchantment(NamespacedKey.minecraft(id)), EcoEnchantLike {
internal val config by lazy { configProvider(this) }
override val config by lazy { configProvider(this) }
override val enchant by lazy { this }
private val levels = Caffeine.newBuilder()
@@ -179,49 +179,6 @@ abstract class EcoEnchant(
this.plugin.eventManager.registerListener(listener)
}
override fun getUnformattedDescription(level: Int): String {
// Fetch custom placeholders other than %placeholder%
val uncompiledPlaceholders = config.getSubsection("placeholders").getKeys(false).associateWith {
config.getString("placeholders.$it")
}.toMutableMap()
// Add %placeholder% placeholder in
uncompiledPlaceholders["placeholder"] = config.getString("placeholder")
// Evaluate each placeholder
val placeholders = uncompiledPlaceholders.map { (id, expr) ->
DescriptionPlaceholder(
id,
NumberUtils.evaluateExpression(
expr,
null,
object : PlaceholderInjectable {
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
return listOf(
StaticPlaceholder(
"level",
) { level.toString() }
)
}
override fun clearInjectedPlaceholders() {
// Do nothing
}
}
)
)
}
// Apply placeholders to description
val rawDescription = config.getString("description")
var description = rawDescription
for (placeholder in placeholders) {
description = description.replace("%${placeholder.id}%", NumberUtils.format(placeholder.value))
}
return description
}
@Deprecated(
message = "getName is a legacy Spigot API",
replaceWith = ReplaceWith("this.displayName(level)")

View File

@@ -1,7 +1,12 @@
package com.willfp.ecoenchants.enchants
import com.github.benmanes.caffeine.cache.Caffeine
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.fast.fast
import com.willfp.eco.core.placeholder.InjectablePlaceholder
import com.willfp.eco.core.placeholder.PlaceholderInjectable
import com.willfp.eco.core.placeholder.StaticPlaceholder
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy
import com.willfp.ecoenchants.rarity.EnchantmentRarities
@@ -15,16 +20,59 @@ import org.bukkit.inventory.ItemStack
import java.util.*
interface EcoEnchantLike {
val config: Config
val type: EnchantmentType
val displayName: String
val unformattedDisplayName: String
val enchant: Enchantment
val rarity: EnchantmentRarity
fun getUnformattedDescription(level: Int): String
// Includes all extra logic not found in vanilla canEnchantItem
fun canEnchantItem(item: ItemStack): Boolean
// Method body goes here
fun getUnformattedDescription(level: Int): String {
// Fetch custom placeholders other than %placeholder%
val uncompiledPlaceholders = config.getSubsection("placeholders").getKeys(false).associateWith {
config.getString("placeholders.$it")
}.toMutableMap()
// Add %placeholder% placeholder in
uncompiledPlaceholders["placeholder"] = config.getString("placeholder")
// Evaluate each placeholder
val placeholders = uncompiledPlaceholders.map { (id, expr) ->
DescriptionPlaceholder(
id,
NumberUtils.evaluateExpression(
expr,
null,
object : PlaceholderInjectable {
override fun getPlaceholderInjections(): List<InjectablePlaceholder> {
return listOf(
StaticPlaceholder(
"level",
) { level.toString() }
)
}
override fun clearInjectedPlaceholders() {
// Do nothing
}
}
)
)
}
// Apply placeholders to description
val rawDescription = config.getString("description")
var description = rawDescription
for (placeholder in placeholders) {
description = description.replace("%${placeholder.id}%", NumberUtils.format(placeholder.value))
}
return description
}
}
private val ecoEnchantLikes = Caffeine.newBuilder()
@@ -47,6 +95,8 @@ class VanillaEcoEnchantLike(
override val enchant: Enchantment,
private val plugin: EcoEnchantsPlugin
) : EcoEnchantLike {
override val config = plugin.vanillaEnchantsYml.getSubsection(enchant.key.key)
override val type: EnchantmentType =
EnchantmentTypes.getByID(plugin.vanillaEnchantsYml.getString("${enchant.key.key}.type"))
?: EnchantmentTypes.values().first()
@@ -58,10 +108,6 @@ class VanillaEcoEnchantLike(
override val displayName = plugin.vanillaEnchantsYml.getFormattedString("${enchant.key.key}.name")
override val unformattedDisplayName = plugin.vanillaEnchantsYml.getString("${enchant.key.key}.name")
override fun getUnformattedDescription(level: Int): String {
return plugin.vanillaEnchantsYml.getString("${enchant.key.key}.description")
}
override fun canEnchantItem(item: ItemStack): Boolean {
// Yes this code is copied from EcoEnchant, but I can't be bothered to abstract it properly
if (

View File

@@ -68,7 +68,7 @@ display:
descriptions:
enabled: true # If enchantment descriptions should be shown in lore
threshold: 5 # Above this amount, enchantment descriptions will not be shown
word-wrap: 30 # Number of characters to have on each line
word-wrap: 40 # Number of characters to have on each line
format: "&8"
# Options for the /enchantinfo GUI

View File

@@ -1,5 +1,5 @@
display-name: "Bleed"
description: "&a%placeholder%% &rchance to cause your opponent to bleed, damaging them repeatedly"
description: "Gives a &a%placeholder%%&r chance to cause your opponent to bleed, damaging them repeatedly"
placeholder: "1.5 * %level%"
type: normal

View File

@@ -1,5 +1,5 @@
display-name: "Blind"
description: "&a%placeholder%% &rchance of blinding your opponent"
description: "Gives a &a%placeholder%%&r chance of blinding your opponent"
placeholder: "%level%"
type: normal

View File

@@ -1,6 +1,6 @@
display-name: "Lifesteal"
description: "Heals &a%placeholder%%&r of damage dealt"
placeholder: "%placeholder% * 10"
placeholder: "%level% * 10"
type: normal
targets:

View File

@@ -1,5 +1,5 @@
display-name: "Quake"
description: "Gives &a%damage%&r damage to all entities in a radius of &a%radius%&r blocks"
description: "Gives &a%damage%&r damage to all entities in a &a%radius%&r block radius"
placeholders:
radius: "2 + %level%"
damage: "3 * %level%"

View File

@@ -7,7 +7,8 @@
protection:
name: "Protection"
description: Reduces most types of damage
description: "Reduces incoming damage by &a%placeholder%%"
placeholder: "%level% * 4"
type: normal
rarity: common
#max-level: 6 # Custom max level to override for the enchantment. Raise it, but lowering it may cause bugs.
@@ -15,55 +16,69 @@ protection:
fire_protection:
name: "Fire Protection"
description: Reduces fire damage and burn time
description: "Reduces incoming fire damage by &a%damage%%&r and burn time by &a%time%%"
placeholders:
damage: "%level% * 8"
time: "%level% * 15"
type: normal
rarity: common
feather_falling:
name: "Feather Falling"
description: Reduces fall damage
description: "Reduces fall damage by &a%placeholder%%"
placeholder: "%level% * 12"
type: normal
rarity: common
blast_protection:
name: "Blast Protection"
description: "Reduces incoming explosion damage by &a%damage%%&r and incoming blast knockback by &a%knockback%%"
placeholders:
damage: "%level% * 8"
knockback: "%level% * 15"
type: normal
description: Reduces explosion damage and knockback
rarity: common
projectile_protection:
name: "Projectile Protection"
description: Reduces projectile damage
description: "Reduces incoming projectile damage by &a%placeholder%%"
placeholder: "%level% * 8"
type: normal
rarity: common
respiration:
name: "Respiration"
description: Extends underwater breathing time
description: "Extends underwater breathing time by &a%seconds%&r seconds and gives a &a%chance%%&r chance to ignore drowning damage"
placeholders:
seconds: "15 * %level%"
chance: "%level% / (%level% + 1)"
type: normal
rarity: common
aqua_affinity:
name: "Aqua Affinity"
description: Increases underwater mining speed
description: "Removes underwater mining speed penalty"
type: normal
rarity: common
thorns:
name: "Thorns"
description: Reflects some of the damage taken when hit
description: "Gives a &a%placeholder%%&r chance to reflect some incoming damage to the attacker"
placeholder: "%level% * 15"
type: normal
rarity: common
depth_strider:
name: "Depth Strider"
description: Increases underwater movement speed
description: "Reduces underwater movement slowdown by &a%placeholder%%"
placeholder: "%level% * 33.333333"
type: normal
rarity: common
frost_walker:
name: "Frost Walker"
description: Turns water beneath the player into ice
description: "Turns water within a &a%placeholder%&r block radius of the player into ice"
placeholder: "%level% + 2"
type: normal
rarity: common
@@ -75,103 +90,121 @@ binding_curse:
sharpness:
name: "Sharpness"
description: Increases damage
description: "Gives a &a%placeholder%&r bonus to melee damage"
placeholder: "0.5 * %level% + 1"
type: normal
rarity: common
smite:
name: "Smite"
description: Increases damage against undead mobs
description: "Gives a &a%placeholder%&r bonus to melee damage against undead mobs"
placeholder: "2.5 * %level%"
type: normal
rarity: common
bane_of_arthropods:
name: "Bane of Arthropods"
description: Increases damage and slows arthropod mobs
description: "Gives a &a%damage%&r bonus to melee damage against arthropods and gives up to &a%seconds%&r seconds of Slowness IV"
placeholders:
damage: "2.5 * %level%"
seconds: "0.5 * %level%"
type: normal
rarity: common
knockback:
name: "Knockback"
description: Increases knockback
description: "Gives a &a%placeholder%%&r bonus to attack knockback"
placeholder: "%level% * 85 + 20"
type: normal
rarity: common
fire_aspect:
name: "Fire Aspect"
description: Sets target on fire
description: "Sets opponents on fire for &a4&r seconds, dealing &a%placeholder%&r damage each fire tick"
placeholder: "(%level% * 4) - 1"
type: normal
rarity: common
looting:
name: "Looting"
description: Increases mob loot
description: "Increases maximum common drops by &a%common%&r, and the chance to get rare drops by &a%rare%%"
placeholders:
common: "%level%"
rare: "%level%"
type: normal
rarity: common
sweeping:
name: "Sweeping Edge"
description: Increases sweeping attack damage
description: "Increases sweeping attack damage by &a%placeholder%%"
placeholder: "%level% / (%level% + 1)"
type: normal
rarity: common
efficiency:
name: "Efficiency"
description: Increases mining speed
description: "Increases mining speed by &a%placeholder%%"
placeholder: "20 + 5 * %level%"
type: normal
rarity: common
silk_touch:
name: "Silk Touch"
description: Mined blocks drop themselves exactly
description: "Mined blocks drop themselves exactly"
type: normal
rarity: common
unbreaking:
name: "Unbreaking"
description: Increases item durability
description: "Increases item durability &a%placeholder%x"
placeholder: "%level% + 1"
type: normal
rarity: common
fortune:
name: "Fortune"
description: Increases certain block drops
description: "Gives a &a%placeholder%%&r boost to certain block drops"
placeholder: "(1 / (%level% + 2)) + ((%level% + 1) / 2)"
type: normal
rarity: common
power:
name: "Power"
description: Increases arrow damage
description: "Gives a &a%placeholder%%&r bonus to arrow damage"
placeholder: "0.25 * (%level% + 1)"
type: normal
rarity: common
punch:
name: "Punch"
description: Increases arrow knockback
description: "Increases arrow knockback by &a%placeholder%&r blocks"
placeholder: "3 * %level%"
type: normal
rarity: common
flame:
name: "Flame"
description: Arrows set target on fire
description: "Arrows set target on fire, dealing &a5&r fire damage"
type: normal
rarity: common
infinity:
name: "Infinity"
description: Shooting consumes no regular arrows
description: Stops regular arrows from being consumed when shot
type: normal
rarity: common
luck_of_the_sea:
name: "Luck of the Sea"
description: Increases rate of good loot
description: "Increases chance of getting treasure loot by &a%placeholder%%"
placeholder: "2 * %level%"
type: normal
rarity: common
lure:
name: "Lure"
description: Decreases fishing wait time
description: "Decreases fishing wait time by &a%placeholder%&r seconds"
placeholder: "%level% * 5"
type: normal
rarity: common
@@ -183,7 +216,8 @@ loyalty:
impaling:
name: "Impaling"
description: Trident deals additional damage to ocean mobs
description: "Deals &a%placeholder%&r additional damage to ocean mobs"
placeholder: "%level% * 2.5"
type: normal
rarity: common
@@ -201,19 +235,21 @@ channeling:
multishot:
name: "Multishot"
description: Shoots 3 arrows
description: Shoots 3 arrows instead of 1
type: normal
rarity: common
quick_charge:
name: "Quick Charge"
description: Decreases crossbow charging time
description: "Decreases crossbow charging time by &a%placeholder%&r seconds"
placeholder: "%level% * 0.25"
type: normal
rarity: common
piercing:
name: "Piercing"
description: Arrows pass through multiple entities
description: "Arrows pass through &a%placeholder%&r entities"
placeholder: "%level% + 1"
type: normal
rarity: common
@@ -231,12 +267,14 @@ vanishing_curse:
soul_speed:
name: "Soul Speed"
description: Increases walking speed on soul sand and soul soil
description: "Increases walking speed on soul sand and soul soil by &a%placeholder%%"
placeholder: "(%level% * 0.105) + 1.3"
type: normal
rarity: common
swift_sneak:
name: "Swift Sneak"
description: Increases speed while sneaking
description: "Reduces sneaking movement slowdown by &a%placeholder%%"
placeholder: "min(%level% * 15, 100)"
type: normal
rarity: common