Browse Source

Refactored mob powers to rune powers. Now uses rune_id to call into system which is derived in the getter to support minions.

feature-workorder
MagicBot 1 year ago
parent
commit
70a0ed135b
  1. 20
      src/engine/db/handlers/dbPowerHandler.java
  2. 6
      src/engine/devcmd/cmds/aiInfoCmd.java
  3. 30
      src/engine/gameManager/PowersManager.java
  4. 33
      src/engine/mobileAI/MobAI.java
  5. 3
      src/engine/objects/Mob.java
  6. 17
      src/engine/powers/MobPowerEntry.java
  7. 21
      src/engine/powers/RunePowerEntry.java
  8. 2
      src/engine/server/world/WorldServer.java

20
src/engine/db/handlers/dbPowerHandler.java

@ -15,7 +15,7 @@ import engine.gameManager.PowersManager;
import engine.objects.Mob; import engine.objects.Mob;
import engine.objects.PreparedStatementShared; import engine.objects.PreparedStatementShared;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import engine.powers.MobPowerEntry; import engine.powers.RunePowerEntry;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection; import java.sql.Connection;
@ -86,16 +86,16 @@ public class dbPowerHandler extends dbHandlerBase {
} }
} }
public static HashMap<Integer, ArrayList<MobPowerEntry>> LOAD_MOB_POWERS() { public static HashMap<Integer, ArrayList<RunePowerEntry>> LOAD_MOB_POWERS() {
HashMap<Integer, ArrayList<MobPowerEntry>> mobPowers = new HashMap<>(); HashMap<Integer, ArrayList<RunePowerEntry>> mobPowers = new HashMap<>();
MobPowerEntry mobPowerEntry; RunePowerEntry runePowerEntry;
int mobbaseID; int mobbaseID;
int recordsRead = 0; int recordsRead = 0;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_mobbase_powers ORDER BY `id` ASC;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_powers")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
@ -104,15 +104,15 @@ public class dbPowerHandler extends dbHandlerBase {
recordsRead++; recordsRead++;
mobbaseID = rs.getInt("mobbaseUUID"); mobbaseID = rs.getInt("mobbaseUUID");
mobPowerEntry = new MobPowerEntry(rs); runePowerEntry = new RunePowerEntry(rs);
if (mobPowers.get(mobbaseID) == null) { if (mobPowers.get(mobbaseID) == null) {
ArrayList<MobPowerEntry> powerList = new ArrayList<>(); ArrayList<RunePowerEntry> powerList = new ArrayList<>();
powerList.add(mobPowerEntry); powerList.add(runePowerEntry);
mobPowers.put(mobbaseID, powerList); mobPowers.put(mobbaseID, powerList);
} else { } else {
ArrayList<MobPowerEntry> powerList = mobPowers.get(mobbaseID); ArrayList<RunePowerEntry> powerList = mobPowers.get(mobbaseID);
powerList.add(mobPowerEntry); powerList.add(runePowerEntry);
mobPowers.put(mobbaseID, powerList); mobPowers.put(mobbaseID, powerList);
} }
} }

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

@ -15,7 +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 engine.powers.RunePowerEntry;
import java.util.Map; import java.util.Map;
@ -91,8 +91,8 @@ public class aiInfoCmd extends AbstractDevCmd {
output += "Powers:" + newline; output += "Powers:" + newline;
for (MobPowerEntry mobPowerEntry : PowersManager.getPowersForMobile(mob)) for (RunePowerEntry runePowerEntry : PowersManager.getPowersForRune(mob.getMobBaseID()))
output += PowersManager.getPowerByToken(mobPowerEntry.token).getName() + newline; output += PowersManager.getPowerByToken(runePowerEntry.token).getName() + newline;
throwbackInfo(playerCharacter, output); throwbackInfo(playerCharacter, output);
} }

30
src/engine/gameManager/PowersManager.java

