Exemplo n.º 1
0
    private static void HandleChangeAttributes(GameSession session, PacketReader packet)
    {
        short lockStatId    = -1;
        bool  isSpecialStat = false;
        long  scrollUid     = packet.ReadLong();
        long  gearUid       = packet.ReadLong();

        packet.Skip(9);
        bool useLock = packet.ReadBool();

        if (useLock)
        {
            isSpecialStat = packet.ReadBool();
            lockStatId    = packet.ReadShort();

            if (isSpecialStat)
            {
                // Match the enum ID for ItemAttribute
                lockStatId += 11000;
            }
        }

        IInventory inventory  = session.Player.Inventory;
        Item       scroll     = inventory.GetByUid(scrollUid);
        Item       gear       = inventory.GetByUid(gearUid);
        Item       scrollLock = null;

        // Check if gear and scroll exists in inventory
        if (scroll == null || gear == null)
        {
            return;
        }

        string tag = "";

        if (Item.IsAccessory(gear.ItemSlot))
        {
            tag = "LockItemOptionAccessory";
        }
        else if (Item.IsArmor(gear.ItemSlot))
        {
            tag = "LockItemOptionArmor";
        }
        else if (Item.IsWeapon(gear.ItemSlot))
        {
            tag = "LockItemOptionWeapon";
        }
        else if (gear.IsPet())
        {
            tag = "LockItemOptionPet";
        }

        if (useLock)
        {
            scrollLock = inventory.GetAllByTag(tag).FirstOrDefault(x => x.Rarity == gear.Rarity);

            // Check if scroll lock exists in inventory
            if (scrollLock == null)
            {
                return;
            }
        }

        Item newItem = new(gear);

        // Set new values for attributes
        newItem.Stats.Randoms = RandomStats.RollNewBonusValues(newItem, lockStatId, isSpecialStat);

        inventory.TemporaryStorage[newItem.Uid] = newItem;

        session.Player.Inventory.ConsumeItem(session, scroll.Uid, 1);
        if (useLock)
        {
            session.Player.Inventory.ConsumeItem(session, scrollLock.Uid, 1);
        }

        session.Send(ChangeAttributesScrollPacket.PreviewNewItem(newItem));
    }
        private static void HandleChangeAttributes(GameSession session, PacketReader packet)
        {
            short lockStatId    = -1;
            bool  isSpecialStat = false;
            long  scrollUid     = packet.ReadLong();
            long  gearUid       = packet.ReadLong();

            packet.Skip(9);
            bool useLock = packet.ReadBool();

            if (useLock)
            {
                isSpecialStat = packet.ReadBool();
                lockStatId    = packet.ReadShort();
            }

            Inventory inventory  = session.Player.Inventory;
            Item      scroll     = inventory.Items.FirstOrDefault(x => x.Key == scrollUid).Value;
            Item      gear       = inventory.Items.FirstOrDefault(x => x.Key == gearUid).Value;
            Item      scrollLock = null;

            // Check if gear and scroll exists in inventory
            if (scroll == null || gear == null)
            {
                return;
            }

            string tag = "";

            if (Item.IsAccessory(gear.ItemSlot))
            {
                tag = "LockItemOptionAccessory";
            }
            else if (Item.IsArmor(gear.ItemSlot))
            {
                tag = "LockItemOptionArmor";
            }
            else if (Item.IsWeapon(gear.ItemSlot))
            {
                tag = "LockItemOptionWeapon";
            }
            else if (Item.IsPet(gear.Id))
            {
                tag = "LockItemOptionPet";
            }

            if (useLock)
            {
                scrollLock = inventory.Items.FirstOrDefault(x => x.Value.Tag == tag && x.Value.Rarity == gear.Rarity).Value;
                // Check if scroll lock exists in inventory
                if (scrollLock == null)
                {
                    return;
                }
            }

            Item newItem = new Item(gear);

            // Set new values for attributes
            newItem.Stats.BonusStats = ItemStats.RollNewBonusValues(newItem, lockStatId, isSpecialStat);

            inventory.TemporaryStorage[newItem.Uid] = newItem;

            InventoryController.Consume(session, scroll.Uid, 1);
            if (useLock)
            {
                InventoryController.Consume(session, scrollLock.Uid, 1);
            }

            session.Send(ChangeAttributesScrollPacket.PreviewNewItem(newItem));
        }