From 9464500e953e8b957c9a8521c4639e006a3ac9d5 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 14 Apr 2024 14:48:59 -0400 Subject: [PATCH] More integration work --- src/engine/db/handlers/dbNPCHandler.java | 83 +- src/engine/devcmd/cmds/CreateItemCmd.java | 3 +- src/engine/gameManager/ForgeManager.java | 15 +- src/engine/net/ItemProductionManager.java | 135 --- src/engine/net/ItemQueue.java | 86 -- .../handlers/ItemProductionMsgHandler.java | 12 +- .../net/client/msg/ItemProductionMsg.java | 45 +- src/engine/net/client/msg/ManageNPCMsg.java | 3 +- src/engine/objects/CharacterItemManager.java | 32 +- src/engine/objects/ItemFactory.java | 1029 ----------------- src/engine/objects/NPC.java | 188 --- src/engine/objects/ProducedItem.java | 225 ---- src/engine/server/world/WorldServer.java | 6 - 13 files changed, 59 insertions(+), 1803 deletions(-) delete mode 100644 src/engine/net/ItemProductionManager.java delete mode 100644 src/engine/net/ItemQueue.java delete mode 100644 src/engine/objects/ItemFactory.java delete mode 100644 src/engine/objects/ProducedItem.java diff --git a/src/engine/db/handlers/dbNPCHandler.java b/src/engine/db/handlers/dbNPCHandler.java index edf1005f..9e0a18ff 100644 --- a/src/engine/db/handlers/dbNPCHandler.java +++ b/src/engine/db/handlers/dbNPCHandler.java @@ -9,13 +9,12 @@ package engine.db.handlers; -import engine.mbEnums; -import engine.mbEnums.ProfitType; import engine.gameManager.DbManager; import engine.math.Vector3fImmutable; +import engine.mbEnums; +import engine.mbEnums.ProfitType; import engine.objects.NPC; import engine.objects.NPCProfits; -import engine.objects.ProducedItem; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; @@ -346,29 +345,6 @@ public class dbNPCHandler extends dbHandlerBase { + NPC._pirateNames.size() + " mobBases"); } - public boolean ADD_TO_PRODUCTION_LIST(final long ID, final long npcUID, final long templateID, DateTime dateTime, String prefix, String suffix, String name, boolean isRandom, int playerID) { - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_npc_production` (`ID`,`npcUID`, `templateID`,`dateToUpgrade`, `isRandom`, `prefix`, `suffix`, `name`,`playerID`) VALUES (?,?,?,?,?,?,?,?,?)")) { - - preparedStatement.setLong(1, ID); - preparedStatement.setLong(2, npcUID); - preparedStatement.setLong(3, templateID); - preparedStatement.setTimestamp(4, new java.sql.Timestamp(dateTime.getMillis())); - preparedStatement.setBoolean(5, isRandom); - preparedStatement.setString(6, prefix); - preparedStatement.setString(7, suffix); - preparedStatement.setString(8, name); - preparedStatement.setInt(9, playerID); - - return (preparedStatement.executeUpdate() > 0); - - } catch (SQLException e) { - Logger.error(e); - return false; - } - } - public boolean REMOVE_FROM_PRODUCTION_LIST(final long ID, final long npcUID) { try (Connection connection = DbManager.getConnection(); @@ -385,23 +361,6 @@ public class dbNPCHandler extends dbHandlerBase { } } - public boolean UPDATE_ITEM_TO_INVENTORY(final long ID, final long npcUID) { - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `inForge`=? WHERE `ID`=? AND `npcUID`=?;")) { - - preparedStatement.setByte(1, (byte) 0); - preparedStatement.setLong(2, ID); - preparedStatement.setLong(3, npcUID); - - return (preparedStatement.executeUpdate() > 0); - - } catch (SQLException e) { - Logger.error(e); - return false; - } - } - public boolean UPDATE_ITEM_PRICE(final long ID, final long npcUID, int value) { try (Connection connection = DbManager.getConnection(); @@ -419,44 +378,6 @@ public class dbNPCHandler extends dbHandlerBase { } } - public boolean UPDATE_ITEM_ID(final long ID, final long npcUID, final long value) { - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `ID`=? WHERE `ID`=? AND `npcUID`=? LIMIT 1;")) { - - preparedStatement.setLong(1, value); - preparedStatement.setLong(2, ID); - preparedStatement.setLong(3, npcUID); - - return (preparedStatement.executeUpdate() > 0); - - } catch (SQLException e) { - Logger.error(e); - return false; - } - } - - public void LOAD_ALL_ITEMS_TO_PRODUCE(NPC npc) { - - if (npc == null) - return; - - try (Connection connection = DbManager.getConnection(); - PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_npc_production` WHERE `npcUID` = ?")) { - - preparedStatement.setInt(1, npc.getObjectUUID()); - ResultSet rs = preparedStatement.executeQuery(); - - while (rs.next()) { - ProducedItem producedItem = new ProducedItem(rs); - npc.forgedItems.add(producedItem); - } - - } catch (SQLException e) { - Logger.error(e); - } - } - public boolean UPDATE_PROFITS(NPC npc, ProfitType profitType, float value) { try (Connection connection = DbManager.getConnection(); diff --git a/src/engine/devcmd/cmds/CreateItemCmd.java b/src/engine/devcmd/cmds/CreateItemCmd.java index 5e0bfdf9..c5acefab 100644 --- a/src/engine/devcmd/cmds/CreateItemCmd.java +++ b/src/engine/devcmd/cmds/CreateItemCmd.java @@ -11,7 +11,6 @@ package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; import engine.objects.AbstractGameObject; -import engine.objects.ItemFactory; import engine.objects.PlayerCharacter; /** @@ -39,7 +38,7 @@ public class CreateItemCmd extends AbstractDevCmd { if (words.length == 2) size = Integer.parseInt(words[1]); - ItemFactory.fillInventory(pc, templateID, size); + } @Override diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 363d908f..ba456e29 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -17,6 +17,7 @@ import engine.powers.EffectsBase; import engine.powers.poweractions.AbstractPowerAction; import org.pmw.tinylog.Logger; +import java.util.ArrayList; import java.util.HashMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.DelayQueue; @@ -30,9 +31,12 @@ public enum ForgeManager implements Runnable { private static final BlockingQueue forge = new DelayQueue<>(); public static final AtomicInteger wordOrderCounter = new AtomicInteger(0); - public static final HashMap workOrderMap = new HashMap(); + public static final HashMap inMemoryItemLookup = new HashMap<>(); + public static final HashMap> vendorItemLookup = new HashMap<>(); + public static final HashMap> vendorWorkOrderLookup = new HashMap<>(); @Override + public void run() { while (true) { @@ -71,10 +75,7 @@ public enum ForgeManager implements Runnable { // worker after first removing the negative id item from all // collections. - // Add new item to the vendors inventory - workOrder.runCompleted = true; - workOrder.vendor.workOrders.remove(workOrder); continue; } @@ -124,7 +125,6 @@ public enum ForgeManager implements Runnable { forgeItems(workOrder); Logger.info(workOrder.toString()); - workOrder.vendor.workOrders.add(workOrder); forge.add(workOrder); return validation_result; @@ -180,7 +180,7 @@ public enum ForgeManager implements Runnable { // Slots currently used up by the npc workOrders - for (WorkOrder npcWorkOrder : workOrder.vendor.workOrders) + for (WorkOrder npcWorkOrder : ForgeManager.vendorWorkOrderLookup.get(workOrder.vendor)) availableSlots = availableSlots - npcWorkOrder.slots_used; // Single item rolls are msg_size of 0; @@ -287,9 +287,10 @@ public enum ForgeManager implements Runnable { for (int i = 0; i < workOrder.slots_used; ++i) { Item forged_item = forgeItem(workOrder); - ForgeManager.workOrderMap.put(forged_item, workOrder); + ForgeManager.inMemoryItemLookup.put(forged_item.objectUUID, forged_item); workOrder.cooking.add(forged_item); + vendorItemLookup.get(workOrder.vendor).add(forged_item); Logger.info("Forging item: " + forged_item.objectUUID + " (" + forged_item.templateID + ") " + forged_item.template.item_base_name); workOrder.total_produced = workOrder.total_produced + 1; diff --git a/src/engine/net/ItemProductionManager.java b/src/engine/net/ItemProductionManager.java deleted file mode 100644 index 1e8c8ec1..00000000 --- a/src/engine/net/ItemProductionManager.java +++ /dev/null @@ -1,135 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.net; - -import engine.mbEnums.DispatchChannel; -import engine.objects.ProducedItem; -import org.pmw.tinylog.Logger; - -import java.util.HashSet; -import java.util.concurrent.DelayQueue; -import java.util.concurrent.atomic.LongAdder; - -/** - * Thread blocks until MagicBane dispatch messages are - * enqueued then processes them in FIFO order. The collection - * is thread safe. - *

- * Any large messages not time sensitive such as load object - * sent to more than a single individual should be spawned - * individually on a DispatchMessageThread. - */ - - -public enum ItemProductionManager implements Runnable { - - ITEMPRODUCTIONMANAGER; - - - // Instance variables - - @SuppressWarnings("unchecked") // Cannot have arrays of generics in java. - private static final DelayQueue producedQueue = new DelayQueue<>(); - public static volatile long[] messageCount = new long[DispatchChannel.values().length]; - - // Class variables - public static LongAdder[] dispatchCount = new LongAdder[DispatchChannel.values().length]; - - - // Performance metrics - public static volatile long[] maxRecipients = new long[DispatchChannel.values().length]; - public static LongAdder dispatchPoolSize = new LongAdder(); - public static HashSet FailedItems = new HashSet<>(); - public Thread itemProductionThread = null; - private ItemQueue itemQueue; - private long nextFailedItemAudit; - - // Thread constructor - - public static void send(ItemQueue item) { - - // Don't queue up empty dispatches! - - if (item == null) - return; - - producedQueue.add(item); - - } - - public static String getNetstatString() { - - String outString = null; - String newLine = System.getProperty("line.separator"); - outString = "[LUA_NETSTA()]" + newLine; - outString += "poolSize: " + dispatchPoolSize.longValue() + '\n'; - - for (DispatchChannel dispatchChannel : DispatchChannel.values()) { - - outString += "Channel: " + dispatchChannel.name() + '\n'; - outString += "Dispatches: " + dispatchCount[dispatchChannel.getChannelID()].longValue() + '\n'; - outString += "Messages: " + messageCount[dispatchChannel.getChannelID()] + '\n'; - outString += "maxRecipients: " + maxRecipients[dispatchChannel.getChannelID()] + '\n'; - } - return outString; - } - - public void startMessagePump() { - - itemProductionThread = new Thread(this); - itemProductionThread.setName("ItemProductionManager"); - - } - - public void initialize() { - itemProductionThread.start(); - } - - @Override - public void run() { - - - while (true) { - try { - - this.itemQueue = producedQueue.take(); - - if (this.itemQueue == null) { - return; - } - - if (this.itemQueue != null) { - if (this.itemQueue.item == null) { - this.itemQueue.release(); - return; - } - - - boolean created = this.itemQueue.item.finishProduction(); - - if (!created) - FailedItems.add(this.itemQueue.item); - - this.itemQueue.release(); - - - } - - - } catch (Exception e) { - Logger.error(e); - } - - } - } - - // For Debugging: - //Logger.error("MessageDispatcher", messageDispatch.msg.getOpcodeAsString() + " sent to " + messageDispatch.playerList.size() + " players"); -} diff --git a/src/engine/net/ItemQueue.java b/src/engine/net/ItemQueue.java deleted file mode 100644 index e5373324..00000000 --- a/src/engine/net/ItemQueue.java +++ /dev/null @@ -1,86 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.net; - -import engine.objects.ProducedItem; - -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Delayed; -import java.util.concurrent.TimeUnit; - -import static engine.net.MessageDispatcher.itemPoolSize; - -/** - * Data class holds a message and a distribution list - */ - -public class ItemQueue implements Delayed { - - private static final ConcurrentLinkedQueue itemPool = new ConcurrentLinkedQueue<>(); - - public ProducedItem item; - public long delayTime; - - - public ItemQueue(ProducedItem item, long delayTime) { - this.item = item; - this.delayTime = System.currentTimeMillis() + delayTime; - - } - - public static ItemQueue borrow(ProducedItem item, long delayTime) { - - ItemQueue itemQueue; - - itemQueue = itemPool.poll(); - - if (itemQueue == null) { - itemQueue = new ItemQueue(item, delayTime); - } else { - itemQueue.item = item; - itemQueue.delayTime = System.currentTimeMillis() + delayTime; - itemPoolSize.decrement(); - } - - return itemQueue; - } - - public void reset() { - this.item = null; - this.delayTime = 0; - } - - public void release() { - this.reset(); - itemPool.add(this); - itemPoolSize.increment(); - } - - @Override - public int compareTo(Delayed another) { - ItemQueue anotherTask = (ItemQueue) another; - - if (this.delayTime < anotherTask.delayTime) { - return -1; - } - - if (this.delayTime > anotherTask.delayTime) { - return 1; - } - - return 0; - } - - @Override - public long getDelay(TimeUnit unit) { - long difference = delayTime - System.currentTimeMillis(); - return unit.convert(difference, TimeUnit.MILLISECONDS); - } -} diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index f7386b54..ad926368 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -82,7 +82,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { WorkOrder workOrder = new WorkOrder(); workOrder.total_to_produce = msg.total_to_produce; workOrder.vendor = vendorNPC; - workOrder.templateID = msg.templateID; + workOrder.templateID = msg.itemUUID; workOrder.prefixToken = msg.pToken; workOrder.suffixToken = msg.sToken; workOrder.item_name_override = msg.name; @@ -101,7 +101,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { } break; case JUNK: - junkItem(msg.templateID, vendorNPC, origin); + junkItem(msg.itemUUID, vendorNPC, origin); break; case RECYCLE: recycleItem(msg.items, vendorNPC, origin); @@ -110,13 +110,13 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); break; case COMPLETE: - vendorNPC.completeItem(msg.templateID); + // todo fix vendorNPC.completeItem(msg.itemUUID); break; case DEPOSIT: - depositItem(msg.templateID, vendorNPC, origin); + depositItem(msg.itemUUID, vendorNPC, origin); break; case SETPRICE: - setItemPrice(msg.itemType, msg.templateID, msg.itemPrice, vendorNPC, origin); + setItemPrice(msg.itemType, msg.itemUUID, msg.itemPrice, vendorNPC, origin); break; case TAKE: takeItem(msg.items, vendorNPC, origin); @@ -364,7 +364,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { // Delete the item and cancel any pending rolling timer jobs targetItem.recycle(vendor); - vendor.removeItemFromForge(targetItem); + // todo fix vendor.removeItemFromForge(targetItem); // Refresh vendor's inventory to client diff --git a/src/engine/net/client/msg/ItemProductionMsg.java b/src/engine/net/client/msg/ItemProductionMsg.java index 7dce78ff..98ea5320 100644 --- a/src/engine/net/client/msg/ItemProductionMsg.java +++ b/src/engine/net/client/msg/ItemProductionMsg.java @@ -10,6 +10,7 @@ package engine.net.client.msg; import engine.gameManager.BuildingManager; +import engine.gameManager.ForgeManager; import engine.gameManager.PowersManager; import engine.mbEnums; import engine.mbEnums.GameObjectType; @@ -27,7 +28,7 @@ public class ItemProductionMsg extends ClientNetMsg { public int size; public int buildingUUID; public int unknown01; - public int templateID; + public int itemUUID; public int itemType; public int total_to_produce; public int unknown03; @@ -50,7 +51,7 @@ public class ItemProductionMsg extends ClientNetMsg { this.size = 0; this.buildingUUID = 0; this.unknown01 = 0; - this.templateID = 0; + this.itemUUID = 0; this.total_to_produce = 0; this.unknown03 = 0; this.pToken = 0; @@ -70,7 +71,7 @@ public class ItemProductionMsg extends ClientNetMsg { this.buildingUUID = building.getObjectUUID(); this.npcUUID = vendor.getObjectUUID(); this.itemType = item.getObjectType().ordinal(); - this.templateID = item.getObjectUUID(); + this.itemUUID = item.getObjectUUID(); this.unknown01 = 0; this.total_to_produce = 0; this.unknown03 = 0; @@ -128,7 +129,7 @@ public class ItemProductionMsg extends ClientNetMsg { if (!add) { writer.put((byte) 1); - Item item = Item.getFromCache(this.templateID); + Item item = Item.getFromCache(this.itemUUID); if (item != null) Item.serializeForClientMsgWithoutSlot(item, writer); writer.putInt(building.getStrongboxValue()); @@ -142,12 +143,14 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.put((byte) 1); Item item; - if (this.itemType == GameObjectType.Item.ordinal()) - item = Item.getFromCache(this.templateID); + if (this.itemUUID > 0) + item = Item.getFromCache(this.itemUUID); else - item = MobLoot.getFromCache(this.templateID); + item = ForgeManager.inMemoryItemLookup.get(this.itemUUID); + if (item != null) Item.serializeForClientMsgWithoutSlot(item, writer); + writer.putInt(building.getStrongboxValue()); writer.putInt(0); writer.putInt(0); @@ -155,7 +158,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case CONFIRM_TAKE: writer.putInt(this.itemType); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(1); writer.putInt(0); writer.putInt(0); @@ -167,7 +170,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case SETPRICE: writer.putInt(this.itemType); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(1); writer.putInt(0); writer.putInt(0); @@ -180,7 +183,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case CONFIRM_SETPRICE: writer.putInt(this.itemType); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(1); writer.putInt(0); writer.putInt(0); @@ -194,7 +197,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case DEPOSIT: writer.putInt(this.itemType); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(1); writer.putInt(0); writer.putInt(0); @@ -234,7 +237,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(0); writer.putInt(0); writer.putInt(1); - MobLoot toRoll = MobLoot.getFromCache(this.templateID); + MobLoot toRoll = MobLoot.getFromCache(this.itemUUID); writer.putInt(-1497023830); if (toRoll != null && toRoll.getPrefix() != null && !toRoll.getPrefix().isEmpty()) { @@ -262,7 +265,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putString(toRoll.name); writer.putInt(GameObjectType.MobLoot.ordinal()); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(0); //items left to produce? writer.putInt(toRoll.templateID); @@ -306,7 +309,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case COMPLETE: writer.putInt(this.itemType); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(this.total_to_produce); writer.putInt(this.unknown03); writer.putInt(this.pToken); @@ -318,7 +321,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case JUNK: writer.putInt(this.itemType); - writer.putInt(this.templateID); + writer.putInt(this.itemUUID); writer.putInt(this.total_to_produce); writer.putInt(this.unknown03); writer.putInt(this.pToken); @@ -355,7 +358,7 @@ public class ItemProductionMsg extends ClientNetMsg { switch (this.actionType) { case SETPRICE: this.itemType = reader.getInt(); - this.templateID = reader.getInt(); + this.itemUUID = reader.getInt(); reader.getInt(); reader.getInt(); reader.getInt(); @@ -380,15 +383,15 @@ public class ItemProductionMsg extends ClientNetMsg { HashMap tempIDs = new HashMap<>(); for (int i = 0; i < this.size; i++) { int type = reader.getInt(); // Item type padding - this.templateID = reader.getInt(); - tempIDs.put(this.templateID, type); + this.itemUUID = reader.getInt(); + tempIDs.put(this.itemUUID, type); } reader.getInt(); this.items = tempIDs; break; case DEPOSIT: this.itemType = reader.getInt(); - this.templateID = reader.getInt(); + this.itemUUID = reader.getInt(); reader.getInt(); reader.getInt(); reader.getInt(); @@ -400,7 +403,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; case JUNK: this.itemType = reader.getInt(); - this.templateID = reader.getInt(); + this.itemUUID = reader.getInt(); this.total_to_produce = reader.getInt(); this.unknown03 = reader.getInt(); this.pToken = reader.getInt(); @@ -412,7 +415,7 @@ public class ItemProductionMsg extends ClientNetMsg { break; default: this.itemType = reader.getInt(); - this.templateID = reader.getInt(); + this.itemUUID = reader.getInt(); this.total_to_produce = reader.getInt(); this.unknown03 = reader.getInt(); this.pToken = reader.getInt(); diff --git a/src/engine/net/client/msg/ManageNPCMsg.java b/src/engine/net/client/msg/ManageNPCMsg.java index 3be1d778..c4898efa 100644 --- a/src/engine/net/client/msg/ManageNPCMsg.java +++ b/src/engine/net/client/msg/ManageNPCMsg.java @@ -9,6 +9,7 @@ package engine.net.client.msg; +import engine.gameManager.ForgeManager; import engine.gameManager.NPCManager; import engine.gameManager.PowersManager; import engine.mbEnums.GameObjectType; @@ -435,7 +436,7 @@ public class ManageNPCMsg extends ClientNetMsg { writer.put((byte) template.modTable);//EffectItemType } - List itemList = npc.getRolling(); + List itemList = ForgeManager.vendorItemLookup.get(npc); itemList = itemList.stream().limit(npc.getRank()).collect(Collectors.toList()); writer.putInt(itemList.size()); diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 4003ff5d..70f2e7d5 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -1341,28 +1341,28 @@ public class CharacterItemManager { /* * Delegates */ - public synchronized boolean bankContains(Item i) { - if (i.template.item_type.equals(ItemType.GOLD)) - return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == i.getObjectUUID()); - return bank.contains(i); + public synchronized boolean bankContains(Item item) { + if (item.template.item_type.equals(ItemType.GOLD)) + return (this.getGoldBank() != null && this.goldBank.getObjectUUID() == item.getObjectUUID()); + return bank.contains(item); } - public synchronized boolean inventoryContains(Item i) { - if (i.template.item_type.equals(ItemType.GOLD)) - return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID()); - return inventory.contains(i); + public synchronized boolean inventoryContains(Item item) { + if (item.template.item_type.equals(ItemType.GOLD)) + return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == item.getObjectUUID()); + return inventory.contains(item); } - public synchronized boolean forgeContains(Item i, NPC vendor) { - if (i.template.item_type.equals(ItemType.GOLD)) - return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == i.getObjectUUID()); - return vendor.getRolling().contains(i); + public synchronized boolean forgeContains(Item item, NPC vendor) { + if (item.template.item_type.equals(ItemType.GOLD)) + return (this.getGoldInventory() != null && this.goldInventory.getObjectUUID() == item.getObjectUUID()); + return ForgeManager.vendorItemLookup.get(vendor).contains(item); } - public synchronized boolean vaultContains(Item i) { - if (i.template.item_type.equals(ItemType.GOLD)) - return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == i.getObjectUUID()); - return this.account.getVault().contains(i); + public synchronized boolean vaultContains(Item item) { + if (item.template.item_type.equals(ItemType.GOLD)) + return (this.getGoldVault() != null && this.goldVault.getObjectUUID() == item.getObjectUUID()); + return this.account.getVault().contains(item); } public synchronized boolean equippedContains(Item i) { diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java deleted file mode 100644 index b5d937e6..00000000 --- a/src/engine/objects/ItemFactory.java +++ /dev/null @@ -1,1029 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.objects; - -import engine.gameManager.*; -import engine.loot.ModTableEntry; -import engine.loot.ModTypeTableEntry; -import engine.mbEnums; -import engine.mbEnums.ItemContainerType; -import engine.mbEnums.ItemType; -import engine.mbEnums.OwnerType; -import engine.net.ItemProductionManager; -import engine.net.ItemQueue; -import engine.net.client.ClientConnection; -import engine.net.client.msg.ErrorPopupMsg; -import engine.powers.EffectsBase; -import engine.server.MBServerStatics; -import org.joda.time.DateTime; -import org.pmw.tinylog.Logger; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ThreadLocalRandom; - -public class ItemFactory { - - public static void fillInventory(PlayerCharacter pc, int templateID, int count) { - - if (pc == null) - return; - - int max = 20; - CharacterItemManager itemManager = pc.charItemManager; - - ItemTemplate template = ItemTemplate.templates.get(templateID); - - if (count > max) - count = max; - - ClientConnection cc = pc.getClientConnection(); - - if (itemManager == null || template == null || cc == null) - return; - - boolean worked; - - for (int i = 0; i < count; i++) { - worked = false; - - if (!itemManager.hasRoomInventory(template.item_wt)) { - if (pc != null) - ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); - break; - } - - Item item = new Item(templateID); - item.ownerID = pc.getObjectUUID(); - item.ownerType = OwnerType.PlayerCharacter; - item.containerType = ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.PERSIST(item); - worked = true; - } catch (Exception e) { - Logger.error(e); - } - if (worked) { - itemManager.addItemToInventory(item); - } - } - itemManager.updateInventory(); - } - - public static Item fillForge(NPC npc, PlayerCharacter pc, int itemsToRoll, int templateID, int pToken, int sToken, String customName) { - - String prefixString = ""; - String suffixString = ""; - if (npc == null) - return null; - - boolean useWarehouse = false; - - ItemTemplate template = ItemTemplate.templates.get(templateID); - - if (template == null) - return null; - - Building forge = npc.getBuilding(); - - if (forge == null) - return null; - - if (!npc.charItemManager.hasRoomInventory(template.item_wt)) { - if (pc != null) - ErrorPopupMsg.sendErrorPopup(pc, 21); - return null; - } - - Zone zone = npc.getBuilding().getParentZone(); - - if (zone == null) - return null; - - City city = City.getCity(zone.playerCityUUID); - - if (city == null) - return null; - - MobLoot ml = null; - city.transactionLock.writeLock().lock(); - - try { - Warehouse cityWarehouse = city.warehouse; - - if (cityWarehouse != null && forge.assetIsProtected()) - useWarehouse = true; - // ROLL BANE SCROLL. - - if (templateID > 910010 && templateID < 910019) { - ConcurrentHashMap resources = cityWarehouse.resources; - - - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, template.item_value); - int overdraft = BuildingManager.GetOverdraft(forge, template.item_value); - - if (overdraft > 0 && !useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + template.item_base_name); - return null; - } - - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + template.item_base_name); - return null; - } - - if (overdraft > resources.get(mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + " " + template.item_base_name); - return null; - } - - if (!forge.transferGold(-buildingWithdraw, false)) { - overdraft += buildingWithdraw; - - if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); - return null; - } else { - if (overdraft > resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); - return null; - } - } - } - - if (overdraft > 0) - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); - return null; - } - - ml = new MobLoot(npc, template, false); - - ml.containerType = mbEnums.ItemContainerType.FORGE; - ml.setValue(0); - ml.loadEnchantments(); - - float time; - float rank = npc.getBuilding().getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= MBServerStatics.ONE_MINUTE; - - if (ml.templateID > 910010 && ml.templateID < 910019) { - rank = ml.templateID - 910010; - time = rank * 60 * 60 * 3 * 1000; - - } - - // No job is submitted, as object's upgradetime field - // is used to determin whether or not an object has - // compelted rolling. The game object exists previously - // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); - - DateTime dateTime = new DateTime(); - dateTime = dateTime.withMillis(upgradeTime); - ml.setDateToUpgrade(upgradeTime); - - npc.addItemToForge(ml); - - int playerID = 0; - - if (pc != null) - playerID = pc.getObjectUUID(); - DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(ml.getObjectUUID(), npc.getObjectUUID(), ml.templateID, dateTime, "", "", "", false, playerID); - ProducedItem pi = new ProducedItem(ml.getObjectUUID(), npc.getObjectUUID(), ml.templateID, dateTime, false, "", "", "", playerID); - pi.setProducedItemID(ml.getObjectUUID()); - pi.setAmount(itemsToRoll); - pi.setRandom(false); - - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); - ItemProductionManager.send(produced); - - return ml; - } - - int galvorAmount = 0; - int wormwoodAmount = 0; - int prefixCost = 0; - int suffixCost = 0; - - if (template.item_type.equals(ItemType.WEAPON) && template.item_skill_required.isEmpty() == false && - template.item_skill_required.values().iterator().next() == 110) { - switch (template.item_skill_used) { - case "Bow": - case "Crossbow": - case "Spear": - case "Pole Arm": - case "Staff": - wormwoodAmount = 20; - break; - case "Axe": - case "Dagger": - case "Sword": - case "Hammer": - case "Unarmed Combat": - - if (ItemManager.isTwoHanded(template)) - galvorAmount = 20; - else - galvorAmount = 10; - break; - } - } - - if (galvorAmount > 0 || wormwoodAmount > 0) - if (!useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "This item requires resources to roll! Please make sure the forge is protected to access the warehouse." + template.item_base_name); - return null; - - } - - if (galvorAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GALVOR)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); - return null; - } - - if (cityWarehouse.resources.get(mbEnums.ResourceType.GALVOR) < galvorAmount) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); - return null; - } - } - - if (wormwoodAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.WORMWOOD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + template.item_base_name); - return null; - } - - if (cityWarehouse.resources.get(mbEnums.ResourceType.WORMWOOD) < wormwoodAmount) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item." + template.item_base_name); - return null; - } - } - ConcurrentHashMap suffixResourceCosts = null; - ConcurrentHashMap prefixResourceCosts = null; - - EffectsBase prefix = null; - - if (pToken != 0) { - - if (!useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + template.item_base_name); - return null; - } - prefix = PowersManager.getEffectByToken(pToken); - if (prefix == null) - return null; - EffectsBase prefixValue = PowersManager.getEffectByIDString(prefix.getIDString() + 'A'); - if (prefixValue == null) - return null; - - int baseCost = template.item_value; - int effectCost = (int) prefixValue.getValue(); - int total = baseCost * 10 + effectCost; - - prefixCost = effectCost; - int overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); - return null; - } - - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); - return null; - } - - if (overdraft > cityWarehouse.resources.get(mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); - return null; - } - prefixResourceCosts = prefix.getResourcesForEffect(); - - for (mbEnums.ResourceType ibResources : prefixResourceCosts.keySet()) { - int warehouseAmount = cityWarehouse.resources.get(ibResources); - int creationAmount = prefixResourceCosts.get(ibResources); - - if (warehouseAmount < creationAmount) - return null; - } - } - EffectsBase suffix = null; - - if (sToken != 0) { - - if (!useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + template.item_base_name); - return null; - } - suffix = PowersManager.getEffectByToken(sToken); - if (suffix == null) - return null; - EffectsBase suffixValue = PowersManager.getEffectByIDString(suffix.getIDString() + 'A'); - if (suffixValue == null) - return null; - suffixResourceCosts = suffix.getResourcesForEffect(); - int baseCost = template.item_value; - int effectCost = (int) suffixValue.getValue(); - suffixCost = effectCost; - int total = baseCost * 10 + effectCost; - - - // int buildingWithdraw = Building.GetWithdrawAmountForRolling(forge, total); - int overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); - return null; - } - - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); - return null; - } - - if (overdraft > cityWarehouse.resources.get(mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); - return null; - } - - - for (mbEnums.ResourceType ibResources : suffixResourceCosts.keySet()) { - int warehouseAmount = cityWarehouse.resources.get(ibResources); - int creationAmount = suffixResourceCosts.get(ibResources); - - if (warehouseAmount < creationAmount) - return null; - } - } - - //Check if Total suffix and prefix costs + itemCost can be withdrawn. - - int costToCreate = suffixCost + prefixCost + template.item_value; - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); - - int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); - - if (overdraft > 0 && !useWarehouse) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); - return null; - } - - if (overdraft > 0 && useWarehouse && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); - return null; - } - - if (useWarehouse && overdraft > cityWarehouse.resources.get(mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); - return null; - } - - // if (pc != null){ - // ChatManager.chatGuildInfo(pc.getGuild(), "Building withdraw = " + buildingWithdraw); - // ChatManager.chatGuildInfo(pc.getGuild(), "Warehouse overdraft withdraw = " + overdraft); - // - // ChatManager.chatGuildInfo(pc.getGuild(), "total withdraw = " + (overdraft + buildingWithdraw)); - // } - - if (!forge.transferGold(-buildingWithdraw, false)) { - overdraft += buildingWithdraw; - - if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); - return null; - } else { - if (overdraft > cityWarehouse.resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); - return null; - } - } - } - - if (overdraft > 0 && useWarehouse) - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); - return null; - } - - - if (prefix != null) { - - if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Cannot Resource Roll without access to the warehouse! Make sure the forge is currently protected." + template.item_base_name); - return null; - } - - - for (mbEnums.ResourceType ibResources : prefixResourceCosts.keySet()) { - - int creationAmount = prefixResourceCosts.get(ibResources); - - if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true) - return null; - - int oldAmount = cityWarehouse.resources.get(ibResources); - int amount = creationAmount; - - if (oldAmount < amount) - amount = oldAmount; - - if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); - return null; - } - } - } - - if (suffix != null) { - - for (mbEnums.ResourceType ibResources : suffixResourceCosts.keySet()) { - int creationAmount = suffixResourceCosts.get(ibResources); - - if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true) { - ChatManager.chatSystemError(pc, "Resource is locked!" + template.item_base_name); - return null; - } - - int oldAmount = cityWarehouse.resources.get(ibResources); - int amount = creationAmount; - - if (oldAmount < amount) - amount = oldAmount; - - if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); - return null; - } - } - } - - if (prefix == null && suffix == null) { - - int baseCost = template.item_value; - int total = (int) (baseCost + baseCost * (float) .10); - - buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); - - overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse) { - - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); - return null; - } - - if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); - return null; - } - - if (useWarehouse && overdraft > cityWarehouse.resources.get(mbEnums.ResourceType.GOLD)) { - - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); - return null; - } - } - - if (!forge.transferGold(-buildingWithdraw, false)) { - overdraft += buildingWithdraw; - - if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); - return null; - } else { - if (overdraft > cityWarehouse.resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); - return null; - } - } - } - - if (overdraft > 0) - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GOLD, overdraft, true)) { - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); - return null; - } - - // ChatManager.chatGuildInfo(pc, "Gold Cost = " + total); - - if (galvorAmount > 0) { - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GALVOR, galvorAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } - - if (wormwoodAmount > 0) { - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.WORMWOOD, wormwoodAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + template.item_base_name); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } - - ml = new MobLoot(npc, template, false); - - ml.containerType = mbEnums.ItemContainerType.FORGE; - - if (customName.isEmpty() == false) - ml.name = customName; - - if (prefix != null) { - ml.addPermanentEnchantment(prefix.getIDString(), 0, 0, true); - ml.setPrefix(prefix.getIDString()); - prefixString = prefix.getIDString(); - } - - if (suffix != null) { - ml.addPermanentEnchantment(suffix.getIDString(), 0, 0, false); - ml.setSuffix(suffix.getIDString()); - suffixString = suffix.getIDString(); - } - - ml.loadEnchantments(); - //set value to 0 so magicvalue can be recalculated in getValue. - ml.setValue(0); - - float time; - float rank = npc.getBuilding().getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= MBServerStatics.ONE_MINUTE; - - if (ml.templateID > 910010 && ml.templateID < 910019) { - rank = ml.templateID - 910010; - time = rank * 60 * 60 * 3 * 1000; - } - - - // No job is submitted, as object's upgradetime field - // is used to determin whether or not an object has - // compelted rolling. The game object exists previously - // to this, not when 'compelte' is pressed. - long upgradeTime = System.currentTimeMillis() + (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); - - DateTime dateTime = new DateTime(); - dateTime = dateTime.withMillis(upgradeTime); - ml.setDateToUpgrade(upgradeTime); - - npc.addItemToForge(ml); - int playerID = 0; - - if (pc != null) - playerID = pc.getObjectUUID(); - - DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(ml.getObjectUUID(), npc.getObjectUUID(), ml.templateID, dateTime, prefixString, suffixString, ml.name, false, playerID); - ProducedItem pi = new ProducedItem(npc.getRolling().size(), npc.getObjectUUID(), ml.templateID, dateTime, false, prefixString, suffixString, ml.name, playerID); - pi.setProducedItemID(ml.getObjectUUID()); - pi.setAmount(itemsToRoll); - - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); - ItemProductionManager.send(produced); - } catch (Exception e) { - Logger.error(e); - } finally { - city.transactionLock.writeLock().unlock(); - } - - - // npc.addItemToForge(item); - return ml; - - } - - - public static Item randomRoll(NPC vendor, PlayerCharacter playerCharacter, int itemsToRoll, int templateID) { - byte itemModTable; - int prefixMod = 0; - int suffixMod = 0; - String prefix = ""; - String suffix = ""; - - ModTableEntry prefixEntry = null; - ModTableEntry suffixEntry = null; - - ItemTemplate template = ItemTemplate.templates.get(templateID); - - if (template == null) - return null; - - if (!vendor.charItemManager.hasRoomInventory(template.item_wt)) { - - if (playerCharacter != null) - ChatManager.chatSystemInfo(playerCharacter, vendor.getName() + " " + vendor.getContract().getName() + " Inventory is full."); - - return null; - } - - itemModTable = (byte) template.modTable; - - if (!vendor.getItemModTable().contains(itemModTable)) { - - if (playerCharacter != null) - ErrorPopupMsg.sendErrorPopup(playerCharacter, 59); - - return null; - } - - for (int temp : vendor.getItemModTable()) { - - if (itemModTable != temp) - continue; - - prefixMod = vendor.getModTypeTable().get(vendor.getItemModTable().indexOf(temp)); - suffixMod = vendor.getModSuffixTable().get(vendor.getItemModTable().indexOf(temp)); - } - - if (prefixMod == 0 && suffixMod == 0) { - Logger.info("Failed to find modTables for item " + template.item_base_name); - return null; - } - - // Roll on the tables for this vendor - - ModTypeTableEntry prefixTypeTable = ModTypeTableEntry.rollTable(prefixMod, ThreadLocalRandom.current().nextInt(1, 100 + 1)); - ModTypeTableEntry suffixTypeTable = ModTypeTableEntry.rollTable(suffixMod, ThreadLocalRandom.current().nextInt(1, 100 + 1)); - - // Sanity check. - - if (prefixTypeTable == null || suffixTypeTable == null) - return null; - - int rollPrefix = ThreadLocalRandom.current().nextInt(1, 100 + 1); - - if (rollPrefix < 80) { - - int randomPrefix = LootManager.TableRoll(vendor.getLevel(), false); - prefixEntry = ModTableEntry.rollTable(prefixTypeTable.modTableID, randomPrefix); - - if (prefixEntry != null) - prefix = prefixEntry.action; - - } - - int rollSuffix = ThreadLocalRandom.current().nextInt(1, 100 + 1); - - // Always have at least one mod on a magic rolled item. - // Suffix will be our backup plan. - - if (rollSuffix < 80 || prefixEntry == null) { - - int randomSuffix = LootManager.TableRoll(vendor.getLevel(), false); - suffixEntry = ModTableEntry.rollTable(suffixTypeTable.modTableID, randomSuffix); - - if (suffixEntry != null) - suffix = suffixEntry.action; - } - - MobLoot toRoll = ItemFactory.produceRandomRoll(vendor, playerCharacter, prefix, suffix, templateID); - - if (toRoll == null) - return null; - - toRoll.setValue(0); - - float time; - float rank = vendor.getBuilding().getRank() - 1; - float rate = (float) (2.5 * rank); - time = (20 - rate); - time *= MBServerStatics.ONE_MINUTE; - - // Bane circles - - if (toRoll.templateID > 910010 && toRoll.templateID < 910019) { - rank = toRoll.templateID - 910010; - time = rank * 60 * 60 * 3 * 1000; - } - - // No job is submitted, as object's upgradetime field - // is used to determine whether an object has - // completed rolling. The game object exists previously - // to this, not when 'complete' is pressed. - - long upgradeTime = System.currentTimeMillis() + (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue())); - - DateTime dateTime = new DateTime(); - dateTime = dateTime.withMillis(upgradeTime); - toRoll.setDateToUpgrade(upgradeTime); - - int playerID = 0; - - if (playerCharacter != null) - playerID = playerCharacter.getObjectUUID(); - - DbManager.NPCQueries.ADD_TO_PRODUCTION_LIST(toRoll.getObjectUUID(), vendor.getObjectUUID(), toRoll.templateID, dateTime, prefix, suffix, toRoll.name, true, playerID); - - ProducedItem pi = new ProducedItem(toRoll.getObjectUUID(), vendor.getObjectUUID(), toRoll.templateID, dateTime, true, prefix, suffix, toRoll.name, playerID); - pi.setProducedItemID(toRoll.getObjectUUID()); - pi.setAmount(itemsToRoll); - ItemQueue produced = ItemQueue.borrow(pi, (long) (time * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()))); - ItemProductionManager.send(produced); - - return toRoll; - } - - public static MobLoot produceRandomRoll(NPC npc, PlayerCharacter pc, String prefixString, String suffixString, int templateID) { - - boolean useWarehouse = false; - - if (npc == null) - return null; - - ItemTemplate template = ItemTemplate.templates.get(templateID); - - Building forge = npc.getBuilding(); - - if (forge == null) - return null; - - Zone zone = npc.getBuilding().getParentZone(); - - if (zone == null) - return null; - - City city = City.getCity(zone.playerCityUUID); - - if (city == null) - return null; - - MobLoot ml = null; - city.transactionLock.writeLock().lock(); - - try { - - - Warehouse cityWarehouse = city.warehouse; - - if (cityWarehouse != null && forge.assetIsProtected()) - useWarehouse = true; - - ConcurrentHashMap resources = null; - - if (useWarehouse) - resources = cityWarehouse.resources; - - int galvorAmount = 0; - int wormwoodAmount = 0; - - if (template.item_type.equals(ItemType.WEAPON) && template.item_skill_required.isEmpty() == false && - template.item_skill_required.values().iterator().next() == 110) { - switch (template.item_skill_used) { - case "Bow": - case "Crossbow": - case "Spear": - case "Pole Arm": - case "Staff": - wormwoodAmount = 22; - break; - case "Axe": - case "Dagger": - case "Sword": - case "Hammer": - case "Unarmed Combat": - - if (ItemManager.isTwoHanded(template)) - galvorAmount = 22; - else - galvorAmount = 11; - break; - } - } - - //Cant roll 110% weapons that require resources if not allowed to use warehouse. - if (galvorAmount > 0 || wormwoodAmount > 0) - if (!useWarehouse) - return null; - - if (galvorAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GALVOR)) { - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); - return null; - } - - if (cityWarehouse.resources.get(mbEnums.ResourceType.GALVOR) < galvorAmount) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); - return null; - } - } - - if (wormwoodAmount > 0) { - if (Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.WORMWOOD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); - return null; - } - - if (cityWarehouse.resources.get(mbEnums.ResourceType.WORMWOOD) < wormwoodAmount) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); - return null; - } - } - - EffectsBase prefix = null; - - if (!prefixString.isEmpty()) { - prefix = PowersManager.getEffectByIDString(prefixString); - if (prefix == null) - return null; - } - - int baseCost = template.item_value; - int total = (int) (baseCost + baseCost * .10); - - EffectsBase suffix = null; - - if (!suffixString.isEmpty()) { - suffix = PowersManager.getEffectByIDString(suffixString); - - if (suffix == null) - return null; - } - - //calculate gold costs and remove from the warehouse - if (prefix != null || suffix != null) { - int costToCreate = (int) (template.item_value + template.item_value * .10f); - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); - int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); - - if (overdraft > 0 && !useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); - return null; - } - - if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); - return null; - } - - if (useWarehouse && overdraft > resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); - return null; - } - - if (!forge.transferGold(-buildingWithdraw, false)) { - overdraft += buildingWithdraw; - - if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); - return null; - } else { - if (overdraft > resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); - return null; - } - } - } - - // there was an overdraft, withdraw the rest from warehouse. - if (overdraft > 0) { - if (pc != null) { - if (!Warehouse.withdraw(cityWarehouse, pc, mbEnums.ResourceType.GOLD, overdraft, false, true)) { - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } else { - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } - } - } - - if (prefix == null && suffix == null) { - - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); - int overdraft = BuildingManager.GetOverdraft(forge, total); - - if (overdraft > 0 && !useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); - return null; - } - - if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, mbEnums.ResourceType.GOLD)) { - if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); - return null; - } - - if (useWarehouse && overdraft > resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); - return null; - } - - if (!forge.transferGold(-buildingWithdraw, false)) { - overdraft += buildingWithdraw; - - if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); - return null; - } else { - if (overdraft > resources.get(mbEnums.ResourceType.GOLD)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); - return null; - } - } - } - - if (overdraft > 0 && useWarehouse) { - - if (pc != null) { - if (!Warehouse.withdraw(cityWarehouse, pc, mbEnums.ResourceType.GOLD, overdraft, false, true)) { - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } else { - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } - } - } - - if (galvorAmount > 0 && useWarehouse) { - //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.GALVOR, galvorAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - return null; - } - } - - if (wormwoodAmount > 0 && useWarehouse) { - //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); - if (!Warehouse.withdraw(cityWarehouse, npc, mbEnums.ResourceType.WORMWOOD, wormwoodAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + template.item_base_name); - Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); - - return null; - } - } - - ml = new MobLoot(npc, template, false); - - ml.containerType = mbEnums.ItemContainerType.FORGE; - - if (prefix != null) { - ml.addPermanentEnchantment(prefix.getIDString(), 0, 0, true); - ml.setPrefix(prefix.getIDString()); - } - - if (suffix != null) { - ml.addPermanentEnchantment(suffix.getIDString(), 0, 0, false); - ml.setSuffix(suffix.getIDString()); - } - - ml.loadEnchantments(); - - - ml.setValue(0); - ml.setRandom(true); - npc.addItemToForge(ml); - } catch (Exception e) { - Logger.error(e); - } finally { - city.transactionLock.writeLock().unlock(); - } - return ml; - - } -} diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index 58556907..6fd40f84 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -15,7 +15,6 @@ import engine.gameManager.*; import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.UpgradeNPCJob; -import engine.loot.WorkOrder; import engine.math.Bounds; import engine.math.Vector3f; import engine.math.Vector3fImmutable; @@ -24,8 +23,6 @@ import engine.mbEnums.*; import engine.net.ByteBufferWriter; import engine.net.Dispatch; import engine.net.DispatchMessage; -import engine.net.client.msg.ErrorPopupMsg; -import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.PetMsg; import engine.net.client.msg.PlaceAssetMsg; import engine.server.MBServerStatics; @@ -50,9 +47,7 @@ public class NPC extends AbstractCharacter { public static HashMap> _pirateNames = new HashMap<>(); // Used for thread safety public final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - private final ArrayList rolling = new ArrayList<>(); public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock(); - public ArrayList forgedItems = new ArrayList<>(); public int runeSetID = 0; public int extraRune2 = 0; protected int loadID; @@ -79,7 +74,6 @@ public class NPC extends AbstractCharacter { public int parentZoneUUID; public int equipmentSetID = 0; private int repairCost = 5; - public ArrayList workOrders = new ArrayList<>(); // New NPC constructor. Fill in the blanks and then call // PERSIST. @@ -915,58 +909,6 @@ public class NPC extends AbstractCharacter { this.charItemManager.equipped = loadEquipmentSet(this.equipmentSetID); - try { - - DbManager.NPCQueries.LOAD_ALL_ITEMS_TO_PRODUCE(this); - - for (ProducedItem producedItem : this.forgedItems) { - MobLoot ml = new MobLoot(this, ItemTemplate.templates.get(producedItem.getTemplateID()), false); - - DbManager.NPCQueries.UPDATE_ITEM_ID(producedItem.getID(), currentID, ml.getObjectUUID()); - - if (producedItem.isInForge()) { - - if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true); - ml.setPrefix(producedItem.getPrefix()); - } - - if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false); - ml.setSuffix(producedItem.getSuffix()); - } - - if (!producedItem.isRandom()) - ml.flags.add(ItemFlags.Identified); - - ml.loadEnchantments(); - - ml.setValue(producedItem.getValue()); - ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); - ml.containerType = mbEnums.ItemContainerType.FORGE; - this.addItemToForge(ml); - - } else { - - if (producedItem.getPrefix() != null && !producedItem.getPrefix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getPrefix(), 0, 0, true); - ml.setPrefix(producedItem.getPrefix()); - } - - if (producedItem.getSuffix() != null && !producedItem.getSuffix().isEmpty()) { - ml.addPermanentEnchantment(producedItem.getSuffix(), 0, 0, false); - ml.setSuffix(producedItem.getSuffix()); - } - - ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); - ml.containerType = mbEnums.ItemContainerType.INVENTORY; - ml.flags.add(ItemFlags.Identified); - - this.charItemManager.addItemToInventory(ml); - } - ml.setValue(producedItem.getValue()); - } - // Create NPC bounds object Bounds npcBounds = Bounds.borrow(); npcBounds.setBounds(this.getLoc()); @@ -975,9 +917,6 @@ public class NPC extends AbstractCharacter { NPCManager.applyRunesForNPC(this); this.resists.setImmuneToAll(true); - } catch (Exception e) { - Logger.error(e.getMessage()); - } } public void removeFromZone() { @@ -1008,30 +947,6 @@ public class NPC extends AbstractCharacter { this.upgradeDateTime = upgradeDateTime; } - public ArrayList getRolling() { - synchronized (rolling) { - return rolling; - } - } - - public int getRollingCount() { - synchronized (this.rolling) { - return rolling.size(); - } - } - - public void addItemToForge(MobLoot item) { - synchronized (this.rolling) { - this.rolling.add(item); - } - } - - public void removeItemFromForge(Item item) { - synchronized (this.rolling) { - this.rolling.remove(item); - } - } - @Override public Guild getGuild() { if (this.building != null) @@ -1166,109 +1081,6 @@ public class NPC extends AbstractCharacter { return 0; } - public synchronized Item produceItem(int playerID, int amount, boolean isRandom, int pToken, int sToken, String customName, int itemID) { - - Zone serverZone; - City city; - Item item = null; - - PlayerCharacter player = null; - - if (playerID != 0) - player = SessionManager.getPlayerCharacterByID(playerID); - - try { - - if (this.getRollingCount() >= this.getRank()) { - - if (player != null) - ChatManager.chatSystemInfo(player, this.getName() + " " + this.getContract().getName() + " slots are full"); - - return null; - } - - // Cannot roll items without a warehouse. - // Due to the fact fillForge references the - // warehouse and early exits. *** Refactor??? - - serverZone = this.building.getParentZone(); - - if (serverZone == null) - return null; - - city = City.GetCityFromCache(serverZone.playerCityUUID); - - if (city == null) { - - if (player != null) - ErrorPopupMsg.sendErrorMsg(player, "Could not find city."); // Production denied: This building must be protected to gain access to warehouse resources. - - return null; - } - - if (this.building == null) { - - if (player != null) - ErrorPopupMsg.sendErrorMsg(player, "Could not find building."); // Production denied: This building must be protected to gain ac - - return null; - } - - //TODO create Normal Items. - - if (amount == 0) - amount = 1; - - if (isRandom) - item = ItemFactory.randomRoll(this, player, amount, itemID); - else - item = ItemFactory.fillForge(this, player, amount, itemID, pToken, sToken, customName); - - if (item == null) - return null; - - ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, item, 8, true); - DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, 700, false, false); - - } catch (Exception e) { - Logger.error(e); - } - return item; - } - - public synchronized boolean completeItem(int itemUUID) { - - MobLoot targetItem; - - try { - targetItem = MobLoot.getFromCache(itemUUID); - - if (targetItem == null) - return false; - - if (!this.charItemManager.forgeContains(targetItem, this)) - return false; - - if (!DbManager.NPCQueries.UPDATE_ITEM_TO_INVENTORY(targetItem.getObjectUUID(), currentID)) - return false; - - targetItem.flags.add(ItemFlags.Identified); - - this.rolling.remove(targetItem); - this.charItemManager.addItemToInventory(targetItem); - - //remove from client forge window - - ItemProductionMsg outMsg1 = new ItemProductionMsg(this.building, this, targetItem, 9, true); - DispatchMessage.dispatchMsgToInterestArea(this, outMsg1, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); - ItemProductionMsg outMsg = new ItemProductionMsg(this.building, this, targetItem, 10, true); - DispatchMessage.dispatchMsgToInterestArea(this, outMsg, DispatchChannel.SECONDARY, MBServerStatics.STRUCTURE_LOAD_RANGE, false, false); - - } catch (Exception e) { - Logger.error(e.getMessage()); - } - return true; - } public int getEquipmentSetID() { return equipmentSetID; diff --git a/src/engine/objects/ProducedItem.java b/src/engine/objects/ProducedItem.java deleted file mode 100644 index e999fb44..00000000 --- a/src/engine/objects/ProducedItem.java +++ /dev/null @@ -1,225 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.objects; - -import engine.gameManager.PowersManager; -import engine.mbEnums.DispatchChannel; -import engine.net.DispatchMessage; -import engine.net.client.msg.ItemProductionMsg; -import engine.powers.EffectsBase; -import org.joda.time.DateTime; -import org.pmw.tinylog.Logger; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Date; - -public class ProducedItem { - - private int ID; - private int npcUID; - private int templateID; - private DateTime dateToUpgrade; - private boolean isRandom; - - private String prefix; - private String suffix; - private String name; - private int amount; - private int producedItemID = 0; - private boolean inForge; - private int value; - - private int playerID; - - - /** - * ResultSet Constructor - */ - - public ProducedItem(ResultSet rs) throws SQLException { - this.ID = rs.getInt("ID"); - this.npcUID = rs.getInt("npcUID"); - this.templateID = rs.getInt("templateID"); - - Date sqlDateTime = rs.getTimestamp("dateToUpgrade"); - - if (sqlDateTime != null) - this.dateToUpgrade = new DateTime(sqlDateTime); - else - dateToUpgrade = null; - this.isRandom = rs.getBoolean("isRandom"); - this.prefix = rs.getString("prefix"); - this.suffix = rs.getString("suffix"); - this.name = rs.getString("name"); - this.inForge = rs.getBoolean("inForge"); - this.value = rs.getInt("value"); - this.playerID = rs.getInt("playerID"); - } - - public ProducedItem(int ID, int npcUID, int templateID, DateTime dateToUpgrade, boolean isRandom, String prefix, String suffix, String name, int playerID) { - super(); - this.ID = ID; - this.npcUID = npcUID; - this.templateID = templateID; - this.dateToUpgrade = dateToUpgrade; - this.isRandom = isRandom; - this.prefix = prefix; - this.suffix = suffix; - this.name = name; - this.value = 0; - this.playerID = playerID; - - - } - - public int getNpcUID() { - return npcUID; - } - - public DateTime getDateToUpgrade() { - return dateToUpgrade; - } - - public int getTemplateID() { - return templateID; - } - - public void setTemplateID(int templateID) { - this.templateID = templateID; - } - - public boolean isRandom() { - return isRandom; - } - - public void setRandom(boolean isRandom) { - this.isRandom = isRandom; - } - - public String getPrefix() { - return prefix; - } - - public String getSuffix() { - return suffix; - } - - public void setSuffix(String suffix) { - this.suffix = suffix; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getID() { - return ID; - } - - public void setID(int iD) { - ID = iD; - } - - public int getAmount() { - return amount; - } - - public void setAmount(int amount) { - this.amount = amount; - } - - - public int getProducedItemID() { - return producedItemID; - } - - public void setProducedItemID(int producedItemID) { - this.producedItemID = producedItemID; - } - - public boolean isInForge() { - return inForge; - } - - public int getValue() { - return value; - } - - public void setValue(int value) { - this.value = value; - } - - public boolean finishProduction() { - NPC npc = NPC.getFromCache(this.getNpcUID()); - - if (npc == null) - return false; - - - //update the client to ID the item in the window when item finishes rolling. - //If there is more than 1 item left to roll, complete the item and throw it in inventory - //and reproduce next item. - - try { - - if (this.getAmount() > 1) { - this.setAmount(this.getAmount() - 1); - npc.completeItem(this.getProducedItemID()); - - int pToken = 0; - int sToken = 0; - - if (!this.isRandom()) { - EffectsBase eb = PowersManager.getEffectByIDString(this.getPrefix()); - if (eb != null) - pToken = eb.getToken(); - eb = PowersManager.getEffectByIDString(this.getSuffix()); - if (eb != null) - sToken = eb.getToken(); - - } - - Item item = npc.produceItem(0, this.getAmount(), this.isRandom(), pToken, sToken, this.getName(), this.getTemplateID()); - - if (item == null) - return false; - - } else { - - //update item to complete - MobLoot targetItem = MobLoot.getFromCache(this.getProducedItemID()); - - if (targetItem == null) - return false; - - ItemProductionMsg outMsg = new ItemProductionMsg(npc.getBuilding(), npc, targetItem, 8, true); - - - DispatchMessage.dispatchMsgToInterestArea(npc, outMsg, DispatchChannel.SECONDARY, 700, false, false); - } - - } catch (Exception e) { - Logger.error(e); - return false; - } - return true; - } - - public int getPlayerID() { - return playerID; - } - - -} diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 9895e271..ed45878a 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -26,7 +26,6 @@ import engine.mbEnums.SupportMsgType; import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.Threads.Respawner; import engine.net.DispatchMessage; -import engine.net.ItemProductionManager; import engine.net.Network; import engine.net.Protocol; import engine.net.client.ClientConnection; @@ -267,9 +266,6 @@ public class WorldServer { Logger.info("Setting cross server session behavior"); SessionManager.setCrossServerBehavior(1); // Sets cross server behavior - Logger.info("Starting Item Production thread"); - ItemProductionManager.ITEMPRODUCTIONMANAGER.startMessagePump(); - Logger.info("Initializing Errant Guild"); Guild.getErrantGuild(); @@ -427,8 +423,6 @@ public class WorldServer { //pick a startup Hotzone ZoneManager.generateAndSetRandomHotzone(); - ItemProductionManager.ITEMPRODUCTIONMANAGER.initialize(); - Logger.info("Loading Player Heraldries"); DbManager.PlayerCharacterQueries.LOAD_HERALDY();