예제 #1
0
    private void UpdateWallet()
    {
        switch (Type)
        {
        case CurrencyType.Meso:
            Session.Send(MesosPacket.UpdateMesos(Amount));
            break;

        case CurrencyType.Meret:
        case CurrencyType.GameMeret:
        case CurrencyType.EventMeret:
            Session.Send(MeretsPacket.UpdateMerets(Session.Player.Account));
            break;

        case CurrencyType.ValorToken:
        case CurrencyType.Treva:
        case CurrencyType.Rue:
        case CurrencyType.HaviFruit:
        case CurrencyType.MesoToken:
            Session.Send(WalletPacket.UpdateWallet(Type, Amount));
            break;

        case CurrencyType.BankMesos:
            Session.Send(StorageInventoryPacket.UpdateMesos(Amount));
            break;
        }
    }
예제 #2
0
        public bool Remove(GameSession session, long uid, short slot, int amount, out Item outItem)
        {
            outItem = null;
            if (session.Player.Inventory.Items.ContainsKey(slot))
            {
                return(false);
            }

            int outItemIndex = Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == uid);

            outItem = Items[outItemIndex];
            if (amount >= outItem.Amount)
            {
                Items[outItemIndex] = null;
                session.Send(StorageInventoryPacket.Remove(uid));
                return(true);
            }

            if (outItem.TrySplit(amount, out Item splitItem))
            {
                outItem.Amount -= amount;
                outItem.Slot    = slot;
                session.Send(StorageInventoryPacket.Add(outItem));
                outItem = splitItem;
                return(true);
            }
            return(false);
        }
예제 #3
0
    public bool Remove(GameSession session, long uid, int amount, out Item outItem)
    {
        outItem = null;
        if (!session.Player.Account.BankInventory.Items.Any(x => x is not null && x.Uid == uid))
        {
            return(false);
        }

        int outItemIndex = Array.FindIndex(Items, 0, Items.Length, x => x is not null && x.Uid == uid);

        outItem = Items[outItemIndex];

        if (ItemMetadataStorage.IsTradeDisabledWithinAccount(outItem.Id) && outItem.IsBound() && !outItem.IsSelfBound(session.Player.CharacterId))
        {
            return(false);
        }

        if (amount >= outItem.Amount)
        {
            Items[outItemIndex] = null;
            session.Send(StorageInventoryPacket.Remove(uid));
            return(true);
        }

        if (outItem.TrySplit(amount, out Item splitItem))
        {
            session.Send(StorageInventoryPacket.UpdateItem(outItem));

            outItem = splitItem;
            return(true);
        }

        return(false);
    }
예제 #4
0
    public bool Remove(GameSession session, long uid, int amount, out Item outItem)
    {
        outItem = null;
        if (!session.Player.Account.BankInventory.Items.Any(x => x is not null && x.Uid == uid))
        {
            return(false);
        }

        int outItemIndex = Array.FindIndex(Items, 0, Items.Length, x => x is not null && x.Uid == uid);

        outItem = Items[outItemIndex];
        if (amount >= outItem.Amount)
        {
            Items[outItemIndex] = null;
            session.Send(StorageInventoryPacket.Remove(uid));
            return(true);
        }

        if (outItem.TrySplit(amount, out Item splitItem))
        {
            session.Send(StorageInventoryPacket.UpdateItem(outItem));

            outItem = splitItem;
            return(true);
        }

        return(false);
    }
예제 #5
0
 public void LoadBank(GameSession session)
 {
     session.Send(StorageInventoryPacket.Update());
     session.Send(StorageInventoryPacket.Expand(ExtraSize));
     session.Send(StorageInventoryPacket.ExpandAnim());
     session.Send(StorageInventoryPacket.UpdateMesos(Mesos.Amount));
     LoadItems(session);
 }
예제 #6
0
    public void Add(GameSession session, long uid, int amount, short slot)
    {
        Item item = session.Player.Inventory.GetByUid(uid);

        if (amount < item.Amount)
        {
            item.TrySplit(amount, out Item splitItem);
            session.Send(ItemInventoryPacket.UpdateAmount(uid, item.Amount));
            item = splitItem;
        }
        else
        {
            session.Player.Inventory.RemoveItem(session, uid, out Item removedItem);
            item = removedItem;
        }

        // If slot is free, add item to it
        if (Items[slot] is null)
        {
            item.Slot   = slot;
            Items[slot] = item;
            session.Send(StorageInventoryPacket.Add(item));
            return;
        }

        // Find first item with the same id, if true update the amount
        Item existingItem = Items.FirstOrDefault(x => x is not null && x.Id == item.Id && x.Rarity == item.Rarity);

        if (existingItem is not null)
        {
            if (existingItem.Amount + item.Amount <= existingItem.StackLimit)
            {
                existingItem.Amount += item.Amount;
                session.Send(StorageInventoryPacket.UpdateItem(existingItem));
                return;
            }

            existingItem.Amount = existingItem.StackLimit;
            item.Amount         = existingItem.Amount + item.Amount - existingItem.StackLimit;
            session.Send(StorageInventoryPacket.UpdateItem(existingItem));
        }

        // Find first free slot
        for (short i = 0; i < Items.Length; i++)
        {
            if (Items[i] is not null)
            {
                continue;
            }

            item.Slot = i;
            Items[i]  = item;
            session.Send(StorageInventoryPacket.Add(item));
            return;
        }
    }
