Refactored to static methods.

This commit is contained in:
2023-04-23 11:19:34 -04:00
parent c0e92bddc2
commit 4adfbc0723
3 changed files with 371 additions and 387 deletions
+1 -74
View File
@@ -24,9 +24,6 @@ import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter;
import engine.net.Dispatch;
import engine.net.DispatchMessage;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.ManageCityAssetsMsg;
import engine.net.client.msg.PetMsg;
import engine.net.client.msg.PlaceAssetMsg;
import engine.powers.EffectsBase;
@@ -53,7 +50,7 @@ public class Mob extends AbstractIntelligenceAgent {
//mob specific
public final ConcurrentHashMap<Integer, Boolean> playerAgroMap = new ConcurrentHashMap<>();
public final ConcurrentHashMap<Mob, Integer> siegeMinionMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
public final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
public long nextCastTime = 0;
public long nextCallForHelp = 0;
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
@@ -2145,76 +2142,6 @@ public class Mob extends AbstractIntelligenceAgent {
}
}
public void processRedeedMob(ClientConnection origin) {
PlayerCharacter player;
Contract contract;
CharacterItemManager itemMan;
ItemBase itemBase;
Item item;
this.lock.writeLock().lock();
try {
player = SessionManager.getPlayerCharacter(origin);
itemMan = player.getCharItemManager();
contract = this.getContract();
if (!player.getCharItemManager().hasRoomInventory((short) 1)) {
ErrorPopupMsg.sendErrorPopup(player, 21);
return;
}
if (!building.getHirelings().containsKey(this))
return;
if (!NPCManager.removeMobileFromBuilding(this, building)) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return;
}
building.getHirelings().remove(this);
itemBase = ItemBase.getItemBase(contract.getContractID());
if (itemBase == null) {
Logger.error("Could not find Contract for npc: " + this.getObjectUUID());
return;
}
boolean itemWorked = false;
item = new Item(itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) this.getRank() - 1), (byte) ((byte) this.getRank() - 1), (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, new ArrayList<>(), "");
item.setNumOfItems(1);
item.containerType = Enum.ItemContainerType.INVENTORY;
try {
item = DbManager.ItemQueries.ADD_ITEM(item);
itemWorked = true;
} catch (Exception e) {
Logger.error(e);
}
if (itemWorked) {
itemMan.addItemToInventory(item);
itemMan.updateInventory();
}
ManageCityAssetsMsg mca = new ManageCityAssetsMsg();
mca.actionType = NPC.SVR_CLOSE_WINDOW;
mca.setTargetType(building.getObjectType().ordinal());
mca.setTargetID(building.getObjectUUID());
origin.sendMsg(mca);
} catch (Exception e) {
Logger.error(e);
} finally {
this.lock.writeLock().unlock();
}
}
public void dismiss() {
if (this.isPet()) {
+10 -14
View File
@@ -53,7 +53,7 @@ public class NPC extends AbstractCharacter {
protected boolean isMob;
protected MobBase mobBase;
protected String name;
protected Building building;
public Building building;
protected Contract contract;
protected int dbID;
protected int currentID;
@@ -99,10 +99,6 @@ public class NPC extends AbstractCharacter {
public Vector3fImmutable inBuildingLoc = Vector3fImmutable.ZERO;
private int repairCost = 5;
public int classID = 0;
public int professionID = 0;
public int extraRune = 0;
public int extraRune2 = 0;
@@ -1716,7 +1712,7 @@ public class NPC extends AbstractCharacter {
}
}
public void processRedeedNPC( ClientConnection origin) {
public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) {
// Member variable declaration
PlayerCharacter player;
@@ -1725,7 +1721,7 @@ public class NPC extends AbstractCharacter {
ItemBase itemBase;
Item item;
this.lock.writeLock().lock();
npc.lock.writeLock().lock();
try{
@@ -1735,7 +1731,7 @@ public class NPC extends AbstractCharacter {
player = SessionManager.getPlayerCharacter(origin);
itemMan = player.getCharItemManager();
contract = this.getContract();
contract = npc.getContract();
if (!player.getCharItemManager().hasRoomInventory((short)1)){
ErrorPopupMsg.sendErrorPopup(player, 21);
@@ -1743,26 +1739,26 @@ public class NPC extends AbstractCharacter {
}
if (!building.getHirelings().containsKey(this))
if (!building.getHirelings().containsKey(npc))
return;
if (!this.remove()) {
if (!npc.remove()) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return;
}
building.getHirelings().remove(this);
building.getHirelings().remove(npc);
itemBase = ItemBase.getItemBase(contract.getContractID());
if (itemBase == null) {
Logger.error("Could not find Contract for npc: " + this.getObjectUUID());
Logger.error("Could not find Contract for npc: " + npc.getObjectUUID());
return;
}
boolean itemWorked = false;
item = new Item( itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) this.getRank() - 1), (byte) ((byte) this.getRank() - 1),
item = new Item( itemBase, player.getObjectUUID(), OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.getRank() - 1),
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
new ArrayList<>(),"");
item.setNumOfItems(1);
@@ -1788,7 +1784,7 @@ public class NPC extends AbstractCharacter {
}catch(Exception e){
Logger.error(e);
}finally{
this.lock.writeLock().unlock();
npc.lock.writeLock().unlock();
}
}