diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 4861fa4e..97e256e2 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -16,10 +16,7 @@ import engine.Enum.GameObjectType; import engine.InterestManagement.WorldGrid; import engine.ai.utilities.CombatUtilities; import engine.ai.utilities.MovementUtilities; -import engine.gameManager.BuildingManager; -import engine.gameManager.CombatManager; -import engine.gameManager.MovementManager; -import engine.gameManager.PowersManager; +import engine.gameManager.*; import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.msg.PerformActionMsg; @@ -1130,7 +1127,6 @@ public class MobileFSM { } HashMap staticPowers = aiAgent.getMobBase().getStaticPowers(); - if (staticPowers != null && !staticPowers.isEmpty()) { int chance = ThreadLocalRandom.current().nextInt(100); diff --git a/src/engine/ai/utilities/CombatUtilities.java b/src/engine/ai/utilities/CombatUtilities.java index 60b538b9..c29d6fe0 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -12,16 +12,26 @@ package engine.ai.utilities; import engine.Enum; import engine.Enum.*; +import engine.ai.MobileFSM; import engine.ai.MobileFSM.STATE; import engine.gameManager.ChatManager; import engine.gameManager.CombatManager; +import engine.gameManager.DbManager; +import engine.gameManager.PowersManager; import engine.math.Vector3fImmutable; import engine.net.DispatchMessage; import engine.net.client.msg.TargetedActionMsg; import engine.objects.*; +import engine.powers.ActionsBase; +import engine.powers.PowersBase; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import sun.security.util.Debug; +import java.security.KeyStore; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; @@ -237,7 +247,6 @@ public class CombatUtilities { speed = agent.getSpeedHandOne(); else speed = agent.getSpeedHandTwo(); - DamageType dt = DamageType.Crush; if (agent.isSiege()) dt = DamageType.Siege; @@ -280,6 +289,64 @@ public class CombatUtilities { else if(triggerBlock(agent,target)) swingIsBlock(agent,target, passiveAnim); else + //check for a cast here? + + //agent.mobPowers = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(agent.getMobBaseID()); + + if(agent.mobPowers.size() > 0 && agent.mobPowers != null) + { + //get cast chance 33% cast 67% mele + int random = ThreadLocalRandom.current().nextInt(agent.mobPowers.size() * 3); + //allow casting of spell + if(random <= agent.mobPowers.size()) + { + int powerToken; + int powerRank; + //cast a spell + Map entries = agent.mobPowers; + int count = 0; + for(Map.Entry entry : entries.entrySet()) + { + count += 1; + if(count == random) + { + powerToken = entry.getKey(); + //powerRank = entry.getValue(); + switch(agent.getLevel()) + { + default: + powerRank = 1; + break; + case 10: + powerRank = 5; + break; + case 20: + powerRank = 10; + break; + case 30: + powerRank = 15; + break; + case 40: + powerRank = 25; + break; + case 50: + powerRank = 30; + break; + case 60: + powerRank = 35; + break; + case 70: + powerRank = 40; + break; + } + System.out.println(agent.getMobBase().getFirstName() + " is casting: " + PowersManager.getPowerByToken(powerToken).skillName); + PowersManager.applyPower(agent,target,target.getLoc(),powerToken,powerRank, false); + } + } + return; + } + } + //finished with casting check swingIsDamage(agent,target, determineDamage(agent,target, mainHand, speed, dt), anim); if (agent.getWeaponPower() != null) @@ -381,10 +448,45 @@ public class CombatUtilities { 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; float damage = min + ((ThreadLocalRandom.current().nextFloat()*range)+(ThreadLocalRandom.current().nextFloat()*range))/2; - +//DAMAGE FORMULA FOR PET if (AbstractWorldObject.IsAbstractCharacter(target)) if (((AbstractCharacter)target).isSit()) damage *= 2.5f; //increase damage if sitting diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index dfd30590..c5856358 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -32,6 +32,7 @@ import engine.net.client.msg.ManageCityAssetsMsg; import engine.net.client.msg.PetMsg; import engine.net.client.msg.PlaceAssetMsg; import engine.powers.EffectsBase; +import engine.powers.PowersBase; import engine.server.MBServerStatics; import engine.server.world.WorldServer; import org.joda.time.DateTime; @@ -111,7 +112,7 @@ public class Mob extends AbstractIntelligenceAgent { public boolean despawned = false; public Vector3fImmutable destination = Vector3fImmutable.ZERO; public Vector3fImmutable localLoc = Vector3fImmutable.ZERO; - + public HashMap mobPowers; /** * No Id Constructor */ @@ -365,6 +366,7 @@ public class Mob extends AbstractIntelligenceAgent { this.setObjectTypeMask(MBServerStatics.MASK_PET | this.getTypeMasks()); if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) this.setLoc(this.getLoc()); + mobPowers = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(this.getMobBaseID()); } if (!isPet && this.contract == null) { this.level = (short) this.mobBase.getLevel(); @@ -393,10 +395,10 @@ public class Mob extends AbstractIntelligenceAgent { //TODO set these correctly later this.rangeHandOne = 8; this.rangeHandTwo = -1; - this.minDamageHandOne = 0; - this.maxDamageHandOne = 0; - this.minDamageHandTwo = 1; - this.maxDamageHandTwo = 4; + this.minDamageHandOne = 0; + this.maxDamageHandOne = 0; + this.minDamageHandTwo = 1; + this.maxDamageHandTwo = 4; this.atrHandOne = 300; this.atrHandOne = 300; this.defenseRating = (short) this.mobBase.getDefenseRating(); @@ -2201,7 +2203,7 @@ public class Mob extends AbstractIntelligenceAgent { } catch(Exception e){ Logger.error( e.getMessage()); } - + mobPowers = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(this.getMobBaseID()); if (this.equip == null) { Logger.error("Null equipset returned for uuid " + currentID); this.equip = new HashMap<>(0);