public bool HasSlotsFreeForItem(int itemid, short amount, bool stackable) { short slotsRequired = 0; byte inventory = Constants.getInventory(itemid); if (!Constants.isStackable(itemid) && !Constants.isStar(itemid)) { slotsRequired = amount; } else if (Constants.isStar(itemid)) { slotsRequired = 1; } else { short maxPerSlot = (short)DataProvider.Items[itemid].MaxSlot; if (maxPerSlot == 0) { maxPerSlot = 100; // default 100 O.o >_> } short amountAlready = (short)(ItemAmounts.ContainsKey(itemid) ? ItemAmounts[itemid] : 0); if (stackable && amountAlready > 0) { // We should try to see which slots we can fill, and determine how much new slots are left short amountLeft = amount; byte inv = Constants.getInventory(itemid); inv -= 1; foreach (var item in Items[inv].ToList().FindAll(x => x != null && x.ItemID == itemid && x.Amount < maxPerSlot)) { amountLeft -= (short)(maxPerSlot - item.Amount); // Substract the amount of 'slots' left for this slot if (amountLeft <= 0) { amountLeft = 0; break; } } // Okay, so we need to figure out where to keep these stackable items. // Apparently we've got space left on slots if (amountLeft == 0) { return(true); } // Hmm, still need to get more slots amount = amountLeft; } slotsRequired = (short)(amount / maxPerSlot); // Leftover slots to handle if ((amount % maxPerSlot) > 0) { slotsRequired++; } } return(GetOpenSlotsInInventory(inventory) >= slotsRequired); }
private ModificationInvoice CreateModificationInvoice(InvoiceNumber originalDocumentNumber, Receiver receiver) { var nowUtc = DateTime.UtcNow.Date; var item1Amount = new Amount(net: new AmountValue(-1694.92m), gross: new AmountValue(-2000), tax: new AmountValue(-305.08m)); var item2Amount = new Amount(new AmountValue(-2362.20m), new AmountValue(-3000), new AmountValue(-637.8m)); var item3Amount = new Amount(new AmountValue(-952.38m), new AmountValue(-1000), new AmountValue(-47.62m)); var unitAmount1 = new ItemAmounts(item1Amount, item1Amount, 0.18m); var unitAmount2 = new ItemAmounts(item2Amount, item2Amount, 0.27m); var unitAmount3 = new ItemAmounts(item3Amount, item3Amount, 0.05m); var items = new[] { new InvoiceItem( consumptionDate: nowUtc, totalAmounts: new ItemAmounts(item1Amount, item1Amount, 0.18m), description: Description.Create("Item 1 description").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: -1, unitAmounts: unitAmount1, exchangeRate: ExchangeRate.Create(1).Success.Get() ), new InvoiceItem( consumptionDate: nowUtc, totalAmounts: new ItemAmounts(item2Amount, item2Amount, 0.27m), description: Description.Create("Item 2 description").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: -1, unitAmounts: unitAmount2, exchangeRate: ExchangeRate.Create(1).Success.Get() ), new InvoiceItem( consumptionDate: nowUtc, totalAmounts: new ItemAmounts(item3Amount, item3Amount, 0.05m), description: Description.Create("Item 3 description").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: -1, unitAmounts: unitAmount3, exchangeRate: ExchangeRate.Create(1).Success.Get() ) }; return(new ModificationInvoice( number: InvoiceNumber.Create($"REBATE-{Guid.NewGuid()}").Success.Get(), supplierInfo: CreateSupplierInfo(), receiver: receiver, items: Sequence.FromPreordered(items, startIndex: 1).Get(), currencyCode: CurrencyCode.Create("EUR").Success.Get(), issueDate: nowUtc, paymentDate: nowUtc, itemIndexOffset: 3, modificationIndex: 1, modifyWithoutMaster: false, originalDocumentNumber: originalDocumentNumber, paymentMethod: PaymentMethod.Cash )); }
public virtual void AddItem(byte inventory, short slot, BaseItem item, bool isLoading) { if (slot == 0) { // Would bug the client, so ignore Trace.WriteLine($"Ignoring item {item.ItemID} because its in the wrong slot (0)"); return; } int itemid = item.ItemID; if (Constants.getInventory(itemid) != inventory) { Trace.WriteLine($"Ignoring item {item.ItemID} because its in the wrong inventory ({inventory} vs {Constants.getInventory(itemid)})"); return; } item.InventorySlot = slot; short amount; if (!ItemAmounts.TryGetValue(itemid, out amount)) { amount = 0; } amount += item.Amount; ItemAmounts[itemid] = amount; if (slot < 0) { if (item is EquipItem equipItem) { slot = Math.Abs(slot); if (slot > 100) { Equips[1][(byte)(slot - 100)] = equipItem; } else { Equips[0][(byte)slot] = equipItem; } } else { throw new Exception("Tried to AddItem on an equip slot but its not an equip! " + item); } } else { Items[inventory - 1][slot] = item; } }
private Invoice CreateInvoice(Receiver receiver, InvoiceNumber invoiceNumber = null) { var nowUtc = DateTime.UtcNow.Date; var item1Amount = new Amount(net: new AmountValue(1694.92m), gross: new AmountValue(2000), tax: new AmountValue(305.08m)); var item2Amount = new Amount(new AmountValue(2362.20m), new AmountValue(3000), new AmountValue(637.8m)); var item3Amount = new Amount(new AmountValue(952.38m), new AmountValue(1000), new AmountValue(47.62m)); var unitAmount1 = new ItemAmounts(item1Amount, item1Amount, 0.18m); var unitAmount2 = new ItemAmounts(item2Amount, item2Amount, 0.27m); var unitAmount3 = new ItemAmounts(item3Amount, item3Amount, 0.05m); var items = new[] { new InvoiceItem( consumptionDate: nowUtc, totalAmounts: new ItemAmounts(item1Amount, item1Amount, 0.18m), description: Description.Create("Item 1 description").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: 1, unitAmounts: unitAmount1, exchangeRate: ExchangeRate.Create(1).Success.Get() ), new InvoiceItem( consumptionDate: nowUtc, totalAmounts: new ItemAmounts(item2Amount, item2Amount, 0.27m), description: Description.Create("Item 2 description").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: 1, unitAmounts: unitAmount2, exchangeRate: ExchangeRate.Create(1).Success.Get() ), new InvoiceItem( consumptionDate: nowUtc, totalAmounts: new ItemAmounts(item3Amount, item3Amount, 0.05m), description: Description.Create("Item 3 description").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: 1, unitAmounts: unitAmount3, exchangeRate: ExchangeRate.Create(1).Success.Get() ) }; return(new Invoice( number: invoiceNumber ?? InvoiceNumber.Create($"INVOICE-{Guid.NewGuid()}").Success.Get(), issueDate: nowUtc, supplierInfo: CreateSupplierInfo(), receiver: receiver, items: Sequence.FromPreordered(items, startIndex: 1).Get(), paymentDate: nowUtc, currencyCode: CurrencyCode.Create("EUR").Success.Get(), paymentMethod: PaymentMethod.Card )); }
public virtual void RemoveItem(BaseItem item) { var inventory = Constants.getInventory(item.ItemID); var slot = item.InventorySlot; int itemid = item.ItemID; if (slot == 0) { // Would bug the client, so ignore Trace.WriteLine($"Ignoring item {itemid} because its in the wrong slot (0)"); return; } if (ItemAmounts.TryGetValue(itemid, out var amount)) { if (amount - item.Amount <= 0) { ItemAmounts.Remove(itemid); } else { ItemAmounts[itemid] -= item.Amount; } } if (slot < 0) { if (item is EquipItem) { slot = Math.Abs(slot); if (slot > 100) { Equips[1][(byte)(slot - 100)] = null; } else { Equips[0][(byte)slot] = null; } } else { throw new Exception("Tried to RemoveItem on an equip slot but its not an equip! " + item); } } else { Items[inventory - 1][slot] = null; } }
private Invoice GetInvoice() { var item1Amount = new Amount(new AmountValue(1), new AmountValue(1), new AmountValue(0)); var item2Amount = new Amount(new AmountValue(20m), new AmountValue(16.81m), new AmountValue(3.19m)); var unitAmount1 = new ItemAmounts(item1Amount, item2Amount, 0.05m); var items = new[] { new InvoiceItem( consumptionDate: new DateTime(2020, 06, 30), totalAmounts: new ItemAmounts(item1Amount, item1Amount, 0.05m), description: Description.Create("Httt hzi serts (fl)").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: 15, unitAmounts: unitAmount1, exchangeRate: ExchangeRate.Create(1).Success.Get() ), new InvoiceItem( consumptionDate: new DateTime(2020, 06, 30), totalAmounts: new ItemAmounts(item2Amount, item2Amount, 0.05m), description: Description.Create("Httt hzi serts (fl)").Success.Get(), measurementUnit: MeasurementUnit.Night, quantity: -15, unitAmounts: unitAmount1, exchangeRate: ExchangeRate.Create(1).Success.Get() ), }; var address = GetAddress(); return(new Invoice( number: InvoiceNumber.Create("ABC-18a").Success.Get(), issueDate: new DateTime(2020, 06, 30), supplierInfo: GetSupplierInfo(), customerInfo: GetCustomerInfo(), items: Sequence.FromPreordered(items, startIndex: 1).Get(), paymentDate: new DateTime(2020, 06, 14), currencyCode: CurrencyCode.Create("EUR").Success.Get() )); }