Browse Source

Minions now use copyonwrite collection. Slot agnostic.

feature-workorder
MagicBot 1 year ago
parent
commit
9a6510c320
  1. 21
      src/engine/devcmd/cmds/PurgeObjectsCmd.java
  2. 41
      src/engine/devcmd/cmds/RemoveObjectCmd.java
  3. 26
      src/engine/gameManager/NPCManager.java
  4. 38
      src/engine/mobileAI/MobAI.java
  5. 12
      src/engine/net/client/handlers/MinionTrainingMsgHandler.java
  6. 21
      src/engine/net/client/msg/ManageNPCMsg.java
  7. 4
      src/engine/objects/AbstractCharacter.java
  8. 11
      src/engine/objects/Mob.java
  9. 20
      src/engine/objects/NPC.java

21
src/engine/devcmd/cmds/PurgeObjectsCmd.java

@ -59,22 +59,25 @@ public class PurgeObjectsCmd extends AbstractDevCmd {
if (npc != null) { if (npc != null) {
for (Mob mob : npc.siegeMinionMap.keySet()) { for (Integer minionUUID : npc.minions) {
Mob mob = Mob.getMob(minionUUID);
WorldGrid.RemoveWorldObject(mob); WorldGrid.RemoveWorldObject(mob);
WorldGrid.removeObject(mob, pc); WorldGrid.removeObject(mob, pc);
//Mob.getRespawnMap().remove(mob);
if (mob.getParentZone() != null) if (mob.getParentZone() != null)
mob.getParentZone().zoneMobSet.remove(mob); mob.getParentZone().zoneMobSet.remove(mob);
} }
DbManager.NPCQueries.DELETE_NPC(npc); DbManager.NPCQueries.DELETE_NPC(npc);
DbManager.removeFromCache(GameObjectType.NPC, DbManager.removeFromCache(GameObjectType.NPC,
npc.getObjectUUID()); npc.getObjectUUID());
WorldGrid.RemoveWorldObject(npc); WorldGrid.RemoveWorldObject(npc);
} else if (mobA != null) { } else if (mobA != null) {
for (Mob mob : mobA.getSiegeMinionMap().keySet()) { for (Integer minionUUID : mobA.minions) {
Mob mob = Mob.getMob(minionUUID);
WorldGrid.RemoveWorldObject(mob); WorldGrid.RemoveWorldObject(mob);
WorldGrid.removeObject(mob, pc); WorldGrid.removeObject(mob, pc);
//Mob.getRespawnMap().remove(mob);
if (mob.getParentZone() != null) if (mob.getParentZone() != null)
mob.getParentZone().zoneMobSet.remove(mob); mob.getParentZone().zoneMobSet.remove(mob);
} }
@ -151,10 +154,11 @@ public class PurgeObjectsCmd extends AbstractDevCmd {
if (npc != null) { if (npc != null) {
for (Mob mob : npc.siegeMinionMap.keySet()) { for (Integer minionUUID : npc.minions) {
Mob mob = Mob.getMob(minionUUID);
WorldGrid.RemoveWorldObject(mob); WorldGrid.RemoveWorldObject(mob);
WorldGrid.removeObject(mob, pc); WorldGrid.removeObject(mob, pc);
//Mob.getRespawnMap().remove(mob);
if (mob.getParentZone() != null) if (mob.getParentZone() != null)
mob.getParentZone().zoneMobSet.remove(mob); mob.getParentZone().zoneMobSet.remove(mob);
} }
@ -163,10 +167,11 @@ public class PurgeObjectsCmd extends AbstractDevCmd {
npc.getObjectUUID()); npc.getObjectUUID());
WorldGrid.RemoveWorldObject(npc); WorldGrid.RemoveWorldObject(npc);
} else if (mobA != null) { } else if (mobA != null) {
for (Mob mob : mobA.getSiegeMinionMap().keySet()) { for (Integer minionUUID : mobA.minions) {
Mob mob = Mob.getMob(minionUUID);
WorldGrid.RemoveWorldObject(mob); WorldGrid.RemoveWorldObject(mob);
WorldGrid.removeObject(mob, pc); WorldGrid.removeObject(mob, pc);
//Mob.getRespawnMap().remove(mob);
if (mob.getParentZone() != null) if (mob.getParentZone() != null)
mob.getParentZone().zoneMobSet.remove(mob); mob.getParentZone().zoneMobSet.remove(mob);
} }

41
src/engine/devcmd/cmds/RemoveObjectCmd.java

@ -154,24 +154,29 @@ public class RemoveObjectCmd extends AbstractDevCmd {
mobA = (Mob) ac; mobA = (Mob) ac;
if (npc != null) { if (npc != null) {
for (Mob mob : npc.siegeMinionMap.keySet()) {
WorldGrid.RemoveWorldObject(mob); for (Integer minionUUID : npc.minions) {
WorldGrid.removeObject(mob, pc); Mob minionMob = Mob.getMob(minionUUID);
//Mob.getRespawnMap().remove(mob); WorldGrid.RemoveWorldObject(minionMob);
if (mob.getParentZone() != null) WorldGrid.removeObject(minionMob, pc);
mob.getParentZone().zoneMobSet.remove(mob);
if (minionMob.getParentZone() != null)
minionMob.getParentZone().zoneMobSet.remove(minionMob);
} }
DbManager.NPCQueries.DELETE_NPC(npc); DbManager.NPCQueries.DELETE_NPC(npc);
DbManager.removeFromCache(npc); DbManager.removeFromCache(npc);
WorldGrid.RemoveWorldObject(npc); WorldGrid.RemoveWorldObject(npc);
WorldGrid.removeObject(npc, pc); WorldGrid.removeObject(npc, pc);
} else if (mobA != null) { } else if (mobA != null) {
for (Mob mob : mobA.getSiegeMinionMap().keySet()) {
WorldGrid.RemoveWorldObject(mob); for (Integer minionUUID : mobA.minions) {
WorldGrid.removeObject(mob, pc); Mob minionMob = Mob.getMob(minionUUID);
//Mob.getRespawnMap().remove(mob); WorldGrid.RemoveWorldObject(minionMob);
if (mob.getParentZone() != null) WorldGrid.removeObject(minionMob, pc);
mob.getParentZone().zoneMobSet.remove(mob);
if (minionMob.getParentZone() != null)
minionMob.getParentZone().zoneMobSet.remove(minionMob);
} }
DbManager.MobQueries.DELETE_MOB(mobA); DbManager.MobQueries.DELETE_MOB(mobA);
DbManager.removeFromCache(mobA); DbManager.removeFromCache(mobA);
@ -209,11 +214,13 @@ public class RemoveObjectCmd extends AbstractDevCmd {
if (npc.building != null) if (npc.building != null)
npc.building.getHirelings().remove(npc); npc.building.getHirelings().remove(npc);
for (Mob mob : npc.siegeMinionMap.keySet()) { for (Integer minionUUID : npc.minions) {
WorldGrid.RemoveWorldObject(mob); Mob minionMob = Mob.getMob(minionUUID);
WorldGrid.removeObject(mob, pc); WorldGrid.RemoveWorldObject(minionMob);
if (mob.getParentZone() != null) WorldGrid.removeObject(minionMob, pc);
mob.getParentZone().zoneMobSet.remove(mob);
if (minionMob.getParentZone() != null)
minionMob.getParentZone().zoneMobSet.remove(minionMob);
} }
DbManager.NPCQueries.DELETE_NPC(npc); DbManager.NPCQueries.DELETE_NPC(npc);

26
src/engine/gameManager/NPCManager.java

@ -122,37 +122,39 @@ public enum NPCManager {
public static void removeSiegeMinions(Mob mobile) { public static void removeSiegeMinions(Mob mobile) {
for (Mob toRemove : mobile.siegeMinionMap.keySet()) { for (Integer minionUUID : mobile.minions) {
Mob siegeMinion = Mob.getMob(minionUUID);
if (mobile.isMoving()) { if (mobile.isMoving()) {
mobile.stopMovement(mobile.getLoc()); mobile.stopMovement(mobile.getLoc());
if (toRemove.parentZone != null) if (siegeMinion.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove); siegeMinion.parentZone.zoneMobSet.remove(siegeMinion);
} }
try { try {
toRemove.clearEffects(); siegeMinion.clearEffects();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.getMessage()); Logger.error(e.getMessage());
} }
if (toRemove.parentZone != null) if (siegeMinion.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove); siegeMinion.parentZone.zoneMobSet.remove(siegeMinion);
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(siegeMinion);
WorldGrid.removeObject(toRemove); WorldGrid.removeObject(siegeMinion);
DbManager.removeFromCache(toRemove); DbManager.removeFromCache(siegeMinion);
PlayerCharacter petOwner = (PlayerCharacter) toRemove.guardCaptain; PlayerCharacter petOwner = (PlayerCharacter) siegeMinion.guardCaptain;
if (petOwner != null) { if (petOwner != null) {
petOwner.setPet(null); petOwner.setPet(null);
toRemove.guardCaptain = null; siegeMinion.guardCaptain = null;
PetMsg petMsg = new PetMsg(5, null); PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
@ -263,7 +265,7 @@ public enum NPCManager {
if (abstractCharacter.getObjectType().equals(Enum.GameObjectType.Mob) && ((Mob) abstractCharacter).behaviourType.equals(Enum.MobBehaviourType.SiegeEngine)) { if (abstractCharacter.getObjectType().equals(Enum.GameObjectType.Mob) && ((Mob) abstractCharacter).behaviourType.equals(Enum.MobBehaviourType.SiegeEngine)) {
Mob siegeMobile = (Mob) abstractCharacter; Mob siegeMobile = (Mob) abstractCharacter;
buildingSlot = siegeMobile.guardCaptain.siegeMinionMap.size() + 2; buildingSlot = siegeMobile.guardCaptain.minions.size() + 2;
} }
if (buildingSlot == -1) if (buildingSlot == -1)

38
src/engine/mobileAI/MobAI.java

@ -288,18 +288,22 @@ public class MobAI {
MovementUtilities.aiMove(mob, mob.destination, true); MovementUtilities.aiMove(mob, mob.destination, true);
if (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) if (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN))
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) for (Integer minionUUUD : mob.minions) {
Mob minion = Mob.getMob(minionUUUD);
//make sure mob is out of combat stance //make sure mob is out of combat stance
if (minion.getKey().despawned == false) { if (minion.despawned == false) {
if (MovementUtilities.canMove(minion.getKey())) { if (MovementUtilities.canMove(minion)) {
Vector3f minionOffset = Formation.getOffset(2, minion.getValue() + 3); Vector3f minionOffset = Formation.getOffset(2, mob.minions.indexOf(minionUUUD) + 3);
minion.getKey().updateLocation(); minion.updateLocation();
Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z); Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z);
MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true); MovementUtilities.aiMove(minion, formationPatrolPoint, true);
}
} }
} }
} catch (Exception e) { } catch (Exception e) {
Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage()); Logger.info(mob.getObjectUUID() + " " + mob.getName() + " Failed At: AttackTarget" + " " + e.getMessage());
} }
@ -987,9 +991,11 @@ public class MobAI {
//guard captain pulls his minions home with him //guard captain pulls his minions home with him
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) { for (Integer minionUUID : mob.minions) {
PowersManager.useMobPower(minion.getKey(), minion.getKey(), recall, 40); Mob minion = Mob.getMob(minionUUID);
minion.getKey().setCombatTarget(null);
PowersManager.useMobPower(minion, minion, recall, 40);
minion.setCombatTarget(null);
} }
} }
} }
@ -1381,16 +1387,18 @@ public class MobAI {
MovementUtilities.aiMove(mob, mob.destination, true); MovementUtilities.aiMove(mob, mob.destination, true);
if (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) { if (mob.agentType.equals(Enum.AIAgentType.GUARDCAPTAIN)) {
for (Entry<Mob, Integer> minion : mob.siegeMinionMap.entrySet()) { for (Integer minionUUID : mob.minions) {
Mob minion = Mob.getMob(minionUUID);
//make sure mob is out of combat stance //make sure mob is out of combat stance
if (minion.getKey().despawned == false) { if (minion.despawned == false) {
if (MovementUtilities.canMove(minion.getKey())) { if (MovementUtilities.canMove(minion)) {
Vector3f minionOffset = Formation.getOffset(2, minion.getValue() + 3); Vector3f minionOffset = Formation.getOffset(2, mob.minions.indexOf(minionUUID) + 3);
minion.getKey().updateLocation(); minion.updateLocation();
Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z); Vector3fImmutable formationPatrolPoint = new Vector3fImmutable(mob.destination.x + minionOffset.x, mob.destination.y, mob.destination.z + minionOffset.z);
MovementUtilities.aiMove(minion.getKey(), formationPatrolPoint, true); MovementUtilities.aiMove(minion, formationPatrolPoint, true);
} }
} }
} }

12
src/engine/net/client/handlers/MinionTrainingMsgHandler.java

@ -58,10 +58,10 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); Mob toRemove = Mob.getFromCache(minionMsg.getUUID());
if (!npc.siegeMinionMap.containsKey(toRemove)) if (!npc.minions.contains(toRemove.getObjectUUID()))
return true; return true;
npc.siegeMinionMap.remove(toRemove); npc.minions.remove(toRemove.getObjectUUID());
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(toRemove);
@ -112,7 +112,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
if (npc.getContractID() == 842) if (npc.getContractID() == 842)
maxSlots = 1; maxSlots = 1;
if (npc.siegeMinionMap.size() == maxSlots) if (npc.minions.size() == maxSlots)
return true; return true;
int mobBase; int mobBase;
@ -179,13 +179,13 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
Mob toRemove = Mob.getFromCache(minionMsg.getUUID()); Mob toRemove = Mob.getFromCache(minionMsg.getUUID());
if (!npc.getSiegeMinionMap().containsKey(toRemove)) if (!npc.minions.contains(toRemove.getObjectUUID()))
return true; return true;
if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.firstName)) if (!DbManager.MobQueries.REMOVE_FROM_GUARDS(npc.getObjectUUID(), toRemove.firstName))
return true; return true;
npc.getSiegeMinionMap().remove(toRemove); npc.minions.remove(toRemove.getObjectUUID());
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(toRemove);
@ -258,7 +258,7 @@ public class MinionTrainingMsgHandler extends AbstractClientMsgHandler {
break; break;
} }
if (npc.getSiegeMinionMap().size() == maxSlots) if (npc.minions.size() == maxSlots)
return true; return true;
int mobBase = npc.getMobBaseID(); int mobBase = npc.getMobBaseID();

21
src/engine/net/client/msg/ManageNPCMsg.java

@ -27,7 +27,6 @@ import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -343,14 +342,17 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putInt(0); //runemaster list writer.putInt(0); //runemaster list
//artillery captain list //artillery captain list
ConcurrentHashMap<Mob, Integer> siegeMinions = npc.siegeMinionMap;
writer.putInt(1 + siegeMinions.size()); writer.putInt(1 + npc.minions.size());
serializeBulwarkList(writer, 1); //Trebuchet serializeBulwarkList(writer, 1); //Trebuchet
//serializeBulwarkList(writer, 2); //Ballista //serializeBulwarkList(writer, 2); //Ballista
if (siegeMinions != null && siegeMinions.size() > 0) if (npc.minions != null && npc.minions.size() > 0)
for (Integer minionUUID : npc.minions) {
Mob mob = Mob.getMob(minionUUID);
for (Mob mob : siegeMinions.keySet()) {
this.unknown83 = mob.getObjectUUID(); this.unknown83 = mob.getObjectUUID();
writer.putInt(2); writer.putInt(2);
writer.putInt(mob.getObjectType().ordinal()); writer.putInt(mob.getObjectType().ordinal());
@ -666,14 +668,15 @@ public class ManageNPCMsg extends ClientNetMsg {
writer.putInt(0); //runemaster list writer.putInt(0); //runemaster list
//artillery captain list //artillery captain list
ConcurrentHashMap<Mob, Integer> siegeMinions = mobA.getSiegeMinionMap();
writer.putInt(siegeMinions.size() + 1); writer.putInt(mobA.minions.size() + 1);
serializeGuardList(writer, mobA.getContract().getContractID(), mobA); //Guard serializeGuardList(writer, mobA.getContract().getContractID(), mobA); //Guard
if (siegeMinions != null && siegeMinions.size() > 0) if (mobA.minions != null && mobA.minions.size() > 0)
for (Mob mob : siegeMinions.keySet()) { for (Integer minionUUID : mobA.minions) {
Mob mob = Mob.getMob(minionUUID);
this.unknown83 = mob.getObjectUUID(); this.unknown83 = mob.getObjectUUID();
writer.putInt(2); writer.putInt(2);
writer.putInt(mob.getObjectType().ordinal()); writer.putInt(mob.getObjectType().ordinal());

4
src/engine/objects/AbstractCharacter.java

@ -39,6 +39,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
@ -121,8 +122,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
private byte aoecntr = 0; private byte aoecntr = 0;
public int hidden = 0; // current rank of hide/sneak/invis public int hidden = 0; // current rank of hide/sneak/invis
public CopyOnWriteArrayList<Integer> minions = new CopyOnWriteArrayList();
public final ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public AbstractCharacter() { public AbstractCharacter() {
super(); super();

11
src/engine/objects/Mob.java

@ -26,7 +26,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.RuneSkillAdjustEntry;
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;
@ -489,8 +488,7 @@ public class Mob extends AbstractIntelligenceAgent {
minionMobile.setLoc(minionMobile.bindLoc); minionMobile.setLoc(minionMobile.bindLoc);
minionMobile.despawn(); minionMobile.despawn();
int slot = guardCaptain.siegeMinionMap.size() + 1; guardCaptain.minions.add(minionMobile.getObjectUUID());
guardCaptain.siegeMinionMap.put(minionMobile, slot);
return minionMobile; return minionMobile;
} }
@ -520,8 +518,7 @@ public class Mob extends AbstractIntelligenceAgent {
siegeMinion.setLoc(siegeMinion.bindLoc); siegeMinion.setLoc(siegeMinion.bindLoc);
siegeMinion.despawn(); siegeMinion.despawn();
int slot = artyCaptain.siegeMinionMap.size() + 1; artyCaptain.minions.add(siegeMinion.getObjectUUID());
artyCaptain.siegeMinionMap.put(siegeMinion, slot);
return siegeMinion; return siegeMinion;
} }
@ -1783,10 +1780,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.weaponPower = weaponPower; this.weaponPower = weaponPower;
} }
public ConcurrentHashMap<Mob, Integer> getSiegeMinionMap() {
return siegeMinionMap;
}
public DateTime getUpgradeDateTime() { public DateTime getUpgradeDateTime() {
lock.readLock().lock(); lock.readLock().lock();

20
src/engine/objects/NPC.java

@ -640,28 +640,31 @@ public class NPC extends AbstractCharacter {
public void removeMinions() { public void removeMinions() {
for (Mob toRemove : this.siegeMinionMap.keySet()) {
for (Integer minionUUID : this.minions) {
Mob minionMob = Mob.getMob(minionUUID);
try { try {
toRemove.clearEffects(); minionMob.clearEffects();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e.getMessage()); Logger.error(e.getMessage());
} }
if (toRemove.getParentZone() != null) if (minionMob.getParentZone() != null)
toRemove.getParentZone().zoneMobSet.remove(toRemove); minionMob.getParentZone().zoneMobSet.remove(minionMob);
WorldGrid.RemoveWorldObject(toRemove); WorldGrid.RemoveWorldObject(minionMob);
DbManager.removeFromCache(toRemove); DbManager.removeFromCache(minionMob);
PlayerCharacter petOwner = (PlayerCharacter) toRemove.guardCaptain; PlayerCharacter petOwner = (PlayerCharacter) minionMob.guardCaptain;
if (petOwner != null) { if (petOwner != null) {
petOwner.setPet(null); petOwner.setPet(null);
toRemove.guardCaptain = null; minionMob.guardCaptain = null;
PetMsg petMsg = new PetMsg(5, null); PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg); Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
@ -669,6 +672,7 @@ public class NPC extends AbstractCharacter {
} }
} }
} }
@Override @Override

Loading…
Cancel
Save