Browse Source

More itembase refactor work

combat-2
MagicBot 8 months ago
parent
commit
2ceaece7d9
  1. 44
      src/engine/net/client/ClientMessagePump.java
  2. 4
      src/engine/objects/Item.java

44
src/engine/net/client/ClientMessagePump.java

@ -1243,16 +1243,15 @@ 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) {
if (me.getObjectUUID() == msg.getItemID()) {
ItemBase ib = me.getItemBase(); for (MobEquipment me : sellInventory) {
if (ib == null) if (me.getObjectUUID() == msg.getItemID()) {
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))
@ -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)

4
src/engine/objects/Item.java

@ -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;

Loading…
Cancel
Save