Relevant methods made static and moved into NPCManager

This commit is contained in:
2023-03-31 09:59:49 -04:00
parent bbdbead1ff
commit 3881c2b1d0
20 changed files with 507 additions and 539 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
protected float manaMax; // Health/Mana/Stamina
protected AtomicBoolean isAlive = new AtomicBoolean(true);
protected Resists resists = new Resists("Genric");
protected AbstractWorldObject combatTarget;
public AbstractWorldObject combatTarget;
protected ConcurrentHashMap<String, JobContainer> timers;
protected ConcurrentHashMap<String, Long> timestamps;
protected int atrHandOne;
@@ -204,8 +204,8 @@ public abstract class AbstractIntelligenceAgent extends AbstractCharacter {
WorldGrid.RemoveWorldObject(this);
if (this.getObjectType() == GameObjectType.Mob){
((Mob)this).setState(STATE.Disabled);
if (((Mob)this).getParentZone() != null)
((Mob)this).state = STATE.Disabled;
if (((Mob)this).getParentZone() != null)
((Mob)this).getParentZone().zoneMobSet.remove(this);
}
+15 -290
View File
@@ -11,7 +11,6 @@ package engine.objects;
import engine.Enum;
import engine.Enum.*;
import engine.InterestManagement.HeightMap;
import engine.InterestManagement.WorldGrid;
import engine.ai.MobileFSM;
import engine.ai.MobileFSM.STATE;
@@ -32,7 +31,6 @@ import engine.net.client.msg.ManageCityAssetsMsg;
import engine.net.client.msg.PetMsg;
import engine.net.client.msg.PlaceAssetMsg;
import engine.net.client.msg.chat.ChatSystemMsg;
import engine.powers.EffectsBase;
import engine.server.MBServerStatics;
import org.joda.time.DateTime;
import org.pmw.tinylog.Logger;
@@ -57,7 +55,7 @@ public class Mob extends AbstractIntelligenceAgent {
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
//mob specific
private final ConcurrentHashMap<Integer, Boolean> playerAgroMap = new ConcurrentHashMap<>();
public final ConcurrentHashMap<Integer, Boolean> playerAgroMap = new ConcurrentHashMap<>();
public long nextCastTime = 0;
public long nextCallForHelp = 0;
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
@@ -70,42 +68,42 @@ public class Mob extends AbstractIntelligenceAgent {
protected boolean isMob;
public MobBase mobBase;
protected float spawnRadius;
protected int spawnTime;
public int spawnTime;
//used by static mobs
protected int parentZoneID;
protected Zone parentZone;
public Zone parentZone;
protected float statLat;
protected float statLon;
protected float statAlt;
protected Building building;
public Building building;
public Contract contract;
private int currentID;
private int ownerUID = 0; //only used by pets
private boolean hasLoot = false;
public boolean hasLoot = false;
private AbstractWorldObject fearedObject = null;
private int buildingID;
private boolean isSiege = false;
public boolean isPlayerGuard = false;
private long timeToSpawnSiege;
private AbstractCharacter npcOwner;
private Vector3fImmutable inBuildingLoc = null;
public AbstractCharacter npcOwner;
public Vector3fImmutable inBuildingLoc = null;
private boolean noAggro = false;
private STATE state = STATE.Disabled;
public STATE state = STATE.Disabled;
private int aggroTargetID = 0;
private boolean walkingHome = true;
private long lastAttackTime = 0;
private long deathTime = 0;
private final ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public long deathTime = 0;
public final ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
private int patrolPointIndex = 0;
private int lastMobPowerToken = 0;
private HashMap<Integer, MobEquipment> equip = null;
private String nameOverride = "";
public String nameOverride = "";
private Regions lastRegion = null;
private long despawnTime = 0;
private DeferredPowerJob weaponPower;
private DateTime upgradeDateTime = null;
private boolean lootSync = false;
private int equipmentSetID = 0;
public int equipmentSetID = 0;
public int runeSetID = 0;
public int bootySetID = 0;
@@ -1950,10 +1948,6 @@ public class Mob extends AbstractIntelligenceAgent {
}
public Vector3fImmutable getInBuildingLoc() {
return inBuildingLoc;
}
public ItemBase getWeaponItemBase(boolean mainHand) {
if (this.equipmentSetID != 0) {
@@ -2070,10 +2064,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.timeToSpawnSiege = timeToSpawnSiege;
}
public AbstractCharacter getNpcOwner() {
return npcOwner;
}
public void setNpcOwner(AbstractCharacter npcOwner) {
this.npcOwner = npcOwner;
}
@@ -2106,81 +2096,6 @@ public class Mob extends AbstractIntelligenceAgent {
}
}
public boolean remove(Building building) {
// Remove npc from it's building
this.state = STATE.Disabled;
try {
this.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
if (this.parentZone != null)
this.parentZone.zoneMobSet.remove(this);
if (building != null) {
building.getHirelings().remove(this);
this.removeMinions();
}
// Delete npc from database
if (DbManager.MobQueries.DELETE_MOB(this) == 0)
return false;
// Remove npc from the simulation
this.removeFromCache();
DbManager.removeFromCache(this);
WorldGrid.RemoveWorldObject(this);
WorldGrid.removeObject(this);
return true;
}
public void removeMinions() {
for (Mob toRemove : this.siegeMinionMap.keySet()) {
toRemove.state = STATE.Disabled;
if (this.isMoving()) {
this.stopMovement(this.getLoc());
this.state = STATE.Disabled;
if (toRemove.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove);
}
try {
toRemove.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
if (toRemove.parentZone != null)
toRemove.parentZone.zoneMobSet.remove(toRemove);
WorldGrid.RemoveWorldObject(toRemove);
WorldGrid.removeObject(toRemove);
DbManager.removeFromCache(toRemove);
PlayerCharacter petOwner = toRemove.getOwner();
if (petOwner != null) {
petOwner.setPet(null);
toRemove.setOwner(null);
PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
}
}
public void setRank(int newRank) {
DbManager.MobQueries.SET_PROPERTY(this, "mob_level", newRank);
@@ -2201,14 +2116,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.noAggro = noAggro;
}
public STATE getState() {
return state;
}
public void setState(STATE state) {
this.state = state;
}
public int getAggroTargetID() {
return aggroTargetID;
}
@@ -2233,14 +2140,6 @@ public class Mob extends AbstractIntelligenceAgent {
this.lastAttackTime = lastAttackTime;
}
public ConcurrentHashMap<Integer, Boolean> getPlayerAgroMap() {
return playerAgroMap;
}
public long getDeathTime() {
return deathTime;
}
public void setDeathTime(long deathTime) {
this.deathTime = deathTime;
}
@@ -2261,10 +2160,6 @@ public class Mob extends AbstractIntelligenceAgent {
return siegeMinionMap;
}
public Building getBuilding() {
return this.building;
}
public DateTime getUpgradeDateTime() {
lock.readLock().lock();
@@ -2276,136 +2171,6 @@ public class Mob extends AbstractIntelligenceAgent {
}
}
public synchronized Mob createGuardMob(int loadID, Guild guild, Zone parent, Vector3fImmutable loc, short level, String pirateName) {
MobBase minionMobBase;
Mob mob;
int maxSlots = 1;
switch (this.getRank()) {
case 1:
case 2:
maxSlots = 1;
break;
case 3:
maxSlots = 2;
break;
case 4:
case 5:
maxSlots = 3;
break;
case 6:
maxSlots = 4;
break;
case 7:
maxSlots = 5;
break;
default:
maxSlots = 1;
}
if (siegeMinionMap.size() == maxSlots)
return null;
minionMobBase = this.mobBase;
if (minionMobBase == null)
return null;
mob = new Mob(minionMobBase, guild, parent, level, new Vector3fImmutable(1, 1, 1), 0, true);
mob.despawned = true;
mob.setLevel(level);
//grab equipment and name from minionbase.
if (this.contract != null) {
MinionType minionType = MinionType.ContractToMinionMap.get(this.contract.getContractID());
if (minionType != null) {
mob.equipmentSetID = minionType.getEquipSetID();
String rank = "";
if (this.getRank() < 3)
rank = MBServerStatics.JUNIOR;
else if (this.getRank() < 6)
rank = "";
else if (this.getRank() == 6)
rank = MBServerStatics.VETERAN;
else
rank = MBServerStatics.ELITE;
if (rank.isEmpty())
mob.nameOverride = pirateName + " " + minionType.getRace() + " " + minionType.getName();
else
mob.nameOverride = pirateName + " " + minionType.getRace() + " " + rank + " " + minionType.getName();
}
}
if (parent != null)
mob.setRelPos(parent, loc.x - parent.absX, loc.y - parent.absY, loc.z - parent.absZ);
mob.setObjectTypeMask(MBServerStatics.MASK_MOB | mob.getTypeMasks());
// mob.setMob();
mob.isPlayerGuard = true;
mob.setParentZone(parent);
DbManager.addToCache(mob);
mob.runAfterLoad();
RuneBase guardRune = RuneBase.getRuneBase(252621);
for (MobBaseEffects mbe : guardRune.getEffectsList()) {
EffectsBase eb = PowersManager.getEffectByToken(mbe.getToken());
if (eb == null) {
Logger.info("EffectsBase Null for Token " + mbe.getToken());
continue;
}
//check to upgrade effects if needed.
if (mob.effects.containsKey(Integer.toString(eb.getUUID()))) {
if (mbe.getReqLvl() > (int) mob.level) {
continue;
}
Effect eff = mob.effects.get(Integer.toString(eb.getUUID()));
if (eff == null)
continue;
//Current effect is a higher rank, dont apply.
if (eff.getTrains() > mbe.getRank())
continue;
//new effect is of a higher rank. remove old effect and apply new one.
eff.cancelJob();
mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true);
} else {
if (mbe.getReqLvl() > (int) mob.level)
continue;
mob.addEffectNoTimer(Integer.toString(eb.getUUID()), eb, mbe.getRank(), true);
}
}
int slot = 0;
slot += siegeMinionMap.size() + 1;
siegeMinionMap.put(mob, slot);
mob.setInBuildingLoc(this.building, this);
mob.setBindLoc(loc.add(mob.inBuildingLoc));
mob.deathTime = System.currentTimeMillis();
mob.spawnTime = 900;
mob.npcOwner = this;
mob.state = STATE.Respawn;
return mob;
}
public Contract getContract() {
return contract;
}
@@ -2472,7 +2237,7 @@ public class Mob extends AbstractIntelligenceAgent {
try {
building = this.getBuilding();
building = this.building;
// Cannot upgrade an npc not within a building
@@ -2550,7 +2315,7 @@ public class Mob extends AbstractIntelligenceAgent {
if (!building.getHirelings().containsKey(this))
return;
if (!this.remove(building)) {
if (!NPCManager.removeMobileFromBuilding(this, building)) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return;
}
@@ -2607,7 +2372,7 @@ public class Mob extends AbstractIntelligenceAgent {
WorldGrid.RemoveWorldObject(this);
DbManager.removeFromCache(this);
if (this.getObjectType() == GameObjectType.Mob) {
this.setState(STATE.Disabled);
this.state = STATE.Disabled;
if (this.getParentZone() != null)
this.getParentZone().zoneMobSet.remove(this);
}
@@ -2639,44 +2404,4 @@ public class Mob extends AbstractIntelligenceAgent {
}
}
public void dismissNecroPet(boolean updateOwner) {
this.state = STATE.Disabled;
this.combatTarget = null;
this.hasLoot = false;
if (this.parentZone != null)
this.parentZone.zoneMobSet.remove(this);
try {
this.clearEffects();
} catch (Exception e) {
Logger.error(e.getMessage());
}
this.playerAgroMap.clear();
WorldGrid.RemoveWorldObject(this);
DbManager.removeFromCache(this);
// YEAH BONUS CODE! THANKS UNNAMED ASSHOLE!
//WorldServer.removeObject(this);
//WorldGrid.INSTANCE.removeWorldObject(this);
//owner.getPet().disableIntelligence();
PlayerCharacter petOwner = this.getOwner();
if (petOwner != null) {
this.setOwner(null);
petOwner.setPet(null);
if (updateOwner == false)
return;
PetMsg petMsg = new PetMsg(5, null);
Dispatch dispatch = Dispatch.borrow(petOwner, petMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY);
}
}
}
+4 -4
View File
@@ -797,7 +797,7 @@ public class NPC extends AbstractCharacter {
for (Mob toRemove : this.siegeMinionMap.keySet()) {
toRemove.setState(STATE.Disabled);
toRemove.state = STATE.Disabled;
try {
toRemove.clearEffects();
@@ -1461,14 +1461,14 @@ public class NPC extends AbstractCharacter {
siegeMinionMap.put(mob, slot);
mob.setInBuildingLoc(this.building, this);
Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(this.building, mob.getInBuildingLoc());
Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(this.building, mob.inBuildingLoc);
mob.setBindLoc(buildingWorldLoc);
mob.setLoc(buildingWorldLoc);
mob.setSpawnTime(10);
mob.setNpcOwner(this);
mob.setState(STATE.Awake);
mob.state = STATE.Awake;
return mob;
}
+4 -68
View File
@@ -626,7 +626,7 @@ public class PlayerCharacter extends AbstractCharacter {
if (this.pet != null)
this.dismissPet();
this.dismissNecroPets();
NPCManager.dismissNecroPets(this);
// remove flight job.
this.setTakeOffTime(0);
@@ -1586,77 +1586,13 @@ public class PlayerCharacter extends AbstractCharacter {
return this.pet;
}
public Mob getNecroPet(int i) {
return this.necroPets.get(i);
}
public static void auditNecroPets(PlayerCharacter player){
int removeIndex =0;
while(player.necroPets.size() >= 10){
if (removeIndex == player.necroPets.size())
break;
Mob toRemove = player.necroPets.get(removeIndex);
if (toRemove == null){
removeIndex++;
continue;
}
toRemove.dismissNecroPet(true);
player.necroPets.remove(toRemove);
removeIndex++;
}
}
public static void resetNecroPets(PlayerCharacter player){
for (Mob necroPet: player.necroPets)
if (necroPet.isPet())
necroPet.setMob();
}
public void spawnNecroPet(Mob mob) {
if (mob == null)
return;
if (mob.getMobBaseID() != 12021 && mob.getMobBaseID() != 12022)
return;
PlayerCharacter.auditNecroPets(this);
PlayerCharacter.resetNecroPets(this);
this.necroPets.add(mob);
}
public void dismissPet() {
if (this.pet != null) {
this.pet.dismiss();
this.pet = null;
}
}
public void dismissNecroPets() {
if (this.necroPets.isEmpty())
return;
for (Mob necroPet: this.necroPets){
try{
necroPet.dismissNecroPet(true);
}catch(Exception e){
necroPet.setState(STATE.Disabled);
Logger.error(e);
}
}
this.necroPets.clear();
}
//called to verify player has correct item equipped for casting.
public boolean validEquip(int slot, String type) {
@@ -4644,7 +4580,7 @@ public void dismissNecroPets() {
if (!currentPet.isSiege()) {
currentPet.setCombatTarget(null);
currentPet.setState(STATE.Disabled);
currentPet.state = STATE.Disabled;
if (currentPet.getParentZone() != null)
@@ -4655,7 +4591,7 @@ public void dismissNecroPets() {
}catch(Exception e){
Logger.error( e.getMessage());
}
currentPet.getPlayerAgroMap().clear();
currentPet.playerAgroMap.clear();
WorldGrid.RemoveWorldObject(currentPet);
DbManager.removeFromCache(currentPet);