Browse Source

mob mele damage formula update

master
FatBoy-DOTC 2 years ago
parent
commit
ce02a1ea65
  1. 146
      src/engine/ai/MobileFSM.java
  2. 226
      src/engine/ai/utilities/CombatUtilities.java
  3. 2
      src/engine/objects/Mob.java

146
src/engine/ai/MobileFSM.java

@ -53,6 +53,7 @@ public class MobileFSM {
Recalling, Recalling,
Retaliate Retaliate
} }
public static void run(Mob mob) { public static void run(Mob mob) {
if (mob == null) { if (mob == null) {
return; return;
@ -166,11 +167,9 @@ public class MobileFSM {
} }
return false; return false;
} }
public static Mob getMobile(int mobileID) { public static Mob getMobile(int mobileID) {
return Mob.getFromCache(mobileID); return Mob.getFromCache(mobileID);
} }
private static void idle(Mob mob) { private static void idle(Mob mob) {
if (mob.getLoc().distanceSquared2D(mob.getBindLoc()) > sqr(2000)) { if (mob.getLoc().distanceSquared2D(mob.getBindLoc()) > sqr(2000)) {
@ -179,8 +178,6 @@ public class MobileFSM {
mob.setState(STATE.Home); mob.setState(STATE.Home);
} }
} }
private static void awake(Mob aiAgent) { private static void awake(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.setState(STATE.Dead);
@ -269,7 +266,6 @@ public class MobileFSM {
} }
} }
private static void guardAttackMob(Mob aiAgent) { private static void guardAttackMob(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.setState(STATE.Dead);
@ -354,7 +350,6 @@ public class MobileFSM {
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void awakeNPCguard(Mob aiAgent) { private static void awakeNPCguard(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
aiAgent.setState(STATE.Dead); aiAgent.setState(STATE.Dead);
@ -393,7 +388,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Attack); aiAgent.setState(STATE.Attack);
} }
} }
private static void petAwake(Mob aiAgent) { private static void petAwake(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -430,7 +424,6 @@ public class MobileFSM {
MovementUtilities.moveToLocation(aiAgent, petOwner.getLoc(), aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, petOwner.getLoc(), aiAgent.getRange());
} }
} }
private static void aggro(Mob aiAgent, int targetID) { private static void aggro(Mob aiAgent, int targetID) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -474,13 +467,11 @@ public class MobileFSM {
aiAgent.setState(STATE.Patrol); aiAgent.setState(STATE.Patrol);
return; return;
} }
if(canCast(aiAgent) == true){ if (canCast(aiAgent) == true) {
if(MobCast(aiAgent) == false) { if (MobCast(aiAgent) == false) {
attack(aiAgent, targetID); attack(aiAgent, targetID);
} }
} } else if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) {
else
if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) {
aiAgent.setState(STATE.Attack); aiAgent.setState(STATE.Attack);
attack(aiAgent, targetID); attack(aiAgent, targetID);
return; return;
@ -518,7 +509,6 @@ public class MobileFSM {
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void petAttack(Mob aiAgent) { private static void petAttack(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -564,7 +554,6 @@ public class MobileFSM {
break; break;
} }
} }
private static void mobAttack(Mob aiAgent) { private static void mobAttack(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -603,12 +592,11 @@ public class MobileFSM {
aiAgent.setState(STATE.Idle); aiAgent.setState(STATE.Idle);
return; return;
} }
if(canCast(aiAgent) == true){ if (canCast(aiAgent) == true) {
if(MobCast(aiAgent) == false) { if (MobCast(aiAgent) == false) {
handlePlayerAttackForMob(aiAgent, player); handlePlayerAttackForMob(aiAgent, player);
} }
} } else {
else {
handlePlayerAttackForMob(aiAgent, player); handlePlayerAttackForMob(aiAgent, player);
} }
break; break;
@ -621,7 +609,6 @@ public class MobileFSM {
handleMobAttackForMob(aiAgent, mob); handleMobAttackForMob(aiAgent, mob);
} }
} }
private static void petHandleBuildingAttack(Mob aiAgent, Building building) { private static void petHandleBuildingAttack(Mob aiAgent, Building building) {
int buildingHitBox = (int) CombatManager.calcHitBox(building); int buildingHitBox = (int) CombatManager.calcHitBox(building);
@ -732,7 +719,6 @@ public class MobileFSM {
if (MovementUtilities.canMove(aiAgent)) if (MovementUtilities.canMove(aiAgent))
MovementUtilities.moveToLocation(aiAgent, building.getLoc(), aiAgent.getRange() + buildingHitBox); MovementUtilities.moveToLocation(aiAgent, building.getLoc(), aiAgent.getRange() + buildingHitBox);
} }
private static void handlePlayerAttackForPet(Mob aiAgent, PlayerCharacter player) { private static void handlePlayerAttackForPet(Mob aiAgent, PlayerCharacter player) {
if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) { if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) {
@ -809,7 +795,6 @@ public class MobileFSM {
aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, player); aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, player);
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void handlePlayerAttackForMob(Mob aiAgent, PlayerCharacter player) { private static void handlePlayerAttackForMob(Mob aiAgent, PlayerCharacter player) {
if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) { if (aiAgent.getMobBase().getSeeInvis() < player.getHidden()) {
@ -824,36 +809,9 @@ public class MobileFSM {
return; return;
} }
if (System.currentTimeMillis() > aiAgent.getTimeStamp("CallForHelp")) { if (aiAgent.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)) {
CombatUtilities.CallForHelp(aiAgent); MobCallForHelp(aiAgent);
aiAgent.getTimestamps().put("CallForHelp", System.currentTimeMillis() + 60000);
} }
HashMap<Integer, Integer> staticPowers = aiAgent.getMobBase().getStaticPowers();
if (staticPowers != null && !staticPowers.isEmpty()) {
int chance = ThreadLocalRandom.current().nextInt(300);
if (chance <= 1) {
int randomPower = ThreadLocalRandom.current().nextInt(staticPowers.size());
int powerToken = (int) staticPowers.keySet().toArray()[randomPower];
PowersBase pb = PowersManager.getPowerByToken(powerToken);
if (pb == null)
return;
if (System.currentTimeMillis() > aiAgent.getTimeStamp(pb.getIDString())) {
PowersManager.useMobPower(aiAgent, player, pb, staticPowers.get(powerToken));
int cooldown = pb.getRecycleTime(staticPowers.get(powerToken));
aiAgent.getTimestamps().put(pb.getIDString(), System.currentTimeMillis() + cooldown + (pb.getToken() == 429023263 ? 10000 : 120000));
return;
}
}
}
if (!MovementUtilities.inRangeOfBindLocation(aiAgent)) { if (!MovementUtilities.inRangeOfBindLocation(aiAgent)) {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
@ -861,7 +819,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Home); aiAgent.setState(STATE.Home);
return; return;
} }
if (!MovementUtilities.inRangeDropAggro(aiAgent, player)) { if (!MovementUtilities.inRangeDropAggro(aiAgent, player)) {
aiAgent.setAggroTargetID(0); aiAgent.setAggroTargetID(0);
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
@ -869,7 +826,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Awake); aiAgent.setState(STATE.Awake);
return; return;
} }
if (CombatUtilities.inRangeToAttack(aiAgent, player)) { if (CombatUtilities.inRangeToAttack(aiAgent, player)) {
//no weapons, defualt mob attack speed 3 seconds. //no weapons, defualt mob attack speed 3 seconds.
@ -916,7 +872,9 @@ public class MobileFSM {
if (aiAgent.isSiege()) if (aiAgent.isSiege())
attackDelay = 11000; attackDelay = 11000;
if (aiAgent.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)) {
MobCallForHelp(aiAgent);
}
CombatUtilities.combatCycle(aiAgent, player, false, aiAgent.getWeaponItemBase(false)); CombatUtilities.combatCycle(aiAgent, player, false, aiAgent.getWeaponItemBase(false));
aiAgent.setLastAttackTime(System.currentTimeMillis() + attackDelay); aiAgent.setLastAttackTime(System.currentTimeMillis() + attackDelay);
} }
@ -937,7 +895,6 @@ public class MobileFSM {
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void handleMobAttackForPet(Mob aiAgent, Mob mob) { private static void handleMobAttackForPet(Mob aiAgent, Mob mob) {
if (!mob.isAlive()) { if (!mob.isAlive()) {
@ -1009,7 +966,6 @@ public class MobileFSM {
aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, mob); aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, mob);
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void handleMobAttackForMob(Mob aiAgent, Mob mob) { private static void handleMobAttackForMob(Mob aiAgent, Mob mob) {
@ -1082,7 +1038,6 @@ public class MobileFSM {
aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, mob); aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, mob);
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void attack(Mob aiAgent, int targetID) { private static void attack(Mob aiAgent, int targetID) {
//in range to attack, start attacking now! //in range to attack, start attacking now!
@ -1210,7 +1165,6 @@ public class MobileFSM {
aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, aggroTarget); aiAgent.destination = MovementUtilities.GetDestinationToCharacter(aiAgent, aggroTarget);
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void home(Mob aiAgent, boolean walk) { private static void home(Mob aiAgent, boolean walk) {
//recall home. //recall home.
@ -1219,14 +1173,12 @@ public class MobileFSM {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.setState(STATE.Awake);
} }
private static void recall(Mob aiAgent) { private static void recall(Mob aiAgent) {
//recall home. //recall home.
PowersBase recall = PowersManager.getPowerByToken(-1994153779); PowersBase recall = PowersManager.getPowerByToken(-1994153779);
PowersManager.useMobPower(aiAgent, aiAgent, recall, 40); PowersManager.useMobPower(aiAgent, aiAgent, recall, 40);
aiAgent.setState(MobileFSM.STATE.Recalling); aiAgent.setState(MobileFSM.STATE.Recalling);
} }
private static void recalling(Mob aiAgent) { private static void recalling(Mob aiAgent) {
//recall home. //recall home.
if (aiAgent.getLoc() == aiAgent.getBindLoc()) if (aiAgent.getLoc() == aiAgent.getBindLoc())
@ -1238,7 +1190,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Home); aiAgent.setState(STATE.Home);
} }
} }
private static void patrol(Mob aiAgent) { private static void patrol(Mob aiAgent) {
MobBase mobbase = aiAgent.getMobBase(); MobBase mobbase = aiAgent.getMobBase();
@ -1262,7 +1213,6 @@ public class MobileFSM {
} }
aiAgent.setState(STATE.Awake); aiAgent.setState(STATE.Awake);
} }
public static void goHome(Mob aiAgent, boolean walk) { public static void goHome(Mob aiAgent, boolean walk) {
if (aiAgent.getState() != STATE.Dead) { if (aiAgent.getState() != STATE.Dead) {
@ -1271,7 +1221,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Home); aiAgent.setState(STATE.Home);
} }
} }
private static void dead(Mob aiAgent) { private static void dead(Mob aiAgent) {
//Despawn Timer with Loot currently in inventory. //Despawn Timer with Loot currently in inventory.
if (aiAgent.getCharItemManager().getInventoryCount() > 0) { if (aiAgent.getCharItemManager().getInventoryCount() > 0) {
@ -1303,7 +1252,6 @@ public class MobileFSM {
} }
} }
} }
private static void guardAwake(Mob aiAgent) { private static void guardAwake(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -1451,7 +1399,6 @@ public class MobileFSM {
if (aiAgent.isMoving() == false) if (aiAgent.isMoving() == false)
aiAgent.setState(STATE.Patrol); aiAgent.setState(STATE.Patrol);
} }
private static void guardAggro(Mob aiAgent, int targetID) { private static void guardAggro(Mob aiAgent, int targetID) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -1487,13 +1434,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Patrol); aiAgent.setState(STATE.Patrol);
return; return;
} }
if (System.currentTimeMillis() > aiAgent.getTimeStamp("CallForHelp")) {
CombatUtilities.CallForHelp(aiAgent);
aiAgent.getTimestamps().put("CallForHelp", System.currentTimeMillis() + 60000);
}
if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) { if (CombatUtilities.inRangeToAttack(aiAgent, aggroTarget)) {
aiAgent.setCombatTarget(aggroTarget); aiAgent.setCombatTarget(aggroTarget);
aiAgent.setState(STATE.Attack); aiAgent.setState(STATE.Attack);
@ -1536,7 +1476,6 @@ public class MobileFSM {
MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.destination, aiAgent.getRange());
} }
private static void guardPatrol(Mob aiAgent) { private static void guardPatrol(Mob aiAgent) {
if (aiAgent.getPlayerAgroMap().isEmpty()) { if (aiAgent.getPlayerAgroMap().isEmpty()) {
@ -1637,7 +1576,6 @@ public class MobileFSM {
} }
aiAgent.setState(STATE.Awake); aiAgent.setState(STATE.Awake);
} }
private static void guardAttack(Mob aiAgent) { private static void guardAttack(Mob aiAgent) {
if (!aiAgent.isAlive()) { if (!aiAgent.isAlive()) {
@ -1668,12 +1606,11 @@ public class MobileFSM {
aiAgent.setState(STATE.Idle); aiAgent.setState(STATE.Idle);
return; return;
} }
if(canCast(aiAgent) == true){ if (canCast(aiAgent) == true) {
if(MobCast(aiAgent) == false) { if (MobCast(aiAgent) == false) {
handlePlayerAttackForMob(aiAgent, player); handlePlayerAttackForMob(aiAgent, player);
} }
} } else {
else {
handlePlayerAttackForMob(aiAgent, player); handlePlayerAttackForMob(aiAgent, player);
} }
break; break;
@ -1686,7 +1623,6 @@ public class MobileFSM {
handleMobAttackForMob(aiAgent, mob); handleMobAttackForMob(aiAgent, mob);
} }
} }
private static void guardHome(Mob aiAgent, boolean walk) { private static void guardHome(Mob aiAgent, boolean walk) {
//recall home. //recall home.
@ -1697,7 +1633,6 @@ public class MobileFSM {
aiAgent.setCombatTarget(null); aiAgent.setCombatTarget(null);
aiAgent.setState(STATE.Awake); aiAgent.setState(STATE.Awake);
} }
private static void guardRespawn(Mob aiAgent) { private static void guardRespawn(Mob aiAgent) {
if (!aiAgent.canRespawn()) if (!aiAgent.canRespawn())
@ -1713,7 +1648,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Idle); aiAgent.setState(STATE.Idle);
} }
} }
private static void respawn(Mob aiAgent) { private static void respawn(Mob aiAgent) {
if (!aiAgent.canRespawn()) if (!aiAgent.canRespawn())
@ -1729,7 +1663,6 @@ public class MobileFSM {
aiAgent.setState(STATE.Idle); aiAgent.setState(STATE.Idle);
} }
} }
private static void retaliate(Mob aiAgent) { private static void retaliate(Mob aiAgent) {
if (aiAgent.getCombatTarget() == null) if (aiAgent.getCombatTarget() == null)
@ -1749,7 +1682,6 @@ public class MobileFSM {
MovementUtilities.moveToLocation(aiAgent, aiAgent.getCombatTarget().getLoc(), aiAgent.getRange()); MovementUtilities.moveToLocation(aiAgent, aiAgent.getCombatTarget().getLoc(), aiAgent.getRange());
} }
private static void moveToWorldObjectRegion(Mob mob, AbstractWorldObject regionObject) { private static void moveToWorldObjectRegion(Mob mob, AbstractWorldObject regionObject) {
if (regionObject.getRegion() == null) if (regionObject.getRegion() == null)
@ -1757,52 +1689,62 @@ public class MobileFSM {
MovementManager.translocate(mob, regionObject.getLoc(), null); MovementManager.translocate(mob, regionObject.getLoc(), null);
} }
public static boolean canCast(Mob mob) {
public static boolean canCast(Mob mob){ if(mob == null){
if(mob == null || mob.mobPowers.isEmpty() == true || mob.nextCastTime > System.currentTimeMillis()){
return false; return false;
} }
else{ if(mob.mobPowers.isEmpty() == true){
return true; return false;
}
if(mob.nextCastTime == 0){
mob.nextCastTime = System.currentTimeMillis();
}
if (mob.nextCastTime > System.currentTimeMillis()) {
return false;
} }
return true;
} }
public static boolean MobCast(Mob mob){ public static boolean MobCast(Mob mob) {
if(mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)){ if (mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)) {
MobCallForHelp(mob); MobCallForHelp(mob);
} }
PlayerCharacter target = (PlayerCharacter)mob.getCombatTarget(); PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget();
int random = ThreadLocalRandom.current().nextInt(mob.mobPowers.size() * 2); int random = ThreadLocalRandom.current().nextInt(mob.mobPowers.size() * 2);
int powerToken = 0; int powerToken = 0;
int powerRank = 0; int powerRank = 0;
Map<Integer,Integer> entries = mob.mobPowers; Map<Integer, Integer> entries = mob.mobPowers;
int count = -1; int count = -1;
for(Map.Entry<Integer,Integer> entry : entries.entrySet()) for (Map.Entry<Integer, Integer> entry : entries.entrySet()) {
{
count += 1; count += 1;
if(count == random) if (count == random) {
{
powerToken = entry.getKey(); powerToken = entry.getKey();
powerRank = entry.getValue(); powerRank = entry.getValue();
PowersBase mobPower = PowersManager.getPowerByToken(powerToken); PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
if(CombatUtilities.inRangeToCast2D(mob, mob.getCombatTarget(),mobPower)) { if (CombatUtilities.inRangeToCast2D(mob, mob.getCombatTarget(), mobPower)) {
//PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank); //PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank);
PerformActionMsg msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); PerformActionMsg msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target);
msg.setUnknown04(2); msg.setUnknown04(2);
PowersManager.finishUseMobPower(msg, mob, 0, 0); PowersManager.finishUseMobPower(msg, mob, 0, 0);
mob.nextCastTime = System.currentTimeMillis() + (mobPower.getCooldown() * 1000); mob.nextCastTime = System.currentTimeMillis() + (mobPower.getCooldown());
return true; return true;
} }
} }
} }
return false; return false;
} }
public static void MobCallForHelp(Mob mob){ public static void MobCallForHelp(Mob mob) {
if(mob.nextCallForHelp > System.currentTimeMillis()){
return;
}
Zone mobCamp = mob.getParentZone(); Zone mobCamp = mob.getParentZone();
for (Mob mob1 : mobCamp.zoneMobSet) { for (Mob mob1 : mobCamp.zoneMobSet) {
if(mob1.getMobBase().getFlags().contains(Enum.MobFlagType.RESPONDSTOCALLSFORHELP)){ if (mob1.getMobBase().getFlags().contains(Enum.MobFlagType.RESPONDSTOCALLSFORHELP)) {
mob1.setCombatTarget(mob.getCombatTarget()); if (mob1.getState() == STATE.Idle) {
mob1.setState(STATE.Aggro); MovementUtilities.moveToLocation(mob1, mob.getLoc(), 0);
}
} }
} }
//wait 60 seconds to call for help again
mob.nextCallForHelp = System.currentTimeMillis() + 60000;
} }
} }

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

