Browse Source

Refactored out duplicate power collection.

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

20
src/engine/gameManager/PowersManager.java

@ -53,7 +53,7 @@ public enum PowersManager {
public static HashMap<Integer, AbstractPowerAction> powerActionsByID = new HashMap<>(); public static HashMap<Integer, AbstractPowerAction> powerActionsByID = new HashMap<>();
public static HashMap<String, Integer> ActionTokenByIDString = new HashMap<>(); public static HashMap<String, Integer> ActionTokenByIDString = new HashMap<>();
public static HashMap<String, Integer> AnimationOverrides = 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 static JobScheduler js;
private PowersManager() { private 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 // This pre-loads all powers and effects
public static void InitializePowers() { public static void InitializePowers() {

53
src/engine/mobileAI/MobAI.java

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

15
src/engine/objects/Mob.java

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

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

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

Loading…
Cancel
Save