From 1285d12915f677f2c47c72333fb4584f04e08396 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 5 Sep 2023 14:25:24 -0400 Subject: [PATCH] Consolidated cast methods. --- src/engine/mobileAI/MobAI.java | 172 +++++++-------------------------- 1 file changed, 33 insertions(+), 139 deletions(-) diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index 4bf9ef65..fbc26b45 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -58,15 +58,11 @@ public class MobAI { if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) { - if (mob.isPlayerGuard() == false && MobCast(mob)) { + if (MobCast(mob)) { mob.updateLocation(); return; } - if (mob.isPlayerGuard() == true && GuardCast(mob)) { - mob.updateLocation(); - return; - } } if (!CombatUtilities.inRangeToAttack(mob, target)) @@ -412,10 +408,13 @@ public class MobAI { // Pick random spell from our list of powers - int powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token; - int powerRank = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).rank; + RunePowerEntry runePowerEntry = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())); + + PowersBase mobPower = PowersManager.getPowerByToken(runePowerEntry.token); + int powerRank = runePowerEntry.rank; - PowersBase mobPower = PowersManager.getPowerByToken(powerToken); + if (mob.isPlayerGuard()) + powerRank = getGuardPowerRank(mob); //check for hit-roll @@ -451,138 +450,33 @@ public class MobAI { return false; } - public static boolean GuardCast(Mob mob) { - - try { - // Method picks a random spell from a mobile's list of powers - // and casts it on the current target (or itself). Validation - // (including empty lists) is done previously within canCast(); - - ArrayList powerEntries; - ArrayList purgeEntries; - AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); - - if (mob.behaviourType.callsForHelp) - MobCallForHelp(mob); - - // If player has this effect on them currently then remove - // this token from our list. - - powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID())); - purgeEntries = new ArrayList<>(); - - // Additional powers may come from the contract ID. This is to support - // powers for player guards irrespective of the mobbase used. - - if (mob.isPlayerGuard()) { - - ArrayList contractEntries = new ArrayList<>(); - - if (mob.contract != null) - contractEntries = PowersManager.getPowersForRune(mob.contractUUID); - - if (mob.agentType.equals(Enum.AIAgentType.GUARDMINION)) - contractEntries = PowersManager.getPowersForRune(mob.guardCaptain.contractUUID); - - powerEntries.addAll(contractEntries); - - } - - // If player has this effect on them currently then remove - // this token from our list. - - for (RunePowerEntry runePowerEntry : powerEntries) { - - PowersBase powerBase = PowersManager.getPowerByToken(runePowerEntry.token); - - for (ActionsBase actionBase : powerBase.getActions()) { - - String stackType = actionBase.stackType; - - if (target.getEffects() != null && target.getEffects().containsKey(stackType)) - purgeEntries.add(runePowerEntry); - } - } - - powerEntries.removeAll(purgeEntries); - - // Sanity check - - if (powerEntries.isEmpty()) - return false; - - int powerToken = 0; - - // Choose a random spell. - - powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token; - - int powerRank = 1; - - switch(mob.getRank()){ - case 1: - powerRank = 10; - break; - case 2: - powerRank = 15; - break; - case 3: - powerRank = 20; - break; - case 4: - powerRank = 25; - break; - case 5: - powerRank = 30; - break; - case 6: - powerRank = 35; - break; - case 7: - powerRank = 40; - break; - } - - PowersBase mobPower = PowersManager.getPowerByToken(powerToken); - - //check for hit-roll - - if (mobPower.requiresHitRoll) - if (CombatUtilities.triggerDefense(mob, mob.getCombatTarget())) - return false; - - // Cast the spell - - if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { - - PerformActionMsg msg; - - if (!mobPower.isHarmful() || mobPower.targetSelf) { - - if (mobPower.category.equals("DISPEL")) { - PowersManager.useMobPower(mob, target, mobPower, powerRank); - msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); - } else { - PowersManager.useMobPower(mob, mob, mobPower, powerRank); - msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob); - } - } else { - PowersManager.useMobPower(mob, target, mobPower, powerRank); - msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target); - } - - msg.setUnknown04(2); - - PowersManager.finishUseMobPower(msg, mob, 0, 0); - - long randomCooldown = (long)((ThreadLocalRandom.current().nextInt(10,15) * 1000) * MobAIThread.AI_CAST_FREQUENCY); - mob.nextCastTime = System.currentTimeMillis() + randomCooldown; - return true; - } - } catch (Exception e) { - Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: MobCast" + " " + e.getMessage()); + private static int getGuardPowerRank(Mob mob) { + int powerRank = 1; + + switch (mob.getRank()) { + case 1: + powerRank = 10; + break; + case 2: + powerRank = 15; + break; + case 3: + powerRank = 20; + break; + case 4: + powerRank = 25; + break; + case 5: + powerRank = 30; + break; + case 6: + powerRank = 35; + break; + case 7: + powerRank = 40; + break; } - return false; + return powerRank; } public static void MobCallForHelp(Mob mob) {