From 16db4d15bc5506969bcc89ff3be549d2fc2b6ab9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 15 Mar 2023 08:52:00 -0400 Subject: [PATCH] Reformatting of MobCast() method in manager. --- src/engine/ai/MobileFSM.java | 103 ++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 45 deletions(-) diff --git a/src/engine/ai/MobileFSM.java b/src/engine/ai/MobileFSM.java index 8d7bb536..514c1a34 100644 --- a/src/engine/ai/MobileFSM.java +++ b/src/engine/ai/MobileFSM.java @@ -1642,59 +1642,72 @@ public class MobileFSM { return true; } public static boolean MobCast(Mob mob) { - if (mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)) { - MobCallForHelp(mob); - } + + // Method picks a random spell from a mobile's list of powers + // and casts it on the player. Validation (including empty lists) + // if done previously in canCast(); + + ArrayList powerTokens; PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget(); - HashMap eligiblePowers = mob.mobPowers; - for(Map.Entry power : mob.mobPowers.entrySet()) { - PowersBase pwr= PowersManager.getPowerByToken(power.getKey()); + + if (mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP)) + MobCallForHelp(mob); + + // Generate a list of tokens from the mob powers for this mobile. + + powerTokens = new ArrayList<>(mob.mobPowers.keySet()); + + // If player has this effect on them already then remove the token + // from the list of mob powers + + for (int powerToken : powerTokens){ + + PowersBase pwr= PowersManager.getPowerByToken(powerToken); + for(ActionsBase act : pwr.getActions()){ + String des = act.stackType; - try { - if (target.getEffects() != null && target.getEffects().containsKey(des) == true) { - eligiblePowers.remove(power.getKey()); - } - }catch(Exception ex){ - } + if (target.getEffects() != null && target.getEffects().containsKey(des)) + powerTokens.remove(powerToken); } + } + + // Pick random spell from our list of powers + int powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size())); + int powerRank = mob.mobPowers.get(powerToken); + PowersBase mobPower = PowersManager.getPowerByToken(powerToken); + + // Cast the spell + + if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { + PowersManager.useMobPower(mob, (AbstractCharacter) mob.getCombatTarget(), mobPower, powerRank); + PerformActionMsg msg; + + if (mobPower.isHarmful() == false || mobPower.targetSelf == true) + msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob); + else + msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); + + msg.setUnknown04(2); + PowersManager.finishUseMobPower(msg, mob, 0, 0); + + //default minimum seconds between cast = 10 + + long coolDown = mobPower.getCooldown(); + + if (coolDown < 10000) + mob.nextCastTime = System.currentTimeMillis() + 10000 + coolDown; + else + mob.nextCastTime = System.currentTimeMillis() + coolDown; + + return true; } - int random = ThreadLocalRandom.current().nextInt(eligiblePowers.size()); - int powerToken = 0; - int powerRank = 0; - Map entries = eligiblePowers; - int count = -1; - for (Map.Entry entry : entries.entrySet()) { - count += 1; - if (count == random) { - powerToken = entry.getKey(); - powerRank = entry.getValue(); - PowersBase mobPower = PowersManager.getPowerByToken(powerToken); - if (CombatUtilities.inRange2D(mob, target, mobPower.getRange())) { - PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank); - PerformActionMsg msg = new PerformActionMsg(); - if(mobPower.isHarmful() == false || mobPower.targetSelf == true){ - msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob); - } else { - msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); - } - msg.setUnknown04(2); - PowersManager.finishUseMobPower(msg, mob, 0, 0); - //default minimum seconds between cast = 10 - long cooldown = mobPower.getCooldown(); - if(cooldown < 10000){ - mob.nextCastTime = System.currentTimeMillis() + 10000 + cooldown; - } else { - mob.nextCastTime = System.currentTimeMillis() + cooldown; - } - return true; + + return false; } - } - } - return false; - } + public static void MobCallForHelp(Mob mob) { if(mob.nextCallForHelp == 0){ mob.nextCallForHelp = System.currentTimeMillis();