Browse Source

Class cleanup

combat-2
MagicBot 8 months ago
parent
commit
55e2d3fb5e
  1. 107
      src/engine/objects/Warehouse.java

107
src/engine/objects/Warehouse.java

@ -70,7 +70,7 @@ public class Warehouse {
} }
public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc) { public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter playerCharacter, NPC npc) {
Building warehouseBuilding; Building warehouseBuilding;
Warehouse warehouse; Warehouse warehouse;
@ -83,7 +83,7 @@ public class Warehouse {
return; return;
depositAmount = msg.getAmount(); depositAmount = msg.getAmount();
CharacterItemManager itemMan = player.charItemManager; CharacterItemManager itemMan = playerCharacter.charItemManager;
if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID()))
return; return;
@ -93,25 +93,28 @@ public class Warehouse {
if (warehouseBuilding == null) if (warehouseBuilding == null)
return; return;
warehouse = warehouseBuilding.getCity().warehouse; City city = warehouseBuilding.getCity();
if (warehouse == null) if (city == null)
return; return;
warehouse = city.warehouse;
if (warehouse == null)
return;
if (!deposit(player, resource, depositAmount, true, true, warehouse)) { if (!deposit(playerCharacter, resource, depositAmount, true, true, warehouse))
return; return;
}
ViewResourcesMsg vrm = new ViewResourcesMsg(player); ViewResourcesMsg vrm = new ViewResourcesMsg(playerCharacter);
vrm.setGuild(player.getGuild()); vrm.setGuild(playerCharacter.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding); vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure(); vrm.configure();
dispatch = Dispatch.borrow(player, vrm); dispatch = Dispatch.borrow(playerCharacter, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} }
public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc) { public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter playerCharacter, NPC npc) {
int withdrawAmount; int withdrawAmount;
Building warehouseBuilding; Building warehouseBuilding;
@ -124,7 +127,7 @@ public class Warehouse {
if (warehouseBuilding == null) if (warehouseBuilding == null)
return; return;
if (player.getGuild() != warehouseBuilding.getGuild() || !GuildStatusController.isInnerCouncil(player.getGuildStatus())) if (playerCharacter.getGuild() != warehouseBuilding.getGuild() || !GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()))
return; return;
City city = warehouseBuilding.getCity(); City city = warehouseBuilding.getCity();
@ -140,24 +143,24 @@ public class Warehouse {
mbEnums.ResourceType resourceType = mbEnums.ResourceType.hashLookup.get(msg.getHashID()); mbEnums.ResourceType resourceType = mbEnums.ResourceType.hashLookup.get(msg.getHashID());
if (isResourceLocked(warehouse, resourceType)) { if (isResourceLocked(warehouse, resourceType)) {
ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); ChatManager.chatSystemInfo(playerCharacter, "You cannot withdrawl a locked resource.");
return; return;
} }
if (!withdraw(warehouse, player, resourceType, withdrawAmount, true, true)) { if (!withdraw(warehouse, playerCharacter, resourceType, withdrawAmount, true, true)) {
ChatManager.chatGuildError(player, "Failed to withdrawl " + resourceType.name() + '.'); ChatManager.chatGuildError(playerCharacter, "Failed to withdrawl " + resourceType.name() + '.');
Logger.debug(player.getName() + " Failed to withdrawl =" + resourceType.name() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); Logger.debug(playerCharacter.getName() + " Failed to withdrawl =" + resourceType.name() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID());
return; return;
} }
ViewResourcesMsg vrm = new ViewResourcesMsg(player); ViewResourcesMsg vrm = new ViewResourcesMsg(playerCharacter);
vrm.setGuild(player.getGuild()); vrm.setGuild(playerCharacter.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding); vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure(); vrm.configure();
dispatch = Dispatch.borrow(player, vrm); dispatch = Dispatch.borrow(playerCharacter, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} }
public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc) { public static void warehouseLock(MerchantMsg msg, PlayerCharacter playerCharacter, NPC npc) {
Building warehouseBuilding; Building warehouseBuilding;
Warehouse warehouse; Warehouse warehouse;
int hashID; int hashID;
@ -169,7 +172,7 @@ public class Warehouse {
if (warehouseBuilding == null) if (warehouseBuilding == null)
return; return;
if (player.getGuild() != warehouseBuilding.getGuild() || !GuildStatusController.isInnerCouncil(player.getGuildStatus())) if (playerCharacter.getGuild() != warehouseBuilding.getGuild() || !GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()))
return; return;
City city = warehouseBuilding.getCity(); City city = warehouseBuilding.getCity();
@ -190,11 +193,11 @@ public class Warehouse {
worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) { if (worked) {
ViewResourcesMsg vrm = new ViewResourcesMsg(player); ViewResourcesMsg vrm = new ViewResourcesMsg(playerCharacter);
vrm.setGuild(player.getGuild()); vrm.setGuild(playerCharacter.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding); vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure(); vrm.configure();
dispatch = Dispatch.borrow(player, vrm); dispatch = Dispatch.borrow(playerCharacter, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} else } else
warehouse.locked.add(resourceType); warehouse.locked.add(resourceType);
@ -207,26 +210,26 @@ public class Warehouse {
worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) { if (worked) {
ViewResourcesMsg vrm = new ViewResourcesMsg(player); ViewResourcesMsg vrm = new ViewResourcesMsg(playerCharacter);
vrm.setGuild(player.getGuild()); vrm.setGuild(playerCharacter.getGuild());
vrm.setWarehouseBuilding(warehouseBuilding); vrm.setWarehouseBuilding(warehouseBuilding);
vrm.configure(); vrm.configure();
dispatch = Dispatch.borrow(player, vrm); dispatch = Dispatch.borrow(playerCharacter, vrm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} else } else
warehouse.locked.remove(resourceType); warehouse.locked.remove(resourceType);
} }
public static synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction, Warehouse warehouse) { public static synchronized boolean deposit(PlayerCharacter playerCharacter, Item resource, int amount, boolean removeFromInventory, boolean transaction, Warehouse warehouse) {
ClientConnection origin = pc.getClientConnection(); ClientConnection origin = playerCharacter.getClientConnection();
if (origin == null) if (origin == null)
return false; return false;
if (amount < 0) { if (amount < 0) {
Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!"); Logger.info(playerCharacter.getFirstName() + " Attempting to Dupe!!!!!!");
return false; return false;
} }
@ -235,20 +238,20 @@ public class Warehouse {
if (warehouse.resources.get(resourceType) == null) if (warehouse.resources.get(resourceType) == null)
return false; return false;
CharacterItemManager itemMan = pc.charItemManager; CharacterItemManager itemMan = playerCharacter.charItemManager;
if (itemMan == null) if (itemMan == null)
return false; return false;
if (itemMan.getGoldTrading() > 0) { if (itemMan.getGoldTrading() > 0) {
ErrorPopupMsg.sendErrorPopup(pc, 195); ErrorPopupMsg.sendErrorPopup(playerCharacter, 195);
return false; return false;
} }
if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID()))
return false; return false;
if (!resource.validForInventory(origin, pc, itemMan)) if (!resource.validForInventory(origin, playerCharacter, itemMan))
return false; return false;
if (resource.getNumOfItems() < amount) if (resource.getNumOfItems() < amount)
@ -273,9 +276,9 @@ public class Warehouse {
if (!itemMan.modifyInventoryGold(-amount)) if (!itemMan.modifyInventoryGold(-amount))
return false; return false;
UpdateGoldMsg ugm = new UpdateGoldMsg(pc); UpdateGoldMsg ugm = new UpdateGoldMsg(playerCharacter);
ugm.configure(); ugm.configure();
Dispatch dispatch = Dispatch.borrow(pc, ugm); Dispatch dispatch = Dispatch.borrow(playerCharacter, ugm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
itemMan.updateInventory(); itemMan.updateInventory();
@ -304,7 +307,7 @@ public class Warehouse {
resourceType = mbEnums.ResourceType.valueOf(ItemTemplate.templates.get(resource.templateID).item_base_name.toUpperCase()); resourceType = mbEnums.ResourceType.valueOf(ItemTemplate.templates.get(resource.templateID).item_base_name.toUpperCase());
if (transaction) if (transaction)
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), mbEnums.TransactionType.DEPOSIT, resourceType, amount); AddTransactionToWarehouse(warehouse, playerCharacter.getObjectType(), playerCharacter.getObjectUUID(), mbEnums.TransactionType.DEPOSIT, resourceType, amount);
return true; return true;
} }
@ -437,9 +440,9 @@ public class Warehouse {
} }
} }
public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, mbEnums.ResourceType resourceType, int amount, boolean addToInventory, boolean transaction) { public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter playerCharacter, mbEnums.ResourceType resourceType, int amount, boolean addToInventory, boolean transaction) {
if (pc == null) if (playerCharacter == null)
return false; return false;
ItemTemplate template = ItemTemplate.templates.get(resourceType.templateID); ItemTemplate template = ItemTemplate.templates.get(resourceType.templateID);
@ -450,22 +453,22 @@ public class Warehouse {
if (amount <= 0) if (amount <= 0)
return false; return false;
CharacterItemManager itemMan = pc.charItemManager; CharacterItemManager itemMan = playerCharacter.charItemManager;
if (itemMan == null) if (itemMan == null)
return false; return false;
if (addToInventory) if (addToInventory)
if (!itemMan.hasRoomInventory(template.item_wt * amount)) { if (!itemMan.hasRoomInventory(template.item_wt * amount)) {
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); ChatManager.chatSystemInfo(playerCharacter, "You can not carry any more of that item.");
return false; return false;
} }
if (addToInventory && resourceType.equals(mbEnums.ResourceType.GOLD)) { if (addToInventory && resourceType.equals(mbEnums.ResourceType.GOLD)) {
if (pc.charItemManager.getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) if (playerCharacter.charItemManager.getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT)
return false; return false;
if (pc.charItemManager.getGoldInventory().getNumOfItems() + amount < 0) if (playerCharacter.charItemManager.getGoldInventory().getNumOfItems() + amount < 0)
return false; return false;
} }
int oldAmount = warehouse.resources.get(resourceType); int oldAmount = warehouse.resources.get(resourceType);
@ -486,9 +489,9 @@ public class Warehouse {
if (resourceType.equals(mbEnums.ResourceType.GOLD)) { if (resourceType.equals(mbEnums.ResourceType.GOLD)) {
itemMan.addGoldToInventory(amount, false); itemMan.addGoldToInventory(amount, false);
UpdateGoldMsg ugm = new UpdateGoldMsg(pc); UpdateGoldMsg ugm = new UpdateGoldMsg(playerCharacter);
ugm.configure(); ugm.configure();
Dispatch dispatch = Dispatch.borrow(pc, ugm); Dispatch dispatch = Dispatch.borrow(playerCharacter, ugm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
itemMan.updateInventory(); itemMan.updateInventory();
@ -496,7 +499,7 @@ public class Warehouse {
boolean itemWorked = false; boolean itemWorked = false;
Item item = new Item(resourceType.templateID); Item item = new Item(resourceType.templateID);
item.ownerID = pc.getObjectUUID(); item.ownerID = playerCharacter.getObjectUUID();
item.ownerType = mbEnums.OwnerType.PlayerCharacter; item.ownerType = mbEnums.OwnerType.PlayerCharacter;
item.containerType = mbEnums.ItemContainerType.INVENTORY; item.containerType = mbEnums.ItemContainerType.INVENTORY;
item.numberOfItems = amount; item.numberOfItems = amount;
@ -515,14 +518,14 @@ public class Warehouse {
} }
if (transaction) if (transaction)
AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), mbEnums.TransactionType.WITHDRAWL, resourceType, amount); AddTransactionToWarehouse(warehouse, playerCharacter.getObjectType(), playerCharacter.getObjectUUID(), mbEnums.TransactionType.WITHDRAWL, resourceType, amount);
return true; return true;
} }
public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, mbEnums.ResourceType resourceType, int amount, boolean addToInventory) { public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter playerCharacter, mbEnums.ResourceType resourceType, int amount, boolean addToInventory) {
if (pc == null) if (playerCharacter == null)
return false; return false;
ItemTemplate template = ItemTemplate.templates.get(resourceType); ItemTemplate template = ItemTemplate.templates.get(resourceType);
@ -536,13 +539,13 @@ public class Warehouse {
if (amount <= 0) if (amount <= 0)
return false; return false;
CharacterItemManager itemMan = pc.charItemManager; CharacterItemManager itemMan = playerCharacter.charItemManager;
if (itemMan == null) if (itemMan == null)
return false; return false;
if (!itemMan.hasRoomInventory(template.item_wt)) { if (!itemMan.hasRoomInventory(template.item_wt)) {
ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); ChatManager.chatSystemInfo(playerCharacter, "You can not carry any more of that item.");
return false; return false;
} }
@ -559,16 +562,16 @@ public class Warehouse {
if (resourceType.equals(mbEnums.ResourceType.GOLD)) { if (resourceType.equals(mbEnums.ResourceType.GOLD)) {
itemMan.addGoldToInventory(amount, false); itemMan.addGoldToInventory(amount, false);
UpdateGoldMsg ugm = new UpdateGoldMsg(pc); UpdateGoldMsg ugm = new UpdateGoldMsg(playerCharacter);
ugm.configure(); ugm.configure();
Dispatch dispatch = Dispatch.borrow(pc, ugm); Dispatch dispatch = Dispatch.borrow(playerCharacter, ugm);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
itemMan.updateInventory(); itemMan.updateInventory();
} else { } else {
boolean itemWorked = false; boolean itemWorked = false;
Item item = new Item(resourceType.templateID); Item item = new Item(resourceType.templateID);
item.ownerID = pc.getObjectUUID(); item.ownerID = playerCharacter.getObjectUUID();
item.ownerType = mbEnums.OwnerType.PlayerCharacter; item.ownerType = mbEnums.OwnerType.PlayerCharacter;
item.containerType = mbEnums.ItemContainerType.INVENTORY; item.containerType = mbEnums.ItemContainerType.INVENTORY;
item.numberOfItems = amount; item.numberOfItems = amount;

Loading…
Cancel
Save