From 69c78fa5a63306a47ef1864373d9d67be3fc5618 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Tue, 7 Jun 2022 20:24:11 -0500 Subject: [PATCH] added power casting for pets who have DB entires --- src/engine/ai/MobileFSM.java | 3 +- src/engine/ai/utilities/CombatUtilities.java | 40 +++++++++++++++++++- src/engine/objects/Mob.java | 12 +++--- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 78b4dccd..97e256e2 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -1126,8 +1126,7 @@ public class MobileFSM { return; } - //HashMap staticPowers = aiAgent.getMobBase().getStaticPowers(); - HashMap staticPowers = DbManager.MobBaseQueries.LOAD_STATIC_POWERS(aiAgent.getMobBaseID()); + 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..f6c36e8a 100644 --- a/src/engine/ai/utilities/CombatUtilities.java +++ b/src/engine/ai/utilities/CombatUtilities.java @@ -15,13 +15,17 @@ import engine.Enum.*; import engine.ai.MobileFSM.STATE; import engine.gameManager.ChatManager; import engine.gameManager.CombatManager; +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 java.util.Random; import java.util.Set; import java.util.concurrent.ThreadLocalRandom; @@ -381,10 +385,42 @@ public class CombatUtilities { float min = (mainHand) ? agent.getMinDamageHandOne() : agent.getMinDamageHandTwo(); float max = (mainHand) ? agent.getMaxDamageHandOne() : agent.getMaxDamageHandTwo();; - + if(agent.isSummonedPet() == true) + { + //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..d1aa7b31 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();