public void AddToItemDB(PraeItem i) { if (i == null) throw new System.NullReferenceException("cannot add null to item database"); if (i.id <= 0) i.id = GetNewItemID(); itemDB.items.Add(i); }
public bool RemoveItem(PraeItem d) { return _items.Remove(d); }
/** * */ protected int AddPartial(PraeItem itemCopy) { if (itemCopy.weight + _weight > _maxWeight) { float weightDiff = itemCopy.weight + _weight - _maxWeight; int fitAmount = (int)(weightDiff / itemCopy.weightSingle); // the amount of the item that can still be added if (fitAmount > 0) { itemCopy.amount = fitAmount; _items.Add(itemCopy); _weight += itemCopy.weight; return itemCopy.amount - fitAmount; } else return itemCopy.amount; } else { // item fits completely _items.Add(itemCopy); _weight += itemCopy.weight; return 0; } }
public void Set(PraeItem item, int g, int k, int t) { _item = item; _icon = item.icon; _value.Set(g, k, t); }
/** * @item the item being added to this inventory * @stack TRUE: try to find items of the same type as 'item' and add the item by increasing * 'amount' attribute of the items found in this inventory * @addPartial TRUE: add 'item' even if it cannot fit completly in this inventory * return will be greater than 0 if item could not fit * @return the amount of 'item' that could not be fit into this inventory by having either * not enough space left or the inventory getting to heavy (weight > maxweight) */ public int AddItem(PraeItem item, bool stack = false, bool addPartial = true) { PraeItem itemCopy = new PraeItem(item); // decouple references if (stack) { if (addPartial || (itemCopy.weight + _weight <= _maxWeight)) { /* iterate all items and add 'item' until its amount is zero or weight constraint is reached */ int rest = itemCopy.amount; foreach (PraeItem i in _items) { // item names must match and stacksize not reached if (i.Equals(itemCopy) && i.amount < i.stackSize) { if (i.stackSize - i.amount > rest) { // rest amount fits i.amount += rest; return 0; } else { // i can only take some of our item rest -= (i.stackSize - i.amount); i.amount = i.stackSize; } } } if (rest > 0) { // all items in inventory checked. Add a new item, if weight constraint not violated itemCopy.amount = rest; return AddPartial(itemCopy); } else return 0; } else { // cannot fit return itemCopy.amount; } } else { // items will be added in new slot if (addPartial) { /* add as much as can still fit */ return AddPartial(itemCopy); } else { /* only add stuff if enough space and weight available */ if (itemCopy.weight + _weight > _maxWeight) return itemCopy.amount; else { // item fits completely _items.Add(itemCopy); _weight += itemCopy.weight; return 0; } } } }
public void AddItem(PraeItem item) { PraeItem itemCopy = new PraeItem(item); // decouple references /* iterate all items and add 'item' until its amount is zero or weight constraint is reached */ int rest = itemCopy.amount; foreach (PraeItem i in _items) { // item names must match and stacksize not reached if (i.Equals(itemCopy) && i.amount < i.stackSize) { if (i.stackSize - i.amount > rest) { // rest amount fits i.amount += rest; return; } else { // i can only take some of our item rest -= (i.stackSize - i.amount); i.amount = i.stackSize; } } } if (rest > 0) { // all items in inventory checked. Add a new item, if weight constraint not violated itemCopy.amount = rest; _items.Add(itemCopy); } }
/** * use the value of the item */ public void Set(PraeItem item) { if (item != null) { _item = item; _icon = item.icon; _value.Set(item.value.G, item.value.K, item.value.T, item.amount); _hasItem = true; } else { _value.SetEmpty(); _hasItem = false; } }
public void AddBoughtItem(PraeItem item) { _boughtItems.Add(item); }
public PraeItem(PraeItem copy, int newAmount) : this(copy) { _amount = newAmount; }
public PraeItem(PraeItem copy) { Set(copy); }
public virtual void Set(PraeItem it) { _id = it._id; name = it.name; desc = it.desc; _weightSingle = it._weightSingle; value = it.value; _amount = it._amount; _stackSize = it._stackSize; sellable = it.sellable; _icon = it._icon; }
public bool Equals(PraeItem i) { return name.Equals(i.name) && desc.Equals(i.desc) && _weightSingle == i._weightSingle && _stackSize == i._stackSize && value.Equals(i.value); _quest.Equals(i._quest); // TODO: icon equals? }