mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
alpha version up & cleanup code.
This commit is contained in:
parent
1b83c8db81
commit
00fba2f4b0
40 changed files with 893 additions and 718 deletions
|
|
@ -12,67 +12,94 @@ object ConfigOptions {
|
|||
|
||||
// Path for default enchantment limits
|
||||
private const val DEFAULT_LIMIT_PATH = "default_limit"
|
||||
|
||||
// Path for limiting repair cost
|
||||
const val LIMIT_REPAIR_COST = "limit_repair_cost"
|
||||
|
||||
// Path for repair value limit
|
||||
const val LIMIT_REPAIR_VALUE = "limit_repair_value"
|
||||
|
||||
// Path for level cost on item repair
|
||||
const val ITEM_REPAIR_COST = "item_repair_cost"
|
||||
|
||||
// Path for level cost on unit repair
|
||||
const val UNIT_REPAIR_COST = "unit_repair_cost"
|
||||
|
||||
// Path for level cost on item renaming
|
||||
const val ITEM_RENAME_COST = "item_rename_cost"
|
||||
|
||||
// Path for level cost on illegal enchantment on sacrifice
|
||||
const val SACRIFICE_ILLEGAL_COST = "sacrifice_illegal_enchant_cost"
|
||||
|
||||
// Path for removing repair cost limits
|
||||
const val REMOVE_REPAIR_LIMIT = "remove_repair_limit"
|
||||
|
||||
// Root path for enchantment limits
|
||||
const val ENCHANT_LIMIT_ROOT = "enchant_limits"
|
||||
|
||||
// Root path for enchantment values
|
||||
const val ENCHANT_VALUES_ROOT = "enchant_values"
|
||||
|
||||
// Keys for specific enchantment values
|
||||
private const val KEY_BOOK = "book"
|
||||
private const val KEY_ITEM = "item"
|
||||
|
||||
// Debug logging toggle path
|
||||
private const val DEBUG_LOGGING = "debug_log"
|
||||
|
||||
// Debug verbose logging toggle path
|
||||
private const val VERBOSE_DEBUG_LOGGING = "debug_log_verbose"
|
||||
|
||||
// Default value for enchantment limits
|
||||
private const val DEFAULT_ENCHANT_LIMIT = 5
|
||||
|
||||
// Default value for limiting repair cost
|
||||
const val DEFAULT_LIMIT_REPAIR = false
|
||||
|
||||
// Default value for repair cost limit
|
||||
const val DEFAULT_LIMIT_REPAIR_VALUE = 39
|
||||
|
||||
// Default value for level cost on item repair
|
||||
const val DEFAULT_ITEM_REPAIR_COST = 2
|
||||
|
||||
// Default value for level cost per unit repair
|
||||
const val DEFAULT_UNIT_REPAIR_COST = 1
|
||||
|
||||
// Default value for level cost on item renaming
|
||||
const val DEFAULT_ITEM_RENAME_COST = 1
|
||||
|
||||
// Default value for level cost on illegal enchantment on sacrifice
|
||||
const val DEFAULT_SACRIFICE_ILLEGAL_COST = 1
|
||||
|
||||
// Valid range for repair cost limit
|
||||
@JvmField
|
||||
val REPAIR_LIMIT_RANGE = 1..39
|
||||
|
||||
// Valid range for repair cost
|
||||
@JvmField
|
||||
val REPAIR_COST_RANGE = 0..255
|
||||
|
||||
// Valid range for rename cost
|
||||
@JvmField
|
||||
val ITEM_RENAME_COST_RANGE = 0..255
|
||||
|
||||
// Valid range for illegal enchantment conflict cost
|
||||
@JvmField
|
||||
val SACRIFICE_ILLEGAL_COST_RANGE = 0..255
|
||||
|
||||
// Default for removing repair cost limits
|
||||
const val DEFAULT_REMOVE_LIMIT = false
|
||||
|
||||
// Valid range for an enchantment limit
|
||||
@JvmField
|
||||
val ENCHANT_LIMIT_RANGE = 1..255
|
||||
|
||||
// Default value for an enchantment multiplier
|
||||
private const val DEFAULT_ENCHANT_VALUE = 0
|
||||
|
||||
// Default value for debug logging
|
||||
private const val DEFAULT_DEBUG_LOG = false
|
||||
|
||||
// Default value for debug logging
|
||||
private const val DEFAULT_VERBOSE_DEBUG_LOG = false
|
||||
|
||||
|
|
@ -155,6 +182,7 @@ object ConfigOptions {
|
|||
.takeIf { it in SACRIFICE_ILLEGAL_COST_RANGE }
|
||||
?: DEFAULT_SACRIFICE_ILLEGAL_COST
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to remove repair cost limit
|
||||
*/
|
||||
|
|
@ -217,8 +245,9 @@ object ConfigOptions {
|
|||
/**
|
||||
* Get an array of key of basic config options
|
||||
*/
|
||||
fun getBasicConfigKeys(): Array<String>{
|
||||
return arrayOf(DEFAULT_LIMIT_PATH,
|
||||
fun getBasicConfigKeys(): Array<String> {
|
||||
return arrayOf(
|
||||
DEFAULT_LIMIT_PATH,
|
||||
LIMIT_REPAIR_COST,
|
||||
LIMIT_REPAIR_VALUE,
|
||||
ITEM_REPAIR_COST,
|
||||
|
|
|
|||
|
|
@ -34,43 +34,51 @@ object EnchantmentUtil {
|
|||
if (!containsKey(enchantment)) {
|
||||
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
||||
this[enchantment] = level
|
||||
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment);
|
||||
if(!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
||||
(conflictType != ConflictType.NO_CONFLICT)){
|
||||
val conflictType =
|
||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||
if (!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
||||
(conflictType != ConflictType.NO_CONFLICT)
|
||||
) {
|
||||
CustomAnvil.verboseLog("Enchantment not yet in result list, but there is conflict (${enchantment.key}, conflict: $conflictType)")
|
||||
this.remove(enchantment)
|
||||
}
|
||||
|
||||
}
|
||||
// Enchantment already in result list
|
||||
else{
|
||||
else {
|
||||
// ... and they are conflicting
|
||||
val conflictType = ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys,mat,enchantment)
|
||||
if((conflictType != ConflictType.NO_CONFLICT)
|
||||
&& !player.hasPermission(CustomAnvil.bypassFusePermission)){
|
||||
val conflictType =
|
||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||
if ((conflictType != ConflictType.NO_CONFLICT)
|
||||
&& !player.hasPermission(CustomAnvil.bypassFusePermission)
|
||||
) {
|
||||
CustomAnvil.verboseLog("Enchantment already in result list, and they are conflicting (${enchantment.key}, conflict: $conflictType)")
|
||||
return@forEach
|
||||
}
|
||||
|
||||
// ... and they're not the same level
|
||||
if(this[enchantment] != other[enchantment]){
|
||||
if (this[enchantment] != other[enchantment]) {
|
||||
val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0)
|
||||
// apply the greater of the two if non-zero
|
||||
|
||||
if (newLevel > 0) { this[enchantment] = newLevel }
|
||||
if (newLevel > 0) {
|
||||
this[enchantment] = newLevel
|
||||
}
|
||||
}
|
||||
// ... and they're the same level
|
||||
else {
|
||||
// try to increase the enchantment level by 1
|
||||
var newLevel = this[enchantment]!! +1
|
||||
var newLevel = this[enchantment]!! + 1
|
||||
// Get max level or 255 if player can bypass
|
||||
val maxLevel = if(player.hasPermission(CustomAnvil.bypassLevelPermission)){
|
||||
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission)) {
|
||||
255
|
||||
}else{
|
||||
} else {
|
||||
ConfigOptions.enchantLimit(enchantment)
|
||||
}
|
||||
newLevel = min(newLevel, maxLevel)
|
||||
if (newLevel > 0) { this[enchantment] = newLevel }
|
||||
if (newLevel > 0) {
|
||||
this[enchantment] = newLevel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ object ItemUtil {
|
|||
(itemMeta as? Damageable)?.let {
|
||||
val durability = type.maxDurability.toInt()
|
||||
val firstDamage = (first.itemMeta as? Damageable)?.damage ?: 0
|
||||
if( firstDamage == 0) return false
|
||||
if (firstDamage == 0) return false
|
||||
|
||||
val firstDurability = durability - firstDamage
|
||||
val secondDamage = (second.itemMeta as? Damageable)?.damage ?: 0
|
||||
|
|
@ -96,12 +96,12 @@ object ItemUtil {
|
|||
(itemMeta as? Damageable)?.let {
|
||||
val durability = type.maxDurability.toInt()
|
||||
val firstDamage = it.damage
|
||||
if( firstDamage == 0) return 0
|
||||
if (firstDamage == 0) return 0
|
||||
var unitCount = 0
|
||||
var damage = firstDamage
|
||||
while((unitCount < unitAmount) && (damage > 0)){
|
||||
while ((unitCount < unitAmount) && (damage > 0)) {
|
||||
unitCount++
|
||||
damage = ceil(firstDamage - durability*percentPerUnit*unitCount).toInt()
|
||||
damage = ceil(firstDamage - durability * percentPerUnit * unitCount).toInt()
|
||||
}
|
||||
|
||||
it.damage = max(damage, 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue