Update to WU 1.8.

Removal of all Armour-related options.
Removed options for fixArmourLimitSpellEffect and fixArmourLimitBuffBug. These were fixed in vanilla WU 1.8.
This commit is contained in:
Sindusk
2018-09-20 04:46:44 -04:00
parent b657797f1b
commit 82056ece66
5 changed files with 10 additions and 931 deletions

View File

@@ -1,459 +0,0 @@
package mod.sin.armoury;
import com.wurmonline.server.Server;
import com.wurmonline.server.combat.Armour;
import com.wurmonline.server.combat.ArmourTypes;
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;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
import java.util.ArrayList;
import java.util.HashMap;
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<Integer, Float> armourDamageReduction = new HashMap<>();
public static HashMap<Integer, HashMap<Byte, Float>> armourEffectiveness = new HashMap<>();
public static HashMap<Integer, HashMap<Byte, Float>> armourGlanceRates = new HashMap<>();
public static HashMap<Byte, Float> materialDamageReduction = new HashMap<>();
public static HashMap<Byte, HashMap<Byte, Float>> materialEffectiveness = new HashMap<>();
public static HashMap<Byte, HashMap<Byte, Float>> materialGlanceRate = new HashMap<>();
public static HashMap<Byte, Float> materialMovementModifier = new HashMap<>();
public static HashMap<String, Integer> armourNameToItemTemplate = new HashMap<>();
public static ArrayList<Armour> clothArmour = new ArrayList<>();
public static ArrayList<Armour> leatherArmour = new ArrayList<>();
public static ArrayList<Armour> studdedArmour = new ArrayList<>();
public static ArrayList<Armour> chainArmour = new ArrayList<>();
public static ArrayList<Armour> plateArmour = new ArrayList<>();
public static ArrayList<Armour> drakeArmour = new ArrayList<>();
public static ArrayList<Armour> dragonscaleArmour = new ArrayList<>();
public static float unarmouredReduction = 0.05f;
public static float newGetArmourModFor(Item armour, byte woundType){
float toReturn = 0.0f;
if(armour != null){
int armourType = armour.getArmourType();
// Use custom armour reductions if available:
if(armourDamageReduction.containsKey(armourType)){
toReturn = armourDamageReduction.get(armourType);
}else{ // Otherwise simply use the vanilla base DR
toReturn = ArmourTypes.getArmourBaseDR(armourType);
//logger.warning("Could not find armour reduction reference for armour type "+armourType+". Using default value ("+toReturn+")");
}
// Overwrite again if item template is in the armour reduction override (custom armour):
if (ArmouryMod.armourReductionOverride.containsKey(armour.getTemplateId())){
toReturn = ArmouryMod.armourReductionOverride.get(armour.getTemplateId())-unarmouredReduction;
}
//logger.info("Base DR: "+toReturn);
if(armourType > -1){
byte material = armour.getMaterial();
// Use the material damage reduction set from configs if available
if(materialDamageReduction.containsKey(material)){
toReturn += materialDamageReduction.get(material);
//logger.info(String.format("Found armour made of material %s. Adding %.1f Base DR", material, materialDamageReduction.get(material)*100f));
}else { // Otherwise simply use the vanilla material bonuses
toReturn += ArmourTypes.getArmourMatBonus(material);
}
//logger.info("Post-Material DR: "+toReturn);
// Base armour effectiveness calculations
float armourEff;
if(armourEffectiveness.containsKey(armourType) && armourEffectiveness.get(armourType).containsKey(woundType)){
armourEff = armourEffectiveness.get(armourType).get(woundType);
//logger.info(String.format("Found of type %s. Adding %.2f effectiveness.", armourType, armourEffectiveness.get(armourType).get(woundType)*100f));
}else{
armourEff = ArmourTypes.getArmourEffModifier(armourType, woundType);
}
//logger.info("Base effectiveness: "+armourEff);
// Material effectiveness calculations
if(materialEffectiveness.containsKey(material) && materialEffectiveness.get(material).containsKey(woundType)){
float mod = materialEffectiveness.get(material).get(woundType);
//logger.info(String.format("Found armour made of material %s against %s. Multiplying by %.3f", material, woundType, mod));
toReturn *= (armourEff*mod);
}else {
toReturn *= armourEff;
}
//logger.info("Post-Effectiveness: "+toReturn);
toReturn *= 1.0f + Armour.getRarityArmourBonus(armour.getRarity());
toReturn = unarmouredReduction + (float)((double)toReturn * Server.getBuffedQualityEffect(armour.getCurrentQualityLevel() / 100.0f));
}
}
return 1.0f - Math.min(1.0f, toReturn);
}
public static float newGetArmourGlanceModifier(int armourType, byte armourMaterial, byte damageType){
if(armourGlanceRates.containsKey(armourType) && armourGlanceRates.get(armourType).containsKey(damageType)){
float toReturn = armourGlanceRates.get(armourType).get(damageType);
//logger.info("Base glance rate: "+toReturn);
if(materialGlanceRate.containsKey(armourMaterial) && materialGlanceRate.get(armourMaterial).containsKey(damageType)){
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 = ArmourAssist.getArmourName(armourType);
String wound = WoundAssist.getWoundName(damageType);
//logger.info(String.format("Glance rate for %s against %s: %.2f", name, wound, toReturn));
return toReturn;
}
logger.warning("Found no glance rate for armour type "+armourType+" against "+damageType);
return 0.0f;
}
public static float newGetMaterialMovementModifier(byte armourMaterial){
if(materialMovementModifier.containsKey(armourMaterial)){
//logger.info(String.format("Adjusting movement speed to %.2f%% because of material %s", materialMovementModifier.get(armourMaterial)*100f, armourMaterial));
return materialMovementModifier.get(armourMaterial);
}
return 1.0f;
}
public static void setArmourLimitFactors(){
try{
logger.info("Setting armour limit factors");
for(Armour armour : clothArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.clothArmourLimitFactor);
}
for(Armour armour : leatherArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.leatherArmourLimitFactor);
}
for(Armour armour : studdedArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.studdedArmourLimitFactor);
}
for(Armour armour : chainArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.chainArmourLimitFactor);
}
for(Armour armour : plateArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.plateArmourLimitFactor);
}
for(Armour armour : drakeArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.drakeArmourLimitFactor);
}
for(Armour armour : dragonscaleArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.dragonscaleArmourLimitFactor);
}
} catch (IllegalArgumentException | IllegalAccessException | ClassCastException | NoSuchFieldException e) {
e.printStackTrace();
}
}
protected static ArrayList<Byte> getWoundTypes(String[] split){
ArrayList<Byte> woundTypes = new ArrayList<>();
int i = 0;
while(i < split.length-1){
if(split[i].equalsIgnoreCase("all")){
byte x = 0;
while(x <= 10){
woundTypes.add(x);
x++;
}
}else if(split[i].equalsIgnoreCase("physical")){
woundTypes.add((byte) 0); // Crush
woundTypes.add((byte) 1); // Slash
woundTypes.add((byte) 2); // Pierce
woundTypes.add((byte) 3); // Bite
}else if(split[i].equalsIgnoreCase("elemental")){
woundTypes.add((byte) 4); // Burn
woundTypes.add((byte) 8); // Cold
woundTypes.add((byte) 10); // Acid
}else if(split[i].equalsIgnoreCase("other")){
woundTypes.add((byte) 5); // Poison
woundTypes.add((byte) 6); // Infection
woundTypes.add((byte) 7); // Water
woundTypes.add((byte) 9); // Internal
}else{
woundTypes.add(WoundAssist.getWoundType(split[i]));
}
i++;
}
return woundTypes;
}
public static void addArmourDamageReduction(int armourType, float reduction){
armourDamageReduction.put(armourType, reduction);
}
public static void addArmourEffectiveness(int armourType, String[] split){
float reduction = Float.parseFloat(split[split.length-1]);
ArrayList<Byte> woundTypes = getWoundTypes(split);
for(byte woundType : woundTypes) {
HashMap<Byte, Float> map;
if (armourEffectiveness.containsKey(armourType)) {
map = armourEffectiveness.get(armourType);
} else {
map = new HashMap<>();
}
map.put(woundType, reduction);
armourEffectiveness.put(armourType, map);
}
}
public static void addArmourGlanceRate(int armourType, String[] split){
float rate = Float.parseFloat(split[split.length-1]);
ArrayList<Byte> woundTypes = getWoundTypes(split);
for(byte woundType : woundTypes) {
HashMap<Byte, Float> map;
if (armourGlanceRates.containsKey(armourType)) {
map = armourGlanceRates.get(armourType);
} else {
map = new HashMap<>();
}
map.put(woundType, rate);
armourGlanceRates.put(armourType, map);
}
}
public static void addMaterialReduction(byte material, float reduction){
materialDamageReduction.put(material, reduction);
}
public static void addMaterialEffectiveness(byte material, String[] split){
float reduction = Float.parseFloat(split[split.length-1]);
ArrayList<Byte> woundTypes = getWoundTypes(split);
for(byte woundType : woundTypes) {
HashMap<Byte, Float> map;
if (materialEffectiveness.containsKey(material)) {
map = materialEffectiveness.get(material);
} else {
map = new HashMap<>();
}
map.put(woundType, reduction);
materialEffectiveness.put(material, map);
}
}
public static void addMaterialGlanceRate(byte material, String[] split){
float rate = Float.parseFloat(split[split.length-1]);
ArrayList<Byte> woundTypes = getWoundTypes(split);
for(byte woundType : woundTypes) {
HashMap<Byte, Float> map;
if (materialGlanceRate.containsKey(material)) {
map = materialGlanceRate.get(material);
} else {
map = new HashMap<>();
}
map.put(woundType, rate);
materialGlanceRate.put(material, map);
}
}
public static void addMaterialMovementModifier(byte material, float speed){
materialMovementModifier.put(material, speed);
}
public static void initializeArmourMaps(){
// Armour name mapping:
/*armourNameToType.put("cloth", ArmourTypes.ARMOUR_CLOTH);
armourNameToType.put("leather", ArmourTypes.ARMOUR_LEATHER);
armourNameToType.put("studded", ArmourTypes.ARMOUR_STUDDED);
armourNameToType.put("chain", ArmourTypes.ARMOUR_CHAIN);
armourNameToType.put("plate", ArmourTypes.ARMOUR_PLATE);
armourNameToType.put("drake", ArmourTypes.ARMOUR_LEATHER_DRAGON);
armourNameToType.put("dragonscale", ArmourTypes.ARMOUR_SCALE_DRAGON);
armourNameToType.put("scale", ArmourTypes.ARMOUR_SCALE);
armourNameToType.put("ring", ArmourTypes.ARMOUR_RING);
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);
materialMovementModifier.put(Materials.MATERIAL_COPPER, 0.99f);
materialMovementModifier.put(Materials.MATERIAL_GLIMMERSTEEL, 0.90f);
materialMovementModifier.put(Materials.MATERIAL_GOLD, 1.05f);
materialMovementModifier.put(Materials.MATERIAL_LEAD, 1.025f);
materialMovementModifier.put(Materials.MATERIAL_SERYLL, 0.90f);
materialMovementModifier.put(Materials.MATERIAL_SILVER, 1.02f);
materialMovementModifier.put(Materials.MATERIAL_TIN, 0.98f);
materialMovementModifier.put(Materials.MATERIAL_ZINC, 0.975f);
// Defaults
/*materialDamageReduction.put(Materials.MATERIAL_GOLD, -0.01f);
materialDamageReduction.put(Materials.MATERIAL_SILVER, -0.0075f);
materialDamageReduction.put(Materials.MATERIAL_STEEL, 0.025f);
materialDamageReduction.put(Materials.MATERIAL_COPPER, -0.01f);
materialDamageReduction.put(Materials.MATERIAL_IRON, 0.0f);
materialDamageReduction.put(Materials.MATERIAL_LEAD, -0.025f);
materialDamageReduction.put(Materials.MATERIAL_ZINC, -0.02f);
materialDamageReduction.put(Materials.MATERIAL_BRASS, 0.01f);
materialDamageReduction.put(Materials.MATERIAL_BRONZE, 0.01f);
materialDamageReduction.put(Materials.MATERIAL_TIN, -0.0175f);
materialDamageReduction.put(Materials.MATERIAL_ADAMANTINE, 0.05f);
materialDamageReduction.put(Materials.MATERIAL_GLIMMERSTEEL, 0.1f);
materialDamageReduction.put(Materials.MATERIAL_SERYLL, 0.1f);*/
}
private static void addArmour(ArrayList<Armour> typeList, int itemTemplate){
ItemTemplate it = ItemTemplateFactory.getInstance().getTemplateOrNull(itemTemplate);
if(it != null){
armourNameToItemTemplate.put(it.getName(), itemTemplate);
}
typeList.add(Armour.getArmour(itemTemplate));
}
public static void createArmourTemplateLists(){
addArmour(clothArmour, ItemList.clothHood);
addArmour(clothArmour, ItemList.clothSleeve);
addArmour(clothArmour, ItemList.clothJacket);
addArmour(clothArmour, ItemList.clothShirt);
addArmour(clothArmour, ItemList.clothGlove);
addArmour(clothArmour, ItemList.clothHose);
addArmour(clothArmour, ItemList.clothShoes);
addArmour(leatherArmour, ItemList.leatherHat0);
addArmour(leatherArmour, ItemList.leatherCap);
addArmour(leatherArmour, ItemList.leatherSleeve);
addArmour(leatherArmour, ItemList.leatherJacket);
addArmour(leatherArmour, ItemList.leatherGlove);
addArmour(leatherArmour, ItemList.leatherHose);
addArmour(leatherArmour, ItemList.leatherBoot);
addArmour(studdedArmour, ItemList.studdedLeatherCap);
addArmour(studdedArmour, ItemList.studdedLeatherSleeve);
addArmour(studdedArmour, ItemList.studdedLeatherJacket);
addArmour(studdedArmour, ItemList.studdedLeatherGlove);
addArmour(studdedArmour, ItemList.studdedLeatherHose);
addArmour(studdedArmour, ItemList.studdedLeatherBoot);
addArmour(chainArmour, ItemList.chainCoif);
addArmour(chainArmour, ItemList.chainSleeve);
addArmour(chainArmour, ItemList.chainJacket);
addArmour(chainArmour, ItemList.chainGlove);
addArmour(chainArmour, ItemList.chainHose);
addArmour(chainArmour, ItemList.chainBoot);
addArmour(plateArmour, ItemList.helmetGreat);
addArmour(plateArmour, ItemList.helmetBasinet);
addArmour(plateArmour, ItemList.helmetOpen);
addArmour(plateArmour, ItemList.plateSleeve);
addArmour(plateArmour, ItemList.plateJacket);
addArmour(plateArmour, ItemList.plateGauntlet);
addArmour(plateArmour, ItemList.plateHose);
addArmour(plateArmour, ItemList.plateBoot);
addArmour(drakeArmour, ItemList.dragonLeatherCap);
addArmour(drakeArmour, ItemList.dragonLeatherSleeve);
addArmour(drakeArmour, ItemList.dragonLeatherJacket);
addArmour(drakeArmour, ItemList.dragonLeatherGlove);
addArmour(drakeArmour, ItemList.dragonLeatherHose);
addArmour(drakeArmour, ItemList.dragonLeatherBoot);
addArmour(dragonscaleArmour, ItemList.dragonScaleSleeve);
addArmour(dragonscaleArmour, ItemList.dragonScaleJacket);
addArmour(dragonscaleArmour, ItemList.dragonScaleGauntlet);
addArmour(dragonscaleArmour, ItemList.dragonScaleHose);
addArmour(dragonscaleArmour, ItemList.dragonScaleBoot);
}
protected static void loadDefaultGlanceRates(){
// Initialize glance rates:
float[][] types = new float[11][];
types[0] = ArmourTypes.ARMOUR_GLANCE_CRUSH;
types[1] = ArmourTypes.ARMOUR_GLANCE_SLASH;
types[2] = ArmourTypes.ARMOUR_GLANCE_PIERCE;
types[3] = ArmourTypes.ARMOUR_GLANCE_BITE;
types[4] = ArmourTypes.ARMOUR_GLANCE_BURN;
types[5] = ArmourTypes.ARMOUR_GLANCE_POISON;
types[6] = ArmourTypes.ARMOUR_GLANCE_INFECTION;
types[7] = ArmourTypes.ARMOUR_GLANCE_WATER;
types[8] = ArmourTypes.ARMOUR_GLANCE_COLD;
types[9] = ArmourTypes.ARMOUR_GLANCE_INTERNAL;
types[10] = ArmourTypes.ARMOUR_GLANCE_ACID;
byte woundType = 0;
while(woundType < types.length){
int armourType = 0;
while(armourType < types[woundType].length){
HashMap<Byte, Float> map;
if(armourGlanceRates.containsKey(armourType)){
map = armourGlanceRates.get(armourType);
}else{
map = new HashMap<>();
}
if(!map.containsKey(woundType)) {
map.put(woundType, types[woundType][armourType]);
//logger.info(String.format("Putting glance rate for %s against %s to %.2f", armourTypeToName.get(armourType), WoundAssist.woundTypeToName.get(woundType), types[woundType][armourType]));
}/*else{
logger.info(String.format("Glance rate for %s against %s already set to %.2f", armourTypeToName.get(armourType), WoundAssist.woundTypeToName.get(woundType), map.get(woundType)));
}*/
armourGlanceRates.put(armourType, map);
armourType++;
}
woundType++;
}
}
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
final Class<ArmourTweaks> thisClass = ArmourTweaks.class;
String replace;
if(ArmouryMod.enableArmourModifications){
Util.setReason("Enable armour damage reduction modifications.");
CtClass ctArmour = classPool.get("com.wurmonline.server.combat.Armour");
replace = "{"
+ " return "+ArmourTweaks.class.getName()+".newGetArmourModFor($1, $2);"
+ "}";
Util.setBodyDeclared(thisClass, ctArmour, "getArmourModFor", replace);
Util.setReason("Enable armour glance rate modifications.");
CtClass ctArmourTypes = classPool.get("com.wurmonline.server.combat.ArmourTypes");
replace = "{"
+ " return "+ArmourTweaks.class.getName()+".newGetArmourGlanceModifier($1, $2, $3);"
+ "}";
Util.setBodyDeclared(thisClass, ctArmourTypes, "getArmourGlanceModifier", replace);
Util.setReason("Enable material movement modifications.");
replace = "{"
+ " return "+ArmourTweaks.class.getName()+".newGetMaterialMovementModifier($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctArmourTypes, "getMaterialMovementModifier", replace);
}
} catch (NotFoundException e) {
e.printStackTrace();
}
}
public static void onItemTemplatesCreated(){
createArmourTemplateLists();
loadDefaultGlanceRates();
try {
if(ArmouryMod.enableArmourMovementModifications){
logger.info("Starting armour movement modifications...");
for(String armourName : ArmouryMod.armourMovement.keySet()){
int armourTemplate;
if(armourNameToItemTemplate.containsKey(armourName)){
armourTemplate = armourNameToItemTemplate.get(armourName);
}else{
logger.severe("[ERROR]: Could not edit armour movement for item name \""+armourName+"\". It may be invalid.");
continue;
}
Armour armourToEdit = Armour.getArmour(armourTemplate);
if(armourToEdit != null){
float oldValue = ReflectionUtil.getPrivateField(armourToEdit, ReflectionUtil.getField(armourToEdit.getClass(), "movemodifier"));
ReflectionUtil.setPrivateField(armourToEdit, ReflectionUtil.getField(armourToEdit.getClass(), "movemodifier"), ArmouryMod.armourMovement.get(armourName));
logger.info("Editing movement modifier for armour \""+armourName+"\": From "+oldValue+" to "+ ArmouryMod.armourMovement.get(armourName));
}else{
logger.severe("[ERROR]: Could not edit armour movement for item name \""+armourName+"\". It may be invalid.");
}
}
}
if(ArmouryMod.enableCustomArmourLimitFactors){
setArmourLimitFactors();
}
} catch (IllegalArgumentException | IllegalAccessException | ClassCastException | NoSuchFieldException e) {
e.printStackTrace();
}
}
}

