Browse Source

junk, complete and produce wrapped with same lock as warehouse.

combat-2
MagicBot 8 months ago
parent
commit
364fb40e0b
  1. 16
      src/engine/gameManager/ForgeManager.java
  2. 36
      src/engine/net/client/handlers/ItemProductionMsgHandler.java

16
src/engine/gameManager/ForgeManager.java

@ -14,10 +14,7 @@ import engine.loot.WorkOrder;
import engine.mbEnums; import engine.mbEnums;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.ItemProductionMsg;
import engine.objects.Item; import engine.objects.*;
import engine.objects.ItemTemplate;
import engine.objects.NPC;
import engine.objects.Warehouse;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -108,6 +105,10 @@ public enum ForgeManager implements Runnable {
if (validation_result != 0) if (validation_result != 0)
return validation_result; return validation_result;
City city = workOrder.vendor.building.getCity();
city.transactionLock.writeLock().lock();
try {
// Configure this production run. // Configure this production run.
workOrder.workOrderID = wordOrderCounter.incrementAndGet(); workOrder.workOrderID = wordOrderCounter.incrementAndGet();
@ -137,8 +138,11 @@ public enum ForgeManager implements Runnable {
forge.add(workOrder); forge.add(workOrder);
Logger.info(workOrder.toString()); } catch (Exception e) {
Logger.error(e);
} finally {
city.transactionLock.writeLock().unlock();
}
return validation_result; return validation_result;
} }

36
src/engine/net/client/handlers/ItemProductionMsgHandler.java

@ -24,10 +24,7 @@ import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.ErrorPopupMsg;
import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.ItemProductionMsg;
import engine.net.client.msg.ManageNPCMsg; import engine.net.client.msg.ManageNPCMsg;
import engine.objects.CharacterItemManager; import engine.objects.*;
import engine.objects.Item;
import engine.objects.NPC;
import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.HashMap; import java.util.HashMap;
@ -132,6 +129,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
Item virtualItem = Item.getFromCache(itemUUID); Item virtualItem = Item.getFromCache(itemUUID);
WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(virtualItem); WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(virtualItem);
City city = workOrder.vendor.building.getCity();
city.transactionLock.writeLock().lock();
try {
// Refresh the window. SetPrice is used only to force a window refresh. // Refresh the window. SetPrice is used only to force a window refresh.
// What controls items displayed are the contents of the workOrders. (ManageNPCMsg) // What controls items displayed are the contents of the workOrders. (ManageNPCMsg)
@ -170,6 +172,11 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
ItemProductionMsg outMsg2 = new ItemProductionMsg(vendor.building, vendor, completedItem, mbEnums.ProductionActionType.CONFIRM_DEPOSIT, true); ItemProductionMsg outMsg2 = new ItemProductionMsg(vendor.building, vendor, completedItem, mbEnums.ProductionActionType.CONFIRM_DEPOSIT, true);
DispatchMessage.dispatchMsgToInterestArea(vendor, outMsg2, mbEnums.DispatchChannel.SECONDARY, 700, false, false); DispatchMessage.dispatchMsgToInterestArea(vendor, outMsg2, mbEnums.DispatchChannel.SECONDARY, 700, false, false);
} catch (Exception e) {
Logger.error(e);
} finally {
city.transactionLock.writeLock().unlock();
}
} }
private static void setItemPrice(int itemUUID, int itemPrice, NPC vendor, ClientConnection origin) { private static void setItemPrice(int itemUUID, int itemPrice, NPC vendor, ClientConnection origin) {
@ -312,7 +319,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
if (!vendor.charItemManager.doesCharOwnThisItem(targetItem.getObjectUUID())) if (!vendor.charItemManager.doesCharOwnThisItem(targetItem.getObjectUUID()))
continue; continue;
if (vendor.charItemManager.inventoryContains(targetItem) == false) if (!vendor.charItemManager.inventoryContains(targetItem))
continue; continue;
itemValue = targetItem.template.item_value; itemValue = targetItem.template.item_value;
@ -361,10 +368,6 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
ManageNPCMsg outMsg; ManageNPCMsg outMsg;
Dispatch dispatch; Dispatch dispatch;
if (origin.sellLock.tryLock()) {
try {
targetItem = Item.getFromCache(itemUUID); targetItem = Item.getFromCache(itemUUID);
PlayerCharacter player = origin.getPlayerCharacter(); PlayerCharacter player = origin.getPlayerCharacter();
@ -383,6 +386,12 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
return; return;
WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(targetItem); WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(targetItem);
City city = workOrder.vendor.building.getCity();
city.transactionLock.writeLock().lock();
try {
workOrder.cooking.remove(targetItem); workOrder.cooking.remove(targetItem);
DbManager.removeFromCache(targetItem); DbManager.removeFromCache(targetItem);
@ -400,9 +409,10 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
outMsg.setMessageType(1); outMsg.setMessageType(1);
dispatch = Dispatch.borrow(player, outMsg); dispatch = Dispatch.borrow(player, outMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, mbEnums.DispatchChannel.SECONDARY);
} catch (Exception e) {
Logger.error(e);
} finally { } finally {
origin.sellLock.unlock(); city.transactionLock.writeLock().unlock();
}
} }
} }
@ -425,10 +435,10 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
if (targetItem.template.item_type.equals(ItemType.GOLD)) if (targetItem.template.item_type.equals(ItemType.GOLD))
return; return;
if (vendor.charItemManager.inventoryContains(targetItem) == false) if (!vendor.charItemManager.inventoryContains(targetItem))
return; return;
if (player.charItemManager.hasRoomInventory(targetItem.template.item_wt) == false) if (!player.charItemManager.hasRoomInventory(targetItem.template.item_wt))
return; return;
player.charItemManager.buyFromNPC(targetItem, vendor); player.charItemManager.buyFromNPC(targetItem, vendor);

Loading…
Cancel
Save