From d8897f5adde33db368e85c5c07737670f5245592 Mon Sep 17 00:00:00 2001 From: Sindusk Date: Sun, 24 Jun 2018 07:43:04 -0400 Subject: [PATCH] Update to fix ArmourTypes freeze. --- build.gradle | 4 +-- .../java/mod/sin/armoury/ArmourTweaks.java | 21 ++++-------- src/main/java/mod/sin/armoury/ArmouryMod.java | 33 +++++++++---------- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/build.gradle b/build.gradle index 945358a..d2c7a67 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'java' group "mod.sin" -version "2.2" +version "2.3" repositories { mavenCentral() @@ -10,7 +10,7 @@ repositories { } dependencies { - compile 'com.github.Sindusk:sindusklibrary:v1.5' + compile 'com.github.Sindusk:sindusklibrary:v1.6' } jar { diff --git a/src/main/java/mod/sin/armoury/ArmourTweaks.java b/src/main/java/mod/sin/armoury/ArmourTweaks.java index f2fee13..de80b31 100644 --- a/src/main/java/mod/sin/armoury/ArmourTweaks.java +++ b/src/main/java/mod/sin/armoury/ArmourTweaks.java @@ -7,6 +7,7 @@ import com.wurmonline.server.items.*; import javassist.ClassPool; import javassist.CtClass; import javassist.NotFoundException; +import mod.sin.lib.ArmourAssist; import mod.sin.lib.Util; import mod.sin.lib.WoundAssist; import org.gotti.wurmunlimited.modloader.ReflectionUtil; @@ -19,10 +20,8 @@ import java.util.logging.Logger; public class ArmourTweaks { public static Logger logger = Logger.getLogger(ArmourTweaks.class.getName()); - public static String[] armourTypes = {"cloth", "leather", "studded", "chain", "plate", "drake", "dragonscale", // Worn armour pieces - "scale", "ring", "splint"}; // Used by the system but not worn by players - public static HashMap armourNameToType = new HashMap<>(); - public static HashMap armourTypeToName = new HashMap<>(); + //public static String[] armourTypes = {"cloth", "leather", "studded", "chain", "plate", "drake", "dragonscale", // Worn armour pieces + // "scale", "ring", "splint"}; // Used by the system but not worn by players public static HashMap armourDamageReduction = new HashMap<>(); public static HashMap> armourEffectiveness = new HashMap<>(); @@ -107,14 +106,8 @@ public class ArmourTweaks { toReturn *= materialGlanceRate.get(armourMaterial).get(damageType); //logger.info(String.format("Found material %s, adjusting glance rate by %.2f%%.", armourMaterial, materialGlanceRate.get(armourMaterial).get(damageType))); } - String name = String.valueOf(armourType); - if(ArmourTweaks.armourTypeToName.containsKey(armourType)){ - name = ArmourTweaks.armourTypeToName.get(armourType); - } - String wound = String.valueOf(damageType); - if(WoundAssist.woundTypeToName.containsKey(damageType)){ - wound = WoundAssist.woundTypeToName.get(damageType); - } + String name = ArmourAssist.getArmourName(armourType); + String wound = WoundAssist.getWoundName(damageType); //logger.info(String.format("Glance rate for %s against %s: %.2f", name, wound, toReturn)); return toReturn; } @@ -265,7 +258,7 @@ public class ArmourTweaks { public static void initializeArmourMaps(){ // Armour name mapping: - armourNameToType.put("cloth", ArmourTypes.ARMOUR_CLOTH); + /*armourNameToType.put("cloth", ArmourTypes.ARMOUR_CLOTH); armourNameToType.put("leather", ArmourTypes.ARMOUR_LEATHER); armourNameToType.put("studded", ArmourTypes.ARMOUR_STUDDED); armourNameToType.put("chain", ArmourTypes.ARMOUR_CHAIN); @@ -277,7 +270,7 @@ public class ArmourTweaks { armourNameToType.put("splint", ArmourTypes.ARMOUR_SPLINT); for(String name : armourNameToType.keySet()){ armourTypeToName.put(armourNameToType.get(name), name); - } + }*/ // Default material movement speed modifiers: materialMovementModifier.put(Materials.MATERIAL_ADAMANTINE, 0.95f); diff --git a/src/main/java/mod/sin/armoury/ArmouryMod.java b/src/main/java/mod/sin/armoury/ArmouryMod.java index 9299dfc..06b6478 100644 --- a/src/main/java/mod/sin/armoury/ArmouryMod.java +++ b/src/main/java/mod/sin/armoury/ArmouryMod.java @@ -3,6 +3,7 @@ package mod.sin.armoury; import com.wurmonline.server.creatures.CreatureTemplate; import com.wurmonline.server.creatures.CreatureTemplateFactory; import com.wurmonline.server.items.Materials; +import mod.sin.lib.ArmourAssist; import mod.sin.lib.Prop; import mod.sin.lib.WoundAssist; import org.gotti.wurmunlimited.modloader.interfaces.*; @@ -62,13 +63,6 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene public static HashMap weaponParryPercent = new HashMap<>(); public static HashMap weaponSkillPenalty = new HashMap<>(); - public static int parseArmourType(String str){ - if(ArmourTweaks.armourNameToType.containsKey(str.toLowerCase())){ - return ArmourTweaks.armourNameToType.get(str.toLowerCase()); - } - return Integer.parseInt(str); - } - public static byte parseMaterialType(String str){ byte mat = Materials.convertMaterialStringIntoByte(str); if(mat > 0){ @@ -148,17 +142,17 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene armourReductionOverride.put(armourId, reductionValue); } else if (name.startsWith("armourDamageReduction")) { String[] split = value.split(","); - int armourId = parseArmourType(split[0]); + int armourId = ArmourAssist.getArmourType(split[0]); float reductionValue = Float.parseFloat(split[1]); ArmourTweaks.addArmourDamageReduction(armourId, reductionValue); } else if (name.startsWith("armourEffectiveness")) { String[] split = value.split(";"); - int armourType = parseArmourType(split[0]); + int armourType = ArmourAssist.getArmourType(split[0]); String[] split2 = split[1].split(","); ArmourTweaks.addArmourEffectiveness(armourType, split2); } else if (name.startsWith("armourGlanceRate")) { String[] split = value.split(";"); - int armourType = parseArmourType(split[0]); + int armourType = ArmourAssist.getArmourType(split[0]); String[] split2 = split[1].split(","); ArmourTweaks.addArmourGlanceRate(armourType, split2); } else if (name.startsWith("materialDamageReduction")) { @@ -326,19 +320,21 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene logger.log(Level.INFO, "unarmouredReduction: " + ArmourTweaks.unarmouredReduction); logger.info("> Armour Base DR Settings <"); for(int armourType : ArmourTweaks.armourDamageReduction.keySet()){ - String name = String.valueOf(armourType); + String name = ArmourAssist.getArmourName(armourType); + /*String name = String.valueOf(armourType); if(ArmourTweaks.armourTypeToName.containsKey(armourType)){ name = ArmourTweaks.armourTypeToName.get(armourType); - } + }*/ //logger.info("Base DR for "+name+": "+(ArmourTweaks.armourDamageReduction.get(armourType)*100f) +"%"); logger.info(String.format("Base DR for %s: %.2f%%", name, ArmourTweaks.armourDamageReduction.get(armourType)*100f)); } logger.info("> Armour Effectiveness Settings <"); for(int armourType : ArmourTweaks.armourEffectiveness.keySet()){ - String name = String.valueOf(armourType); + String name = ArmourAssist.getArmourName(armourType); + /*String name = String.valueOf(armourType); if(ArmourTweaks.armourTypeToName.containsKey(armourType)){ name = ArmourTweaks.armourTypeToName.get(armourType); - } + }*/ HashMap woundMap = ArmourTweaks.armourEffectiveness.get(armourType); for(byte woundType : woundMap.keySet()){ String wound = WoundAssist.getWoundName(woundType); @@ -348,10 +344,11 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene } logger.info("> Armour Glance Rate Settings <"); for(int armourType : ArmourTweaks.armourGlanceRates.keySet()){ - String name = String.valueOf(armourType); + String name = ArmourAssist.getArmourName(armourType); + /*String name = String.valueOf(armourType); if(ArmourTweaks.armourTypeToName.containsKey(armourType)){ name = ArmourTweaks.armourTypeToName.get(armourType); - } + }*/ HashMap woundMap = ArmourTweaks.armourGlanceRates.get(armourType); for(byte woundType : woundMap.keySet()){ String wound = WoundAssist.getWoundName(woundType); @@ -506,8 +503,8 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene public void onServerStarted(){ WeaponTweaks.onServerStarted(); for(CreatureTemplate template : CreatureTemplateFactory.getInstance().getTemplates()){ - if(ArmourTweaks.armourTypeToName.containsKey((int) template.getArmourType())) { - logger.info(template.getName() + " - " + ArmourTweaks.armourTypeToName.get((int) template.getArmourType())); + if(ArmourAssist.armourTypeToName.containsKey((int) template.getArmourType())) { + logger.info(template.getName() + " - " + ArmourAssist.armourTypeToName.get((int) template.getArmourType())); } } }