public void DismantleAdd(GameSession session, short slot, long uid, int amount)
        {
            if (slot >= 0)
            {
                if (Slots[slot] == null)
                {
                    Slots[slot] = new Tuple <long, int>(uid, amount);
                    session.Send(ItemBreakPacket.Add(uid, slot, amount));
                    UpdateRewards(session);
                    return;
                }
                else
                {
                    slot = -1;
                }
            }

            if (slot == -1)
            {
                for (slot = 0; slot < Slots.Length; slot++)
                {
                    if (Slots[slot] != null)
                    {
                        continue;
                    }
                    Slots[slot] = new Tuple <long, int>(uid, amount);
                    session.Send(ItemBreakPacket.Add(uid, slot, amount));
                    UpdateRewards(session);
                    return;
                }
            }
        }
Beispiel #2
0
        public void Remove(GameSession session, long uid)
        {
            int index = Array.FindIndex(Slots, 0, Slots.Length, x => x != null && x.Item1 == uid);

            Slots[index] = null;
            session.Send(ItemBreakPacket.Remove(uid));
            UpdateRewards(session);
        }
        private static void HandleRemove(GameSession session, PacketReader packet)
        {
            long uid = packet.ReadLong();

            Tuple <long, int>[] dismantleSlots = session.Player.DismantleSlots;
            int index = Array.FindIndex(dismantleSlots, 0, dismantleSlots.Length, x => x != null && x.Item1 == uid);

            session.Player.DismantleSlots[index] = null;
            session.Send(ItemBreakPacket.Remove(uid));
            UpdateRewards(session);
        }
        public void Dismantle(GameSession session)
        {
            foreach (Tuple <long, int> slot in Slots.Where(i => i != null))
            {
                InventoryController.Consume(session, slot.Item1, slot.Item2);
            }
            foreach (KeyValuePair <int, int> reward in Rewards)
            {
                Item item = new Item(reward.Key)
                {
                    Amount = reward.Value
                };

                InventoryController.Add(session, item, true);
            }
            Slots = new Tuple <long, int> [100];
            session.Send(ItemBreakPacket.ShowRewards(Rewards));
        }
        private static void HandleDismantle(GameSession session)
        {
            Player player = session.Player;

            foreach (Tuple <long, int> slot in player.DismantleSlots.Where(i => i != null))
            {
                InventoryController.Consume(session, slot.Item1, slot.Item2);
            }
            foreach (KeyValuePair <int, int> reward in player.Rewards)
            {
                Item item = new Item(reward.Key)
                {
                    Amount = reward.Value
                };

                InventoryController.Add(session, item, true);
            }
            player.DismantleSlots = new Tuple <long, int> [100];
            session.Send(ItemBreakPacket.ShowRewards(player.Rewards));
        }
    public void Dismantle(GameSession session)
    {
        foreach ((long uid, int amount) in Slots.Where(i => i != null))
        {
            session.Player.Inventory.ConsumeItem(session, uid, amount);
        }

        foreach ((int id, int amount) in Rewards)
        {
            Item item = new(id)
            {
                Amount = amount
            };

            session.Player.Inventory.AddItem(session, item, true);
        }

        Slots = new Tuple <long, int> [100];
        session.Send(ItemBreakPacket.ShowRewards(Rewards));
    }
    public void UpdateRewards(GameSession session)
    {
        Rewards = new();
        foreach ((long uid, int amount) in Slots.Where(x => x != null))
        {
            Item item = session.Player.Inventory.Items.FirstOrDefault(x => x.Value.Uid == uid).Value;
            if (!ItemMetadataStorage.IsValid(item.Id))
            {
                continue;
            }

            List <ItemBreakReward> breakRewards = ItemMetadataStorage.GetBreakRewards(item.Id);
            if (breakRewards == null)
            {
                continue;
            }

            foreach (ItemBreakReward ingredient in breakRewards)
            {
                if (ingredient.Id == 0)
                {
                    continue;
                }

                if (Rewards.ContainsKey(ingredient.Id))
                {
                    Rewards[ingredient.Id] += ingredient.Count;
                }
                else
                {
                    Rewards[ingredient.Id] = ingredient.Count;
                }

                Rewards[ingredient.Id] *= amount;
            }
            // TODO: Add Onyx Crystal (40100023) and Chaos Onyx Crystal (40100024) to rewards if InventoryTab = Gear, based on level and rarity
            // TODO: Add rewards for outfits
        }

        session.Send(ItemBreakPacket.Results(Rewards));
    }
        private static void UpdateRewards(GameSession session)
        {
            Player player = session.Player;

            player.Rewards = new Dictionary <int, int>();
            foreach (Tuple <long, int> slot in player.DismantleSlots.Where(x => x != null))
            {
                Item item = player.Inventory.Items.FirstOrDefault(x => x.Value.Uid == slot.Item1).Value;
                if (!ItemMetadataStorage.IsValid(item.Id))
                {
                    continue;
                }

                List <ItemBreakReward> breakRewards = ItemMetadataStorage.GetBreakRewards(item.Id);
                if (breakRewards == null)
                {
                    continue;
                }

                foreach (ItemBreakReward ingredient in breakRewards)
                {
                    if (ingredient.Id != 0)
                    {
                        if (player.Rewards.ContainsKey(ingredient.Id))
                        {
                            player.Rewards[ingredient.Id] += ingredient.Count;
                        }
                        else
                        {
                            player.Rewards[ingredient.Id] = ingredient.Count;
                        }
                        player.Rewards[ingredient.Id] *= slot.Item2;
                    }
                }
                // TODO: Add Onyx Crystal (40100023) and Chaos Onyx Crystal (40100024) to rewards if InventoryTab = Gear, based on level and rarity
                // TODO: Add rewards for outfits
            }
            session.Send(ItemBreakPacket.Results(player.Rewards));
        }