Browse Source

Reformatting of MobCast() method in manager.

master
MagicBot 2 years ago
parent
commit
7473067329
  1. 101
      src/engine/ai/MobileFSM.java
  2. 5447
      src/engine/objects/Mob.java

101
src/engine/ai/MobileFSM.java

@ -1648,59 +1648,72 @@ public class MobileFSM {
return true; return true;
} }
public static boolean MobCast(Mob mob) { 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<Integer> powerTokens;
PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget(); PlayerCharacter target = (PlayerCharacter) mob.getCombatTarget();
HashMap<Integer,Integer> eligiblePowers = mob.mobPowers;
for(Map.Entry<Integer,Integer> power : mob.mobPowers.entrySet()) { if (mob.getMobBase().getFlags().contains(Enum.MobFlagType.CALLSFORHELP))
PowersBase pwr= PowersManager.getPowerByToken(power.getKey()); 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()){ for(ActionsBase act : pwr.getActions()){
String des = act.stackType; 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);
} }
} }
int random = ThreadLocalRandom.current().nextInt(eligiblePowers.size());
int powerToken = 0; // Pick random spell from our list of powers
int powerRank = 0;
Map<Integer, Integer> entries = eligiblePowers; int powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size()));
int count = -1; int powerRank = mob.mobPowers.get(powerToken);
for (Map.Entry<Integer, Integer> entry : entries.entrySet()) { PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
count += 1;
if (count == random) { // Cast the spell
powerToken = entry.getKey();
powerRank = entry.getValue(); if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) {
PowersBase mobPower = PowersManager.getPowerByToken(powerToken); PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank);
if (CombatUtilities.inRange2D(mob, mob.getCombatTarget(), mobPower.getRange())) { PerformActionMsg msg;
PowersManager.useMobPower(mob,(AbstractCharacter)mob.getCombatTarget(),mobPower,powerRank);
PerformActionMsg msg = new PerformActionMsg(); if(mobPower.isHarmful() == false || mobPower.targetSelf == true)
if(mobPower.isHarmful() == false || mobPower.targetSelf == true){ msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob);
msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, mob); else
} else { msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target);
msg = PowersManager.createPowerMsg(mobPower, powerRank, mob, target);
} msg.setUnknown04(2);
msg.setUnknown04(2); PowersManager.finishUseMobPower(msg, mob, 0, 0);
PowersManager.finishUseMobPower(msg, mob, 0, 0);
//default minimum seconds between cast = 10 //default minimum seconds between cast = 10
long cooldown = mobPower.getCooldown();
if(cooldown < 10000){ long coolDown = mobPower.getCooldown();
mob.nextCastTime = System.currentTimeMillis() + 10000 + cooldown;
} else { if(coolDown < 10000)
mob.nextCastTime = System.currentTimeMillis() + cooldown; mob.nextCastTime = System.currentTimeMillis() + 10000 + coolDown;
} else
return true; mob.nextCastTime = System.currentTimeMillis() + coolDown;
return true;
} }
}
}
return false; return false;
} }
public static void MobCallForHelp(Mob mob) { public static void MobCallForHelp(Mob mob) {
if(mob.nextCallForHelp == 0){ if(mob.nextCallForHelp == 0){
mob.nextCallForHelp = System.currentTimeMillis(); mob.nextCallForHelp = System.currentTimeMillis();

5447
src/engine/objects/Mob.java

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save