mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
This commit is contained in:
parent
d67d998dc1
commit
460114ac01
4 changed files with 35 additions and 22 deletions
|
|
@ -285,14 +285,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getConfiguredValue() {
|
public int getConfiguredValue() {
|
||||||
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false);
|
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The configured value for the enchant setting book value.
|
* @return The configured value for the enchant setting book value.
|
||||||
*/
|
*/
|
||||||
public int getConfiguredBookValue() {
|
public int getConfiguredBookValue() {
|
||||||
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, true);
|
return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ object ConfigOptions {
|
||||||
|
|
||||||
// Keys for specific enchantment values
|
// Keys for specific enchantment values
|
||||||
private const val KEY_BOOK = "book"
|
private const val KEY_BOOK = "book"
|
||||||
|
private const val KEY_BOOK_ON_BOOK = "book_on_book"
|
||||||
private const val KEY_ITEM = "item"
|
private const val KEY_ITEM = "item"
|
||||||
|
|
||||||
// Debug flag
|
// Debug flag
|
||||||
|
|
@ -578,14 +579,15 @@ object ConfigOptions {
|
||||||
*/
|
*/
|
||||||
fun enchantmentValue(
|
fun enchantmentValue(
|
||||||
enchantment: CAEnchantment,
|
enchantment: CAEnchantment,
|
||||||
isFromBook: Boolean
|
isToBook: Boolean,
|
||||||
|
isFromBook: Boolean,
|
||||||
): Int {
|
): Int {
|
||||||
// Test namespace
|
// Test namespace
|
||||||
var limit = enchantmentValue(enchantment.key.toString(), isFromBook)
|
var limit = enchantmentValue(enchantment.key.toString(), isToBook, isFromBook)
|
||||||
if (limit != null) return limit
|
if (limit != null) return limit
|
||||||
|
|
||||||
// Test legacy (name only)
|
// Test legacy (name only)
|
||||||
limit = enchantmentValue(enchantment.enchantmentName, isFromBook)
|
limit = enchantmentValue(enchantment.enchantmentName, isToBook, isFromBook)
|
||||||
if (limit != null) return limit
|
if (limit != null) return limit
|
||||||
|
|
||||||
// get default (and test old legacy if present)
|
// get default (and test old legacy if present)
|
||||||
|
|
@ -599,13 +601,22 @@ object ConfigOptions {
|
||||||
*/
|
*/
|
||||||
private fun enchantmentValue(
|
private fun enchantmentValue(
|
||||||
enchantmentName: String,
|
enchantmentName: String,
|
||||||
isFromBook: Boolean
|
isToBook: Boolean,
|
||||||
|
isFromBook: Boolean,
|
||||||
): Int? {
|
): Int? {
|
||||||
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
|
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
|
||||||
val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey"
|
val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey"
|
||||||
return CustomAnvil.instance
|
|
||||||
.config
|
val config = ConfigHolder.DEFAULT_CONFIG.config
|
||||||
.getInt(path, DEFAULT_ENCHANT_VALUE - 1)
|
if(isFromBook && isToBook) {
|
||||||
|
val specialPath = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$KEY_BOOK_ON_BOOK"
|
||||||
|
|
||||||
|
if(config.isInt(specialPath))
|
||||||
|
return config.getInt(specialPath)
|
||||||
|
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.getInt(path, DEFAULT_ENCHANT_VALUE - 1)
|
||||||
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager
|
||||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||||
import xyz.alexcrea.cuanvil.util.AnvilTitleUtil
|
import xyz.alexcrea.cuanvil.util.AnvilTitleUtil
|
||||||
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
|
import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil
|
||||||
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
object AnvilXpUtil {
|
object AnvilXpUtil {
|
||||||
|
|
||||||
|
|
@ -35,7 +36,8 @@ object AnvilXpUtil {
|
||||||
inventory: AnvilInventory,
|
inventory: AnvilInventory,
|
||||||
view: InventoryView,
|
view: InventoryView,
|
||||||
player: Player,
|
player: Player,
|
||||||
result: AnvilResult) {
|
result: AnvilResult
|
||||||
|
) {
|
||||||
if (result.item == null) {
|
if (result.item == null) {
|
||||||
onNoResult(player, view)
|
onNoResult(player, view)
|
||||||
return
|
return
|
||||||
|
|
@ -246,7 +248,8 @@ object AnvilXpUtil {
|
||||||
fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) {
|
fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) {
|
||||||
// Calculate right value and illegal enchant penalty
|
// Calculate right value and illegal enchant penalty
|
||||||
|
|
||||||
val rightIsFormBook = right.isEnchantedBook()
|
val isToBook = left.isEnchantedBook()
|
||||||
|
val isFromBook = right.isEnchantedBook()
|
||||||
val rightEnchs = EnchantmentApi.getEnchantments(right)
|
val rightEnchs = EnchantmentApi.getEnchantments(right)
|
||||||
val resultEnchs = EnchantmentApi.getEnchantments(result)
|
val resultEnchs = EnchantmentApi.getEnchantments(result)
|
||||||
val resultEnchsKeys = HashMap(resultEnchs)
|
val resultEnchsKeys = HashMap(resultEnchs)
|
||||||
|
|
@ -274,14 +277,13 @@ object AnvilXpUtil {
|
||||||
// We know "enchantment.key in resultEnchs" true
|
// We know "enchantment.key in resultEnchs" true
|
||||||
val resultLevel = resultEnchs[enchantment.key]!!
|
val resultLevel = resultEnchs[enchantment.key]!!
|
||||||
|
|
||||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook)
|
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook)
|
||||||
val value = resultLevel * enchantmentMultiplier
|
val value = resultLevel * enchantmentMultiplier
|
||||||
CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||||
rightValue += value
|
rightValue += value
|
||||||
|
|
||||||
}
|
}
|
||||||
if (ConfigOptions.includeLeftEnchantmentForCost) {
|
if (ConfigOptions.includeLeftEnchantmentForCost) {
|
||||||
val leftIsFormBook = left.isEnchantedBook()
|
|
||||||
val leftEnchs = EnchantmentApi.getEnchantments(left)
|
val leftEnchs = EnchantmentApi.getEnchantments(left)
|
||||||
for (enchantment in leftEnchs) {
|
for (enchantment in leftEnchs) {
|
||||||
// Do not process enchantment that are present on the sacrifice
|
// Do not process enchantment that are present on the sacrifice
|
||||||
|
|
@ -289,7 +291,7 @@ object AnvilXpUtil {
|
||||||
|
|
||||||
val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0)
|
val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0)
|
||||||
|
|
||||||
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, leftIsFormBook)
|
val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook)
|
||||||
val value = resultLevel * enchantmentMultiplier
|
val value = resultLevel * enchantmentMultiplier
|
||||||
CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)")
|
||||||
leftValue += value
|
leftValue += value
|
||||||
|
|
@ -312,15 +314,15 @@ object AnvilXpUtil {
|
||||||
*/
|
*/
|
||||||
fun calculateLevelForXp(xp: Int): Int {
|
fun calculateLevelForXp(xp: Int): Int {
|
||||||
return when {
|
return when {
|
||||||
xp <= 352 -> (Math.sqrt((xp + 9).toDouble()) - 3).toInt()
|
xp <= 352 -> (sqrt((xp + 9).toDouble()) - 3).toInt()
|
||||||
xp <= 1507 -> {
|
xp <= 1507 -> {
|
||||||
val inner = (2.0 / 5.0) * (xp - 7839.0 / 40.0)
|
val inner = (2.0 / 5.0) * (xp - 7839.0 / 40.0)
|
||||||
(81.0 / 10.0 + Math.sqrt(inner)).toInt()
|
(81.0 / 10.0 + sqrt(inner)).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val inner = (2.0 / 9.0) * (xp - 54215.0 / 72.0)
|
val inner = (2.0 / 9.0) * (xp - 54215.0 / 72.0)
|
||||||
(325.0 / 18.0 + Math.sqrt(inner)).toInt()
|
(325.0 / 18.0 + sqrt(inner)).toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ public class DefaultConfigTests extends SharedCustomAnvilTest {
|
||||||
CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key);
|
CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key);
|
||||||
Assertions.assertNotNull(enchantment, "Enchantment was somehow not found");
|
Assertions.assertNotNull(enchantment, "Enchantment was somehow not found");
|
||||||
|
|
||||||
int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false);
|
int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false);
|
||||||
int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, true);
|
int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true);
|
||||||
|
|
||||||
EnchantmentRarity rarity = enchantment.defaultRarity();
|
EnchantmentRarity rarity = enchantment.defaultRarity();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue