More itembase refactor work

This commit is contained in:
2024-03-15 11:30:03 -04:00
parent b9b04c2b9f
commit 2ceaece7d9
2 changed files with 23 additions and 25 deletions
+21 -23
View File
@@ -1243,17 +1243,16 @@ public class ClientMessagePump implements NetMsgHandler {
Item buy = null; Item buy = null;
if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) { if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) {
ArrayList<MobEquipment> sellInventory = npc.getContract().getSellInventory(); ArrayList<MobEquipment> sellInventory = npc.getContract().getSellInventory();
if (sellInventory == null) if (sellInventory == null)
return; return;
for (MobEquipment me : sellInventory) { for (MobEquipment me : sellInventory) {
if (me.getObjectUUID() == msg.getItemID()) { if (me.getObjectUUID() == msg.getItemID()) {
ItemBase ib = me.getItemBase();
if (ib == null)
return;
//test room available for item //test room available for item
if (!itemMan.hasRoomInventory(me.template.item_wt)) if (!itemMan.hasRoomInventory(me.template.item_wt))
return; return;
@@ -1275,22 +1274,22 @@ public class ClientMessagePump implements NetMsgHandler {
return; return;
} }
Building b = (!npc.isStatic()) ? npc.getBuilding() : null; Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) if (building != null && building.getProtectionState().equals(ProtectionState.NPC))
b = null; building = null;
int buildingDeposit = cost - me.getMagicValue(); int buildingDeposit = cost - me.getMagicValue();
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
return; return;
} }
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) {
// chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item."); // chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item.");
return; return;
} }
buy = Item.createItemForPlayer(sourcePlayer, ib); buy = Item.createItemForPlayer(sourcePlayer, me.templateID);
if (buy != null) { if (buy != null) {
me.transferEnchants(buy); me.transferEnchants(buy);
@@ -1344,20 +1343,20 @@ public class ClientMessagePump implements NetMsgHandler {
return; return;
} }
Building b = (!npc.isStatic()) ? npc.getBuilding() : null; Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null) if (building != null)
if (b.getProtectionState().equals(ProtectionState.NPC)) if (building.getProtectionState().equals(ProtectionState.NPC))
b = null; building = null;
int buildingDeposit = cost; int buildingDeposit = cost;
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
return; return;
} }
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) { if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110); ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110);
return; return;
} }
@@ -1391,24 +1390,23 @@ public class ClientMessagePump implements NetMsgHandler {
int cost = buy.getMagicValue(); int cost = buy.getMagicValue();
cost *= npc.getSellPercent(sourcePlayer); cost *= npc.getSellPercent(sourcePlayer);
if (gold.getNumOfItems() - cost < 0) { if (gold.getNumOfItems() - cost < 0) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold
return; return;
} }
Building b = (!npc.isStatic()) ? npc.getBuilding() : null; Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null && b.getProtectionState().equals(ProtectionState.NPC)) if (building != null && building.getProtectionState().equals(ProtectionState.NPC))
b = null; building = null;
int buildingDeposit = cost; int buildingDeposit = cost;
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) { if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206); ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
return; return;
} }
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) if (!itemMan.buyFromNPC(building, cost, buildingDeposit))
return; return;
if (buy != null) if (buy != null)
+2 -2
View File
@@ -523,9 +523,9 @@ public class Item extends AbstractWorldObject {
writer.putIntAt(serialized, indexPosition); writer.putIntAt(serialized, indexPosition);
} }
public static Item createItemForPlayer(PlayerCharacter pc, ItemBase ib) { public static Item createItemForPlayer(PlayerCharacter pc, int templateID) {
Item item = new Item(ib.getUUID()); Item item = new Item(templateID);
item.ownerID = pc.getObjectUUID(); item.ownerID = pc.getObjectUUID();
item.ownerType = OwnerType.PlayerCharacter; item.ownerType = OwnerType.PlayerCharacter;