Gruppe22.Backend.Actor.AddItem C# (CSharp) Метод

AddItem() публичный Метод

Add new item to inventory
public AddItem ( Item item ) : void
item Item The item to add to inventory
Результат void
        public void AddItem(Item item)
        {
            _newItems += 1;
            int max = 0;
            for (int i = 0; i < _inventory.Count; ++i)
            {
                if (_inventory[i].id > max)
                {
                    max = _inventory[i].id;
                }
            }
            item.id = max + 1;
            item.owner = this;
            item.tile = null;
            item.isNew = true;
            _inventory.Add(item);
        }

Usage Example

Пример #1
0
 /// <summary>
 /// Method called when an actor picks up an item from the ground.
 /// Replaces the old owner and deletes the itemtile from the map
 /// </summary>
 /// <param name="actor">The actor which gains the item</param>
 public void Pickup(Actor actor)
 {
     if (_owner != null)
     {
         _owner.inventory.Remove(this);
     }
     _owner = actor;
     int temp = 0;
     if (_itemType != Backend.ItemType.Gold)
     {
         for (int i = 0; i < actor.inventory.Count; ++i)
         {
             temp = Math.Max(id, actor.inventory[i].id);
         }
         _id = temp + 1;
         actor.AddItem(this);
     }
     else
     {
         actor.gold += _value;
     }
     _tile = null;
 }