diff --git a/Assets/Scripts/Models/Inventory/Inventory.cs b/Assets/Scripts/Models/Inventory/Inventory.cs index 122df2f33..9a05c73fb 100644 --- a/Assets/Scripts/Models/Inventory/Inventory.cs +++ b/Assets/Scripts/Models/Inventory/Inventory.cs @@ -18,6 +18,7 @@ public class Inventory : ISelectable, IContextActionProvider { private int stackSize = 1; + private DateTime claim; public Inventory() { @@ -81,6 +82,29 @@ public Inventory Clone() return new Inventory(this); } + public bool Claim() + { + // FIXME: The various Claim related functions should most likely track claim time in an in game time increment. + DateTime requestTime = DateTime.Now; + if ((requestTime - claim).TotalSeconds > 5) + { + claim = requestTime; + return true; + } + + return false; + } + + public void ReleaseClaim() + { + claim = new DateTime(); + } + + public bool CanClaim() + { + return (DateTime.Now - claim).TotalSeconds > 5; + } + public string GetName() { return Type; @@ -152,7 +176,7 @@ public IEnumerable GetContextMenuActions(ContextMenu contextM public bool CanBePickedUp(bool canTakeFromStockpile) { // You can't pick up stuff that isn't on a tile or if it's locked - if (Tile == null || Locked) + if (Tile == null || Locked || !CanClaim()) { return false; } diff --git a/Assets/Scripts/Models/Inventory/InventoryManager.cs b/Assets/Scripts/Models/Inventory/InventoryManager.cs index e241b3be1..f3bf06ed5 100644 --- a/Assets/Scripts/Models/Inventory/InventoryManager.cs +++ b/Assets/Scripts/Models/Inventory/InventoryManager.cs @@ -173,7 +173,7 @@ public bool PlaceInventory(Job job, Character character) public bool PlaceInventory(Character character, Inventory sourceInventory, int amount = -1) { amount = amount < 0 ? sourceInventory.StackSize : Math.Min(amount, sourceInventory.StackSize); - + sourceInventory.ReleaseClaim(); if (character.inventory == null) { character.inventory = sourceInventory.Clone(); diff --git a/Assets/Scripts/State/HaulState.cs b/Assets/Scripts/State/HaulState.cs index bb85a07c2..d12efe7ba 100644 --- a/Assets/Scripts/State/HaulState.cs +++ b/Assets/Scripts/State/HaulState.cs @@ -56,6 +56,7 @@ public override void Update(float deltaTime) path = World.Current.InventoryManager.GetPathToClosestInventoryOfType(inventoryTypes, character.CurrTile, Job.canTakeFromStockpile); if (path != null && path.Count > 0) { + path.Last().Inventory.Claim(); character.SetState(new MoveState(character, Pathfinder.GoalTileEvaluator(path.Last(), false), path, this)); } else if (character.inventory == null)