New armour stat controls

New material modifications
Control material statistics
Improved configuration
Fix for dual wield change error
This commit is contained in:
Sindusk
2018-05-29 07:06:12 -04:00
parent d46b52b101
commit 1ce8da9c65
9 changed files with 1767 additions and 372 deletions

View File

@@ -1,113 +1,446 @@
package mod.sin.armoury;
import java.util.logging.Logger;
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.combat.Armour;
import com.wurmonline.server.combat.ArmourTypes;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.items.Materials;
import com.wurmonline.server.items.*;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import mod.sin.lib.Util;
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 ArmouryMod mod;
public static float newGetArmourModFor(Item armour){
int armourType;
float toReturn = 0.0f;
if (armour != null && (armourType = armour.getArmourType()) > -1) {
if(mod.armourTypeReduction.containsKey(armourType)){
toReturn = mod.armourTypeReduction.get(armourType)-mod.unarmouredReduction;
}else{
logger.severe("[ERROR]: Could not find armour reduction reference for armour type "+armourType);
toReturn = 0f;
}
if (mod.armourReductionOverride.containsKey(armour.getTemplateId())){
toReturn = mod.armourReductionOverride.get(armour.getTemplateId())-mod.unarmouredReduction;
}
if ((armourType == ArmourTypes.ARMOUR_RING || armourType == ArmourTypes.ARMOUR_CHAIN) && armour.getMaterial() == Materials.MATERIAL_STEEL){
toReturn += 0.02f;
}
if (armour.getMaterial() == Materials.MATERIAL_GLIMMERSTEEL){
toReturn += mod.glimmersteelMaterialMod;
} else if(armour.getMaterial() == Materials.MATERIAL_SERYLL) {
toReturn += mod.seryllMaterialMod;
} else if (armour.getMaterial() == Materials.MATERIAL_ADAMANTINE) {
toReturn += mod.adamantineMaterialMod;
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<String, Integer> armourNameToType = new HashMap<>();
public static HashMap<Integer, String> armourTypeToName = new HashMap<>();
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));
}
toReturn *= 1.0f + Armour.getRarityArmourBonus(armour.getRarity());
toReturn = mod.unarmouredReduction + (float)((double)toReturn * Server.getBuffedQualityEffect(armour.getCurrentQualityLevel() / 100.0f));
}
return 1.0f - toReturn;
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 = 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);
}
//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(ArmouryMod mod){
public static void setArmourLimitFactors(){
try{
logger.info("Setting armour limit factors");
for(Armour armour : mod.clothArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.clothArmourLimitFactor);
for(Armour armour : clothArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.clothArmourLimitFactor);
}
for(Armour armour : mod.leatherArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.leatherArmourLimitFactor);
for(Armour armour : leatherArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.leatherArmourLimitFactor);
}
for(Armour armour : mod.studdedArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.studdedArmourLimitFactor);
for(Armour armour : studdedArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.studdedArmourLimitFactor);
}
for(Armour armour : mod.chainArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.chainArmourLimitFactor);
for(Armour armour : chainArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.chainArmourLimitFactor);
}
for(Armour armour : mod.plateArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.plateArmourLimitFactor);
for(Armour armour : plateArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.plateArmourLimitFactor);
}
for(Armour armour : mod.drakeArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.drakeArmourLimitFactor);
for(Armour armour : drakeArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), ArmouryMod.drakeArmourLimitFactor);
}
for(Armour armour : mod.dragonscaleArmour){
ReflectionUtil.setPrivateField(armour, ReflectionUtil.getField(armour.getClass(), "limitingFactor"), mod.dragonscaleArmourLimitFactor);
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(ArmouryMod.parseWoundType(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(ArmouryMod mod){
ArmourTweaks.mod = mod;
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
final Class<ArmourTweaks> thisClass = ArmourTweaks.class;
if(mod.enableArmourReductionModifications){
String replace;
if(ArmouryMod.enableArmourModifications){
Util.setReason("Enable armour damage reduction modifications.");
CtClass ctArmour = classPool.get("com.wurmonline.server.combat.Armour");
String body = ""
+ "{"
+ " return "+ArmourTweaks.class.getName()+".newGetArmourModFor($1);"
replace = "{"
+ " return "+ArmourTweaks.class.getName()+".newGetArmourModFor($1, $2);"
+ "}";
Util.setBodyDeclared(thisClass, ctArmour, "getArmourModFor", body);
/*ctArmour.getDeclaredMethod("getArmourModFor").setBody("{ "
+ "return "+ArmourTweaks.class.getName()+".newGetArmourModFor($1); }");*/
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);
}
loadDefaultGlanceRates();
} catch (NotFoundException e) {
e.printStackTrace();
}
}
public static void onItemTemplatesCreated(ArmouryMod mod){
public static void onItemTemplatesCreated(){
createArmourTemplateLists();
try {
if(mod.enableArmourMovementModifications){
if(ArmouryMod.enableArmourMovementModifications){
logger.info("Starting armour movement modifications...");
for(String armourName : mod.armourMovement.keySet()){
for(String armourName : ArmouryMod.armourMovement.keySet()){
int armourTemplate;
if(mod.armourNameToItemTemplate.containsKey(armourName)){
armourTemplate = mod.armourNameToItemTemplate.get(armourName);
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;
@@ -115,15 +448,15 @@ public class ArmourTweaks {
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"), mod.armourMovement.get(armourName));
logger.info("Editing movement modifier for armour \""+armourName+"\": From "+oldValue+" to "+mod.armourMovement.get(armourName));
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(mod.enableCustomArmourLimitFactors){
setArmourLimitFactors(mod);
if(ArmouryMod.enableCustomArmourLimitFactors){
setArmourLimitFactors();
}
} catch (IllegalArgumentException | IllegalAccessException | ClassCastException | NoSuchFieldException e) {
e.printStackTrace();

View File

@@ -1,126 +1,136 @@
package mod.sin.armoury;
import java.util.ArrayList;
import com.wurmonline.server.creatures.CreatureTemplate;
import com.wurmonline.server.creatures.CreatureTemplateFactory;
import com.wurmonline.server.items.Materials;
import mod.sin.lib.Prop;
import org.gotti.wurmunlimited.modloader.interfaces.*;
import java.util.HashMap;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.gotti.wurmunlimited.modloader.interfaces.Configurable;
import org.gotti.wurmunlimited.modloader.interfaces.ItemTemplatesCreatedListener;
import org.gotti.wurmunlimited.modloader.interfaces.PreInitable;
import org.gotti.wurmunlimited.modloader.interfaces.ServerStartedListener;
import org.gotti.wurmunlimited.modloader.interfaces.WurmServerMod;
import com.wurmonline.server.combat.Armour;
import com.wurmonline.server.combat.ArmourTypes;
import com.wurmonline.server.items.ItemList;
import com.wurmonline.server.items.ItemTemplate;
import com.wurmonline.server.items.ItemTemplateFactory;
public class ArmouryMod
implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListener, ServerStartedListener {
private Logger logger;
public static Logger logger = Logger.getLogger(ArmouryMod.class.getName());
// Configuration options
public boolean bDebug = false;
public boolean enableNonPlayerCrits = true;
public boolean fixArmourLimitBuffBug = true;
public boolean fixArmourLimitSpellEffect = true;
public static boolean enableNonPlayerCrits = true;
public static boolean fixArmourLimitBuffBug = true;
public static boolean fixArmourLimitSpellEffect = true;
// -- Armour configuration -- //
public boolean enableArmourReductionModifications = true;
public float unarmouredReduction = 0.05f;
// Armour Mapping
public 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 HashMap<Integer, Float> armourTypeReduction = new HashMap<>();
public HashMap<String, Integer> armourTypeReference = new HashMap<>();
public static boolean enableArmourModifications = true;
// Armour modifiers
public float adamantineMaterialMod = 0.05f;
public float glimmersteelMaterialMod = 0.1f;
public float seryllMaterialMod = 0.1f;
//public static float adamantineMaterialMod = 0.05f;
//public static float glimmersteelMaterialMod = 0.1f;
//public static float seryllMaterialMod = 0.1f;
// Armour limit factors
public boolean enableCustomArmourLimitFactors = true;
public float clothArmourLimitFactor = 0.3f;
public float leatherArmourLimitFactor = 0.3f;
public float studdedArmourLimitFactor = 0.0f;
public float chainArmourLimitFactor = -0.15f;
public float plateArmourLimitFactor = -0.3f;
public float drakeArmourLimitFactor = -0.3f;
public float dragonscaleArmourLimitFactor = -0.3f;
public HashMap<Integer, Float> armourReductionOverride = new HashMap<>();
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 boolean enableArmourMovementModifications = true;
public HashMap<String, Float> armourMovement = new HashMap<>();
public static boolean enableArmourMovementModifications = true;
public static HashMap<String, Float> armourMovement = new HashMap<>();
// - Shield configuration -- //
public boolean enableShieldDamageEnchants = true;
public boolean enableShieldSpeedEnchants = true;
public static boolean enableShieldDamageEnchants = true;
public static boolean enableShieldSpeedEnchants = true;
// -- Weapon configuration -- //
public float minimumSwingTime = 3.0f;
public boolean raresReduceSwingTime = true;
public float rareSwingSpeedReduction = 0.2f;
public boolean fixSavedSwingTimer = true;
public boolean betterDualWield = true; // HIGHLY EXPERIMENTAL
public static float minimumSwingTime = 3.0f;
public static boolean raresReduceSwingTime = true;
public static float rareSwingSpeedReduction = 0.2f;
public static boolean fixSavedSwingTimer = true;
public static boolean betterDualWield = true; // HIGHLY EXPERIMENTAL
public static boolean enableWeaponMaterialChanges = true;
public static boolean enableItemMaterialChanges = true;
// Weapon variable changes
public HashMap<Integer, Float> weaponDamage = new HashMap<>();
public HashMap<Integer, Float> weaponSpeed = new HashMap<>();
public HashMap<Integer, Float> weaponCritChance = new HashMap<>();
public HashMap<Integer, Integer> weaponReach = new HashMap<>();
public HashMap<Integer, Integer> weaponWeightGroup = new HashMap<>();
public HashMap<Integer, Float> weaponParryPercent = new HashMap<>();
public HashMap<Integer, Double> weaponSkillPenalty = new HashMap<>();
public ArmouryMod(){
this.logger = Logger.getLogger(this.getClass().getName());
public static HashMap<Integer, Float> weaponDamage = new HashMap<>();
public static HashMap<Integer, Float> weaponSpeed = new HashMap<>();
public static HashMap<Integer, Float> weaponCritChance = new HashMap<>();
public static HashMap<Integer, Integer> weaponReach = new HashMap<>();
public static HashMap<Integer, Integer> weaponWeightGroup = new HashMap<>();
public static HashMap<Integer, Float> weaponParryPercent = new HashMap<>();
public static HashMap<Integer, Double> 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 parseWoundType(String str){
if(WoundAssist.woundNameToType.containsKey(str.toLowerCase())){
return WoundAssist.woundNameToType.get(str.toLowerCase());
}
return Byte.parseByte(str);
}
public static byte parseMaterialType(String str){
byte mat = Materials.convertMaterialStringIntoByte(str);
if(mat > 0){
return mat;
}
return Byte.parseByte(str);
}
@Override
public void configure(Properties properties) {
this.logger.info("Beginning configuration... [Testing]");
logger.info("Beginning configuration...");
Prop.properties = properties;
// Initialization sequences
MaterialTweaks.initializeMaterialMaps();
WoundAssist.initializeWoundMaps();
ArmourTweaks.initializeArmourMaps();
WeaponTweaks.initializeWeaponMaps();
// Base configuration options
this.bDebug = Boolean.parseBoolean(properties.getProperty("debug", Boolean.toString(this.bDebug)));
this.enableNonPlayerCrits = Boolean.parseBoolean(properties.getProperty("enableNonPlayerCrits", Boolean.toString(this.enableNonPlayerCrits)));
this.fixArmourLimitBuffBug = Boolean.parseBoolean(properties.getProperty("fixArmourLimitBuffBug", Boolean.toString(this.fixArmourLimitBuffBug)));
this.fixArmourLimitSpellEffect = Boolean.parseBoolean(properties.getProperty("fixArmourLimitSpellEffect", Boolean.toString(this.fixArmourLimitSpellEffect)));
// Armour configuration
this.initArmourDefaults(); // Create references for use soon.
this.enableArmourReductionModifications = Boolean.parseBoolean(properties.getProperty("enableArmourReductionModifications", Boolean.toString(this.enableArmourReductionModifications)));
if(enableArmourReductionModifications){
this.unarmouredReduction = Float.parseFloat(properties.getProperty("unarmouredReduction", Float.toString(this.unarmouredReduction)));
for(String armourType : armourTypes){
int armourNum = armourTypeReference.get(armourType);
float defaultVal = armourTypeReduction.get(armourNum);
armourTypeReduction.put(armourNum, Float.parseFloat(properties.getProperty(armourType+"Reduction", Float.toString(defaultVal))));
if(armourTypeReduction.get(armourNum) <= 0f){
this.logger.warning("[ERROR]: Armour type \""+armourType+"\" not set properly the Armour Reduction configuration in armoury.properties! It will not reduce damage at all until resolved!");
}
}
}
this.adamantineMaterialMod = Float.parseFloat(properties.getProperty("adamantineMaterialMod", Float.toString(this.adamantineMaterialMod)));
this.glimmersteelMaterialMod = Float.parseFloat(properties.getProperty("glimmersteelMaterialMod", Float.toString(this.glimmersteelMaterialMod)));
this.seryllMaterialMod = Float.parseFloat(properties.getProperty("seryllMaterialMod", Float.toString(this.seryllMaterialMod)));
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
this.enableCustomArmourLimitFactors = Boolean.parseBoolean(properties.getProperty("enableCustomArmourLimitFactors", Boolean.toString(this.enableCustomArmourLimitFactors)));
this.clothArmourLimitFactor = Float.parseFloat(properties.getProperty("clothArmourLimitFactor", Float.toString(this.clothArmourLimitFactor)));
this.leatherArmourLimitFactor = Float.parseFloat(properties.getProperty("leatherArmourLimitFactor", Float.toString(this.leatherArmourLimitFactor)));
this.studdedArmourLimitFactor = Float.parseFloat(properties.getProperty("studdedArmourLimitFactor", Float.toString(this.studdedArmourLimitFactor)));
this.chainArmourLimitFactor = Float.parseFloat(properties.getProperty("chainArmourLimitFactor", Float.toString(this.chainArmourLimitFactor)));
this.plateArmourLimitFactor = Float.parseFloat(properties.getProperty("plateArmourLimitFactor", Float.toString(this.plateArmourLimitFactor)));
this.drakeArmourLimitFactor = Float.parseFloat(properties.getProperty("drakeArmourLimitFactor", Float.toString(this.drakeArmourLimitFactor)));
this.dragonscaleArmourLimitFactor = Float.parseFloat(properties.getProperty("dragonscaleArmourLimitFactor", Float.toString(this.dragonscaleArmourLimitFactor)));
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
this.enableArmourMovementModifications = Boolean.parseBoolean(properties.getProperty("enableArmourMovementModifications", Boolean.toString(this.enableArmourMovementModifications)));
enableArmourMovementModifications = Boolean.parseBoolean(properties.getProperty("enableArmourMovementModifications", Boolean.toString(enableArmourMovementModifications)));
// Shield configuration
this.enableShieldDamageEnchants = Boolean.parseBoolean(properties.getProperty("enableShieldDamageEnchants", Boolean.toString(this.enableShieldDamageEnchants)));
enableShieldDamageEnchants = Boolean.parseBoolean(properties.getProperty("enableShieldDamageEnchants", Boolean.toString(enableShieldDamageEnchants)));
// Weapon configuration
this.minimumSwingTime = Float.parseFloat(properties.getProperty("minimumSwingTime", Float.toString(this.minimumSwingTime)));
this.raresReduceSwingTime = Boolean.parseBoolean(properties.getProperty("raresReduceSwingTime", Boolean.toString(this.raresReduceSwingTime)));
this.rareSwingSpeedReduction = Float.parseFloat(properties.getProperty("rareSwingSpeedReduction", Float.toString(this.rareSwingSpeedReduction)));
this.fixSavedSwingTimer = Boolean.parseBoolean(properties.getProperty("fixSavedSwingTimer", Boolean.toString(this.fixSavedSwingTimer)));
this.betterDualWield = Boolean.parseBoolean(properties.getProperty("betterDualWield", Boolean.toString(this.betterDualWield)));
minimumSwingTime = Float.parseFloat(properties.getProperty("minimumSwingTime", Float.toString(minimumSwingTime)));
raresReduceSwingTime = Boolean.parseBoolean(properties.getProperty("raresReduceSwingTime", Boolean.toString(raresReduceSwingTime)));
rareSwingSpeedReduction = Float.parseFloat(properties.getProperty("rareSwingSpeedReduction", Float.toString(rareSwingSpeedReduction)));
fixSavedSwingTimer = Boolean.parseBoolean(properties.getProperty("fixSavedSwingTimer", Boolean.toString(fixSavedSwingTimer)));
betterDualWield = Boolean.parseBoolean(properties.getProperty("betterDualWield", Boolean.toString(betterDualWield)));
enableWeaponMaterialChanges = Prop.getBooleanProperty("enableWeaponMaterialChanges", enableWeaponMaterialChanges);
enableItemMaterialChanges = Prop.getBooleanProperty("enableItemMaterialChanges", enableItemMaterialChanges);
for (String name : properties.stringPropertyNames()) {
try {
String value = properties.getProperty(name);
@@ -129,6 +139,8 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
case "classname":
case "classpath":
case "sharedClassLoader":
case "depend.import":
case "depend.suggests":
break; //ignore
default:
if (name.startsWith("armourMovement")) {
@@ -137,10 +149,135 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
float newVal = Float.parseFloat(split[1]);
armourMovement.put(armourName, newVal);
} else if (name.startsWith("armourReductionOverride")) {
String[] split = value.split(",");
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 = parseArmourType(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]);
String[] split2 = split[1].split(",");
ArmourTweaks.addArmourEffectiveness(armourType, split2);
} else if (name.startsWith("armourGlanceRate")) {
String[] split = value.split(";");
int armourType = parseArmourType(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")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
double mult = Double.parseDouble(split[1]);
WeaponTweaks.addMaterialWeaponDamage(material, mult);
} else if (name.startsWith("materialWeaponSpeed")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float mult = Float.parseFloat(split[1]);
WeaponTweaks.addMaterialWeaponSpeed(material, mult);
} else if (name.startsWith("materialWeaponParry")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float mult = Float.parseFloat(split[1]);
WeaponTweaks.addMaterialWeaponParry(material, mult);
} else if (name.startsWith("materialWeaponArmourDamage")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
double mult = Double.parseDouble(split[1]);
WeaponTweaks.addMaterialWeaponArmourDamage(material, mult);
} else if (name.startsWith("materialDamageModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float mult = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialDamageModifier(material, mult);
} else if (name.startsWith("materialDecayModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float mult = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialDecayModifier(material, mult);
} else if (name.startsWith("materialCreationBonus")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float bonus = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialCreationBonus(material, bonus);
} else if (name.startsWith("materialImproveBonus")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float bonus = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialImproveBonus(material, bonus);
} else if (name.startsWith("materialShatterResistance")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float resistance = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialShatterResistance(material, resistance);
} else if (name.startsWith("materialLockpickBonus")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float bonus = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialLockpickBonus(material, bonus);
} else if (name.startsWith("materialAnchorBonus")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float bonus = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialAnchorBonus(material, bonus);
} else if (name.startsWith("materialPendulumEffect")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float bonus = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialPendulumEffect(material, bonus);
} else if (name.startsWith("materialRepairSpeed")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float mult = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialRepairSpeed(material, mult);
} else if (name.startsWith("materialBashModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
double mult = Double.parseDouble(split[1]);
MaterialTweaks.addMaterialBashModifier(material, mult);
} else if (name.startsWith("materialSpellEffectModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
float mult = Float.parseFloat(split[1]);
MaterialTweaks.addMaterialSpellEffectModifier(material, mult);
} else if (name.startsWith("materialSpecificSpellEffectModifier")) {
String[] split = value.split(";");
byte material = parseMaterialType(split[0]);
String[] split2 = split[1].split(",");
MaterialTweaks.addMaterialSpecificSpellEffectModifier(material, split2);
} else if (name.startsWith("materialDifficultyModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
double mult = Double.parseDouble(split[1]);
MaterialTweaks.addMaterialDifficultyModifier(material, mult);
} else if (name.startsWith("materialActionSpeedModifier")) {
String[] split = value.split(",");
byte material = parseMaterialType(split[0]);
double mult = Double.parseDouble(split[1]);
MaterialTweaks.addMaterialActionSpeedModifier(material, mult);
} else if (name.startsWith("weaponDamage")) {
String[] split = value.split(",");
int weaponId = Integer.parseInt(split[0]);
@@ -177,166 +314,220 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
double newVal = Double.parseDouble(split[1]);
weaponSkillPenalty.put(weaponId, newVal);
} else {
Debug("Unknown config property: " + name);
logger.warning("Unknown config property: " + name);
}
}
} catch (Exception e) {
Debug("Error processing property " + name);
logger.severe("Error processing property " + name);
e.printStackTrace();
}
}
// Print values of main.java.armoury.mod configuration
this.logger.info(" -- Mod Configuration -- ");
this.logger.log(Level.INFO, "enableNonPlayerCrits: " + this.enableNonPlayerCrits);
this.logger.log(Level.INFO, "fixArmourLimitBuffBug: " + this.fixArmourLimitBuffBug);
this.logger.log(Level.INFO, "fixArmourLimitSpellEffect: " + this.fixArmourLimitSpellEffect);
this.logger.info(" -- Armour Configuration -- ");
this.logger.log(Level.INFO, "enableArmourReductionModifications: " + this.enableArmourReductionModifications);
if(enableArmourReductionModifications){
this.logger.log(Level.INFO, "unarmouredReduction: " + this.unarmouredReduction);
this.logger.info("> Armour Reduction Settings <");
for(String armourType : armourTypeReference.keySet()){
this.logger.info(armourType+" - "+((int)(armourTypeReduction.get(armourTypeReference.get(armourType))*100))+"%");
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 = 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);
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 = String.valueOf(woundType);
if(WoundAssist.woundTypeToName.containsKey(woundType)){
wound = WoundAssist.woundTypeToName.get(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 = 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 = String.valueOf(woundType);
if(WoundAssist.woundTypeToName.containsKey(woundType)){
wound = WoundAssist.woundTypeToName.get(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) +"%");
}
}
}
this.logger.log(Level.INFO, "adamantineMaterialMod: " + this.adamantineMaterialMod);
this.logger.log(Level.INFO, "glimmersteelMaterialMod: " + this.glimmersteelMaterialMod);
this.logger.log(Level.INFO, "seryllMaterialMod: " + this.seryllMaterialMod);
this.logger.log(Level.INFO, "enableCustomArmourLimitFactors: " + this.enableCustomArmourLimitFactors);
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 = String.valueOf(woundType);
if(WoundAssist.woundTypeToName.containsKey(woundType)){
wound = WoundAssist.woundTypeToName.get(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 = String.valueOf(woundType);
if(WoundAssist.woundTypeToName.containsKey(woundType)){
wound = WoundAssist.woundTypeToName.get(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));
}
logger.info("> Weapon Material Speed Settings <");
for(byte material : WeaponTweaks.materialWeaponSpeed.keySet()){
logger.info(String.format("Speed modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), WeaponTweaks.materialWeaponSpeed.get(material)*100f));
}
logger.info("> Weapon Material Parry Settings <");
for(byte material : WeaponTweaks.materialWeaponParry.keySet()){
logger.info(String.format("Parry modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), WeaponTweaks.materialWeaponParry.get(material)*100f));
}
logger.info("> Weapon Material Armour Damage Settings <");
for(byte material : WeaponTweaks.materialWeaponArmourDamage.keySet()){
logger.info(String.format("Armour Damage modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), WeaponTweaks.materialWeaponArmourDamage.get(material)*100f));
}
logger.info("> Item Material Damage Modifier Settings <");
for(byte material : MaterialTweaks.materialDamageModifier.keySet()){
logger.info(String.format("Damage modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialDamageModifier.get(material)*100f));
}
logger.info("> Item Material Decay Modifier Settings <");
for(byte material : MaterialTweaks.materialDecayModifier.keySet()){
logger.info(String.format("Decay modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialDecayModifier.get(material)*100f));
}
logger.info("> Item Material Creation Bonus Settings <");
for(byte material : MaterialTweaks.materialCreationBonus.keySet()){
logger.info(String.format("Creation bonus for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialCreationBonus.get(material)*100f));
}
logger.info("> Item Material Improve Bonus Settings <");
for(byte material : MaterialTweaks.materialImproveBonus.keySet()){
logger.info(String.format("Improve bonus for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialImproveBonus.get(material)*100f));
}
logger.info("> Item Material Shatter Resistance Settings <");
for(byte material : MaterialTweaks.materialShatterResistance.keySet()){
logger.info(String.format("Shatter resistance for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialShatterResistance.get(material)*100f));
}
logger.info("> Item Material Lockpick Bonus Settings <");
for(byte material : MaterialTweaks.materialLockpickBonus.keySet()){
logger.info(String.format("Lockpick bonus for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialLockpickBonus.get(material)*100f));
}
logger.info("> Item Material Anchor Bonus Settings <");
for(byte material : MaterialTweaks.materialAnchorBonus.keySet()){
logger.info(String.format("Anchor bonus for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialAnchorBonus.get(material)*100f));
}
logger.info("> Item Material Pendulum Effect Settings <");
for(byte material : MaterialTweaks.materialPendulumEffect.keySet()){
logger.info(String.format("Pendulum effect for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialPendulumEffect.get(material)*100f));
}
logger.info("> Item Material Repair Speed Settings <");
for(byte material : MaterialTweaks.materialRepairSpeed.keySet()){
logger.info(String.format("Repair speed for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialRepairSpeed.get(material)*100f));
}
logger.info("> Item Material Bash Modifier Settings <");
for(byte material : MaterialTweaks.materialBashModifier.keySet()){
logger.info(String.format("Bash modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialBashModifier.get(material)*100f));
}
logger.info("> Item Material Spell Effect Modifier Settings <");
for(byte material : MaterialTweaks.materialSpellEffectModifier.keySet()){
logger.info(String.format("Spell effect modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialSpellEffectModifier.get(material)*100f));
}
logger.info("> Item Material Specific Spell Effect Modifier Settings <");
for(byte material : MaterialTweaks.materialSpecificSpellEffectModifier.keySet()){
//String name = materialNameReference.containsKey(material) ? materialNameReference.get(material) : String.valueOf(material);
HashMap<Byte, Float> enchantMap = MaterialTweaks.materialSpecificSpellEffectModifier.get(material);
for(byte enchant : enchantMap.keySet()){
logger.info(String.format("Spell Effect Power for material %s with enchant %s: %.2f%%", MaterialTweaks.getMaterialName(material), enchant, enchantMap.get(enchant)*100f));
}
}
logger.info("> Item Material Difficulty Modifier Settings <");
for(byte material : MaterialTweaks.materialDifficultyModifier.keySet()){
logger.info(String.format("Difficulty modifier for material %s: %.2f%%", MaterialTweaks.getMaterialName(material), MaterialTweaks.materialDifficultyModifier.get(material)*100f));
}
logger.info("> Item Material Action Speed Modifier Settings <");
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){
this.logger.log(Level.INFO, "clothArmourLimitFactor: " + this.clothArmourLimitFactor);
this.logger.log(Level.INFO, "leatherArmourLimitFactor: " + this.leatherArmourLimitFactor);
this.logger.log(Level.INFO, "studdedArmourLimitFactor: " + this.studdedArmourLimitFactor);
this.logger.log(Level.INFO, "chainArmourLimitFactor: " + this.chainArmourLimitFactor);
this.logger.log(Level.INFO, "plateArmourLimitFactor: " + this.plateArmourLimitFactor);
this.logger.log(Level.INFO, "drakeArmourLimitFactor: " + this.drakeArmourLimitFactor);
this.logger.log(Level.INFO, "dragonscaleArmourLimitFactor: " + this.dragonscaleArmourLimitFactor);
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);
}
this.logger.info(" -- Shield Configuration -- ");
this.logger.log(Level.INFO, "enableShieldDamageEnchants: " + this.enableShieldDamageEnchants);
this.logger.info(" -- Weapon Configuration -- ");
this.logger.log(Level.INFO, "minimumSwingTime: " + this.minimumSwingTime);
this.logger.log(Level.INFO, "raresReduceSwingTime: " + this.raresReduceSwingTime);
this.logger.log(Level.INFO, "rareSwingSpeedReduction: " + this.rareSwingSpeedReduction);
this.logger.log(Level.INFO, "fixSavedSwingTimer: " + this.fixSavedSwingTimer);
this.logger.log(Level.INFO, "betterDualWield: " + this.betterDualWield);
this.Debug("Debugging messages are enabled.");
this.logger.info(" -- Configuration complete -- ");
logger.info(" -- Shield Configuration -- ");
logger.log(Level.INFO, "enableShieldDamageEnchants: " + enableShieldDamageEnchants);
logger.info(" -- Weapon Configuration -- ");
logger.log(Level.INFO, "minimumSwingTime: " + minimumSwingTime);
logger.log(Level.INFO, "raresReduceSwingTime: " + raresReduceSwingTime);
logger.log(Level.INFO, "rareSwingSpeedReduction: " + rareSwingSpeedReduction);
logger.log(Level.INFO, "fixSavedSwingTimer: " + fixSavedSwingTimer);
logger.log(Level.INFO, "betterDualWield: " + betterDualWield);
logger.info(" -- Configuration complete -- ");
}
protected void Debug(String x) {
if (this.bDebug) {
System.out.println(String.valueOf(this.getClass().getSimpleName()) + ": " + x);
System.out.flush();
this.logger.log(Level.INFO, x);
}
}
@Override
public void preInit(){
CombatTweaks.preInit(this);
ArmourTweaks.preInit(this);
ShieldTweaks.preInit(this);
CombatTweaks.preInit();
ArmourTweaks.preInit();
ShieldTweaks.preInit();
WeaponTweaks.preInit();
MaterialTweaks.preInit();
}
@Override
public void onItemTemplatesCreated(){
logger.info("Creating armour template lists...");
createArmourTemplateLists();
ArmourTweaks.onItemTemplatesCreated(this);
logger.info("Beginning onItemTemplatesCreated...");
ArmourTweaks.onItemTemplatesCreated();
}
@Override
public void onServerStarted(){
WeaponTweaks.onServerStarted(this);
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()));
}
}
}
public HashMap<String, Integer> armourNameToItemTemplate = new HashMap<>();
public ArrayList<Armour> clothArmour = new ArrayList<>();
public ArrayList<Armour> leatherArmour = new ArrayList<>();
public ArrayList<Armour> studdedArmour = new ArrayList<>();
public ArrayList<Armour> chainArmour = new ArrayList<>();
public ArrayList<Armour> plateArmour = new ArrayList<>();
public ArrayList<Armour> drakeArmour = new ArrayList<>();
public ArrayList<Armour> dragonscaleArmour = new ArrayList<>();
private 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 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);
}
private void initArmourDefaults(){
armourTypeReference.put("cloth", ArmourTypes.ARMOUR_CLOTH);
armourTypeReduction.put(ArmourTypes.ARMOUR_CLOTH, 0.4f);
armourTypeReference.put("leather", ArmourTypes.ARMOUR_LEATHER);
armourTypeReduction.put(ArmourTypes.ARMOUR_LEATHER, 0.5f);
armourTypeReference.put("studded", ArmourTypes.ARMOUR_STUDDED);
armourTypeReduction.put(ArmourTypes.ARMOUR_STUDDED, 0.55f);
armourTypeReference.put("chain", ArmourTypes.ARMOUR_CHAIN);
armourTypeReduction.put(ArmourTypes.ARMOUR_CHAIN, 0.6f);
armourTypeReference.put("plate", ArmourTypes.ARMOUR_PLATE);
armourTypeReduction.put(ArmourTypes.ARMOUR_PLATE, 0.7f);
armourTypeReference.put("drake", ArmourTypes.ARMOUR_LEATHER_DRAGON);
armourTypeReduction.put(ArmourTypes.ARMOUR_LEATHER_DRAGON, 0.7f);
armourTypeReference.put("dragonscale", ArmourTypes.ARMOUR_SCALE_DRAGON);
armourTypeReduction.put(ArmourTypes.ARMOUR_SCALE_DRAGON, 0.75f);
armourTypeReference.put("scale", ArmourTypes.ARMOUR_SCALE);
armourTypeReduction.put(ArmourTypes.ARMOUR_SCALE, 0.5f);
armourTypeReference.put("ring", ArmourTypes.ARMOUR_RING);
armourTypeReduction.put(ArmourTypes.ARMOUR_RING, 0.55f);
armourTypeReference.put("splint", ArmourTypes.ARMOUR_SPLINT);
armourTypeReduction.put(ArmourTypes.ARMOUR_SPLINT, 0.6f);
}
}

View File

@@ -39,14 +39,14 @@ public class CombatTweaks {
}
}
public static void preInit(ArmouryMod mod){
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
Class<CombatTweaks> thisClass = CombatTweaks.class;
// - Allow critical hits on creatures as well as players -
mod.enableNonPlayerCrits = false; // Disabled for now as it's not working.
if(mod.enableNonPlayerCrits){
ArmouryMod.enableNonPlayerCrits = false; // Disabled for now as it's not working.
if(ArmouryMod.enableNonPlayerCrits){
CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler");
CtClass[] attackParams1 = {
classPool.get("com.wurmonline.server.creatures.Creature"),
@@ -82,7 +82,7 @@ public class CombatTweaks {
}
// - Fix the Armour Limit being shown in the buff bar at all times -
if(mod.fixArmourLimitBuffBug){
if(ArmouryMod.fixArmourLimitBuffBug){
CtClass ctPlayerInfo = classPool.get("com.wurmonline.server.players.PlayerInfo");
String replace = ""
+ "communicator.sendRemoveSpellEffect(com.wurmonline.server.creatures.SpellEffectsEnum.ARMOUR_LIMIT_NONE);"
@@ -123,7 +123,7 @@ public class CombatTweaks {
}
// - Make spell effects hud show your armour limit properly - //
if(mod.fixArmourLimitSpellEffect){
if(ArmouryMod.fixArmourLimitSpellEffect){
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");
@@ -131,16 +131,16 @@ public class CombatTweaks {
}
// - Change the minimum swing timer - //
if(mod.minimumSwingTime != 3.0f){
if(ArmouryMod.minimumSwingTime != 3.0f){
CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler");
String strBuilder = "";
if(mod.raresReduceSwingTime){
if(ArmouryMod.raresReduceSwingTime){
strBuilder += ""
+ "if(weapon.getRarity() > 0){"
+ " calcspeed -= weapon.getRarity()*"+String.valueOf(mod.rareSwingSpeedReduction)+"f;"
+ " calcspeed -= weapon.getRarity()*"+String.valueOf(ArmouryMod.rareSwingSpeedReduction)+"f;"
+ "}";
}
strBuilder += "$_ = $proceed("+String.valueOf(mod.minimumSwingTime)+"f, $2);";
strBuilder += "$_ = $proceed("+String.valueOf(ArmouryMod.minimumSwingTime)+"f, $2);";
final String stringReplace = strBuilder;
CtClass[] params1 = {
@@ -173,7 +173,7 @@ public class CombatTweaks {
}
// - Saved swing timer fix -
if(mod.fixSavedSwingTimer){
if(ArmouryMod.fixSavedSwingTimer){
CtClass ctCreature = classPool.get("com.wurmonline.server.creatures.Creature");
String replace = "$_ = $proceed($1, new Float(0f));";
Util.setReason("Fix saved swing timer.");
@@ -190,7 +190,7 @@ public class CombatTweaks {
// - Attempt for a better dual wield system -
// This really doesn't work. I don't get dual wield and why it's so bad.
if(mod.betterDualWield){
if(ArmouryMod.betterDualWield){
CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler");
CtClass[] params1 = {
classPool.get("com.wurmonline.server.creatures.Creature"),
@@ -201,7 +201,7 @@ public class CombatTweaks {
};
String desc = Descriptor.ofMethod(CtClass.booleanType, params1);
String replace = "if(this.creature.isPlayer()){"
+ " com.wurmonline.server.items.Item weapon = CombatTweaks.handleDualWieldAttack(this, opponent, delta);"
+ " com.wurmonline.server.items.Item weapon = "+CombatTweaks.class.getName()+".handleDualWieldAttack(this, opponent, delta);"
+ " if(weapon != null){"
+ " lDead = attack(opponent, weapon, true);"
+ " }"

View File

@@ -0,0 +1,478 @@
package mod.sin.armoury;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.items.ItemSpellEffects;
import com.wurmonline.server.items.Materials;
import com.wurmonline.server.skills.Skill;
import com.wurmonline.server.spells.SpellEffect;
import com.wurmonline.shared.constants.Enchants;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import mod.sin.lib.Util;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;
public class MaterialTweaks {
public static Logger logger = Logger.getLogger(MaterialTweaks.class.getName());
public static HashMap<Byte, Float> materialDamageModifier = new HashMap<>();
public static HashMap<Byte, Float> materialDecayModifier = new HashMap<>();
public static HashMap<Byte, Float> materialCreationBonus = new HashMap<>();
public static HashMap<Byte, Float> materialImproveBonus = new HashMap<>();
public static HashMap<Byte, Float> materialShatterResistance = new HashMap<>();
public static HashMap<Byte, Float> materialLockpickBonus = new HashMap<>();
public static HashMap<Byte, Float> materialAnchorBonus = new HashMap<>();
public static HashMap<Byte, Float> materialPendulumEffect = new HashMap<>();
public static HashMap<Byte, Float> materialRepairSpeed = new HashMap<>();
public static HashMap<Byte, Double> materialBashModifier = new HashMap<>();
public static HashMap<Byte, Float> materialSpellEffectModifier = new HashMap<>();
public static HashMap<Byte, HashMap<Byte, Float>> materialSpecificSpellEffectModifier = new HashMap<>();
public static HashMap<Byte, Double> materialDifficultyModifier = new HashMap<>();
public static HashMap<Byte, Double> materialActionSpeedModifier = new HashMap<>();
public static float newGetMaterialDamageModifier(Item item){
byte material = item.getMaterial();
if(materialDamageModifier.containsKey(material)){
//logger.info(String.format("Modifying damage by %.2f%% due to material type %s.", materialDamageModifier.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialDamageModifier.get(material);
}
return 1.0f;
}
public static float newGetMaterialDecayModifier(Item item){
byte material = item.getMaterial();
if(materialDecayModifier.containsKey(material)){
//logger.info(String.format("Modifying decay by %.2f%% due to material type %s.", materialDecayModifier.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialDecayModifier.get(material);
}
return 1.0f;
}
public static float newGetMaterialCreationBonus(byte material){
if(materialCreationBonus.containsKey(material)){
//logger.info(String.format("Modifying creation bonus by %.2f%% due to material type %s.", materialCreationBonus.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialCreationBonus.get(material);
}
return 0.0f;
}
public static float newGetMaterialImpBonus(Item item){
byte material = item.getMaterial();
if(materialImproveBonus.containsKey(material)){
//logger.info(String.format("Modifying improve bonus by %.2f%% due to material type %s.", materialImproveBonus.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialImproveBonus.get(material);
}
return 1.0f;
}
public static float newGetMaterialShatterMod(byte material){
if(materialShatterResistance.containsKey(material)){
//logger.info(String.format("Modifying shatter resistance by %.2f%% due to material type %s.", materialShatterResistance.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialShatterResistance.get(material);
}
return 0.0f;
}
public static float newGetMaterialLockpickBonus(byte material){
if(materialLockpickBonus.containsKey(material)){
//logger.info(String.format("Modifying lockpick bonus by %.2f%% due to material type %s.", materialLockpickBonus.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialLockpickBonus.get(material);
}
return 0.0f;
}
public static float newGetMaterialAnchorBonus(byte material){
if(materialAnchorBonus.containsKey(material)){
//logger.info(String.format("Modifying anchor bonus by %.2f%% due to material type %s.", materialAnchorBonus.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialAnchorBonus.get(material);
}
return 1.0f;
}
public static float newGetMaterialPendulumModifier(byte material){
if(materialPendulumEffect.containsKey(material)){
//logger.info(String.format("Modifying pendulum effect by %.2f%% due to material type %s.", materialPendulumEffect.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialPendulumEffect.get(material);
}
return 1.0f;
}
public static float newGetMaterialRepairTimeMod(Item item){
byte material = item.getMaterial();
if(materialRepairSpeed.containsKey(material)){
//logger.info(String.format("Modifying repair speed by %.2f%% due to material type %s.", materialRepairSpeed.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialRepairSpeed.get(material);
}
return 1.0f;
}
public static double newGetMaterialBashModifier(byte material){
if(materialBashModifier.containsKey(material)){
//logger.info(String.format("Modifying bash by %.2f%% due to material type %s.", materialBashModifier.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialBashModifier.get(material);
}
return 1.0f;
}
public static float newGetBonusForSpellEffect(Item item, byte aEnchantment){
ItemSpellEffects eff = item.getSpellEffects();
if (eff != null) {
SpellEffect skillgain = eff.getSpellEffect(aEnchantment);
if(skillgain != null) {
float newPower = skillgain.power;
byte material = item.getMaterial();
if(materialSpellEffectModifier.containsKey(material)) {
newPower *= materialSpellEffectModifier.get(material);
//logger.info(String.format("Modifying spell power by %.2f%% due to material type %s. [%s]", materialSpellEffectModifier.get(material) * 100d, MaterialTweaks.getMaterialName(material), newPower));
}
if(materialSpecificSpellEffectModifier.containsKey(material) && materialSpecificSpellEffectModifier.get(material).containsKey(aEnchantment)) {
newPower *= materialSpecificSpellEffectModifier.get(material).get(aEnchantment);
//logger.info(String.format("Modifying spell power of enchant %s by %.2f%% due to material type %s. [%s]", aEnchantment, materialSpecificSpellEffectModifier.get(material).get(aEnchantment) * 100d, MaterialTweaks.getMaterialName(material), newPower));
}
return newPower;
}
}
return 0.0f;
}
public static double getNewDifficulty(Skill skill, double diff, Item item) {
if(item != null){
byte material = item.getMaterial();
if(materialDifficultyModifier.containsKey(material)){
diff *= materialDifficultyModifier.get(material);
//logger.info(String.format("Modifying difficulty by %.2f%% due to material type %s. [%s]", materialDifficultyModifier.get(material) * 100d, MaterialTweaks.getMaterialName(material), diff));
}
}
return diff;
}
public static double getMaterialSpeedModifier(Item item){
if(item != null){
byte material = item.getMaterial();
if(materialActionSpeedModifier.containsKey(material)){
//logger.info(String.format("Modifying action speed by %.2f%% due to material type %s.", materialActionSpeedModifier.get(material) * 100d, MaterialTweaks.getMaterialName(material)));
return materialActionSpeedModifier.get(material);
}
}
return 1.0f;
}
public static void addMaterialDamageModifier(byte material, float mult){
materialDamageModifier.put(material, mult);
}
public static void addMaterialDecayModifier(byte material, float mult){
materialDecayModifier.put(material, mult);
}
public static void addMaterialCreationBonus(byte material, float bonus){
materialCreationBonus.put(material, bonus);
}
public static void addMaterialImproveBonus(byte material, float bonus){
materialImproveBonus.put(material, bonus);
}
public static void addMaterialShatterResistance(byte material, float resistance){
materialShatterResistance.put(material, resistance);
}
public static void addMaterialLockpickBonus(byte material, float bonus){
materialLockpickBonus.put(material, bonus);
}
public static void addMaterialAnchorBonus(byte material, float bonus){
materialAnchorBonus.put(material, bonus);
}
public static void addMaterialPendulumEffect(byte material, float bonus){
materialPendulumEffect.put(material, bonus);
}
public static void addMaterialRepairSpeed(byte material, float mult){
materialRepairSpeed.put(material, mult);
}
public static void addMaterialBashModifier(byte material, double mult){
materialBashModifier.put(material, mult);
}
public static void addMaterialSpellEffectModifier(byte material, float mult){
materialSpellEffectModifier.put(material, mult);
}
public static void addMaterialActionSpeedModifier(byte material, double mult){
materialActionSpeedModifier.put(material, mult);
}
protected static ArrayList<Byte> getEnchants(String[] split){
ArrayList<Byte> enchants = new ArrayList<>();
int i = 0;
while(i < split.length-1){
if(split[i].equalsIgnoreCase("damage")){
enchants.add(Enchants.BUFF_BLOODTHIRST);
enchants.add(Enchants.BUFF_FLAMING_AURA);
enchants.add(Enchants.BUFF_FROSTBRAND);
enchants.add(Enchants.BUFF_ROTTING_TOUCH);
enchants.add(Enchants.BUFF_VENOM);
}else if(split[i].equalsIgnoreCase("skilling")){
enchants.add(Enchants.BUFF_BLESSINGDARK);
enchants.add(Enchants.BUFF_WIND_OF_AGES);
enchants.add(Enchants.BUFF_CIRCLE_CUNNING);
enchants.add((byte) 120);
}else if(split[i].equalsIgnoreCase("armour")){
enchants.add(Enchants.BUFF_SHARED_PAIN);
enchants.add(Enchants.BUFF_WEBARMOUR);
}else{
enchants.add(Byte.parseByte(split[i]));
}
i++;
}
return enchants;
}
public static void addMaterialSpecificSpellEffectModifier(byte material, String[] split){
float modifier = Float.parseFloat(split[split.length-1]);
ArrayList<Byte> enchants = getEnchants(split);
for(byte enchant : enchants) {
HashMap<Byte, Float> map;
if (materialSpecificSpellEffectModifier.containsKey(material)) {
map = materialSpecificSpellEffectModifier.get(material);
} else {
map = new HashMap<>();
}
map.put(enchant, modifier);
materialSpecificSpellEffectModifier.put(material, map);
}
}
public static void addMaterialDifficultyModifier(byte material, double mult){
materialDifficultyModifier.put(material, mult);
}
public static String getMaterialName(byte material){
String name = Materials.convertMaterialByteIntoString(material);
if(!name.equals("")){
return name;
}
return String.valueOf(material);
}
protected static void initializeMaterialMaps(){
// Material damage taken modifiers
materialDamageModifier.put(Materials.MATERIAL_ADAMANTINE, 0.40f);
materialDamageModifier.put(Materials.MATERIAL_BRASS, 0.95f);
materialDamageModifier.put(Materials.MATERIAL_BRONZE, 0.90f);
materialDamageModifier.put(Materials.MATERIAL_COPPER, 1.15f);
materialDamageModifier.put(Materials.MATERIAL_GLIMMERSTEEL, 0.60f);
materialDamageModifier.put(Materials.MATERIAL_GOLD, 1.20f);
materialDamageModifier.put(Materials.MATERIAL_LEAD, 1.30f);
materialDamageModifier.put(Materials.MATERIAL_SERYLL, 0.50f);
materialDamageModifier.put(Materials.MATERIAL_SILVER, 1.025f);
materialDamageModifier.put(Materials.MATERIAL_STEEL, 0.80f);
materialDamageModifier.put(Materials.MATERIAL_TIN, 1.20f);
materialDamageModifier.put(Materials.MATERIAL_ZINC, 1.25f);
// Material decay taken modifiers
materialDecayModifier.put(Materials.MATERIAL_ADAMANTINE, 0.40f);
materialDecayModifier.put(Materials.MATERIAL_BRASS, 0.95f);
materialDecayModifier.put(Materials.MATERIAL_BRONZE, 0.85f);
materialDecayModifier.put(Materials.MATERIAL_COPPER, 0.95f);
materialDecayModifier.put(Materials.MATERIAL_GLIMMERSTEEL, 0.60f);
materialDecayModifier.put(Materials.MATERIAL_GOLD, 0.40f);
materialDecayModifier.put(Materials.MATERIAL_LEAD, 0.80f);
materialDecayModifier.put(Materials.MATERIAL_SERYLL, 0.50f);
materialDecayModifier.put(Materials.MATERIAL_SILVER, 0.70f);
materialDecayModifier.put(Materials.MATERIAL_STEEL, 0.70f);
materialDecayModifier.put(Materials.MATERIAL_TIN, 0.925f);
materialDecayModifier.put(Materials.MATERIAL_ZINC, 1.20f);
// Material creation bonus
materialCreationBonus.put(Materials.MATERIAL_BRASS, 0.1f);
materialCreationBonus.put(Materials.MATERIAL_BRONZE, 0.05f);
materialCreationBonus.put(Materials.MATERIAL_LEAD, 0.05f);
materialCreationBonus.put(Materials.MATERIAL_TIN, 0.05f);
// Material improve bonus
materialImproveBonus.put(Materials.MATERIAL_BRASS, 1.025f);
materialImproveBonus.put(Materials.MATERIAL_COPPER, 1.05f);
materialImproveBonus.put(Materials.MATERIAL_LEAD, 1.10f);
materialImproveBonus.put(Materials.MATERIAL_TIN, 1.025f);
materialImproveBonus.put(Materials.MATERIAL_ZINC, 1.075f);
// Material shatter resistance
materialShatterResistance.put(Materials.MATERIAL_ADAMANTINE, 0.15f);
materialShatterResistance.put(Materials.MATERIAL_GLIMMERSTEEL, 0.25f);
materialShatterResistance.put(Materials.MATERIAL_GOLD, 0.20f);
materialShatterResistance.put(Materials.MATERIAL_SERYLL, 1.00f);
materialShatterResistance.put(Materials.MATERIAL_SILVER, 0.10f);
// Material lockpick bonus
materialLockpickBonus.put(Materials.MATERIAL_ADAMANTINE, 0.05f);
materialLockpickBonus.put(Materials.MATERIAL_COPPER, -0.05f);
materialLockpickBonus.put(Materials.MATERIAL_GLIMMERSTEEL, 0.05f);
materialLockpickBonus.put(Materials.MATERIAL_GOLD, -0.025f);
materialLockpickBonus.put(Materials.MATERIAL_LEAD, -0.05f);
materialLockpickBonus.put(Materials.MATERIAL_SERYLL, 0.05f);
materialLockpickBonus.put(Materials.MATERIAL_SILVER, 0.025f);
materialLockpickBonus.put(Materials.MATERIAL_STEEL, 0.05f);
materialLockpickBonus.put(Materials.MATERIAL_TIN, -0.025f);
materialLockpickBonus.put(Materials.MATERIAL_ZINC, -0.025f);
// Material anchor bonus
materialAnchorBonus.put(Materials.MATERIAL_ADAMANTINE, 1.50f);
materialAnchorBonus.put(Materials.MATERIAL_BRASS, 0.90f);
materialAnchorBonus.put(Materials.MATERIAL_BRONZE, 0.85f);
materialAnchorBonus.put(Materials.MATERIAL_COPPER, 0.95f);
materialAnchorBonus.put(Materials.MATERIAL_GLIMMERSTEEL, 1.25f);
materialAnchorBonus.put(Materials.MATERIAL_GOLD, 1.70f);
materialAnchorBonus.put(Materials.MATERIAL_IRON, 0.85f);
materialAnchorBonus.put(Materials.MATERIAL_LEAD, 1.00f);
materialAnchorBonus.put(Materials.MATERIAL_SERYLL, 1.25f);
materialAnchorBonus.put(Materials.MATERIAL_SILVER, 0.975f);
materialAnchorBonus.put(Materials.MATERIAL_STEEL, 0.85f);
materialAnchorBonus.put(Materials.MATERIAL_TIN, 0.80f);
materialAnchorBonus.put(Materials.MATERIAL_ZINC, 0.75f);
// Material pendulum effect
materialPendulumEffect.put(Materials.MATERIAL_ADAMANTINE, 1.15f);
materialPendulumEffect.put(Materials.MATERIAL_BRASS, 1.025f);
materialPendulumEffect.put(Materials.MATERIAL_BRONZE, 1.05f);
materialPendulumEffect.put(Materials.MATERIAL_COPPER, 0.95f);
materialPendulumEffect.put(Materials.MATERIAL_GLIMMERSTEEL, 1.20f);
materialPendulumEffect.put(Materials.MATERIAL_GOLD, 1.10f);
materialPendulumEffect.put(Materials.MATERIAL_LEAD, 0.90f);
materialPendulumEffect.put(Materials.MATERIAL_SERYLL, 1.25f);
materialPendulumEffect.put(Materials.MATERIAL_SILVER, 1.05f);
materialPendulumEffect.put(Materials.MATERIAL_STEEL, 1.025f);
materialPendulumEffect.put(Materials.MATERIAL_TIN, 0.95f);
materialPendulumEffect.put(Materials.MATERIAL_ZINC, 0.95f);
// Material repair speed
materialRepairSpeed.put(Materials.MATERIAL_ADAMANTINE, 0.90f);
materialRepairSpeed.put(Materials.MATERIAL_BRONZE, 0.975f);
materialRepairSpeed.put(Materials.MATERIAL_COPPER, 1.075f);
materialRepairSpeed.put(Materials.MATERIAL_GLIMMERSTEEL, 0.95f);
materialRepairSpeed.put(Materials.MATERIAL_GOLD, 1.05f);
materialRepairSpeed.put(Materials.MATERIAL_LEAD, 1.10f);
materialRepairSpeed.put(Materials.MATERIAL_SERYLL, 0.95f);
materialRepairSpeed.put(Materials.MATERIAL_STEEL, 0.975f);
materialRepairSpeed.put(Materials.MATERIAL_TIN, 1.025f);
materialRepairSpeed.put(Materials.MATERIAL_ZINC, 1.05f);
// Material bash modifier
materialBashModifier.put(Materials.MATERIAL_ADAMANTINE, 1.075d);
materialBashModifier.put(Materials.MATERIAL_BRASS, 1.05d);
materialBashModifier.put(Materials.MATERIAL_BRONZE, 1.025d);
materialBashModifier.put(Materials.MATERIAL_COPPER, 0.90d);
materialBashModifier.put(Materials.MATERIAL_GLIMMERSTEEL, 1.10d);
materialBashModifier.put(Materials.MATERIAL_GOLD, 1.10d);
materialBashModifier.put(Materials.MATERIAL_LEAD, 1.20d);
materialBashModifier.put(Materials.MATERIAL_SERYLL, 1.075d);
materialBashModifier.put(Materials.MATERIAL_SILVER, 1.10d);
materialBashModifier.put(Materials.MATERIAL_STEEL, 1.05d);
materialBashModifier.put(Materials.MATERIAL_TIN, 0.90d);
materialBashModifier.put(Materials.MATERIAL_ZINC, 0.85d);
}
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
final Class<MaterialTweaks> thisClass = MaterialTweaks.class;
String replace;
if(ArmouryMod.enableItemMaterialChanges){
Util.setReason("Enable material damage taken modifications.");
CtClass ctItem = classPool.get("com.wurmonline.server.items.Item");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialDamageModifier($0);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialDamageModifier", replace);
Util.setReason("Enable material decay modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialDecayModifier($0);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialDecayModifier", replace);
Util.setReason("Enable material creation bonus modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialCreationBonus($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialCreationBonus", replace);
Util.setReason("Enable material improvement bonus modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialImpBonus($0);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialImpBonus", replace);
Util.setReason("Enable material shatter resistance modifications.");
CtClass ctSpell = classPool.get("com.wurmonline.server.spells.Spell");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialShatterMod($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctSpell, "getMaterialShatterMod", replace);
Util.setReason("Enable material lockpick bonus modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialLockpickBonus($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialLockpickBonus", replace);
Util.setReason("Enable material anchor bonus modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialAnchorBonus($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialAnchorBonus", replace);
Util.setReason("Enable material pendulum effect modifications.");
CtClass ctLocates = classPool.get("com.wurmonline.server.behaviours.Locates");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialPendulumModifier($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctLocates, "getMaterialPendulumModifier", replace);
Util.setReason("Enable material repair speed modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialRepairTimeMod($0);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getMaterialRepairTimeMod", replace);
Util.setReason("Enable material bash modifications.");
CtClass ctWeapon = classPool.get("com.wurmonline.server.combat.Weapon");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetMaterialBashModifier($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctWeapon, "getMaterialBashModifier", replace);
Util.setReason("Enable material spell power modifications.");
replace = "{"
+ " return "+MaterialTweaks.class.getName()+".newGetBonusForSpellEffect($0, $1);"
+ "}";
Util.setBodyDeclared(thisClass, ctItem, "getBonusForSpellEffect", replace);
Util.setReason("Enable material skill difficulty modifications.");
CtClass ctSkill = classPool.get("com.wurmonline.server.skills.Skill");
replace = "$1 = "+MaterialTweaks.class.getName()+".getNewDifficulty(this, $1, $2);";
Util.insertBeforeDeclared(thisClass, ctSkill, "checkAdvance", replace);
Util.setReason("Enable material action speed modifications.");
CtClass ctActions = classPool.get("com.wurmonline.server.behaviours.Actions");
replace = "$_ = $proceed($$)*"+MaterialTweaks.class.getName()+".getMaterialSpeedModifier(source);";
Util.instrumentDeclared(thisClass, ctActions, "getStandardActionTime", "getStaminaModiferFor", replace);
Util.instrumentDeclared(thisClass, ctActions, "getQuickActionTime", "getStaminaModiferFor", replace);
Util.instrumentDeclared(thisClass, ctActions, "getVariableActionTime", "getStaminaModiferFor", replace);
Util.instrumentDeclared(thisClass, ctActions, "getSlowActionTime", "getStaminaModiferFor", replace);
Util.instrumentDeclared(thisClass, ctActions, "getPickActionTime", "getStaminaModiferFor", replace);
Util.instrumentDeclared(thisClass, ctActions, "getItemCreationTime", "getStaminaModiferFor", replace);
}
} catch (NotFoundException e) {
e.printStackTrace();
}
}
}

View File

@@ -18,6 +18,7 @@ import javassist.NotFoundException;
public class ShieldTweaks {
public static Logger logger = Logger.getLogger(ShieldTweaks.class.getName());
public static boolean checkShieldSpeed(Item shield){
if ((shield != null)) {
return (shield.getSpellSpeedBonus() > Server.rand.nextInt(500));
@@ -50,16 +51,16 @@ public class ShieldTweaks {
playSound = true;
}
if(playSound){
SoundPlayer.playSound(attacker.getTemplate().getHitSound(attacker.getSex()), attacker.getTileX(), attacker.getTileY(), true, 0.3f);
SoundPlayer.playSound(attacker.getTemplate().getHitSound(attacker.getSex()), attacker.getTileX(), attacker.getTileY(), attacker.isOnSurface(), 0.3f);
}
}
}
public static void preInit(ArmouryMod mod){
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
Class<ShieldTweaks> thisClass = ShieldTweaks.class;
if(mod.enableShieldDamageEnchants){
if(ArmouryMod.enableShieldDamageEnchants){
CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler");
String replace = ShieldTweaks.class.getName()+".doSharedPain(this.creature, defender, defShield);"
+ "$_ = $proceed($$);";
@@ -75,7 +76,7 @@ public class ShieldTweaks {
}
});*/
}
if(mod.enableShieldSpeedEnchants){
if(ArmouryMod.enableShieldSpeedEnchants){
CtClass ctCombatHandler = classPool.get("com.wurmonline.server.creatures.CombatHandler");
String insert = "if("+ShieldTweaks.class.getName()+".checkShieldSpeed(defender.getShield())){"
+ " defender.getCombatHandler().usedShieldThisRound--;"

View File

@@ -1,17 +1,96 @@
package mod.sin.armoury;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import com.wurmonline.server.items.Item;
import com.wurmonline.server.items.Materials;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.NotFoundException;
import mod.sin.lib.Util;
import org.gotti.wurmunlimited.modloader.ReflectionUtil;
import com.wurmonline.server.combat.Weapon;
import com.wurmonline.server.items.ItemTemplate;
import com.wurmonline.server.items.ItemTemplateFactory;
import org.gotti.wurmunlimited.modloader.classhooks.HookManager;
public class WeaponTweaks {
public static Logger logger = Logger.getLogger(WeaponTweaks.class.getName());
public static Map<Integer, Weapon> weapons;
public static Map<Integer, Weapon> weapons; // Mirror of the Weapon class map
public static HashMap<Byte, Double> materialWeaponDamage = new HashMap<>();
public static HashMap<Byte, Float> materialWeaponSpeed = new HashMap<>();
public static HashMap<Byte, Float> materialWeaponParry = new HashMap<>();
public static HashMap<Byte, Double> materialWeaponArmourDamage = new HashMap<>();
public static double newGetMaterialDamageBonus(byte material){
if(materialWeaponDamage.containsKey(material)){
//logger.info(String.format("Modifying damage by %.2f%% due to material type %s.", materialWeaponDamage.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialWeaponDamage.get(material);
}
return 1.0d;
}
public static float newGetBaseSpeedForWeapon(Item weapon){
if (weapon == null || weapon.isBodyPartAttached()) {
return 1.0f;
}
if(weapons.containsKey(weapon.getTemplateId())){
Weapon weap = weapons.get(weapon.getTemplateId());
try {
float speed = ReflectionUtil.getPrivateField(weap, ReflectionUtil.getField(weap.getClass(), "speed"));
//logger.info("Base speed: "+speed);
byte material = weapon.getMaterial();
if(materialWeaponSpeed.containsKey(material)){
speed *= materialWeaponSpeed.get(material);
//logger.info(String.format("Found material %s, modifying speed by %.2f%%. New speed: %s", MaterialTweaks.getMaterialName(material), materialWeaponSpeed.get(material)*100f, speed));
}
return speed;
} catch (IllegalAccessException | NoSuchFieldException e) {
logger.warning("Could not find valid weapon speed for "+weapon.getName()+" ("+weapon.getTemplateId()+")");
e.printStackTrace();
}
}else{
logger.warning("Weapon map does not contain entry for "+weapon.getName()+" ("+weapon.getTemplateId()+")");
}
return 20.0f;
}
public static float newGetMaterialParryBonus(byte material){
if(materialWeaponParry.containsKey(material)){
//logger.info(String.format("Modifying parry by %.2f%% due to material type %s.", materialWeaponParry.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialWeaponParry.get(material);
}
return 1.0f;
}
public static double newGetMaterialArmourDamageBonus(byte material){
if(materialWeaponArmourDamage.containsKey(material)){
//logger.info(String.format("Modifying armour damage by %.2f%% due to material type %s.", materialWeaponArmourDamage.get(material)*100d, MaterialTweaks.getMaterialName(material)));
return materialWeaponArmourDamage.get(material);
}
return 1.0d;
}
public static void addMaterialWeaponDamage(byte material, double mult){
materialWeaponDamage.put(material, mult);
}
public static void addMaterialWeaponSpeed(byte material, float mult){
materialWeaponSpeed.put(material, mult);
}
public static void addMaterialWeaponParry(byte material, float mult){
materialWeaponParry.put(material, mult);
}
public static void addMaterialWeaponArmourDamage(byte material, double mult){
materialWeaponArmourDamage.put(material, mult);
}
public static void printWeapons(){
try{
@@ -37,14 +116,14 @@ public class WeaponTweaks {
}
}
public static void editWeaponStats(ArmouryMod mod){
public static void editWeaponStats(){
try {
Weapon cw;
ItemTemplate it;
String tweakType;
tweakType = "damage";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponDamage.keySet()){
for(int id : ArmouryMod.weaponDamage.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid.");
@@ -56,7 +135,7 @@ public class WeaponTweaks {
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"));
float newValue = mod.weaponDamage.get(id);
float newValue = ArmouryMod.weaponDamage.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -68,7 +147,7 @@ public class WeaponTweaks {
}
tweakType = "speed";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponSpeed.keySet()){
for(int id : ArmouryMod.weaponSpeed.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration.");
@@ -80,7 +159,7 @@ public class WeaponTweaks {
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"));
float newValue = mod.weaponSpeed.get(id);
float newValue = ArmouryMod.weaponSpeed.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -92,7 +171,7 @@ public class WeaponTweaks {
}
tweakType = "crit chance";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponCritChance.keySet()){
for(int id : ArmouryMod.weaponCritChance.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration.");
@@ -104,7 +183,7 @@ public class WeaponTweaks {
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"));
float newValue = mod.weaponCritChance.get(id);
float newValue = ArmouryMod.weaponCritChance.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -116,7 +195,7 @@ public class WeaponTweaks {
}
tweakType = "reach";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponReach.keySet()){
for(int id : ArmouryMod.weaponReach.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration.");
@@ -128,7 +207,7 @@ public class WeaponTweaks {
continue;
}
int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"));
int newValue = mod.weaponReach.get(id);
int newValue = ArmouryMod.weaponReach.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -140,7 +219,7 @@ public class WeaponTweaks {
}
tweakType = "weight group";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponWeightGroup.keySet()){
for(int id : ArmouryMod.weaponWeightGroup.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration.");
@@ -152,7 +231,7 @@ public class WeaponTweaks {
continue;
}
int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"));
int newValue = mod.weaponWeightGroup.get(id);
int newValue = ArmouryMod.weaponWeightGroup.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -164,7 +243,7 @@ public class WeaponTweaks {
}
tweakType = "parry percent";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponParryPercent.keySet()){
for(int id : ArmouryMod.weaponParryPercent.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration.");
@@ -176,7 +255,7 @@ public class WeaponTweaks {
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"));
float newValue = mod.weaponParryPercent.get(id);
float newValue = ArmouryMod.weaponParryPercent.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -188,7 +267,7 @@ public class WeaponTweaks {
}
tweakType = "skill penalty";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponSkillPenalty.keySet()){
for(int id : ArmouryMod.weaponSkillPenalty.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid. Please double check your configuration.");
@@ -200,7 +279,7 @@ public class WeaponTweaks {
continue;
}
double oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"));
double newValue = mod.weaponSkillPenalty.get(id);
double newValue = ArmouryMod.weaponSkillPenalty.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
@@ -214,15 +293,82 @@ public class WeaponTweaks {
e.printStackTrace();
}
}
public static void initializeWeaponMaps(){
// Material weapon damage
materialWeaponDamage.put(Materials.MATERIAL_ADAMANTINE, 1.1d);
materialWeaponDamage.put(Materials.MATERIAL_BRASS, 0.99d);
materialWeaponDamage.put(Materials.MATERIAL_BRONZE, 0.985d);
materialWeaponDamage.put(Materials.MATERIAL_COPPER, 0.65d);
materialWeaponDamage.put(Materials.MATERIAL_GOLD, 0.975d);
materialWeaponDamage.put(Materials.MATERIAL_LEAD, 0.5d);
materialWeaponDamage.put(Materials.MATERIAL_SERYLL, 1.05d);
materialWeaponDamage.put(Materials.MATERIAL_TIN, 0.925d);
materialWeaponDamage.put(Materials.MATERIAL_ZINC, 0.9d);
// Material weapon speed
materialWeaponSpeed.put(Materials.MATERIAL_GLIMMERSTEEL, 0.9f);
materialWeaponSpeed.put(Materials.MATERIAL_GOLD, 1.05f);
materialWeaponSpeed.put(Materials.MATERIAL_SERYLL, 0.95f);
materialWeaponSpeed.put(Materials.MATERIAL_TIN, 0.96f);
materialWeaponSpeed.put(Materials.MATERIAL_ZINC, 0.95f);
// Material weapon parry
materialWeaponParry.put(Materials.MATERIAL_SILVER, 1.025f);
materialWeaponParry.put(Materials.MATERIAL_TIN, 1.05f);
// Material weapon armour damage
materialWeaponArmourDamage.put(Materials.MATERIAL_BRASS, 1.05d);
materialWeaponArmourDamage.put(Materials.MATERIAL_BRONZE, 1.075d);
materialWeaponArmourDamage.put(Materials.MATERIAL_GOLD, 1.05d);
materialWeaponArmourDamage.put(Materials.MATERIAL_STEEL, 1.025d);
}
public static void preInit(){
try {
ClassPool classPool = HookManager.getInstance().getClassPool();
final Class<WeaponTweaks> thisClass = WeaponTweaks.class;
String replace;
if(ArmouryMod.enableWeaponMaterialChanges){
Util.setReason("Enable weapon material damage modifications.");
CtClass ctWeapon = classPool.get("com.wurmonline.server.combat.Weapon");
replace = "{"
+ " return "+WeaponTweaks.class.getName()+".newGetMaterialDamageBonus($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctWeapon, "getMaterialDamageBonus", replace);
Util.setReason("Enable weapon material speed modifications.");
replace = "{"
+ " return "+WeaponTweaks.class.getName()+".newGetBaseSpeedForWeapon($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctWeapon, "getBaseSpeedForWeapon", replace);
Util.setReason("Enable weapon material parry modifications.");
replace = "{"
+ " return "+WeaponTweaks.class.getName()+".newGetMaterialParryBonus($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctWeapon, "getMaterialParryBonus", replace);
Util.setReason("Enable weapon material armour damage modifications.");
replace = "{"
+ " return "+WeaponTweaks.class.getName()+".newGetMaterialArmourDamageBonus($1);"
+ "}";
Util.setBodyDeclared(thisClass, ctWeapon, "getMaterialArmourDamageBonus", replace);
}
} catch (NotFoundException e) {
e.printStackTrace();
}
}
public static void onServerStarted(ArmouryMod mod){
public static void onServerStarted(){
try {
logger.info("Beginning WeaponTweaks initialization...");
weapons = ReflectionUtil.getPrivateField(Weapon.class, ReflectionUtil.getField(Weapon.class, "weapons"));
//printWeapons(); // For debugging/information purposes
editWeaponStats(mod);
editWeaponStats();
//printWeapons(); // For debugging/information purposes

View File

@@ -0,0 +1,28 @@
package mod.sin.armoury;
import java.util.HashMap;
import java.util.logging.Logger;
public class WoundAssist {
public static Logger logger = Logger.getLogger(WoundAssist.class.getName());
public static HashMap<String, Byte> woundNameToType = new HashMap<>();
public static HashMap<Byte, String> woundTypeToName = new HashMap<>();
public static void initializeWoundMaps(){
woundNameToType.put("crush", (byte) 0);
woundNameToType.put("slash", (byte) 1);
woundNameToType.put("pierce", (byte) 2);
woundNameToType.put("bite", (byte) 3);
woundNameToType.put("burn", (byte) 4);
woundNameToType.put("poison", (byte) 5);
woundNameToType.put("infection", (byte) 6);
woundNameToType.put("water", (byte) 7);
woundNameToType.put("cold", (byte) 8);
woundNameToType.put("internal", (byte) 9);
woundNameToType.put("acid", (byte) 10);
for(String name : woundNameToType.keySet()){
woundTypeToName.put(woundNameToType.get(name), name);
}
}
}