Browse Source

Consolidated cast methods.

feature-workorder
MagicBot 1 year ago
parent
commit
1285d12915
  1. 172
      src/engine/mobileAI/MobAI.java

172
src/engine/mobileAI/MobAI.java

@ -58,15 +58,11 @@ public class MobAI {
if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) { if (target.getObjectType() == Enum.GameObjectType.PlayerCharacter && canCast(mob)) {
if (mob.isPlayerGuard() == false && MobCast(mob)) { if (MobCast(mob)) {
mob.updateLocation(); mob.updateLocation();
return; return;
} }
if (mob.isPlayerGuard() == true && GuardCast(mob)) {
mob.updateLocation();
return;
}
} }
if (!CombatUtilities.inRangeToAttack(mob, target)) if (!CombatUtilities.inRangeToAttack(mob, target))
@ -412,10 +408,13 @@ public class MobAI {
// Pick random spell from our list of powers // Pick random spell from our list of powers
int powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token; RunePowerEntry runePowerEntry = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size()));
int powerRank = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).rank;
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 //check for hit-roll
@ -451,138 +450,33 @@ public class MobAI {
return false; return false;
} }
public static boolean GuardCast(Mob mob) { private static int getGuardPowerRank(Mob mob) {
int powerRank = 1;
try {
// Method picks a random spell from a mobile's list of powers switch (mob.getRank()) {
// and casts it on the current target (or itself). Validation case 1:
// (including empty lists) is done previously within canCast(); powerRank = 10;
break;
ArrayList<RunePowerEntry> powerEntries; case 2:
ArrayList<RunePowerEntry> purgeEntries; powerRank = 15;
AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); break;
case 3:
if (mob.behaviourType.callsForHelp) powerRank = 20;
MobCallForHelp(mob); break;
case 4:
// If player has this effect on them currently then remove powerRank = 25;
// this token from our list. break;
case 5:
powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID())); powerRank = 30;
purgeEntries = new ArrayList<>(); break;
case 6:
// Additional powers may come from the contract ID. This is to support powerRank = 35;
// powers for player guards irrespective of the mobbase used. break;
case 7:
if (mob.isPlayerGuard()) { powerRank = 40;
break;
ArrayList<RunePowerEntry> 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());
} }
return false; return powerRank;
} }
public static void MobCallForHelp(Mob mob) { public static void MobCallForHelp(Mob mob) {

Loading…
Cancel
Save