mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
linear cost logic
This commit is contained in:
parent
ec4351e70d
commit
8f3c721820
3 changed files with 37 additions and 10 deletions
|
|
@ -130,10 +130,17 @@ class AnvilResultListener : Listener {
|
||||||
if (recipe.leftItem == null) return // in case it changed
|
if (recipe.leftItem == null) return // in case it changed
|
||||||
|
|
||||||
val amount = CustomRecipeUtil.getCustomRecipeAmount(recipe, leftItem, rightItem)
|
val amount = CustomRecipeUtil.getCustomRecipeAmount(recipe, leftItem, rightItem)
|
||||||
val xpCost = amount * recipe.levelCostPerCraft
|
val xpCost = recipe.determineCost(amount, leftItem, output)
|
||||||
|
val finalCost =
|
||||||
|
if (recipe.removeExactXp) xpCost
|
||||||
|
else AnvilXpUtil.calculateLevelForXp(xpCost)
|
||||||
|
|
||||||
CustomAnvil.log("gamemode: ${player.gameMode != GameMode.CREATIVE}, cost: $xpCost, level: ${player.level}, result: ${player.level < xpCost}")
|
CustomAnvil.log("gamemode: ${player.gameMode != GameMode.CREATIVE}, cost: $finalCost, level: ${player.level}, result: ${player.totalExperience < finalCost} ${player.level < finalCost}")
|
||||||
if ((player.gameMode != GameMode.CREATIVE) && (player.level < xpCost)) return
|
if (player.gameMode != GameMode.CREATIVE){
|
||||||
|
if(recipe.removeExactXp){
|
||||||
|
if(player.totalExperience < finalCost) return
|
||||||
|
}else if(player.level < finalCost) return
|
||||||
|
}
|
||||||
|
|
||||||
// We give the item manually
|
// We give the item manually
|
||||||
// But first we check if we should give the item
|
// But first we check if we should give the item
|
||||||
|
|
@ -142,7 +149,7 @@ class AnvilResultListener : Listener {
|
||||||
|
|
||||||
// Handle not creative middle click...
|
// Handle not creative middle click...
|
||||||
if (event.click != ClickType.MIDDLE &&
|
if (event.click != ClickType.MIDDLE &&
|
||||||
!handleCustomCraftClick(event, recipe, inventory, player, leftItem, rightItem, amount, xpCost)
|
!handleCustomCraftClick(event, recipe, inventory, player, leftItem, rightItem, amount, finalCost, recipe.removeExactXp)
|
||||||
) return
|
) return
|
||||||
|
|
||||||
// Finally, we add the item to the player
|
// Finally, we add the item to the player
|
||||||
|
|
@ -157,7 +164,7 @@ class AnvilResultListener : Listener {
|
||||||
event: InventoryClickEvent, recipe: AnvilCustomRecipe,
|
event: InventoryClickEvent, recipe: AnvilCustomRecipe,
|
||||||
inventory: AnvilInventory, player: Player,
|
inventory: AnvilInventory, player: Player,
|
||||||
leftItem: ItemStack, rightItem: ItemStack?,
|
leftItem: ItemStack, rightItem: ItemStack?,
|
||||||
amount: Int, xpCost: Int
|
amount: Int, xpCost: Int, linearCost: Boolean = false
|
||||||
): Boolean {
|
): Boolean {
|
||||||
// We remove what should be removed
|
// We remove what should be removed
|
||||||
if (rightItem != null) {
|
if (rightItem != null) {
|
||||||
|
|
@ -171,8 +178,12 @@ class AnvilResultListener : Listener {
|
||||||
inventory.setItem(ANVIL_INPUT_LEFT, leftItem)
|
inventory.setItem(ANVIL_INPUT_LEFT, leftItem)
|
||||||
|
|
||||||
if (player.gameMode != GameMode.CREATIVE) {
|
if (player.gameMode != GameMode.CREATIVE) {
|
||||||
|
if(linearCost){
|
||||||
|
player.totalExperience -= xpCost
|
||||||
|
} else{
|
||||||
player.level -= xpCost
|
player.level -= xpCost
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Then we try to find the new values for the anvil
|
// Then we try to find the new values for the anvil
|
||||||
val newAmount = CustomRecipeUtil.getCustomRecipeAmount(recipe, leftItem, rightItem)
|
val newAmount = CustomRecipeUtil.getCustomRecipeAmount(recipe, leftItem, rightItem)
|
||||||
|
|
|
||||||
|
|
@ -136,12 +136,13 @@ class PrepareAnvilListener : Listener {
|
||||||
event.result = resultItem
|
event.result = resultItem
|
||||||
if (DependencyManager.tryTreatAnvilResult(event, resultItem)) return true
|
if (DependencyManager.tryTreatAnvilResult(event, resultItem)) return true
|
||||||
|
|
||||||
// Maybe add an option on custom craft to ignore/not ignore penalty ??
|
val xpCost = recipe.determineCost(amount, first, resultItem)
|
||||||
var xpCost = recipe.levelCostPerCraft * amount
|
|
||||||
xpCost += AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.CUSTOM_CRAFT)
|
|
||||||
|
|
||||||
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, xpCost, true)
|
val levelCost =
|
||||||
|
if (recipe.removeExactXp) AnvilXpUtil.calculateMinimumLevelForXp(xpCost)
|
||||||
|
else AnvilXpUtil.calculateLevelForXp(xpCost)
|
||||||
|
|
||||||
|
AnvilXpUtil.setAnvilInvXp(inventory, event.view, player, levelCost, true)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import org.bukkit.configuration.ConfigurationSection
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
||||||
|
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||||
|
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||||
|
|
||||||
class AnvilCustomRecipe(
|
class AnvilCustomRecipe(
|
||||||
val name: String,
|
val name: String,
|
||||||
|
|
@ -196,5 +198,18 @@ class AnvilCustomRecipe(
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun determineCost(amount: Int, first: ItemStack, resultItem: ItemStack): Int {
|
||||||
|
// First we determine the non linear level cost
|
||||||
|
var levelCost = levelCostPerCraft * amount
|
||||||
|
// TODO Maybe add an option per custom craft to ignore/not ignore penalty ??
|
||||||
|
levelCost += AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.CUSTOM_CRAFT)
|
||||||
|
|
||||||
|
var xpCost = AnvilXpUtil.calculateXpForLevel(levelCost)
|
||||||
|
// Then we add the linear cost
|
||||||
|
xpCost += XpCostPerCraft * amount
|
||||||
|
|
||||||
|
return xpCost
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue