Skip to content

Commit

Permalink
[Small] Claim inventory (#1671)
Browse files Browse the repository at this point in the history
* Claim Inventory

* Rest of Commit

* Stylecop

* Remove excess commands
  • Loading branch information
koosemose authored Dec 12, 2016
1 parent bd006a7 commit 50b7b5d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
26 changes: 25 additions & 1 deletion Assets/Scripts/Models/Inventory/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class Inventory : ISelectable, IContextActionProvider
{
private int stackSize = 1;
private DateTime claim;

public Inventory()
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -152,7 +176,7 @@ public IEnumerable<ContextMenuAction> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Models/Inventory/InventoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/State/HaulState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 50b7b5d

Please sign in to comment.