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 { @@ -1243,16 +1243,15 @@ public class ClientMessagePump implements NetMsgHandler {
Item buy = null;
if (msg.getItemType() == GameObjectType.MobEquipment.ordinal()) {
ArrayList<MobEquipment> sellInventory = npc.getContract().getSellInventory();
if (sellInventory == null)
return;
for (MobEquipment me : sellInventory) {
if (me.getObjectUUID() == msg.getItemID()) {
ItemBase ib = me.getItemBase();
for (MobEquipment me : sellInventory) {
if (ib == null)
return;
if (me.getObjectUUID() == msg.getItemID()) {
//test room available for item
if (!itemMan.hasRoomInventory(me.template.item_wt))
@ -1275,22 +1274,22 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1275,22 +1274,22 @@ public class ClientMessagePump implements NetMsgHandler {
return;
}
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null && b.getProtectionState().equals(ProtectionState.NPC))
b = null;
if (building != null && building.getProtectionState().equals(ProtectionState.NPC))
building = null;
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);
return;
}
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) {
if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) {
// chatMan.chatSystemInfo(pc, "" + "You Failed to buy the item.");
return;
}
buy = Item.createItemForPlayer(sourcePlayer, ib);
buy = Item.createItemForPlayer(sourcePlayer, me.templateID);
if (buy != null) {
me.transferEnchants(buy);
@ -1344,20 +1343,20 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1344,20 +1343,20 @@ public class ClientMessagePump implements NetMsgHandler {
return;
}
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null)
if (b.getProtectionState().equals(ProtectionState.NPC))
b = null;
if (building != null)
if (building.getProtectionState().equals(ProtectionState.NPC))
building = null;
int buildingDeposit = cost;
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) {
if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
return;
}
if (!itemMan.buyFromNPC(b, cost, buildingDeposit)) {
if (!itemMan.buyFromNPC(building, cost, buildingDeposit)) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 110);
return;
}
@ -1391,24 +1390,23 @@ public class ClientMessagePump implements NetMsgHandler { @@ -1391,24 +1390,23 @@ public class ClientMessagePump implements NetMsgHandler {
int cost = buy.getMagicValue();
cost *= npc.getSellPercent(sourcePlayer);
if (gold.getNumOfItems() - cost < 0) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 128); // Insufficient Gold
return;
}
Building b = (!npc.isStatic()) ? npc.getBuilding() : null;
Building building = (!npc.isStatic()) ? npc.getBuilding() : null;
if (b != null && b.getProtectionState().equals(ProtectionState.NPC))
b = null;
if (building != null && building.getProtectionState().equals(ProtectionState.NPC))
building = null;
int buildingDeposit = cost;
if (b != null && (b.getStrongboxValue() + buildingDeposit) > b.getMaxGold()) {
if (building != null && (building.getStrongboxValue() + buildingDeposit) > building.getMaxGold()) {
ErrorPopupMsg.sendErrorPopup(sourcePlayer, 206);
return;
}
if (!itemMan.buyFromNPC(b, cost, buildingDeposit))
if (!itemMan.buyFromNPC(building, cost, buildingDeposit))
return;
if (buy != null)

4
src/engine/objects/Item.java

@ -523,9 +523,9 @@ public class Item extends AbstractWorldObject { @@ -523,9 +523,9 @@ public class Item extends AbstractWorldObject {
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.ownerType = OwnerType.PlayerCharacter;

Loading…
Cancel
Save