Browse Source

More item refactor work.

combat-2
MagicBot 9 months ago
parent
commit
b98e7cda15
  1. 23
      src/engine/Enum.java
  2. 80
      src/engine/gameManager/BuildingManager.java
  3. 6
      src/engine/net/client/handlers/OrderNPCMsgHandler.java
  4. 35
      src/engine/objects/Item.java
  5. 9
      src/engine/objects/ItemFactory.java
  6. 14
      src/engine/objects/Kit.java
  7. 17
      src/engine/objects/Warehouse.java

23
src/engine/Enum.java

@ -2244,29 +2244,6 @@ public class Enum {
ITEM ITEM
} }
public enum objectMaskType {
PLAYER,
MOB,
PET,
CORPSE,
BUILDING,
UNDEAD,
BEAST,
HUMANOID,
NPC,
IAGENT,
DRAGON,
RAT,
SIEGE,
CITY,
ZONE;
public static EnumSet<objectMaskType> AGGRO = EnumSet.of(PLAYER, PET);
public static EnumSet<objectMaskType> MOBILE = EnumSet.of(PLAYER, MOB, PET);
public static EnumSet<objectMaskType> STATIC = EnumSet.of(CORPSE, BUILDING, NPC);
}
public enum ItemContainerType { public enum ItemContainerType {
NONE, NONE,
INVENTORY, INVENTORY,

80
src/engine/gameManager/BuildingManager.java

@ -19,10 +19,7 @@ import engine.job.JobScheduler;
import engine.jobs.UpgradeBuildingJob; import engine.jobs.UpgradeBuildingJob;
import engine.math.Bounds; import engine.math.Bounds;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.ManageCityAssetsMsg;
import engine.net.client.msg.PlaceAssetMsg;
import engine.objects.*; import engine.objects.*;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -780,83 +777,6 @@ public enum BuildingManager {
} }
public static void processRedeedNPC(NPC npc, Building building, ClientConnection origin) {
// Member variable declaration
PlayerCharacter player;
Contract contract;
CharacterItemManager itemMan;
ItemBase itemBase;
Item item;
npc.lock.writeLock().lock();
try {
if (building == null)
return;
player = SessionManager.getPlayerCharacter(origin);
itemMan = player.getCharItemManager();
contract = npc.getContract();
if (!player.getCharItemManager().hasRoomInventory((short) 1)) {
ErrorPopupMsg.sendErrorPopup(player, 21);
return;
}
if (!building.getHirelings().containsKey(npc))
return;
if (!npc.remove()) {
PlaceAssetMsg.sendPlaceAssetError(player.getClientConnection(), 1, "A Serious error has occurred. Please post details for to ensure transaction integrity");
return;
}
building.getHirelings().remove(npc);
itemBase = ItemBase.getItemBase(contract.getContractID());
if (itemBase == null) {
Logger.error("Could not find Contract for npc: " + npc.getObjectUUID());
return;
}
boolean itemWorked = false;
item = new Item(itemBase, player.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) ((byte) npc.getRank() - 1), (byte) ((byte) npc.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.PERSIST(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 {
npc.lock.writeLock().unlock();
}
}
public static void rebuildMine(Building mineBuilding) { public static void rebuildMine(Building mineBuilding) {
setRank(mineBuilding, 1); setRank(mineBuilding, 1);
mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(mineBuilding.rank); mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(mineBuilding.rank);

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

@ -68,8 +68,10 @@ public class OrderNPCMsgHandler extends AbstractClientMsgHandler {
boolean itemWorked = false; boolean itemWorked = false;
item = new Item(itemBase, player.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) ((byte) hireling.getRank() - 1), (byte) ((byte) hireling.getRank() - 1), (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, new ArrayList<>(), ""); item = new Item(itemBase.getUUID());
item.setNumOfItems(1); item.ownerID = player.getObjectUUID();
item.ownerType = Enum.OwnerType.PlayerCharacter;
item.chargesRemaining = (byte) hireling.getRank() - 1;
item.containerType = Enum.ItemContainerType.INVENTORY; item.containerType = Enum.ItemContainerType.INVENTORY;
try { try {

35
src/engine/objects/Item.java

@ -47,7 +47,7 @@ public class Item extends AbstractWorldObject {
public ReentrantLock lootLock = new ReentrantLock(); public ReentrantLock lootLock = new ReentrantLock();
public int ownerID; //may be character, account, npc, mob public int ownerID; //may be character, account, npc, mob
private int flags; //1 = isIDed private int flags; //1 = isIDed
private int numberOfItems; public int numberOfItems;
public float durabilityCurrent; public float durabilityCurrent;
public int chargesRemaining; public int chargesRemaining;
public byte equipSlot; public byte equipSlot;
@ -73,37 +73,8 @@ public class Item extends AbstractWorldObject {
this.chargesRemaining = this.template.item_initial_charges; this.chargesRemaining = this.template.item_initial_charges;
this.durabilityCurrent = this.template.combat_health_full; this.durabilityCurrent = this.template.combat_health_full;
this.equipSlot = 0; this.equipSlot = 0;
loadEnchantments(); this.containerType = ItemContainerType.NONE;
bakeInStats(); this.numberOfItems = 1;
}
public Item(ItemBase itemBase, int ownerID,
OwnerType ownerType, byte chargesMax, byte chargesRemaining,
short durabilityCurrent, short durabilityMax, boolean canDestroy,
boolean rentable, Enum.ItemContainerType containerType, byte equipSlot,
String name) {
super();
this.templsteID = itemBase.getUUID();
this.ownerID = ownerID;
this.ownerType = ownerType;
if (itemBase.getType().getValue() == 20) {
this.chargesMax = chargesMax;
this.chargesRemaining = chargesRemaining;
} else {
this.chargesMax = (byte) itemBase.getNumCharges();
this.chargesRemaining = (byte) itemBase.getNumCharges();
}
this.durabilityMax = (short) itemBase.getDurability();
this.durabilityCurrent = (short) itemBase.getDurability();
this.containerType = containerType;
this.canDestroy = canDestroy;
this.equipSlot = equipSlot;
this.flags = 1;
this.value = this.magicValue;
this.customName = name;
loadEnchantments(); loadEnchantments();
bakeInStats(); bakeInStats();
} }

9
src/engine/objects/ItemFactory.java

@ -25,7 +25,6 @@ import engine.server.MBServerStatics;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -57,9 +56,11 @@ public class ItemFactory {
break; break;
} }
Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, Item item = new Item(ib.getUUID());
(short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, item.ownerID = pc.getObjectUUID();
new ArrayList<>(), ""); item.ownerType = OwnerType.PlayerCharacter;
item.containerType = ItemContainerType.INVENTORY;
try { try {
item = DbManager.ItemQueries.PERSIST(item); item = DbManager.ItemQueries.PERSIST(item);
worked = true; worked = true;

14
src/engine/objects/Kit.java

@ -112,20 +112,20 @@ public class Kit extends AbstractGameObject {
*/ */
private static boolean kitItemCreator(PlayerCharacter pc, int itemBase, int slot) { private static boolean kitItemCreator(PlayerCharacter pc, int itemBase, int slot) {
ItemBase i = ItemBase.getItemBase(itemBase);
Item temp = new Item(i, pc.getObjectUUID(), Item item = new Item(itemBase);
OwnerType.PlayerCharacter, (byte) 0, (byte) 0, (short) 0, (short) 0, item.ownerID = pc.getObjectUUID();
false, false, ItemContainerType.EQUIPPED, (byte) slot, item.ownerType = OwnerType.PlayerCharacter;
new ArrayList<>(), ""); item.containerType = ItemContainerType.EQUIPPED;
item.equipSlot = (byte) slot;
try { try {
temp = DbManager.ItemQueries.PERSIST(temp); item = DbManager.ItemQueries.PERSIST(item);
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
if (temp == null) { if (item == null) {
Logger.info("Ungoof this goof, something is wrong with our kit."); Logger.info("Ungoof this goof, something is wrong with our kit.");
} }
return true; return true;

17
src/engine/objects/Warehouse.java

@ -753,11 +753,12 @@ public class Warehouse extends AbstractWorldObject {
itemMan.updateInventory(); itemMan.updateInventory();
} else { } else {
boolean itemWorked = false; boolean itemWorked = false;
Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0,
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, Item item = new Item(ib.getUUID());
new ArrayList<>(), ""); item.ownerID = pc.getObjectUUID();
item.setNumOfItems(amount); item.ownerType = Enum.OwnerType.PlayerCharacter;
item.containerType = Enum.ItemContainerType.INVENTORY; item.containerType = Enum.ItemContainerType.INVENTORY;
item.numberOfItems = amount;
try { try {
item = DbManager.ItemQueries.PERSIST(item); item = DbManager.ItemQueries.PERSIST(item);
@ -829,11 +830,11 @@ public class Warehouse extends AbstractWorldObject {
itemMan.updateInventory(); itemMan.updateInventory();
} else { } else {
boolean itemWorked = false; boolean itemWorked = false;
Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, Item item = new Item(ib.getUUID());
(short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, item.ownerID = pc.getObjectUUID();
new ArrayList<>(), ""); item.ownerType = Enum.OwnerType.PlayerCharacter;
item.setNumOfItems(amount);
item.containerType = Enum.ItemContainerType.INVENTORY; item.containerType = Enum.ItemContainerType.INVENTORY;
item.numberOfItems = amount;
try { try {
item = DbManager.ItemQueries.PERSIST(item); item = DbManager.ItemQueries.PERSIST(item);

Loading…
Cancel
Save