View File

@@ -1,11 +1,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.*;
import java.util.HashMap;
@@ -19,28 +15,6 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
// Configuration options
public static boolean enableNonPlayerCrits = true;
public static boolean fixArmourLimitBuffBug = true;
public static boolean fixArmourLimitSpellEffect = true;
// -- Armour configuration -- //
public static boolean enableArmourModifications = true;
// Armour modifiers
//public static float adamantineMaterialMod = 0.05f;
//public static float glimmersteelMaterialMod = 0.1f;
//public static float seryllMaterialMod = 0.1f;
// Armour limit factors
public static boolean enableCustomArmourLimitFactors = true;
public static float clothArmourLimitFactor = 0.3f;
public static float leatherArmourLimitFactor = 0.3f;
public static float studdedArmourLimitFactor = 0.0f;
public static float chainArmourLimitFactor = -0.15f;
public static float plateArmourLimitFactor = -0.3f;
public static float drakeArmourLimitFactor = -0.3f;
public static float dragonscaleArmourLimitFactor = -0.3f;
public static HashMap<Integer, Float> armourReductionOverride = new HashMap<>();
// Armour movement
public static boolean enableArmourMovementModifications = true;
public static HashMap<String, Float> armourMovement = new HashMap<>();
// - Shield configuration -- //
public static boolean enableShieldDamageEnchants = true;
@@ -78,37 +52,17 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
// Initialization sequences
MaterialTweaks.initializeMaterialMaps();
ArmourTweaks.initializeArmourMaps();
WeaponTweaks.initializeWeaponMaps();
// Base configuration options
enableNonPlayerCrits = Prop.getBooleanProperty("enableNonPlayerCrits", enableNonPlayerCrits);
//enableNonPlayerCrits = Boolean.parseBoolean(properties.getProperty("enableNonPlayerCrits", Boolean.toString(enableNonPlayerCrits)));
fixArmourLimitBuffBug = Prop.getBooleanProperty("fixArmourLimitBuffBug", fixArmourLimitBuffBug);
//fixArmourLimitBuffBug = Boolean.parseBoolean(properties.getProperty("fixArmourLimitBuffBug", Boolean.toString(fixArmourLimitBuffBug)));
fixArmourLimitSpellEffect = Prop.getBooleanProperty("fixArmourLimitSpellEffect", fixArmourLimitSpellEffect);
//fixArmourLimitSpellEffect = Boolean.parseBoolean(properties.getProperty("fixArmourLimitSpellEffect", Boolean.toString(fixArmourLimitSpellEffect)));
enableArmourModifications = Prop.getBooleanProperty("enableArmourReductionModifications", enableArmourModifications);
//enableArmourModifications = Boolean.parseBoolean(properties.getProperty("enableArmourModifications", Boolean.toString(enableArmourModifications)));
ArmourTweaks.unarmouredReduction = Prop.getFloatProperty("unarmouredReduction", ArmourTweaks.unarmouredReduction);
/*if(enableArmourModifications){
ArmourTweaks.configure();
}*/
//adamantineMaterialMod = Float.parseFloat(properties.getProperty("adamantineMaterialMod", Float.toString(adamantineMaterialMod)));
//glimmersteelMaterialMod = Float.parseFloat(properties.getProperty("glimmersteelMaterialMod", Float.toString(glimmersteelMaterialMod)));
//seryllMaterialMod = Float.parseFloat(properties.getProperty("seryllMaterialMod", Float.toString(seryllMaterialMod)));
// Armour limit factors
enableCustomArmourLimitFactors = Boolean.parseBoolean(properties.getProperty("enableCustomArmourLimitFactors", Boolean.toString(enableCustomArmourLimitFactors)));
clothArmourLimitFactor = Float.parseFloat(properties.getProperty("clothArmourLimitFactor", Float.toString(clothArmourLimitFactor)));
leatherArmourLimitFactor = Float.parseFloat(properties.getProperty("leatherArmourLimitFactor", Float.toString(leatherArmourLimitFactor)));
studdedArmourLimitFactor = Float.parseFloat(properties.getProperty("studdedArmourLimitFactor", Float.toString(studdedArmourLimitFactor)));
chainArmourLimitFactor = Float.parseFloat(properties.getProperty("chainArmourLimitFactor", Float.toString(chainArmourLimitFactor)));
plateArmourLimitFactor = Float.parseFloat(properties.getProperty("plateArmourLimitFactor", Float.toString(plateArmourLimitFactor)));
drakeArmourLimitFactor = Float.parseFloat(properties.getProperty("drakeArmourLimitFactor", Float.toString(drakeArmourLimitFactor)));
dragonscaleArmourLimitFactor = Float.parseFloat(properties.getProperty("dragonscaleArmourLimitFactor", Float.toString(dragonscaleArmourLimitFactor)));
// Armour movement modifiers
enableArmourMovementModifications = Boolean.parseBoolean(properties.getProperty("enableArmourMovementModifications", Boolean.toString(enableArmourMovementModifications)));
// Shield configuration
// Shield configuration
enableShieldDamageEnchants = Boolean.parseBoolean(properties.getProperty("enableShieldDamageEnchants", Boolean.toString(enableShieldDamageEnchants)));
// Weapon configuration
minimumSwingTime = Float.parseFloat(properties.getProperty("minimumSwingTime", Float.toString(minimumSwingTime)));
@@ -130,52 +84,7 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
case "depend.suggests":
break; //ignore
default:
if (name.startsWith("armourMovement")) {
String[] split = value.split(",");
String armourName = split[0];
float newVal = Float.parseFloat(split[1]);
armourMovement.put(armourName, newVal);
} else if (name.startsWith("armourReductionOverride")) {
String[] split = value.split(",");
int armourId = Integer.parseInt(split[0]);
float reductionValue = Float.parseFloat(split[1]);
armourReductionOverride.put(armourId, reductionValue);
} else if (name.startsWith("armourDamageReduction")) {
String[] split = value.split(",");
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 = ArmourAssist.getArmourType(split[0]);
String[] split2 = split[1].split(",");
ArmourTweaks.addArmourEffectiveness(armourType, split2);
} else if (name.startsWith("armourGlanceRate")) {
String[] split = value.split(";");
int armourType = ArmourAssist.getArmourType(split[0]);
String[] split2 = split[1].split(",");
ArmourTweaks.addArmourGlanceRate(armourType, split2);
} else if (name.startsWith("materialDamageReduction")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float reduction = Float.parseFloat(split[1]);
ArmourTweaks.addMaterialReduction(material, reduction);
} else if (name.startsWith("materialEffectiveness")) {
String[] split = value.split(";");
byte material = parseMaterialType(split[0]);
String[] split2 = split[1].split(",");
ArmourTweaks.addMaterialEffectiveness(material, split2);
} else if (name.startsWith("materialGlanceRate")) {
String[] split = value.split(";");
byte material = parseMaterialType(split[0]);
String[] split2 = split[1].split(",");
ArmourTweaks.addMaterialGlanceRate(material, split2);
} else if (name.startsWith("materialMovementModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float speed = Float.parseFloat(split[1]);
ArmourTweaks.addMaterialMovementModifier(material, speed);
} else if (name.startsWith("materialWeaponDamage")) {
if (name.startsWith("materialWeaponDamage")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
double mult = Double.parseDouble(split[1]);
@@ -312,77 +221,7 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
// Print values of main.java.armoury.mod configuration
logger.info(" -- Mod Configuration -- ");
logger.log(Level.INFO, "enableNonPlayerCrits: " + enableNonPlayerCrits);
logger.log(Level.INFO, "fixArmourLimitBuffBug: " + fixArmourLimitBuffBug);
logger.log(Level.INFO, "fixArmourLimitSpellEffect: " + fixArmourLimitSpellEffect);
logger.info(" -- Armour Configuration -- ");
logger.log(Level.INFO, "enableArmourModifications: " + enableArmourModifications);
if(enableArmourModifications){
logger.log(Level.INFO, "unarmouredReduction: " + ArmourTweaks.unarmouredReduction);
logger.info("> Armour Base DR Settings <");
for(int armourType : ArmourTweaks.armourDamageReduction.keySet()){
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 = ArmourAssist.getArmourName(armourType);
/*String name = String.valueOf(armourType);
if(ArmourTweaks.armourTypeToName.containsKey(armourType)){
name = ArmourTweaks.armourTypeToName.get(armourType);
}*/
HashMap<Byte, Float> woundMap = ArmourTweaks.armourEffectiveness.get(armourType);
for(byte woundType : woundMap.keySet()){
String wound = WoundAssist.getWoundName(woundType);
logger.info(String.format("Effectiveness for armour %s against %s: %.2f%%", name, wound, woundMap.get(woundType)*100f));
//logger.info("Effectiveness for "+name+" against "+woundType+": "+(woundMap.get(woundType)*100f) +"%");
}
}
logger.info("> Armour Glance Rate Settings <");
for(int armourType : ArmourTweaks.armourGlanceRates.keySet()){
String name = ArmourAssist.getArmourName(armourType);
/*String name = String.valueOf(armourType);
if(ArmourTweaks.armourTypeToName.containsKey(armourType)){
name = ArmourTweaks.armourTypeToName.get(armourType);
}*/
HashMap<Byte, Float> woundMap = ArmourTweaks.armourGlanceRates.get(armourType);
for(byte woundType : woundMap.keySet()){
String wound = WoundAssist.getWoundName(woundType);
logger.info(String.format("Glance rate for armour %s against %s: %.2f%%", name, wound, woundMap.get(woundType)*100f));
//logger.info("Effectiveness for "+name+" against "+woundType+": "+(woundMap.get(woundType)*100f) +"%");
}
}
}
logger.info(" -- Material Configuration -- ");
logger.info("> Armour Material Damage Reduction Settings <");
for(byte material : ArmourTweaks.materialDamageReduction.keySet()){
logger.info(String.format("Base DR modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), ArmourTweaks.materialDamageReduction.get(material)*100f));
}
logger.info("> Armour Material Effectiveness Settings <");
for(byte material : ArmourTweaks.materialEffectiveness.keySet()){
HashMap<Byte, Float> woundMap = ArmourTweaks.materialEffectiveness.get(material);
for(byte woundType : woundMap.keySet()){
String wound = WoundAssist.getWoundName(woundType);
logger.info(String.format("Effectiveness for material %s against %s: %.2f%%", MaterialTweaks.getMaterialName(material), wound, woundMap.get(woundType)*100f));
}
}
logger.info("> Armour Material Glance Rate Settings <");
for(byte material : ArmourTweaks.materialGlanceRate.keySet()){
//String name = materialNameReference.containsKey(material) ? materialNameReference.get(material) : String.valueOf(material);
HashMap<Byte, Float> woundMap = ArmourTweaks.materialGlanceRate.get(material);
for(byte woundType : woundMap.keySet()){
String wound = WoundAssist.getWoundName(woundType);
logger.info(String.format("Glance Rate for material %s against %s: %.2f%%", MaterialTweaks.getMaterialName(material), wound, woundMap.get(woundType)*100f));
}
}
logger.info("> Armour Material Movement Modifier Settings <");
for(byte material : ArmourTweaks.materialMovementModifier.keySet()){
logger.info(String.format("Movement Speed modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), ArmourTweaks.materialMovementModifier.get(material)*100f));
}
logger.info("> Weapon Material Damage Settings <");
for(byte material : WeaponTweaks.materialWeaponDamage.keySet()){
logger.info(String.format("Damage modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), WeaponTweaks.materialWeaponDamage.get(material)*100f));
@@ -459,20 +298,6 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
for(byte material : MaterialTweaks.materialActionSpeedModifier.keySet()){
logger.info(String.format("Action Speed modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialActionSpeedModifier.get(material)*100f));
}
/*logger.log(Level.INFO, "adamantineMaterialMod: " + adamantineMaterialMod);
logger.log(Level.INFO, "glimmersteelMaterialMod: " + glimmersteelMaterialMod);
logger.log(Level.INFO, "seryllMaterialMod: " + seryllMaterialMod);*/
logger.info(" -- Armour Limit Configuration -- ");
logger.log(Level.INFO, "enableCustomArmourLimitFactors: " + enableCustomArmourLimitFactors);
if(enableCustomArmourLimitFactors){
logger.log(Level.INFO, "clothArmourLimitFactor: " + clothArmourLimitFactor);
logger.log(Level.INFO, "leatherArmourLimitFactor: " + leatherArmourLimitFactor);
logger.log(Level.INFO, "studdedArmourLimitFactor: " + studdedArmourLimitFactor);
logger.log(Level.INFO, "chainArmourLimitFactor: " + chainArmourLimitFactor);
logger.log(Level.INFO, "plateArmourLimitFactor: " + plateArmourLimitFactor);
logger.log(Level.INFO, "drakeArmourLimitFactor: " + drakeArmourLimitFactor);
logger.log(Level.INFO, "dragonscaleArmourLimitFactor: " + dragonscaleArmourLimitFactor);
}
logger.info(" -- Shield Configuration -- ");
logger.log(Level.INFO, "enableShieldDamageEnchants: " + enableShieldDamageEnchants);
logger.info(" -- Weapon Configuration -- ");
@@ -487,7 +312,6 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
@Override
public void preInit(){
CombatTweaks.preInit();
ArmourTweaks.preInit();
ShieldTweaks.preInit();
WeaponTweaks.preInit();
MaterialTweaks.preInit();
@@ -496,17 +320,10 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
@Override
public void onItemTemplatesCreated(){
logger.info("Beginning onItemTemplatesCreated...");
ArmourTweaks.onItemTemplatesCreated();
}
@Override
public void onServerStarted(){
WeaponTweaks.onServerStarted();
CombatTweaks.onServerStarted();
for(CreatureTemplate template : CreatureTemplateFactory.getInstance().getTemplates()){
if(ArmourAssist.armourTypeToName.containsKey((int) template.getArmourType())) {
logger.info(template.getName() + " - " + ArmourAssist.armourTypeToName.get((int) template.getArmourType()));
}
}
}
}

View File

@@ -1,23 +1,14 @@
package mod.sin.armoury;
import mod.sin.lib.Util;
import org.gotti.wurmunlimited.modloader.ReflectionUtil;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
import com.wurmonline.server.Server;
import com.wurmonline.server.creatures.CombatHandler;
import com.wurmonline.server.creatures.Creature;
import com.wurmonline.server.creatures.SpellEffectsEnum;
import com.wurmonline.server.items.Item;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtPrimitiveType;
import javassist.NotFoundException;
import javassist.*;
import javassist.bytecode.Descriptor;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;
import mod.sin.lib.Util;
import org.gotti.wurmunlimited.modloader.ReflectionUtil;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
public class CombatTweaks {
public static Item handleDualWieldAttack(CombatHandler handler, Creature opponent, float delta){
@@ -39,20 +30,6 @@ public class CombatTweaks {
}
}
public static void onServerStarted(){
// - Make spell effects hud show your armour limit properly - //
if(ArmouryMod.fixArmourLimitSpellEffect){
try {
ReflectionUtil.setPrivateField(SpellEffectsEnum.ARMOUR_LIMIT_HEAVY, ReflectionUtil.getField(SpellEffectsEnum.ARMOUR_LIMIT_HEAVY.getClass(), "name"), "Armour Penalty");
ReflectionUtil.setPrivateField(SpellEffectsEnum.ARMOUR_LIMIT_MEDIUM, ReflectionUtil.getField(SpellEffectsEnum.ARMOUR_LIMIT_MEDIUM.getClass(), "name"), "Armour Penalty");
ReflectionUtil.setPrivateField(SpellEffectsEnum.ARMOUR_LIMIT_LIGHT, ReflectionUtil.getField(SpellEffectsEnum.ARMOUR_LIMIT_LIGHT.getClass(), "name"), "Armour Bonus");
ReflectionUtil.setPrivateField(SpellEffectsEnum.ARMOUR_LIMIT_NONE, ReflectionUtil.getField(SpellEffectsEnum.ARMOUR_LIMIT_NONE.getClass(), "name"), "Armour Bonus");
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
}
}
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
@@ -94,47 +71,6 @@ public class CombatTweaks {
}
});*/
}
// - Fix the Armour Limit being shown in the buff bar at all times -
if(ArmouryMod.fixArmourLimitBuffBug){
CtClass ctPlayerInfo = classPool.get("com.wurmonline.server.players.PlayerInfo");
String replace = ""
+ "communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_NONE);"
+ "communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_MEDIUM);"
+ "communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_HEAVY);"
+ "$_ = $proceed($$);";
Util.setReason("Fix armour limit buff bug.");
Util.instrumentDeclared(thisClass, ctPlayerInfo, "setArmourLimitingFactor", "sendRemoveSpellEffect", replace);
/*ctPlayerInfo.getDeclaredMethod("setArmourLimitingFactor").instrument(new ExprEditor(){
public void edit(MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals("sendRemoveSpellEffect")) {
m.replace("communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_NONE);"
+ "communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_MEDIUM);"
+ "communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_HEAVY);"
+ "$_ = $proceed($$);");
return;
}
}
});*/
replace = "if($1 == null){"
+ " $1 = com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_NONE;"
+ "}"
+ "$_ = $proceed($$);"
+ "communicator.sendAddSpellEffect($1, 100000, this.limitingArmourFactor*100.0f);";
Util.setReason("Fix armour limit buff bug.");
Util.instrumentDeclared(thisClass, ctPlayerInfo, "setArmourLimitingFactor", "sendAddStatusEffect", replace);
ctPlayerInfo.getDeclaredMethod("setArmourLimitingFactor").instrument(new ExprEditor(){
public void edit(MethodCall m) throws CannotCompileException {
if (m.getMethodName().equals("sendAddStatusEffect")) {
m.replace("if($1 == null){"
+ " $1 = com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_NONE;"
+ "}"
+ "$_ = $proceed($$);"
+ "communicator.sendAddSpellEffect($1, 100000, this.limitingArmourFactor*100.0f);");
}
}
});
}
// - Change the minimum swing timer - //
if(ArmouryMod.minimumSwingTime != 3.0f){
@@ -299,7 +235,7 @@ public class CombatTweaks {
desc = Descriptor.ofMethod(CtClass.booleanType, params3);
ctCombatHandler.getMethod("attack", desc).insertBefore("logger.info(\"Calling attack(Creature, Item, boolean)\");");*/
} catch (CannotCompileException | NotFoundException | IllegalArgumentException | ClassCastException e) {
} catch ( NotFoundException | IllegalArgumentException | ClassCastException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}