Minor code cleanup.

This commit is contained in:
Sindusk
2018-04-01 22:09:39 -04:00
parent 3647c7e321
commit d46b52b101
5 changed files with 179 additions and 194 deletions

View File

@@ -105,7 +105,7 @@ public class ArmourTweaks {
if(mod.enableArmourMovementModifications){
logger.info("Starting armour movement modifications...");
for(String armourName : mod.armourMovement.keySet()){
int armourTemplate = 0;
int armourTemplate;
if(mod.armourNameToItemTemplate.containsKey(armourName)){
armourTemplate = mod.armourNameToItemTemplate.get(armourName);
}else{

View File

@@ -34,8 +34,8 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
// 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<Integer, Float>();
public HashMap<String, Integer> armourTypeReference = new HashMap<String, Integer>();
public HashMap<Integer, Float> armourTypeReduction = new HashMap<>();
public HashMap<String, Integer> armourTypeReference = new HashMap<>();
// Armour modifiers
public float adamantineMaterialMod = 0.05f;
public float glimmersteelMaterialMod = 0.1f;
@@ -49,10 +49,10 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
public float plateArmourLimitFactor = -0.3f;
public float drakeArmourLimitFactor = -0.3f;
public float dragonscaleArmourLimitFactor = -0.3f;
public HashMap<Integer, Float> armourReductionOverride = new HashMap<Integer, Float>();
public HashMap<Integer, Float> armourReductionOverride = new HashMap<>();
// Armour movement
public boolean enableArmourMovementModifications = true;
public HashMap<String, Float> armourMovement = new HashMap<String, Float>();
public HashMap<String, Float> armourMovement = new HashMap<>();
// - Shield configuration -- //
public boolean enableShieldDamageEnchants = true;
@@ -65,13 +65,13 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
public boolean fixSavedSwingTimer = true;
public boolean betterDualWield = true; // HIGHLY EXPERIMENTAL
// Weapon variable changes
public HashMap<Integer, Float> weaponDamage = new HashMap<Integer, Float>();
public HashMap<Integer, Float> weaponSpeed = new HashMap<Integer, Float>();
public HashMap<Integer, Float> weaponCritChance = new HashMap<Integer, Float>();
public HashMap<Integer, Integer> weaponReach = new HashMap<Integer, Integer>();
public HashMap<Integer, Integer> weaponWeightGroup = new HashMap<Integer, Integer>();
public HashMap<Integer, Float> weaponParryPercent = new HashMap<Integer, Float>();
public HashMap<Integer, Double> weaponSkillPenalty = new HashMap<Integer, Double>();
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());
@@ -177,7 +177,7 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
double newVal = Double.parseDouble(split[1]);
weaponSkillPenalty.put(weaponId, newVal);
} else {
//Debug("Unknown config property: " + name);
Debug("Unknown config property: " + name);
}
}
} catch (Exception e) {
@@ -251,15 +251,15 @@ implements WurmServerMod, Configurable, PreInitable, ItemTemplatesCreatedListene
WeaponTweaks.onServerStarted(this);
}
public HashMap<String, Integer> armourNameToItemTemplate = new HashMap<String, Integer>();
public HashMap<String, Integer> armourNameToItemTemplate = new HashMap<>();
public ArrayList<Armour> clothArmour = new ArrayList<Armour>();
public ArrayList<Armour> leatherArmour = new ArrayList<Armour>();
public ArrayList<Armour> studdedArmour = new ArrayList<Armour>();
public ArrayList<Armour> chainArmour = new ArrayList<Armour>();
public ArrayList<Armour> plateArmour = new ArrayList<Armour>();
public ArrayList<Armour> drakeArmour = new ArrayList<Armour>();
public ArrayList<Armour> dragonscaleArmour = new ArrayList<Armour>();
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);

View File

@@ -117,7 +117,6 @@ public class CombatTweaks {
+ "}"
+ "$_ = $proceed($$);"
+ "communicator.sendAddSpellEffect($1, 100000, this.limitingArmourFactor*100.0f);");
return;
}
}
});

