Browse Source

Refactored to static methods.

master
MagicBot 2 years ago
parent
commit
4adfbc0723
  1. 499
      src/engine/net/client/handlers/OrderNPCMsgHandler.java
  2. 75
      src/engine/objects/Mob.java
  3. 24
      src/engine/objects/NPC.java

499
src/engine/net/client/handlers/OrderNPCMsgHandler.java

@ -1,5 +1,6 @@
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.Enum;
import engine.Enum.DispatchChannel; import engine.Enum.DispatchChannel;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.Enum.ProfitType; import engine.Enum.ProfitType;
@ -36,242 +37,65 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
super(OrderNPCMsg.class); super(OrderNPCMsg.class);
} }
@Override public static void processRedeedMob(Mob mob, Building building, ClientConnection origin) {
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
// Member variable declarations
PlayerCharacter player; PlayerCharacter player;
NPC npc; Contract contract;
Mob mob; CharacterItemManager itemMan;
Building building; ItemBase itemBase;
OrderNPCMsg orderNPCMsg; Item item;
ManageCityAssetsMsg outMsg;
// Member variable assignment
orderNPCMsg = (OrderNPCMsg) baseMsg;
if (origin.ordernpcspam > System.currentTimeMillis())
return true;
origin.ordernpcspam = System.currentTimeMillis() + 500;
player = SessionManager.getPlayerCharacter(origin); player = SessionManager.getPlayerCharacter(origin);
itemMan = player.getCharItemManager();
if (player == null) contract = mob.getContract();
return true;
if (orderNPCMsg.getActionType() == 28) {
OrderNPCMsgHandler.handleCityCommand(orderNPCMsg, player);
return true;
}
if (orderNPCMsg.getObjectType() == GameObjectType.NPC.ordinal()) {
npc = NPC.getFromCache(orderNPCMsg.getNpcUUID());
if (npc == null)
return true;
building = BuildingManager.getBuildingFromCache(orderNPCMsg.getBuildingUUID());
if (building == null) if (!player.getCharItemManager().hasRoomInventory((short) 1)) {
return true; ErrorPopupMsg.sendErrorPopup(player, 21);
return;
if (building.getHirelings().containsKey(npc) == false)
return true;
if (player.getCharItemManager().getTradingWith() != null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot barter and trade with same timings.");
return true;
} }
player.lastBuildingAccessed = building.getObjectUUID(); if (!building.getHirelings().containsKey(mob))
return;
switch (orderNPCMsg.getActionType()) {
case 2:
player = SessionManager.getPlayerCharacter(origin);
if (ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building) == false)
return true;
if (building.getHirelings().containsKey(npc) == false)
return true;
if (npc.remove() == false) { if (!NPCManager.removeMobileFromBuilding(mob, building)) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity"); PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true; return;
}
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg();
manageCityAssetsMsg.actionType = SVR_CLOSE_WINDOW;
manageCityAssetsMsg.setTargetType(building.getObjectType().ordinal());
manageCityAssetsMsg.setTargetID(building.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(player, manageCityAssetsMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
case CLIENT_UPGRADE_REQUEST:
if (BuildingManager.playerCanManage(player, building) == false)
return true;
processUpgradeNPC(player, npc);
outMsg = new ManageCityAssetsMsg(player, building);
// Action TYPE
outMsg.actionType = 3;
outMsg.setTargetType(building.getObjectType().ordinal());
outMsg.setTargetID(building.getObjectUUID());
outMsg.setTargetType3(building.getObjectType().ordinal());
outMsg.setTargetID3(building.getObjectUUID());
outMsg.setAssetName1(building.getName());
outMsg.setUnknown54(1);
dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case CLIENT_REDEED_REQUEST:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
processRedeedNPC(npc, building, origin);
return true;
//MB TODO HANDLE all profits.
case 7:
case 8:
case 9:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
modifySellProfit(orderNPCMsg, origin);
dispatch = Dispatch.borrow(player, orderNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
case 10:
case 11:
case 12:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
modifyBuyProfit(orderNPCMsg, origin);
dispatch = Dispatch.borrow(player, orderNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
} }
// Validation check Owner or IC or friends building.getHirelings().remove(mob);
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
if (BuildingManager.playerCanManage(player, building) == false)
return true;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg(npc);
Dispatch dispatch = Dispatch.borrow(player, manageNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
} else if (orderNPCMsg.getObjectType() == GameObjectType.Mob.ordinal()) {
mob = Mob.getFromCacheDBID(orderNPCMsg.getNpcUUID());
if (mob == null)
return true;
building = BuildingManager.getBuildingFromCache(orderNPCMsg.getBuildingUUID());
if (building == null)
return true;
if (!building.getHirelings().containsKey(mob)) itemBase = ItemBase.getItemBase(contract.getContractID());
return true;
if (player.getCharItemManager().getTradingWith() != null) { if (itemBase == null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot barter and trade with same timings."); Logger.error("Could not find Contract for npc: " + mob.getObjectUUID());
return true; return;
} }
player.lastBuildingAccessed = building.getObjectUUID(); boolean itemWorked = false;
switch (orderNPCMsg.getActionType()) { item = new Item(itemBase, player.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) ((byte) mob.getRank() - 1), (byte) ((byte) mob.getRank() - 1), (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, new ArrayList<>(), "");
case 2: item.setNumOfItems(1);
item.containerType = Enum.ItemContainerType.INVENTORY;
if (BuildingManager.playerCanManage(player, building) == false) try {
return true; item = DbManager.ItemQueries.ADD_ITEM(item);
itemWorked = true;
if (building.getHirelings().containsKey(mob) == false) } catch (Exception e) {
return true; Logger.error(e);
if (NPCManager.removeMobileFromBuilding(mob, building) == false) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
} }
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg(); if (itemWorked) {
manageCityAssetsMsg.actionType = SVR_CLOSE_WINDOW; itemMan.addItemToInventory(item);
manageCityAssetsMsg.setTargetType(building.getObjectType().ordinal()); itemMan.updateInventory();
manageCityAssetsMsg.setTargetID(building.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(player, manageCityAssetsMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case 3:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
processUpgradeNPC(player, mob);
outMsg = new ManageCityAssetsMsg(player, building);
// Action TYPE
outMsg.actionType = 3;
outMsg.setTargetType(building.getObjectType().ordinal());
outMsg.setTargetID(building.getObjectUUID());
outMsg.setTargetType3(building.getObjectType().ordinal());
outMsg.setTargetID3(building.getObjectUUID());
outMsg.setAssetName1(building.getName());
outMsg.setUnknown54(1);
dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case 6:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
processRedeedNPC(mob, building, origin);
return true;
//MB TODO HANDLE all profits.
case 7:
case 8:
case 9:
break;
case 10:
case 11:
case 12:
break;
} }
// Validation check Owner or IC ManageCityAssetsMsg mca = new ManageCityAssetsMsg();
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false) mca.actionType = NPC.SVR_CLOSE_WINDOW;
if (BuildingManager.playerCanManage(player, building) == false) mca.setTargetType(building.getObjectType().ordinal());
return true; mca.setTargetID(building.getObjectUUID());
origin.sendMsg(mca);
ManageNPCMsg manageNPCMsg = new ManageNPCMsg(mob);
Dispatch dispatch = Dispatch.borrow(player, manageNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
return true;
} }
private static void modifyBuyProfit(OrderNPCMsg msg, ClientConnection origin) { private static void modifyBuyProfit(OrderNPCMsg msg, ClientConnection origin) {
@ -383,7 +207,7 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
if (orderNpcMsg.getPatrolPoints() != null) { if (orderNpcMsg.getPatrolPoints() != null) {
if ( !AddPatrolPoints(building.getObjectUUID(), orderNpcMsg.getPatrolPoints())){ if (!AddPatrolPoints(building.getObjectUUID(), orderNpcMsg.getPatrolPoints())) {
ErrorPopupMsg.sendErrorMsg(player, "Patrol Points must be placed on city zone."); ErrorPopupMsg.sendErrorMsg(player, "Patrol Points must be placed on city zone.");
return; return;
} }
@ -466,7 +290,7 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
} }
} }
private synchronized void processRedeedNPC(AbstractCharacter abstractCharacter, Building building, ClientConnection origin) { private static synchronized void processRedeedNPC(AbstractCharacter abstractCharacter, Building building, ClientConnection origin) {
// Member variable declaration // Member variable declaration
@ -479,11 +303,11 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
if (cityBuilding == null) if (cityBuilding == null)
return; return;
npc.processRedeedNPC(origin); NPC.processRedeedNPC(npc, npc.building, origin);
break; break;
case Mob: case Mob:
Mob mob = (Mob) abstractCharacter; Mob mob = (Mob) abstractCharacter;
mob.processRedeedMob(origin); processRedeedMob(mob, mob.building, origin);
break; break;
} }
} }
@ -509,12 +333,11 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
return false; return false;
//clear first. //clear first.
for (Vector3fImmutable point : patrolPoints) { for (Vector3fImmutable point : patrolPoints) {
if (city.isLocationOnCityZone(point) == false){ if (city.isLocationOnCityZone(point) == false) {
return false; return false;
} }
@ -573,4 +396,242 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
return true; return true;
} }
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
// Member variable declarations
PlayerCharacter player;
NPC npc;
Mob mob;
Building building;
OrderNPCMsg orderNPCMsg;
ManageCityAssetsMsg outMsg;
// Member variable assignment
orderNPCMsg = (OrderNPCMsg) baseMsg;
if (origin.ordernpcspam > System.currentTimeMillis())
return true;
origin.ordernpcspam = System.currentTimeMillis() + 500;
player = SessionManager.getPlayerCharacter(origin);
if (player == null)
return true;
if (orderNPCMsg.getActionType() == 28) {
OrderNPCMsgHandler.handleCityCommand(orderNPCMsg, player);
return true;
}
if (orderNPCMsg.getObjectType() == GameObjectType.NPC.ordinal()) {
npc = NPC.getFromCache(orderNPCMsg.getNpcUUID());
if (npc == null)
return true;
building = BuildingManager.getBuildingFromCache(orderNPCMsg.getBuildingUUID());
if (building == null)
return true;
if (building.getHirelings().containsKey(npc) == false)
return true;
if (player.getCharItemManager().getTradingWith() != null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot barter and trade with same timings.");
return true;
}
player.lastBuildingAccessed = building.getObjectUUID();
switch (orderNPCMsg.getActionType()) {
case 2:
player = SessionManager.getPlayerCharacter(origin);
if (ManageCityAssetMsgHandler.playerCanManageNotFriends(player, building) == false)
return true;
if (building.getHirelings().containsKey(npc) == false)
return true;
if (npc.remove() == false) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
}
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg();
manageCityAssetsMsg.actionType = SVR_CLOSE_WINDOW;
manageCityAssetsMsg.setTargetType(building.getObjectType().ordinal());
manageCityAssetsMsg.setTargetID(building.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(player, manageCityAssetsMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
case CLIENT_UPGRADE_REQUEST:
if (BuildingManager.playerCanManage(player, building) == false)
return true;
processUpgradeNPC(player, npc);
outMsg = new ManageCityAssetsMsg(player, building);
// Action TYPE
outMsg.actionType = 3;
outMsg.setTargetType(building.getObjectType().ordinal());
outMsg.setTargetID(building.getObjectUUID());
outMsg.setTargetType3(building.getObjectType().ordinal());
outMsg.setTargetID3(building.getObjectUUID());
outMsg.setAssetName1(building.getName());
outMsg.setUnknown54(1);
dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case CLIENT_REDEED_REQUEST:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
processRedeedNPC(npc, building, origin);
return true;
//MB TODO HANDLE all profits.
case 7:
case 8:
case 9:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
modifySellProfit(orderNPCMsg, origin);
dispatch = Dispatch.borrow(player, orderNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
case 10:
case 11:
case 12:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
modifyBuyProfit(orderNPCMsg, origin);
dispatch = Dispatch.borrow(player, orderNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
// Validation check Owner or IC or friends
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
if (BuildingManager.playerCanManage(player, building) == false)
return true;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg(npc);
Dispatch dispatch = Dispatch.borrow(player, manageNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
} else if (orderNPCMsg.getObjectType() == GameObjectType.Mob.ordinal()) {
mob = Mob.getFromCacheDBID(orderNPCMsg.getNpcUUID());
if (mob == null)
return true;
building = BuildingManager.getBuildingFromCache(orderNPCMsg.getBuildingUUID());
if (building == null)
return true;
if (!building.getHirelings().containsKey(mob))
return true;
if (player.getCharItemManager().getTradingWith() != null) {
ErrorPopupMsg.sendErrorMsg(player, "Cannot barter and trade with same timings.");
return true;
}
player.lastBuildingAccessed = building.getObjectUUID();
switch (orderNPCMsg.getActionType()) {
case 2:
if (BuildingManager.playerCanManage(player, building) == false)
return true;
if (building.getHirelings().containsKey(mob) == false)
return true;
if (NPCManager.removeMobileFromBuilding(mob, building) == false) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return true;
}
ManageCityAssetsMsg manageCityAssetsMsg = new ManageCityAssetsMsg();
manageCityAssetsMsg.actionType = SVR_CLOSE_WINDOW;
manageCityAssetsMsg.setTargetType(building.getObjectType().ordinal());
manageCityAssetsMsg.setTargetID(building.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(player, manageCityAssetsMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case 3:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
processUpgradeNPC(player, mob);
outMsg = new ManageCityAssetsMsg(player, building);
// Action TYPE
outMsg.actionType = 3;
outMsg.setTargetType(building.getObjectType().ordinal());
outMsg.setTargetID(building.getObjectUUID());
outMsg.setTargetType3(building.getObjectType().ordinal());
outMsg.setTargetID3(building.getObjectUUID());
outMsg.setAssetName1(building.getName());
outMsg.setUnknown54(1);
dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
break;
case 6:
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
return true;
processRedeedNPC(mob, building, origin);
return true;
//MB TODO HANDLE all profits.
case 7:
case 8:
case 9:
break;
case 10:
case 11:
case 12:
break;
}
// Validation check Owner or IC
if (BuildingManager.PlayerCanControlNotOwner(building, player) == false)
if (BuildingManager.playerCanManage(player, building) == false)
return true;
ManageNPCMsg manageNPCMsg = new ManageNPCMsg(mob);
Dispatch dispatch = Dispatch.borrow(player, manageNPCMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
return true;
}
} }

75
src/engine/objects/Mob.java

@ -24,9 +24,6 @@ import engine.math.Vector3fImmutable;
import engine.net.ByteBufferWriter; import engine.net.ByteBufferWriter;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; 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.PetMsg;
import engine.net.client.msg.PlaceAssetMsg; import engine.net.client.msg.PlaceAssetMsg;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
@ -53,7 +50,7 @@ public class Mob extends AbstractIntelligenceAgent {
//mob specific //mob specific
public final ConcurrentHashMap<Integer, Boolean> playerAgroMap = new ConcurrentHashMap<>(); 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); 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 nextCastTime = 0;
public long nextCallForHelp = 0; public long nextCallForHelp = 0;
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); 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() { public void dismiss() {
if (this.isPet()) { if (this.isPet()) {

24
src/engine/objects/NPC.java

@ -53,7 +53,7 @@ public class NPC extends AbstractCharacter {
protected boolean isMob; protected boolean isMob;
protected MobBase mobBase; protected MobBase mobBase;
protected String name; protected String name;
protected Building building; public Building building;
protected Contract contract; protected Contract contract;
protected int dbID; protected int dbID;
protected int currentID; protected int currentID;
@ -99,10 +99,6 @@ public class NPC extends AbstractCharacter {
public Vector3fImmutable inBuildingLoc = Vector3fImmutable.ZERO; public Vector3fImmutable inBuildingLoc = Vector3fImmutable.ZERO;
private int repairCost = 5; private int repairCost = 5;
public int classID = 0;
public int professionID = 0;
public int extraRune = 0;
public int extraRune2 = 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 // Member variable declaration
PlayerCharacter player; PlayerCharacter player;
@ -1725,7 +1721,7 @@ public class NPC extends AbstractCharacter {
ItemBase itemBase; ItemBase itemBase;
Item item; Item item;
this.lock.writeLock().lock(); npc.lock.writeLock().lock();
try{ try{
@ -1735,7 +1731,7 @@ public class NPC extends AbstractCharacter {
player = SessionManager.getPlayerCharacter(origin); player = SessionManager.getPlayerCharacter(origin);
itemMan = player.getCharItemManager(); itemMan = player.getCharItemManager();
contract = this.getContract(); contract = npc.getContract();
if (!player.getCharItemManager().hasRoomInventory((short)1)){ if (!player.getCharItemManager().hasRoomInventory((short)1)){
ErrorPopupMsg.sendErrorPopup(player, 21); ErrorPopupMsg.sendErrorPopup(player, 21);
@ -1743,26 +1739,26 @@ public class NPC extends AbstractCharacter {
} }
if (!building.getHirelings().containsKey(this)) if (!building.getHirelings().containsKey(npc))
return; 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"); PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return; return;
} }
building.getHirelings().remove(this); building.getHirelings().remove(npc);
itemBase = ItemBase.getItemBase(contract.getContractID()); itemBase = ItemBase.getItemBase(contract.getContractID());
if (itemBase == null) { if (itemBase == null) {
Logger.error("Could not find Contract for npc: " + this.getObjectUUID()); Logger.error("Could not find Contract for npc: " + npc.getObjectUUID());
return; return;
} }
boolean itemWorked = false; 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, (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0,
new ArrayList<>(),""); new ArrayList<>(),"");
item.setNumOfItems(1); item.setNumOfItems(1);
@ -1788,7 +1784,7 @@ public class NPC extends AbstractCharacter {
}catch(Exception e){ }catch(Exception e){
Logger.error(e); Logger.error(e);
}finally{ }finally{
this.lock.writeLock().unlock(); npc.lock.writeLock().unlock();
} }
} }

Loading…
Cancel
Save