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

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

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

Loading…
Cancel
Save