public async Task <bool> Eat(IInventory <ResourceType> inventory, float amount = -1) { ActionOption <float> eatOption; lock (this) { if (amount == -1) { amount = value; } eatOption = inventory.Add(_type, amount); /* Determine if this resource will be completely consumed by this operation * If it will be, mark as completely eaten and then get rid of the gameObject when this operation completes */ if (isCompletelyEaten) { return(false); } value -= eatOption.info; if (Mathf.Abs(value) <= float.Epsilon * 10) { isCompletelyEaten = true; } currentConsumerCount++; } await Task.Delay((int)(gatherTime * 1000)); eatOption.Execute(); DestroyIfNoOtherConsumers(); return(true); }
/// <summary> /// Atualiza e remove o piso /// </summary> /// <param name="offsetX">Offset em X</param> /// <param name="offsetY">Offset em Y</param> public void UpdateAndRemoveTile(int offsetX, int offsetY) { var pos = new Vector3Int((int)Math.Floor(transform.position.x) + offsetX, (int)Math.Floor(transform.position.y) + offsetY, 0); if (Math.Floor(transform.position.y) > -5) { return; } if (Math.Floor(transform.position.y) > -7 && (pos.x < -1 || pos.x > 5)) { return; } var tile = m_World.GetTile <Oretile>(pos); if (tile == null) { return; } var item = m_GM.Items.FirstOrDefault(o => o.GetAttributeValue <int>(Motherload.Models.Attribute.ORETYPE) == (int)tile.TileType); if (item == null) { return; } m_Inventory.Add(item.UniqueID, 1); m_World.SetTile(pos, null); m_NextMining = Time.time + m_MiningInterval; }
public bool Buy(Item item, IInventory buyer) { if (buyer.Gold < item.Cost) { return(false); } if (!UnlimitedItems.Contains(item)) { Inventory.Remove(item); buyer.Add(item); } else { buyer.Add(item.Clone()); } buyer.Gold -= item.Cost; Inventory.Gold += item.Cost; return(true); }
public async Task <bool> Eat(IInventory <ResourceType> inventory, float amount = -1) { await Task.Delay((int)(gatherTime * 1000)); if (amount == -1) { amount = float.MaxValue; } var eatenInfo = inventory.Add(_type, amount); eatenInfo.Execute(); return(true); }
private static Dictionary <ResourceType, ResourceSellResult> SellAllGoods(IInventory <ResourceType> seller, IInventory <ResourceType> consumer, ResourceType[] types, Dictionary <ResourceType, float> prices) { var result = seller.DrainAllInto(consumer, types) .Select(pair => { var sellResult = new ResourceSellResult(pair.Value, prices[pair.Key]); return(new { type = pair.Key, sellResult }); }) .ToDictionary(x => x.type, x => x.sellResult); seller.Add(ResourceType.Gold, result.Values.Sum(sellResult => sellResult.totalRevenue)).Execute(); return(result); }
public virtual bool Transfer(IInventory to, Item item, int amount = 1, bool isReal = true, bool isVirutal = true) { if (!this.Remove(item, amount, isReal, isVirutal)) { return(false); } if (!to.Add(item, amount, isReal, isVirutal)) { this.Add(item, amount, isReal, isVirutal); return(false); } return(true); }
/// <summary> /// Transfer <paramref name="amount"/> of <paramref name="type"/> into <paramref name="target"/> /// </summary> /// <param name="type">the type of resource to transfer</param> /// <param name="target">the inventory to transfer into</param> /// <param name="amount">the amount to transfer</param> /// <returns>An option to execute the transfer, wrapping the amount which would be transferred</returns> public static ActionOption <float> TransferResourceInto <T>(this IInventory <T> inventory, T type, IInventory <T> target, float amount) { if (amount < 0) { return(target.TransferResourceInto(type, inventory, -amount) .Then(added => - added)); } var currentAmount = inventory.Get(type); var possibleNewAmount = inventory.SetAmount(type, currentAmount - amount).info; var idealAddAmount = currentAmount - possibleNewAmount; return(target .Add(type, idealAddAmount) .Then(addedAmount => inventory.SetAmount(type, currentAmount - addedAmount)) .Then(newAmount => currentAmount - newAmount)); }
public void PlayerInventoryCanBeAddedNSubs() { // Arrange Player player = new Player(); IInventory inventory = Substitute.For <IInventory>(); IItem item = Substitute.For <IItem>(); int itemCount = 0; player.inventory = inventory; inventory.Add(Arg.Do <IItem>(x => itemCount++)); // Act player.AddToInventory(item); player.AddToInventory(item); // Assert Assert.That(itemCount, Is.EqualTo(2)); }
protected void AddItem(T item) { inventory.Add(item); }
public void Transfer(IItem item, IInventory inventory) { Remove(item); inventory.Add(item); }
public void AddToInventory(IItem item) { Inventory.Add(item); }
public void InsertCoin(Coin coin) { currentBalance += (long)coin; coinInventory.Add(coin); }
public void ItemsCanBeAddedToInventory() { EmptyInventory.Add(TestItem); Assert.That(EmptyInventory.Has(TestItem)); }