public static bool HasSlotFor(this Character c, AbstractItemSlot item) { return(HasSlotFor( c, (ItemInventoryType)(item.TemplateID / 1000000), item )); }
private static void WriteItemBase(this IPacketWriter p, AbstractItemSlot i) { p.WriteInt(i.TemplateID); p.WriteBool(i.CashItemSN.HasValue); if (i.CashItemSN.HasValue) { p.WriteLong(i.CashItemSN.Value); } p.WriteDateTime(i.DateExpire ?? GameConstants.Permanent); // TODO: constants }
public void Add(AbstractItemSlot item) { switch (item) { case ItemSlotBundle bundle: var template = _templates.Retrieve(bundle.TemplateID).Result as ItemBundleTemplate; // if (ItemConstants.IsRechargeableItem(bundle.TemplateID)) goto default; // TODO: rechargeable constants if (bundle.Number < 1) { bundle.Number = 1; } var mergeable = _inventory.Items.Values .OfType <ItemSlotBundle>() .Where(b => bundle.Number + b.Number <= template.MaxPerSlot) .FirstOrDefault(b => b.Equals(bundle)); if (mergeable != null) { var count = bundle.Number + mergeable.Number; var maxNumber = template.MaxPerSlot; if (count > maxNumber) { var leftover = count - maxNumber; bundle.Number = (short)leftover; mergeable.Number = maxNumber; UpdateQuantity(mergeable); Add(bundle); return; } mergeable.Number += bundle.Number; UpdateQuantity(mergeable); return; } goto default; default: var slot = Enumerable.Range(1, _inventory.SlotMax) .Select(i => (short)i) .Except(_inventory.Items.Keys) .First(i => i > 0); Set(slot, item); break; } }
public static void WriteItemData(this IPacketWriter p, AbstractItemSlot i) { switch (i) { case ItemSlotEquip equip: p.WriteItemEquipData(equip); break; case ItemSlotBundle bundle: p.WriteItemBundleData(bundle); break; case ItemSlotPet pet: p.WriteItemPetData(pet); break; } }
public void Remove(AbstractItemSlot item, short count) { if (item is ItemSlotBundle bundle) // TODO: recharageable { if (count > 0) { bundle.Number -= count; bundle.Number = Math.Max((short)0, bundle.Number); if (bundle.Number > 0) { UpdateQuantity(bundle); return; } } } Remove(item); }
public static bool HasSlotFor(this Character c, ItemInventoryType type, AbstractItemSlot item) => AvailableSlotsFor(c, type) > 0;
public void Update(AbstractItemSlot item) => Update(_inventory.Items.First(i => i.Value == item).Key);
public void Remove(AbstractItemSlot item) => Remove(_inventory.Items.First(i => i.Value == item).Key);
public void Set(short slot, AbstractItemSlot item) { _inventory.Items[slot] = item; _history.Enqueue(new AddModifyInventoryOperation(_type, slot, item)); }
public void Update(AbstractItemSlot item) => this[(ItemInventoryType)(item.TemplateID / 1_000_000)].Update(item);
public void Remove(AbstractItemSlot item, short count) => this[(ItemInventoryType)(item.TemplateID / 1_000_000)].Remove(item, count);
public ItemLockerSlot(AbstractItemSlot item) { Item = item; }