Browse Source

damage calculations cleanup

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

261
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.getLevel() == 85){
min = agent.getMinDamageHandOne();
max = agent.getMaxDamageHandOne();
}
float range;
float damage;
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
if(agent.isSummonedPet() == true || agent.isPet() == true || agent.isNecroPet() == true) { if(agent.isSummonedPet() == true || agent.isPet() == true || agent.isNecroPet() == true) {
//damage calc for pet damage = calculatePetDamage(agent);
float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent();
double minDmg = getMinDmg(min,str,dex,agent.getLevel(), null);
double maxDmg = getMaxDmg(max,str,dex,agent.getLevel(), null);
dmgMultiplier += agent.getLevel() / 10;
range = (float) (maxDmg - minDmg);
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target))
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){ }else if(agent.isPlayerGuard() == true){
//damage calc for guard damage = calculateGuardDamage(agent);
ItemBase weapon = agent.getEquip().get(1).getItemBase();
double minDmg = weapon.getMinDamage();
double maxDmg = weapon.getMaxDamage();
float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent();
min = (float) getMinDmg(minDmg,str,dex,agent.getLevel(), weapon);
max = (float) getMaxDmg(maxDmg,str,dex,agent.getLevel(), weapon);
DamageType dt = weapon.getDamageType();
range = max - min;
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target))
if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target))
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0) * dmgMultiplier;
}else if (agent.getLevel() > 80) { }else if (agent.getLevel() > 80) {
//handle r8 mob damage damage = calculateEpicDamage(agent);
DamageType dt = DamageType.Crush;
if (agent.getEquip().get(1).getItemBase() != null) {
dt = agent.getEquip().get(1).getItemBase().getDamageType();
} else if(agent.getEquip().get(2).getItemBase() != null && agent.getEquip().get(2).getItemBase().isShield() == false){
dt = agent.getEquip().get(2).getItemBase().getDamageType();
}
min = agent.getMobBase().getMinDmg();
max = agent.getMobBase().getMaxDmg();
range = max - min;
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, damage, 0) * dmgMultiplier;
} else{ } else{
//damage calc for regular mob damage = calculateMobDamage(agent);
DamageType dt = DamageType.Crush; }
ItemBase mainHand = agent.getEquip().get(1).getItemBase(); if (AbstractWorldObject.IsAbstractCharacter(target)) {
ItemBase offHand = agent.getEquip().get(2).getItemBase(); if (((AbstractCharacter) target).isSit()) {
if(mainHand != null && offHand == null){ damage *= 2.5f; //increase damage if sitting
//main hand only attack
min = mainHand.getMinDamage();
max = mainHand.getMaxDamage();
dt = mainHand.getDamageType();
} else if(mainHand == null && offHand != null && offHand.isShield() == false){
//off hand attack only
min = offHand.getMinDamage();
max = offHand.getMaxDamage();
dt = offHand.getDamageType();
} else if(mainHand != null && offHand != null && offHand.isShield() == false){
//attack from both hands
min = mainHand.getMinDamage() + offHand.getMinDamage();
max = mainHand.getMaxDamage() + offHand.getMaxDamage();
dt = mainHand.getDamageType();
}
min = (float) getMinDmg(min,agent.getStatStrCurrent(),agent.getStatDexCurrent(),agent.getLevel(),mainHand);
max = (float) getMaxDmg(max,agent.getStatStrCurrent(),agent.getStatDexCurrent(),agent.getLevel(),mainHand);
range = max - min;
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target))
if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target))
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, dt, 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;
} }
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))));
} }
//impossible to get this far 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 damage;
float min = 40;
float max = 60;
AbstractWorldObject target = agent.getCombatTarget();
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent();
double minDmg = getMinDmg(min,agent, null);
double maxDmg = getMaxDmg(max,agent, null);
dmgMultiplier += agent.getLevel() / 10;
range = (float) (maxDmg - minDmg);
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
return (int) (damage * dmgMultiplier);
}
public static int calculateGuardDamage(Mob agent){
//damage calc for guard
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 maxDmg = weapon.getMaxDamage();
float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent();
double min = getMinDmg(minDmg,agent, weapon);
double max = getMaxDmg(maxDmg,agent, weapon);
DamageType dt = weapon.getDamageType();
double range = max - min;
double damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (AbstractWorldObject.IsAbstractCharacter(target))
if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target))
return (int) (((AbstractCharacter) target).getResists().getResistedDamage((AbstractCharacter) agent, (AbstractCharacter) target, dt, (float) damage, 0) * dmgMultiplier);
return 0; return 0;
} }
public static double getMinDmg(double min, float str, float dex, int level, ItemBase equipped){ public static int calculateEpicDamage(Mob agent){
if(str == 0){ //handle r8 mob damage
str = 1; 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) {
dt = agent.getEquip().get(1).getItemBase().getDamageType();
} else if(agent.getEquip().get(2).getItemBase() != null && agent.getEquip().get(2).getItemBase().isShield() == false){
dt = agent.getEquip().get(2).getItemBase().getDamageType();
}
double min = agent.getMobBase().getMinDmg();
double max = agent.getMobBase().getMaxDmg();
double range = max - min;
double damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
return (int) (((AbstractCharacter) target).getResists().getResistedDamage((AbstractCharacter) agent, (AbstractCharacter) target, dt, (float) damage, 0) * dmgMultiplier);
}
public static int calculateMobDamage(Mob agent){
ItemBase weapon = null;
double minDmg;
double maxDmg;
DamageType dt;
if(agent.getEquip().get(1).getItemBase() != null){
//mainhand damage
weapon = agent.getEquip().get(1).getItemBase();
} else if(agent.getEquip().get(2).getItemBase() != null){
//offhand damage
weapon = agent.getEquip().get(2).getItemBase();
} }
if(dex == 0){ if(weapon != null){
dex = 1; minDmg = weapon.getMinDamage();
maxDmg = weapon.getMaxDamage();
dt = weapon.getDamageType();
}else{
minDmg = agent.getMobBase().getMinDmg();
maxDmg = agent.getMobBase().getMaxDmg();
dt = DamageType.Crush;
} }
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)))); AbstractWorldObject target = agent.getCombatTarget();
float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
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 (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting
if (AbstractWorldObject.IsAbstractCharacter(target))
return (int) (((AbstractCharacter) target).getResists().getResistedDamage((AbstractCharacter) agent, (AbstractCharacter) target, dt, (float) damage, 0) * dmgMultiplier);
return 0;
} }
public static double getMaxDmg(double max, 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;
int masteryLevel = 0;
if(weapon.isStrBased() == true){
primary = agent.getStatStrCurrent();
secondary = agent.getStatDexCurrent();
} }
if(dex == 0){ else{
dex = 1; primary = agent.getStatDexCurrent();
secondary = agent.getStatStrCurrent();
} }
float primary = 0; if (weapon != null) {
float secondary = 0; focusLevel = (int) agent.getSkills().get(weapon.getSkillRequired()).getModifiedAmount();
if(equipped == null){ masteryLevel = (int) agent.getSkills().get(weapon.getMastery()).getModifiedAmount();
primary = str;
secondary = dex;
} }
else if(equipped.isStrBased()){ 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));
primary = str; }
secondary = dex; public static double getMaxDmg(double max, Mob agent, ItemBase weapon){
int primary = 0;
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