Browse Source

Refactored out duplicate power collection.

feature-workorder
MagicBot 1 year ago
parent
commit
55c6e3cf93
  1. 5
      src/engine/devcmd/cmds/aiInfoCmd.java
  2. 20
      src/engine/gameManager/PowersManager.java
  3. 53
      src/engine/mobileAI/MobAI.java
  4. 15
      src/engine/objects/Mob.java
  5. 2
      src/engine/server/world/WorldServer.java

5
src/engine/devcmd/cmds/aiInfoCmd.java

@ -15,6 +15,7 @@ import engine.gameManager.PowersManager; @@ -15,6 +15,7 @@ import engine.gameManager.PowersManager;
import engine.objects.AbstractGameObject;
import engine.objects.Mob;
import engine.objects.PlayerCharacter;
import engine.powers.MobPowerEntry;
import java.util.Map;
@ -90,8 +91,8 @@ public class aiInfoCmd extends AbstractDevCmd { @@ -90,8 +91,8 @@ public class aiInfoCmd extends AbstractDevCmd {
output += "Powers:" + newline;
for (int token : mob.mobPowers.keySet())
output += PowersManager.getPowerByToken(token).getName() + newline;
for (MobPowerEntry mobPowerEntry : PowersManager._allMobPowers.get(mob.contractUUID))
output += PowersManager.getPowerByToken(mobPowerEntry.token).getName() + newline;
throwbackInfo(playerCharacter, output);
}

20
src/engine/gameManager/PowersManager.java

@ -53,7 +53,7 @@ public enum PowersManager { @@ -53,7 +53,7 @@ public enum PowersManager {
public static HashMap<Integer, AbstractPowerAction> powerActionsByID = new HashMap<>();
public static HashMap<String, Integer> ActionTokenByIDString = new HashMap<>();
public static HashMap<String, Integer> AnimationOverrides = new HashMap<>();
public static HashMap<Integer, ArrayList<MobPowerEntry>> AllMobPowers;
public static HashMap<Integer, ArrayList<MobPowerEntry>> _allMobPowers;
private static JobScheduler js;
private PowersManager() {
@ -103,6 +103,24 @@ public enum PowersManager { @@ -103,6 +103,24 @@ public enum PowersManager {
}
}
public static ArrayList<MobPowerEntry> getPowersForMobile(Mob mobile) {
ArrayList<MobPowerEntry> mobPowers = new ArrayList<>();
ArrayList<MobPowerEntry> powerEntries;
powerEntries = PowersManager._allMobPowers.get(mobile.loadID);
if (powerEntries != null)
mobPowers.addAll(powerEntries);
powerEntries = PowersManager._allMobPowers.get(mobile.contractUUID);
if (powerEntries != null)
mobPowers.addAll(powerEntries);
return mobPowers;
}
// This pre-loads all powers and effects
public static void InitializePowers() {

53
src/engine/mobileAI/MobAI.java

@ -22,6 +22,7 @@ import engine.net.client.msg.PerformActionMsg; @@ -22,6 +22,7 @@ import engine.net.client.msg.PerformActionMsg;
import engine.net.client.msg.PowerProjectileMsg;
import engine.objects.*;
import engine.powers.ActionsBase;
import engine.powers.MobPowerEntry;
import engine.powers.PowersBase;
import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger;
@ -321,7 +322,7 @@ public class MobAI { @@ -321,7 +322,7 @@ public class MobAI {
return false;
}
if (mob.mobPowers.isEmpty())
if (PowersManager.getPowersForMobile(mob).isEmpty())
return false;
if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) {
@ -346,8 +347,8 @@ public class MobAI { @@ -346,8 +347,8 @@ public class MobAI {
// and casts it on the current target (or itself). Validation
// (including empty lists) is done previously within canCast();
ArrayList<Integer> powerTokens;
ArrayList<Integer> purgeTokens;
ArrayList<MobPowerEntry> powerEntries;
ArrayList<MobPowerEntry> purgeEntries;
AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget();
if (mob.behaviourType.callsForHelp)
@ -355,36 +356,36 @@ public class MobAI { @@ -355,36 +356,36 @@ public class MobAI {
// Generate a list of tokens from the mob powers for this mobile.
powerTokens = new ArrayList<>(mob.mobPowers.keySet());
purgeTokens = new ArrayList<>();
powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob));
purgeEntries = new ArrayList<>();
// If player has this effect on them currently then remove
// this token from our list.
for (int powerToken : powerTokens) {
for (MobPowerEntry mobPowerEntry : powerEntries) {
PowersBase powerBase = PowersManager.getPowerByToken(powerToken);
PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token);
for (ActionsBase actionBase : powerBase.getActions()) {
String stackType = actionBase.stackType;
if (target.getEffects() != null && target.getEffects().containsKey(stackType))
purgeTokens.add(powerToken);
purgeEntries.add(mobPowerEntry);
}
}
powerTokens.removeAll(purgeTokens);
powerEntries.removeAll(purgeEntries);
// Sanity check
if (powerTokens.isEmpty())
if (powerEntries.isEmpty())
return false;
// Pick random spell from our list of powers
int powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size()));
int powerRank = mob.mobPowers.get(powerToken);
int powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token;
int powerRank = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).rank;
PowersBase mobPower = PowersManager.getPowerByToken(powerToken);
@ -429,8 +430,8 @@ public class MobAI { @@ -429,8 +430,8 @@ public class MobAI {
// and casts it on the current target (or itself). Validation
// (including empty lists) is done previously within canCast();
ArrayList<Integer> powerTokens;
ArrayList<Integer> purgeTokens;
ArrayList<MobPowerEntry> powerEntries;
ArrayList<MobPowerEntry> purgeEntries;
AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget();
if (mob.behaviourType.callsForHelp)
@ -438,30 +439,36 @@ public class MobAI { @@ -438,30 +439,36 @@ public class MobAI {
// Generate a list of tokens from the mob powers for this mobile.
powerTokens = new ArrayList<>(mob.mobPowers.keySet());
purgeTokens = new ArrayList<>();
powerEntries = PowersManager.getPowersForMobile(mob);
purgeEntries = new ArrayList<>();
// If player has this effect on them currently then remove
// this token from our list.
for (int powerToken : powerTokens) {
powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob));
purgeEntries = new ArrayList<>();
PowersBase powerBase = PowersManager.getPowerByToken(powerToken);
// If player has this effect on them currently then remove
// this token from our list.
for (MobPowerEntry mobPowerEntry : powerEntries) {
PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token);
for (ActionsBase actionBase : powerBase.getActions()) {
String stackType = actionBase.stackType;
if (target.getEffects() != null && target.getEffects().containsKey(stackType))
purgeTokens.add(powerToken);
purgeEntries.add(mobPowerEntry);
}
}
powerTokens.removeAll(purgeTokens);
powerEntries.removeAll(purgeEntries);
// Sanity check
if (powerTokens.isEmpty())
if (powerEntries.isEmpty())
return false;
int powerToken = 0;
@ -470,11 +477,11 @@ public class MobAI { @@ -470,11 +477,11 @@ public class MobAI {
if (nukeRoll < 55) {
//use direct damage spell
powerToken = powerTokens.get(powerTokens.size() - 1);
powerToken = powerEntries.get(powerEntries.size() - 1).token;
} else {
//use random spell
powerToken = powerTokens.get(ThreadLocalRandom.current().nextInt(powerTokens.size()));
powerToken = powerEntries.get(ThreadLocalRandom.current().nextInt(powerEntries.size())).token;
}
int powerRank = 1;

15
src/engine/objects/Mob.java

@ -25,7 +25,6 @@ import engine.net.Dispatch; @@ -25,7 +25,6 @@ import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.msg.PetMsg;
import engine.net.client.msg.PlaceAssetMsg;
import engine.powers.MobPowerEntry;
import engine.server.MBServerStatics;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
@ -34,7 +33,6 @@ import java.sql.ResultSet; @@ -34,7 +33,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -52,7 +50,6 @@ public class Mob extends AbstractIntelligenceAgent { @@ -52,7 +50,6 @@ public class Mob extends AbstractIntelligenceAgent {
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
public boolean despawned = false;
public Vector3fImmutable destination = Vector3fImmutable.ZERO;
public LinkedHashMap<Integer, Integer> mobPowers = new LinkedHashMap<>();
public MobBase mobBase;
public int spawnTime;
public Zone parentZone;
@ -1655,18 +1652,6 @@ public class Mob extends AbstractIntelligenceAgent { @@ -1655,18 +1652,6 @@ public class Mob extends AbstractIntelligenceAgent {
else
this.equip = new HashMap<>();
// Powers from mobbase
if (PowersManager.AllMobPowers.containsKey(this.getMobBaseID()))
for (MobPowerEntry mobPowerEntry : PowersManager.AllMobPowers.get(this.getMobBaseID()))
mobPowers.put(mobPowerEntry.token, mobPowerEntry.rank);
// Powers from contract
if (this.contract != null && PowersManager.AllMobPowers.containsKey(this.contract.getContractID()))
for (MobPowerEntry mobPowerEntry : PowersManager.AllMobPowers.get(this.contract.getContractID()))
mobPowers.put(mobPowerEntry.token, mobPowerEntry.rank);
if (this.equip == null) {
Logger.error("Null equipset returned for uuid " + currentID);
this.equip = new HashMap<>(0);

2
src/engine/server/world/WorldServer.java

@ -352,7 +352,7 @@ public class WorldServer { @@ -352,7 +352,7 @@ public class WorldServer {
DbManager.MobBaseQueries.GET_ALL_MOBBASES();
Logger.info("Loading Mob Powers");
PowersManager.AllMobPowers = dbPowerHandler.LOAD_MOB_POWERS();
PowersManager._allMobPowers = dbPowerHandler.LOAD_MOB_POWERS();
Logger.info("Loading item enchants");
DbManager.LootQueries.LOAD_ENCHANT_VALUES();

Loading…
Cancel
Save