@ -32,6 +32,7 @@ import java.util.Set;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import static engine.math.FastMath.sqr; import static engine.math.FastMath.sqr;
import static java.lang.Math.pow;
public class CombatUtilities { public class CombatUtilities {
@ -109,7 +110,6 @@ public class CombatUtilities {
DispatchMessage.sendToAllInRange(agent,msg); DispatchMessage.sendToAllInRange(agent,msg);
} }
public static void swingIsParry(Mob agent,AbstractWorldObject target, int animation) { public static void swingIsParry(Mob agent,AbstractWorldObject target, int animation) {
if (!target.isAlive()) if (!target.isAlive())
@ -123,7 +123,6 @@ public class CombatUtilities {
DispatchMessage.sendToAllInRange(agent,msg); DispatchMessage.sendToAllInRange(agent,msg);
} }
public static void swingIsDodge(Mob agent,AbstractWorldObject target, int animation) { public static void swingIsDodge(Mob agent,AbstractWorldObject target, int animation) {
if (!target.isAlive()) if (!target.isAlive())
@ -136,7 +135,6 @@ public class CombatUtilities {
else else
DispatchMessage.sendToAllInRange(agent,msg); DispatchMessage.sendToAllInRange(agent,msg);
} }
public static void swingIsDamage(Mob agent,AbstractWorldObject target, float damage, int animation){ public static void swingIsDamage(Mob agent,AbstractWorldObject target, float damage, int animation){
float trueDamage = 0; float trueDamage = 0;
@ -164,11 +162,9 @@ public class CombatUtilities {
if(AbstractWorldObject.IsAbstractCharacter(target) && target.isAlive() && target.getObjectType() != GameObjectType.Mob) if(AbstractWorldObject.IsAbstractCharacter(target) && target.isAlive() && target.getObjectType() != GameObjectType.Mob)
CombatManager.handleDamageShields(agent,(AbstractCharacter)target, damage); CombatManager.handleDamageShields(agent,(AbstractCharacter)target, damage);
} }
public static boolean canSwing(Mob agent) { public static boolean canSwing(Mob agent) {
return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None)); return (agent.isAlive() && !agent.getBonuses().getBool(ModType.Stunned, SourceType.None));
} }
public static void swingIsMiss(Mob agent,AbstractWorldObject target, int animation) { public static void swingIsMiss(Mob agent,AbstractWorldObject target, int animation) {
TargetedActionMsg msg = new TargetedActionMsg(agent,target, 0f, animation); TargetedActionMsg msg = new TargetedActionMsg(agent,target, 0f, animation);
@ -179,7 +175,6 @@ public class CombatUtilities {
DispatchMessage.sendToAllInRange(agent,msg); DispatchMessage.sendToAllInRange(agent,msg);
} }
public static boolean triggerDefense(Mob agent, AbstractWorldObject target) { public static boolean triggerDefense(Mob agent, AbstractWorldObject target) {
int defenseScore = 0; int defenseScore = 0;
int attackScore = agent.getAtrHandOne(); int attackScore = agent.getAtrHandOne();
@ -215,19 +210,15 @@ public class CombatUtilities {
} }
return ThreadLocalRandom.current().nextInt(100) > hitChance; return ThreadLocalRandom.current().nextInt(100) > hitChance;
} }
public static boolean triggerBlock(Mob agent,AbstractWorldObject ac) { public static boolean triggerBlock(Mob agent,AbstractWorldObject ac) {
return triggerPassive(agent,ac, "Block"); return triggerPassive(agent,ac, "Block");
} }
public static boolean triggerParry(Mob agent,AbstractWorldObject ac) { public static boolean triggerParry(Mob agent,AbstractWorldObject ac) {
return triggerPassive(agent,ac, "Parry"); return triggerPassive(agent,ac, "Parry");
} }
public static boolean triggerDodge(Mob agent,AbstractWorldObject ac) { public static boolean triggerDodge(Mob agent,AbstractWorldObject ac) {
return triggerPassive(agent,ac, "Dodge"); return triggerPassive(agent,ac, "Dodge");
} }
public static boolean triggerPassive(Mob agent,AbstractWorldObject ac, String type) { public static boolean triggerPassive(Mob agent,AbstractWorldObject ac, String type) {
float chance = 0; float chance = 0;
if (AbstractWorldObject.IsAbstractCharacter(ac)) if (AbstractWorldObject.IsAbstractCharacter(ac))
@ -240,8 +231,6 @@ public class CombatUtilities {
return ThreadLocalRandom.current().nextInt(100) < chance; return ThreadLocalRandom.current().nextInt(100) < chance;
} }
public static void combatCycle(Mob agent,AbstractWorldObject target, boolean mainHand, ItemBase wb) { public static void combatCycle(Mob agent,AbstractWorldObject target, boolean mainHand, ItemBase wb) {
if (!agent.isAlive() || !target.isAlive()) return; if (!agent.isAlive() || !target.isAlive()) return;
@ -306,7 +295,7 @@ public class CombatUtilities {
swingIsBlock(agent, target, passiveAnim); swingIsBlock(agent, target, passiveAnim);
return; return;
} }
swingIsDamage(agent,target, determineDamage(agent,target, mainHand, speed, dt), anim); swingIsDamage(agent,target, determineDamage(agent,target), anim);
if (agent.getWeaponPower() != null) if (agent.getWeaponPower() != null)
agent.getWeaponPower().attack(target, MBServerStatics.ONE_MINUTE); agent.getWeaponPower().attack(target, MBServerStatics.ONE_MINUTE);
@ -333,136 +322,111 @@ public class CombatUtilities {
Mob targetMob = (Mob)target; Mob targetMob = (Mob)target;
if (targetMob.isSiege()) if (targetMob.isSiege())
return; return;
if (System.currentTimeMillis() < targetMob.getTimeStamp("CallForHelp"))
return;
CallForHelp(targetMob);
targetMob.getTimestamps().put("CallForHelp", System.currentTimeMillis() + 60000);
} }
} }
public static float determineDamage(Mob agent,AbstractWorldObject target) {
public static void CallForHelp(Mob aiAgent) { if(agent == null || target == null){
//early exit for null
Set<Mob> zoneMobs = aiAgent.getParentZone().zoneMobSet; return 0;
AbstractWorldObject target = aiAgent.getCombatTarget();
if (target == null) {
return;
} }
//set default values
int count = 0; float min = 40;
for (Mob mob: zoneMobs){ float max = 60;
if (!mob.isAlive()) float range;
continue; float damage;
if (mob.isSiege() || mob.isPet() || !Enum.MobFlagType.AGGRESSIVE.elementOf(mob.getMobBase().getFlags())) float dmgMultiplier = 1 + agent.getBonuses().getFloatPercentAll(ModType.MeleeDamageModifier, SourceType.None);
continue; if(agent.isSummonedPet() == true || agent.isPet() == true || agent.isNecroPet() == true) {
if (count == 5) //damage calc for pet
continue; float str = agent.getStatStrCurrent();
float dex = agent.getStatDexCurrent();
double minDmg = getMinDmg(min,str,dex,agent.getLevel());
if (mob.getCombatTarget() != null) double maxDmg = getMaxDmg(max,str,dex,agent.getLevel());
continue; range = (float) (maxDmg - minDmg);
damage = min + ((ThreadLocalRandom.current().nextFloat() * range) + (ThreadLocalRandom.current().nextFloat() * range)) / 2;
if (!aiAgent.isPlayerGuard() && mob.isPlayerGuard()) if (AbstractWorldObject.IsAbstractCharacter(target))
continue; if (((AbstractCharacter) target).isSit())
damage *= 2.5f; //increase damage if sitting
if (aiAgent.isPlayerGuard() && !mob.isPlayerGuard() )
continue; if (AbstractWorldObject.IsAbstractCharacter(target))
return ((AbstractCharacter) target).getResists().getResistedDamage(agent, (AbstractCharacter) target, DamageType.Crush, damage, 0) * dmgMultiplier;
if (target.getObjectType() == GameObjectType.PlayerCharacter){
if (target.getObjectType() == GameObjectType.Building) {
if (!MovementUtilities.inRangeToAggro(mob, (PlayerCharacter)target)) Building building = (Building) target;
continue; Resists resists = building.getResists();
count++; return (damage * (1 - (resists.getResist(DamageType.Crush, 0) / 100))) * dmgMultiplier;
}else{
if (count == 5)
continue;
if (aiAgent.getLoc().distanceSquared2D(target.getLoc()) > sqr(aiAgent.getAggroRange()))
continue;
count++;
} }
}else if(agent.isPlayerGuard() == true){
//damage calc for guard
ItemBase weapon = agent.getEquip().get(1).getItemBase();
double minDmg = weapon.getMinDamage();
double maxDmg = weapon.getMaxDamage();
float str = agent.getStatStrCurrent();
if (mob.getState() == STATE.Awake || mob.getState() == STATE.Patrol){ float dex = agent.getStatDexCurrent();
mob.setCombatTarget(target); min = (float) getMinDmg(minDmg,str,dex,agent.getLevel());
mob.setState(STATE.Attack); max = (float) getMaxDmg(maxDmg,str,dex,agent.getLevel());
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 {
//damage calc for regular mob
min = agent.getMobBase().getDamageMin();
max = agent.getMobBase().getMaxDmg();
DamageType dt = DamageType.Crush;
if(agent.getEquip().get(1) != null && agent.getEquip().get(2) == null){
min = agent.getEquip().get(1).getItemBase().getMinDamage();
max = agent.getEquip().get(1).getItemBase().getMaxDamage();
} else if(agent.getEquip().get(1) == null && agent.getEquip().get(2) != null){
min = agent.getEquip().get(2).getItemBase().getMinDamage();
max = agent.getEquip().get(2).getItemBase().getMaxDamage();
} else if(agent.getEquip().get(1) != null && agent.getEquip().get(2) != null){
min = agent.getEquip().get(1).getItemBase().getMinDamage() + agent.getEquip().get(2).getItemBase().getMinDamage();
max = agent.getEquip().get(1).getItemBase().getMaxDamage() + agent.getEquip().get(2).getItemBase().getMaxDamage();
}
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;
} }
} }
//impossible to get this far
return 0;
} }
public static double getMinDmg(double min, float str, float dex, int level){
public static float determineDamage(Mob agent,AbstractWorldObject target, boolean mainHand, float speed, DamageType dt) { if(str == 0){
str = 1;
float min = (mainHand) ? agent.getMinDamageHandOne() : agent.getMinDamageHandTwo();
float max = (mainHand) ? agent.getMaxDamageHandOne() : agent.getMaxDamageHandTwo();
if(agent.isSummonedPet() == true)
{
min = 40 * (1 + (agent.getLevel()/10));
max = 60 * (1 + (agent.getLevel()/8));
//check if we have powers to cast
if(agent.mobPowers.isEmpty() == false) {
//check for power usage
Random random = new Random();
int value = random.nextInt(0 + (agent.mobPowers.size() + (agent.mobPowers.size() * 5))) + 0;
if (value <= agent.mobPowers.size())
{
//do power
int powerId = agent.mobPowers.get(value);
PowersManager.runPowerAction(agent,target,target.getLoc(),new ActionsBase(),40, PowersManager.getPowerByToken(powerId));
}
else
{
//do mele damage
float range = max - min;
float 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);
if (target.getObjectType() == GameObjectType.Building) {
Building building = (Building) target;
Resists resists = building.getResists();
return damage * (1 - (resists.getResist(dt, 0) / 100));
}
}
}
} }
float range = max - min; if(dex == 0){
float damage = min + ((ThreadLocalRandom.current().nextFloat()*range)+(ThreadLocalRandom.current().nextFloat()*range))/2; dex = 1;
//DAMAGE FORMULA FOR PET
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);
if (target.getObjectType() == GameObjectType.Building){
Building building = (Building)target;
Resists resists = building.getResists();
return damage * (1 - (resists.getResist(dt, 0) / 100));
} }
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))));
return damage; }
public static double getMaxDmg(double max, float str, float dex, int level){
if(str == 0){
str = 1;
}
if(dex == 0){
dex = 1;
}
return (max * pow((0.0124*str +0.118*(str-0.75)),pow(0.5 + 0.0022*dex + 0.028*(dex-0.75),0.5 + 0.0075*(200/level))));
} }
public static boolean RunAIRandom(){ public static boolean RunAIRandom(){
int random = ThreadLocalRandom.current().nextInt(4); int random = ThreadLocalRandom.current().nextInt(4);

2
src/engine/objects/Mob.java

@ -92,6 +92,7 @@ public class Mob extends AbstractIntelligenceAgent {
private boolean walkingHome = true; private boolean walkingHome = true;
private long lastAttackTime = 0; private long lastAttackTime = 0;
public long nextCastTime = 0; public long nextCastTime = 0;
public long nextCallForHelp = 0;
private long deathTime = 0; private long deathTime = 0;
private ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
@ -2700,7 +2701,6 @@ public class Mob extends AbstractIntelligenceAgent {
public boolean isPlayerGuard() { public boolean isPlayerGuard() {
return isPlayerGuard; return isPlayerGuard;
} }
public void setPlayerGuard(boolean isPlayerGuard) { public void setPlayerGuard(boolean isPlayerGuard) {
this.isPlayerGuard = isPlayerGuard; this.isPlayerGuard = isPlayerGuard;
} }

Loading…
Cancel
Save