예제 #7
0
        public void Sort(GameSession session)
        {
            List <Item> tempItems = Items.Where(x => x != null).ToList();

            tempItems.Sort((x, y) => x.Id.CompareTo(y.Id));
            Items = new Item[DEFAULT_SIZE + ExtraSize];
            for (int i = 0; i < tempItems.Count; i++)
            {
                Items[i] = tempItems[i];
            }
            session.Send(StorageInventoryPacket.Sort(Items));
        }
예제 #8
0
        public void Expand(GameSession session)
        {
            long meretPrice      = 330;
            int  expansionAmount = 6;

            if (!session.Player.Account.RemoveMerets(meretPrice))
            {
                return;
            }
            ExtraSize += expansionAmount;
            session.Send(StorageInventoryPacket.Expand(ExtraSize));
            session.Send(StorageInventoryPacket.ExpandAnim());
            UpdateInventorySize();
        }
예제 #9
0
        public void Add(GameSession session, long uid, int amount, short slot)
        {
            Item item = session.Player.Inventory.Items[uid];

            if (amount < item.Amount)
            {
                item.TrySplit(amount, out Item splitItem);
                session.Send(ItemInventoryPacket.Update(uid, item.Amount));
                item = splitItem;
            }
            else
            {
                InventoryController.Remove(session, uid, out Item removedItem);
                item = removedItem;
            }

            if (slot >= 0)
            {
                if (Items[slot] == null)
                {
                    item.Slot   = slot;
                    Items[slot] = item;
                    session.Send(StorageInventoryPacket.Add(item));
                    return;
                }
                else
                {
                    slot = -1;
                }
            }

            if (slot == -1)
            {
                for (slot = 0; slot < Items.Length; slot++)
                {
                    if (Items[slot] != null)
                    {
                        continue;
                    }
                    item.Slot   = slot;
                    Items[slot] = item;
                    session.Send(StorageInventoryPacket.Add(item));
                    return;
                }
            }
        }
예제 #10
0
    public void Sort(GameSession session)
    {
        IEnumerable <Item> items = Items.Where(x => x is not null);

        // group items by item id and sum the amount, return a new list of items with updated amount (ty gh copilot)
        List <Item> groupedItems = items.Where(x => x.StackLimit > 1).GroupBy(x => x.Id).Select(x => new Item(x.First())
        {
            Amount          = x.Sum(y => y.Amount),
            BankInventoryId = Id
        }).ToList();

        // Add items that can't be grouped
        groupedItems.AddRange(items.Where(x => x.StackLimit == 1));

        // sort items by id
        groupedItems.Sort((x, y) => x.Id.CompareTo(y.Id));

        // Delete items that got grouped
        foreach (Item oldItem in items)
        {
            Item newItem = groupedItems.FirstOrDefault(x => x.Uid == oldItem.Uid);
            if (newItem is null)
            {
                DatabaseManager.Items.Delete(oldItem.Uid);
            }
        }

        Items = new Item[DEFAULT_SIZE + ExtraSize];
        for (short i = 0; i < groupedItems.Count; i++)
        {
            Item item = groupedItems[i];

            item.Slot = i;
            Items[i]  = item;

            DatabaseManager.Items.Update(item);
        }

        session.Send(StorageInventoryPacket.Update());
        session.Send(StorageInventoryPacket.Sort(Items));
        session.Send(StorageInventoryPacket.ExpandAnim());
    }
예제 #11
0
        public void Move(GameSession session, long dstUid, short dstSlot)
        {
            Item  dstItem = Items[dstSlot];
            long  srcUid  = 0;
            short srcSlot = 0;

            if (dstItem != null)
            {
                srcUid  = dstItem.Uid;
                srcSlot = (short)Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == dstUid);
                Item temp = Items[srcSlot];
                Items[srcSlot] = dstItem;
                Items[dstSlot] = temp;
            }
            else
            {
                short oldSlot = (short)Array.FindIndex(Items, 0, Items.Length, x => x != null && x.Uid == dstUid);
                Items[dstSlot] = Items.FirstOrDefault(x => x != null && x.Uid == dstUid);
                Items[oldSlot] = null;
            }
            session.Send(StorageInventoryPacket.Move(srcUid, srcSlot, dstUid, dstSlot));
        }
예제 #12
0
 public void LoadItems(GameSession session)
 {
     session.Send(StorageInventoryPacket.LoadItems(Items));
 }
 private static void HandleSort(GameSession session)
 {
     session.Send(StorageInventoryPacket.Update());
     session.Player.Account.BankInventory.Sort(session);
 }