public ModifyInventoryContext(ItemInventory inventory) { _type = ItemInventoryType.Equip; _inventory = inventory; Operations = new Queue <AbstractModifyInventoryOperation>(); }
public AbstractModifyInventoryOperation( ItemInventoryType inventory, short slot) { Inventory = inventory; Slot = slot; }
public UpdateQuantityInventoryOperation( ItemInventoryType inventory, short slot, short quantity ) : base(inventory, slot) { _quantity = quantity; }
public MoveInventoryOperation( ItemInventoryType inventory, short slot, short toSlot ) : base(inventory, slot) { ToSlot = toSlot; }
public UpdateEXPInventoryOperation( ItemInventoryType inventory, short slot, int exp ) : base(inventory, slot) { _exp = exp; }
public RemoveModifyInventoryOperation( ItemInventoryType type, short slot ) { Type = type; Slot = slot; }
public AddInventoryOperation( ItemInventoryType inventory, short slot, ItemSlot item ) : base(inventory, slot) { _item = item; }
// TODO: exception throwing for various inventory operations public ModifyInventoryContext( ItemInventoryType type, ItemInventory inventory, ITemplateRepository <ItemTemplate> templates ) { _history = new Queue <AbstractModifyInventoryOperation>(); _type = type; _inventory = inventory; _templates = templates; }
public static int GetItemCount(this Character c, ItemInventoryType type, int templateID) { var inventory = c.GetInventory(type); return(inventory.Items .Select(i => { if (i is ItemSlotBundle bundle) { return bundle.Number; } return 1; }) .Sum()); }
public static bool HasSlotFor(this Character c, ItemInventoryType type, ItemSlot item) { var inventory = c.GetInventory(type); var usedSlots = inventory.Items .Select <ItemSlot, int>(i => i.Position) .Where(s => s > 0) .Where(s => s <= inventory.SlotMax) .ToList(); var unusedSlots = Enumerable.Range(1, inventory.SlotMax) .Except(usedSlots) .ToList(); return(unusedSlots.Count != 0); }
public static int AvailableSlotsFor(this Character c, ItemInventoryType type) { var inventory = c.Inventories[type]; var usedSlots = inventory.Items .Select(kv => (int)kv.Key) .Where(s => s > 0) .Where(s => s <= inventory.SlotMax) .ToList(); var unusedSlots = Enumerable.Range(1, inventory.SlotMax) .Except(usedSlots) .ToList(); return(unusedSlots.Count); }
public static int GetItemCount(this Character c, ItemInventoryType type, int templateID) { var inventory = c.Inventories[type]; return(inventory.Items .Select(kv => kv.Value) .Where(i => i.TemplateID == templateID) .Select(i => { if (i is ItemSlotBundle bundle) { return bundle.Number; } return 1; }) .Sum()); }
public async Task <TrunkResult> Get(ItemInventoryType type, short position) { var item = _trunk.Items.Values .Where(i => (ItemInventoryType)(i.TemplateID / 1000000) == type) .ToList()[position]; if (!User.Character.HasSlotFor(item)) { return(TrunkResult.GetHavingOnlyItem); } if (User.Character.Money < _template.TrunkGet) { return(TrunkResult.GetNoMoney); } await User.ModifyStats(s => s.Money -= _template.TrunkGet); await User.ModifyInventory(i => i.Add(item)); new ModifyInventoryContext(_trunk).Remove(item); return(TrunkResult.GetSuccess); }
public static bool HasItem(this Character c, ItemInventoryType type, int templateID) { return(GetItemCount(c, type, templateID) > 0); }
public void SetInventoryLimit(ItemInventoryType type, byte slotMax) => _fieldUser.ModifyInventoryLimit(type, slotMax).Wait();
public static bool HasSlotFor(this Character c, ItemInventoryType type, AbstractItemSlot item) => AvailableSlotsFor(c, type) > 0;
public byte GetInventoryLimit(ItemInventoryType type) => (byte)_fieldUser.Character.Inventories[type].SlotMax;
public InventoryMoveOperation(ItemInventoryType inventory, short slot, short newSlot) : base(InventoryOperationType.Move, inventory, slot) { _newSlot = newSlot; }
public ItemInventory(ItemInventoryType type, byte slotMax) { Type = type; SlotMax = slotMax; Items = new List <ItemSlot>(); }
public RemoveInventoryOperation( ItemInventoryType inventory, short slot ) : base(inventory, slot) { }
public ItemInventory GetInventory(ItemInventoryType type) => Inventories.Single(i => i.Type == type);
public int SlotCount(ItemInventoryType inventory) => _fieldUser.Character.AvailableSlotsFor(inventory);
public ItemInventory(ItemInventoryType type, byte slotMax) { Type = type; SlotMax = slotMax; }
public IModifyInventoryContext this[ItemInventoryType key] => _contexts[key];
public InventoryOperation(InventoryOperationType type, ItemInventoryType inventory, short slot) { Type = type; Inventory = inventory; Slot = slot; }
public ItemInventory GetInventory(ItemInventoryType type) { return(Inventories.Single(i => i.Type == type)); }
public void Add(ItemInventoryType type, ItemSlot item) { var inventory = _character.GetInventory(type); switch (item) { case ItemSlotBundle bundle: if (ItemInfo.IsRechargeableItem(bundle.TemplateID)) { goto default; } if (bundle.Number < 1) { bundle.Number = 1; } if (bundle.MaxNumber < 1) { bundle.MaxNumber = 1; } var mergeableSlots = inventory.Items .OfType <ItemSlotBundle>() .Where(b => b.TemplateID == bundle.TemplateID) .Where(b => b.DateExpire == bundle.DateExpire) .Where(b => b.Attribute == bundle.Attribute) .Where(b => b.Title == bundle.Title) .Where(b => b.Number != b.MaxNumber) .Where(b => b.Position > 0) .Where(b => b.Position <= inventory.SlotMax) .ToList(); if (mergeableSlots.Count > 0) { var existingBundle = mergeableSlots.First(); var count = bundle.Number + existingBundle.Number; var maxNumber = existingBundle.MaxNumber; if (count > maxNumber) { var leftover = count - maxNumber; bundle.Number = (short)leftover; existingBundle.Number = maxNumber; UpdateQuantity(existingBundle); Add(bundle); return; } existingBundle.Number += bundle.Number; UpdateQuantity(existingBundle); return; } goto default; default: var usedSlots = inventory.Items .Select <ItemSlot, int>(i => i.Position) .Where(s => s > 0) .Where(s => s <= inventory.SlotMax) .ToList(); var unusedSlots = Enumerable.Range(1, inventory.SlotMax) .Except(usedSlots) .ToList(); if (unusedSlots.Count == 0) { throw new InventoryFullException(); } Set(type, item, (short)unusedSlots.First()); break; } }
public InventoryAddOperation(ItemInventoryType inventory, ItemSlot item) : base(InventoryOperationType.Add, inventory, item.Position) { _item = item; }
public AbstractInventoryOperation(ItemInventoryType inventory, short slot) { _inventory = inventory; _slot = slot; }
public InventoryUpdateEXPOperation(ItemInventoryType inventory, short slot, int EXP) : base(InventoryOperationType.UpdateEXP, inventory, slot) { _exp = EXP; }