public override SpellFailedReason InitializeTarget(WorldObject target) { var templId = Effect.ItemId; templ = ItemMgr.GetTemplate(templId); amount = CalcEffectValue(); if (templ == null) { log.Warn("Spell {0} referred to invalid Item {1}", Effect.Spell, templId); return(SpellFailedReason.ItemNotFound); } // find a free slot // TODO: Add & use HoldFreeSlotCheck instead, so slot won't get occupied InventoryError error; slotId = ((Character)target).Inventory.FindFreeSlotCheck(templ, amount, out error); if (error != InventoryError.OK) { ItemHandler.SendInventoryError((Character)target, error); return(SpellFailedReason.DontReport); } return(SpellFailedReason.Ok); }
private void TransferItems(IList <SimpleSlotId> simpleSlots, Item[] items) { int index1 = 0; for (int index2 = 0; index2 < items.Length; ++index2) { Item obj = items[index2]; if (obj != null) { SimpleSlotId simpleSlot = simpleSlots[index1]; int amount = obj.Amount; simpleSlot.Container.Distribute(obj.Template, ref amount); if (amount < obj.Amount) { obj.Remove(true); obj.Amount -= amount; simpleSlot.Container.AddUnchecked(simpleSlot.Slot, obj, true); } else { obj.Destroy(); } ++index1; } } }
public bool Unequip() { PlayerInventory inventory = m_owner.Inventory; SimpleSlotId freeSlot = inventory.FindFreeSlot(this, Amount); if (freeSlot.Slot == byte.MaxValue) { return(false); } inventory.SwapUnchecked(m_container, Slot, freeSlot.Container, freeSlot.Slot); return(true); }