@ -53,13 +53,9 @@ 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<RunePowerEntry>> _allRunePowers;
private static JobScheduler js; private static JobScheduler js;
private PowersManager() {
}
public static void initPowersManager(boolean fullPowersLoad) { public static void initPowersManager(boolean fullPowersLoad) {
if (fullPowersLoad) if (fullPowersLoad)
@ -103,28 +99,14 @@ public enum PowersManager {
} }
} }
public static ArrayList<MobPowerEntry> getPowersForMobile(Mob mobile) { public static ArrayList<RunePowerEntry> getPowersForRune(int rune_id) {
ArrayList<MobPowerEntry> mobPowers = new ArrayList<>();
ArrayList<MobPowerEntry> powerEntries;
if (mobile.agentType.equals(AIAgentType.GUARDMINION)) ArrayList<RunePowerEntry> powerEntries = PowersManager._allRunePowers.get(rune_id);
powerEntries = PowersManager._allMobPowers.get(mobile.guardCaptain.contractUUID);
else
powerEntries = PowersManager._allMobPowers.get(mobile.contractUUID);
if (powerEntries != null)
mobPowers.addAll(powerEntries);
if (mobile.agentType.equals(AIAgentType.GUARDMINION))
powerEntries = PowersManager._allMobPowers.get(((Mob) mobile.guardCaptain).loadID);
else
powerEntries = PowersManager._allMobPowers.get(mobile.loadID);
if (powerEntries != null) if (powerEntries == null)
mobPowers.addAll(powerEntries); powerEntries = new ArrayList<>();
return mobPowers; return powerEntries;
} }
// This pre-loads all powers and effects // This pre-loads all powers and effects

33
src/engine/mobileAI/MobAI.java

@ -22,8 +22,8 @@ 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.powers.RunePowerEntry;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -323,7 +323,7 @@ public class MobAI {
return false; return false;
} }
if (PowersManager.getPowersForMobile(mob).isEmpty()) if (PowersManager.getPowersForRune(mob.getMobBaseID()).isEmpty())
return false; return false;
if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) { if (!mob.canSee((PlayerCharacter) mob.getCombatTarget())) {
@ -348,8 +348,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<MobPowerEntry> powerEntries; ArrayList<RunePowerEntry> powerEntries;
ArrayList<MobPowerEntry> purgeEntries; ArrayList<RunePowerEntry> purgeEntries;
AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget();
if (mob.behaviourType.callsForHelp) if (mob.behaviourType.callsForHelp)
@ -357,22 +357,22 @@ 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.
powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob)); powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID()));
purgeEntries = 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 (MobPowerEntry mobPowerEntry : powerEntries) { for (RunePowerEntry runePowerEntry : powerEntries) {
PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token); PowersBase powerBase = PowersManager.getPowerByToken(runePowerEntry.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))
purgeEntries.add(mobPowerEntry); purgeEntries.add(runePowerEntry);
} }
} }
@ -431,37 +431,32 @@ 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<MobPowerEntry> powerEntries; ArrayList<RunePowerEntry> powerEntries;
ArrayList<MobPowerEntry> purgeEntries; ArrayList<RunePowerEntry> purgeEntries;
AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget(); AbstractCharacter target = (AbstractCharacter) mob.getCombatTarget();
if (mob.behaviourType.callsForHelp) if (mob.behaviourType.callsForHelp)
MobCallForHelp(mob); MobCallForHelp(mob);
// Generate a list of tokens from the mob powers for this mobile.
powerEntries = PowersManager.getPowersForMobile(mob);
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.
powerEntries = new ArrayList<>(PowersManager.getPowersForMobile(mob)); powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID()));
purgeEntries = 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 (MobPowerEntry mobPowerEntry : powerEntries) { for (RunePowerEntry runePowerEntry : powerEntries) {
PowersBase powerBase = PowersManager.getPowerByToken(mobPowerEntry.token); PowersBase powerBase = PowersManager.getPowerByToken(runePowerEntry.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))
purgeEntries.add(mobPowerEntry); purgeEntries.add(runePowerEntry);
} }
} }

3
src/engine/objects/Mob.java

@ -669,6 +669,9 @@ public class Mob extends AbstractIntelligenceAgent {
public int getMobBaseID() { public int getMobBaseID() {
if (this.agentType.equals(AIAgentType.GUARDMINION))
return this.guardCaptain.contract.getMobbaseID();
if (this.mobBase != null) if (this.mobBase != null)
return this.mobBase.getObjectUUID(); return this.mobBase.getObjectUUID();

17
src/engine/powers/MobPowerEntry.java

@ -1,17 +0,0 @@
package engine.powers;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MobPowerEntry {
public int token;
public int rank;
public MobPowerEntry(ResultSet rs) throws SQLException {
this.token = rs.getInt("token");
this.rank = rs.getInt("rank");
}
}

21
src/engine/powers/RunePowerEntry.java

@ -0,0 +1,21 @@
package engine.powers;
import java.sql.ResultSet;
import java.sql.SQLException;
public class RunePowerEntry {
public String name;
public int token;
public String power_type;
public int rank;
public RunePowerEntry(ResultSet rs) throws SQLException {
this.name = rs.getString("name");
this.token = rs.getInt("token");
this.power_type = rs.getString("power_type");
this.rank = rs.getInt("rank");
}
}

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._allRunePowers = 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