Browse Source

damage calculations cleanup

master
FatBoy-DOTC 2 years ago
parent
commit
5830a9ef82
  1. 213
      src/engine/ai/utilities/CombatUtilities.java

213
src/engine/ai/utilities/CombatUtilities.java

@ -331,139 +331,168 @@ public class CombatUtilities {
//early exit for null //early exit for null
return 0; return 0;
} }
//set default values float damage = 0;
float min = 40; DamageType dt = getDamageType(agent);
float max = 60; if(agent.isSummonedPet() == true || agent.isPet() == true || agent.isNecroPet() == true) {
if(agent.getLevel() == 85){ damage = calculatePetDamage(agent);
min = agent.getMinDamageHandOne(); }else if(agent.isPlayerGuard() == true){
max = agent.getMaxDamageHandOne(); damage = calculateGuardDamage(agent);
}else if (agent.getLevel() > 80) {
damage = calculateEpicDamage(agent);
} else{
damage = calculateMobDamage(agent);
}
if (AbstractWorldObject.IsAbstractCharacter(target)) {
if (((AbstractCharacter) target).isSit()) {
damage *= 2.5f; //increase damage if sitting
} }
return (int) (((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0));
}
if (target.getObjectType() == GameObjectType.Building) {
Building building = (Building) target;
Resists resists = building.getResists();
return (int) ((damage * (1 - (resists.getResist(dt, 0) / 100))));
}
return damage;
}
public static DamageType getDamageType(Mob agent){
DamageType dt = DamageType.Crush;
if(agent.getEquip().get(1).getItemBase() != null ){
return agent.getEquip().get(1).getItemBase().getDamageType();
}
if(agent.getEquip().get(2).getItemBase() != null && agent.getEquip().get(2).getItemBase().isShield() == false){
return agent.getEquip().get(2).getItemBase().getDamageType();
}
return dt;
}
public static int calculatePetDamage(Mob agent) {
//damage calc for pet
float range; float range;
float damage; float damage;
float min = 40;
float max = 60;
AbstractWorldObject target = agent.getCombatTarget();
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None); float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
if(agent.isSummonedPet() == true || agent.isPet() == true || agent.isNecroPet() == true) {
//damage calc for pet
float str = agent.getStatStrCurrent(); float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent(); float dex = agent.getStatDexCurrent();
double minDmg = getMinDmg(min,str,dex,agent.getLevel(), null); double minDmg = getMinDmg(min,agent, null);
double maxDmg = getMaxDmg(max,str,dex,agent.getLevel(), null); double maxDmg = getMaxDmg(max,agent, null);
dmgMultiplier += agent.getLevel() / 10; dmgMultiplier += agent.getLevel() / 10;
range = (float) (maxDmg - minDmg); range = (float) (maxDmg - minDmg);
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2; damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target)) return (int) (damage * dmgMultiplier);
if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target))
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, DamageType.Crush, damage, 0) * dmgMultiplier;
if (target.getObjectType() == GameObjectType.Building) {
Building building = (Building) target;
Resists resists = building.getResists();
return (damage * (1 - (resists.getResist(DamageType.Crush, 0) / 100))) * dmgMultiplier;
} }
}else if(agent.isPlayerGuard() == true){ public static int calculateGuardDamage(Mob agent){
//damage calc for guard //damage calc for guard
ItemBase weapon = agent.getEquip().get(1).getItemBase(); ItemBase weapon = agent.getEquip().get(1).getItemBase();
AbstractWorldObject target = agent.getCombatTarget();
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
double minDmg = weapon.getMinDamage(); double minDmg = weapon.getMinDamage();
double maxDmg = weapon.getMaxDamage(); double maxDmg = weapon.getMaxDamage();
float str = agent.getStatStrCurrent(); float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent(); float dex = agent.getStatDexCurrent();
min = (float) getMinDmg(minDmg,str,dex,agent.getLevel(), weapon); double min = getMinDmg(minDmg,agent, weapon);
max = (float) getMaxDmg(maxDmg,str,dex,agent.getLevel(), weapon); double max = getMaxDmg(maxDmg,agent, weapon);
DamageType dt = weapon.getDamageType(); DamageType dt = weapon.getDamageType();
range = max - min; double range = max - min;
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2; double damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target)) if (AbstractWorldObject.IsAbstractCharacter(target))
if (((AbstractCharacter) target).isSit()) if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target)) if (AbstractWorldObject.IsAbstractCharacter(target))
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0) * dmgMultiplier; return (int) (((AbstractCharacter) target).getResists().getResistedDamage((AbstractCharacter) agent, (AbstractCharacter) target, dt, (float) damage, 0) * dmgMultiplier);
}else if (agent.getLevel() > 80) { return 0;
}
public static int calculateEpicDamage(Mob agent){
//handle r8 mob damage //handle r8 mob damage
DamageType dt = DamageType.Crush; DamageType dt = DamageType.Crush;
AbstractWorldObject target = agent.getCombatTarget();
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
if (agent.getEquip().get(1).getItemBase() != null) { if (agent.getEquip().get(1).getItemBase() != null) {
dt = agent.getEquip().get(1).getItemBase().getDamageType(); dt = agent.getEquip().get(1).getItemBase().getDamageType();
} else if(agent.getEquip().get(2).getItemBase() != null && agent.getEquip().get(2).getItemBase().isShield() == false){ } else if(agent.getEquip().get(2).getItemBase() != null && agent.getEquip().get(2).getItemBase().isShield() == false){
dt = agent.getEquip().get(2).getItemBase().getDamageType(); dt = agent.getEquip().get(2).getItemBase().getDamageType();
} }
min = agent.getMobBase().getMinDmg(); double min = agent.getMobBase().getMinDmg();
max = agent.getMobBase().getMaxDmg(); double max = agent.getMobBase().getMaxDmg();
range = max - min; double range = max - min;
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2; double damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0) * dmgMultiplier; return (int) (((AbstractCharacter) target).getResists().getResistedDamage((AbstractCharacter) agent, (AbstractCharacter) target, dt, (float) damage, 0) * dmgMultiplier);
} else{ }
//damage calc for regular mob public static int calculateMobDamage(Mob agent){
DamageType dt = DamageType.Crush; ItemBase weapon = null;
ItemBase mainHand = agent.getEquip().get(1).getItemBase(); double minDmg;
ItemBase offHand = agent.getEquip().get(2).getItemBase(); double maxDmg;
if(mainHand != null && offHand == null){ DamageType dt;
//main hand only attack if(agent.getEquip().get(1).getItemBase() != null){
min = mainHand.getMinDamage(); //mainhand damage
max = mainHand.getMaxDamage(); weapon = agent.getEquip().get(1).getItemBase();
dt = mainHand.getDamageType(); } else if(agent.getEquip().get(2).getItemBase() != null){
} else if(mainHand == null && offHand != null && offHand.isShield() == false){ //offhand damage
//off hand attack only weapon = agent.getEquip().get(2).getItemBase();
min = offHand.getMinDamage(); }
max = offHand.getMaxDamage(); if(weapon != null){
dt = offHand.getDamageType(); minDmg = weapon.getMinDamage();
} else if(mainHand != null && offHand != null && offHand.isShield() == false){ maxDmg = weapon.getMaxDamage();
//attack from both hands dt = weapon.getDamageType();
min = mainHand.getMinDamage() + offHand.getMinDamage(); }else{
max = mainHand.getMaxDamage() + offHand.getMaxDamage(); minDmg = agent.getMobBase().getMinDmg();
dt = mainHand.getDamageType(); maxDmg = agent.getMobBase().getMaxDmg();
} dt = DamageType.Crush;
min = (float) getMinDmg(min,agent.getStatStrCurrent(),agent.getStatDexCurrent(),agent.getLevel(),mainHand); }
max = (float) getMaxDmg(max,agent.getStatStrCurrent(),agent.getStatDexCurrent(),agent.getLevel(),mainHand); AbstractWorldObject target = agent.getCombatTarget();
range = max - min; float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2; float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent();
double min = getMinDmg(minDmg,agent, weapon);
double max = getMaxDmg(maxDmg,agent, weapon);
double range = max - min;
double damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target)) if (AbstractWorldObject.IsAbstractCharacter(target))
if (((AbstractCharacter) target).isSit()) if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target)) if (AbstractWorldObject.IsAbstractCharacter(target))
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0) * dmgMultiplier; return (int) (((AbstractCharacter) target).getResists().getResistedDamage((AbstractCharacter) agent, (AbstractCharacter) target, dt, (float) damage, 0) * dmgMultiplier);
if (target.getObjectType() == GameObjectType.Building) {
Building building = (Building) target;
Resists resists = building.getResists();
return (damage * (1 - (resists.getResist(dt, 0) / 100))) * dmgMultiplier;
}
}
//impossible to get this far
return 0; return 0;
} }
public static double getMinDmg(double min, float str, float dex, int level, ItemBase equipped){ public static double getMinDmg(double min, Mob agent, ItemBase weapon){
if(str == 0){ int primary = 0;
str = 1; int secondary = 0;
} int focusLevel = 0;
if(dex == 0){ int masteryLevel = 0;
dex = 1; if(weapon.isStrBased() == true){
primary = agent.getStatStrCurrent();
secondary = agent.getStatDexCurrent();
} }
return (min * pow((0.0048*str +.049*(str-0.75)),pow(0.5 + 0.0066*dex + 0.064*(dex-0.75),0.5 + 0.01*(200/level)))); else{
} primary = agent.getStatDexCurrent();
public static double getMaxDmg(double max, float str, float dex, int level,ItemBase equipped){ secondary = agent.getStatStrCurrent();
if(str == 0){
str = 1;
} }
if(dex == 0){ if (weapon != null) {
dex = 1; focusLevel = (int) agent.getSkills().get(weapon.getSkillRequired()).getModifiedAmount();
masteryLevel = (int) agent.getSkills().get(weapon.getMastery()).getModifiedAmount();
} }
float primary = 0; return min * (pow(0.0048*primary +.049*(primary-0.75),0.5) + pow(0.0066*secondary + 0.064*(secondary-0.75),0.5) + + 0.01*(focusLevel + masteryLevel));
float secondary = 0;
if(equipped == null){
primary = str;
secondary = dex;
} }
else if(equipped.isStrBased()){ public static double getMaxDmg(double max, Mob agent, ItemBase weapon){
primary = str; int primary = 0;
secondary = dex; int secondary = 0;
int focusLevel = 0;
int masteryLevel = 0;
if(weapon.isStrBased() == true){
primary = agent.getStatStrCurrent();
secondary = agent.getStatDexCurrent();
} }
else{ else{
primary = dex; primary = agent.getStatDexCurrent();
secondary = str; secondary = agent.getStatStrCurrent();
}
if (weapon != null) {
focusLevel = (int) agent.getSkills().get(weapon.getSkillRequired()).getModifiedAmount();
masteryLevel = (int) agent.getSkills().get(weapon.getMastery()).getModifiedAmount();
} }
return (max * pow((0.0124*primary +0.118*(primary-0.75)),pow(0.5 + 0.0022*secondary + 0.028*(secondary-0.75),0.5 + 0.0075*(200/level)))); return max * (pow(0.0124*primary + 0.118*(primary -0.75),0.5) + pow(0.0022*secondary + 0.028*(secondary-0.75),0.5) + 0.0075*(focusLevel + masteryLevel));
} }
public static boolean RunAIRandom(){ public static boolean RunAIRandom(){
int random = ThreadLocalRandom.current().nextInt(4); int random = ThreadLocalRandom.current().nextInt(4);

Loading…
Cancel
Save