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
|
||||
|
||||
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}")
|
||||
if ((player.gameMode != GameMode.CREATIVE) && (player.level < xpCost)) return
|
||||
CustomAnvil.log("gamemode: ${player.gameMode != GameMode.CREATIVE}, cost: $finalCost, level: ${player.level}, result: ${player.totalExperience < finalCost} ${player.level < finalCost}")
|
||||
if (player.gameMode != GameMode.CREATIVE){
|
||||
if(recipe.removeExactXp){
|
||||
if(player.totalExperience < finalCost) return
|
||||
}else if(player.level < finalCost) return
|
||||
}
|
||||
|
||||
// We give the item manually
|
||||
// But first we check if we should give the item
|
||||
|
|
@ -142,7 +149,7 @@ class AnvilResultListener : Listener {
|
|||
|
||||
// Handle not creative middle click...
|
||||
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
|
||||
|
||||
// Finally, we add the item to the player
|
||||
|
|
@ -157,7 +164,7 @@ class AnvilResultListener : Listener {
|
|||
event: InventoryClickEvent, recipe: AnvilCustomRecipe,
|
||||
inventory: AnvilInventory, player: Player,
|
||||
leftItem: ItemStack, rightItem: ItemStack?,
|
||||
amount: Int, xpCost: Int
|
||||
amount: Int, xpCost: Int, linearCost: Boolean = false
|
||||
): Boolean {
|
||||
// We remove what should be removed
|
||||
if (rightItem != null) {
|
||||
|
|
@ -171,7 +178,11 @@ class AnvilResultListener : Listener {
|
|||
inventory.setItem(ANVIL_INPUT_LEFT, leftItem)
|
||||
|
||||
if (player.gameMode != GameMode.CREATIVE) {
|
||||
player.level -= xpCost
|
||||
if(linearCost){
|
||||
player.totalExperience -= xpCost
|
||||
} else{
|
||||
player.level -= xpCost
|
||||
}
|
||||
}
|
||||
|
||||
// Then we try to find the new values for the anvil
|
||||
|
|
|
|||
|
|
@ -136,12 +136,13 @@ class PrepareAnvilListener : Listener {
|
|||
event.result = resultItem
|
||||
if (DependencyManager.tryTreatAnvilResult(event, resultItem)) return true
|
||||
|
||||
// Maybe add an option on custom craft to ignore/not ignore penalty ??
|
||||
var xpCost = recipe.levelCostPerCraft * amount
|
||||
xpCost += AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.CUSTOM_CRAFT)
|
||||
val xpCost = recipe.determineCost(amount, first, resultItem)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.bukkit.configuration.ConfigurationSection
|
|||
import org.bukkit.inventory.ItemStack
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
||||
import xyz.alexcrea.cuanvil.util.AnvilUseType
|
||||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||
|
||||
class AnvilCustomRecipe(
|
||||
val name: String,
|
||||
|
|
@ -196,5 +198,18 @@ class AnvilCustomRecipe(
|
|||
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