View File

@@ -19,9 +19,9 @@ import javassist.NotFoundException;
public class ShieldTweaks {
public static Logger logger = Logger.getLogger(ShieldTweaks.class.getName());
public static boolean checkShieldSpeed(Item shield){
if(shield != null && shield.getSpellSpeedBonus() > Server.rand.nextInt(500)){
return true;
}
if ((shield != null)) {
return (shield.getSpellSpeedBonus() > Server.rand.nextInt(500));
}
return false;
}

View File

@@ -41,188 +41,174 @@ public class WeaponTweaks {
try {
Weapon cw;
ItemTemplate it;
String tweakType = "";
if(mod.weaponDamage.keySet() != null){
tweakType = "damage";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponDamage.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"));
float newValue = mod.weaponDamage.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting damage on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"), newValue);
String tweakType;
tweakType = "damage";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.weaponDamage.keySet()){
it = ItemTemplateFactory.getInstance().getTemplateOrNull(id);
if(it == null){
logger.severe("[ERROR]: Item template for id "+id+" in weapon "+tweakType+" configuration is invalid.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"));
float newValue = mod.weaponDamage.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting damage on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "damage"), newValue);
}
if(mod.weaponSpeed.keySet() != null){
tweakType = "speed";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"));
float newValue = mod.weaponSpeed.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting speed on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"), newValue);
tweakType = "speed";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"));
float newValue = mod.weaponSpeed.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting speed on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "speed"), newValue);
}
if(mod.weaponCritChance.keySet() != null){
tweakType = "crit chance";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"));
float newValue = mod.weaponCritChance.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting crit chance on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"), newValue);
tweakType = "crit chance";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"));
float newValue = mod.weaponCritChance.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting crit chance on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "critchance"), newValue);
}
if(mod.weaponReach.keySet() != null){
tweakType = "reach";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"));
int newValue = mod.weaponReach.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting reach on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"), newValue);
tweakType = "reach";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"));
int newValue = mod.weaponReach.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting reach on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "reach"), newValue);
}
if(mod.weaponWeightGroup.keySet() != null){
tweakType = "weight group";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"));
int newValue = mod.weaponWeightGroup.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting weight group on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"), newValue);
tweakType = "weight group";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
int oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"));
int newValue = mod.weaponWeightGroup.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting weight group on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "weightGroup"), newValue);
}
if(mod.weaponParryPercent.keySet() != null){
tweakType = "parry percent";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"));
float newValue = mod.weaponParryPercent.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting parry percent on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"), newValue);
tweakType = "parry percent";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
float oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"));
float newValue = mod.weaponParryPercent.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting parry percent on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "parryPercent"), newValue);
}
if(mod.weaponSkillPenalty.keySet() != null){
tweakType = "skill penalty";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
double oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"));
double newValue = mod.weaponSkillPenalty.get(id);
String diff = "";
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting skill penalty on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"), newValue);
tweakType = "skill penalty";
logger.info("Beginning weapon "+tweakType+" tweaks...");
for(int id : mod.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.");
continue;
}
cw = weapons.get(id);
if(cw == null){
logger.severe("[ERROR]: Weapon for id "+id+" in the weapon "+tweakType+" configuration is invalid.");
continue;
}
double oldValue = ReflectionUtil.getPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"));
double newValue = mod.weaponSkillPenalty.get(id);
String diff;
if(newValue > oldValue){
diff = "+"+(newValue-oldValue);
}else{
diff = String.valueOf(newValue-oldValue);
}
logger.info("Setting skill penalty on "+it.sizeString+it.getName()+" to "+newValue+" from "+oldValue+" ("+diff+")");
ReflectionUtil.setPrivateField(cw, ReflectionUtil.getField(cw.getClass(), "skillPenalty"), newValue);
}
} catch (IllegalArgumentException | IllegalAccessException | ClassCastException | NoSuchFieldException e) {
e.printStackTrace();