Exemplo n.º 1
0
        private static void HandleNewBeauty(GameSession session, PacketReader packet)
        {
            byte       unk          = packet.ReadByte();
            bool       useVoucher   = packet.ReadBool();
            int        beautyItemId = packet.ReadInt();
            EquipColor equipColor   = packet.Read <EquipColor>();

            Item beautyItem = new Item(beautyItemId)
            {
                Color              = equipColor,
                IsTemplate         = false,
                IsEquipped         = true,
                OwnerCharacterId   = session.Player.CharacterId,
                OwnerCharacterName = session.Player.Name
            };
            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(session.Player.ShopId);

            if (useVoucher)
            {
                if (!PayWithVoucher(session, beautyShop))
                {
                    return;
                }
            }
            else
            {
                if (!PayWithShopItemTokenCost(session, beautyItemId, beautyShop))
                {
                    return;
                }
            }

            ModifyBeauty(session, packet, beautyItem);
        }
Exemplo n.º 2
0
        private static void HandleChangeToSavedHair(GameSession session, PacketReader packet)
        {
            long hairUid = packet.ReadLong();

            Item hair = session.Player.HairInventory.SavedHair.FirstOrDefault(x => x.Uid == hairUid);

            if (hair == null)
            {
                return;
            }

            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(510);

            if (!PayWithShopTokenCost(session, beautyShop))
            {
                return;
            }

            Dictionary <ItemSlot, Item> cosmetics = session.Player.Inventory.Cosmetics;

            if (cosmetics.Remove(hair.ItemSlot, out Item removeItem))
            {
                removeItem.Slot = -1;
                session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.FieldPlayer, removeItem));
            }

            cosmetics[removeItem.ItemSlot] = hair;

            session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(session.FieldPlayer, hair, hair.ItemSlot));
            session.Send(BeautyPacket.ChangetoSavedHair());
        }
Exemplo n.º 3
0
        private static void HandleModifyExistingBeauty(GameSession session, PacketReader packet)
        {
            byte       unk           = packet.ReadByte();
            bool       useVoucher    = packet.ReadBool();
            long       beautyItemUid = packet.ReadLong();
            EquipColor equipColor    = packet.Read <EquipColor>();

            Item beautyItem = session.Player.GetEquippedItem(beautyItemUid);

            if (beautyItem.ItemSlot == ItemSlot.CP)
            {
                HatData hatData = packet.Read <HatData>();
                beautyItem.HatData = hatData;
                session.FieldManager.BroadcastPacket(ItemExtraDataPacket.Update(session.FieldPlayer, beautyItem));
                return;
            }

            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(session.Player.ShopId);

            if (!HandleShopPay(session, beautyShop, useVoucher))
            {
                return;
            }

            beautyItem.Color = equipColor;
            ModifyBeauty(session, packet, beautyItem);
        }
Exemplo n.º 4
0
    private static void HandleBeautyVoucher(GameSession session, PacketReader packet)
    {
        long itemUid = packet.ReadLong();

        Player player  = session.Player;
        Item   voucher = player.Inventory.Items[itemUid];

        if (voucher == null || voucher.Function.Name != "ItemChangeBeauty")
        {
            return;
        }

        BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(voucher.Function.Id);

        if (beautyShop == null)
        {
            return;
        }

        List <BeautyItem> beautyItems = BeautyMetadataStorage.GetGenderItems(beautyShop.ShopId, player.Gender);

        player.ShopId = beautyShop.ShopId;
        session.Send(BeautyPacket.LoadBeautyShop(beautyShop, beautyItems));
        player.Inventory.ConsumeItem(session, voucher.Uid, 1);
    }
Exemplo n.º 5
0
        private static void HandleRandomHair(GameSession session, PacketReader packet)
        {
            int  shopId     = packet.ReadInt();
            bool useVoucher = packet.ReadBool();

            BeautyMetadata    beautyShop  = BeautyMetadataStorage.GetShopById(shopId);
            List <BeautyItem> beautyItems = BeautyMetadataStorage.GetGenderItems(beautyShop.ShopId, session.Player.Gender);

            if (!HandleShopPay(session, beautyShop, useVoucher))
            {
                return;
            }

            // Grab random hair
            Random     random     = new Random();
            int        indexHair  = random.Next(beautyItems.Count);
            BeautyItem chosenHair = beautyItems[indexHair];

            //Grab a preset hair and length of hair
            ItemMetadata beautyItemData = ItemMetadataStorage.GetMetadata(chosenHair.ItemId);
            int          indexPreset    = random.Next(beautyItemData.HairPresets.Count);
            HairPresets  chosenPreset   = beautyItemData.HairPresets[indexPreset];

            //Grab random front hair length
            double chosenFrontLength = random.NextDouble() *
                                       (beautyItemData.HairPresets[indexPreset].MaxScale - beautyItemData.HairPresets[indexPreset].MinScale) + beautyItemData.HairPresets[indexPreset].MinScale;

            //Grab random back hair length
            double chosenBackLength = random.NextDouble() *
                                      (beautyItemData.HairPresets[indexPreset].MaxScale - beautyItemData.HairPresets[indexPreset].MinScale) + beautyItemData.HairPresets[indexPreset].MinScale;

            // Grab random preset color
            ColorPaletteMetadata palette = ColorPaletteMetadataStorage.GetMetadata(2); // pick from palette 2. Seems like it's the correct palette for basic hair colors

            int        indexColor = random.Next(palette.DefaultColors.Count);
            MixedColor color      = palette.DefaultColors[indexColor];

            Dictionary <ItemSlot, Item> equippedInventory = session.Player.GetEquippedInventory(InventoryTab.Gear);

            Item newHair = new Item(chosenHair.ItemId)
            {
                Color      = EquipColor.Argb(color, indexColor, palette.PaletteId),
                HairD      = new HairData((float)chosenBackLength, (float)chosenFrontLength, chosenPreset.BackPositionCoord, chosenPreset.BackPositionRotation, chosenPreset.FrontPositionCoord, chosenPreset.FrontPositionRotation),
                IsTemplate = false
            };

            //Remove old hair
            if (session.Player.Equips.Remove(ItemSlot.HR, out Item previousHair))
            {
                previousHair.Slot = -1;
                session.Player.HairInventory.RandomHair = previousHair; // store the previous hair
                session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.FieldPlayer, previousHair));
            }

            equippedInventory[ItemSlot.HR] = newHair;

            session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(session.FieldPlayer, newHair, ItemSlot.HR));
            session.Send(BeautyPacket.RandomHairOption(previousHair, newHair));
        }
Exemplo n.º 6
0
        private static void HandleDyeItem(GameSession session, PacketReader packet)
        {
            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(506);

            byte itemCount = packet.ReadByte();

            short[]      quantity     = new short[itemCount];
            bool[]       useVoucher   = new bool[itemCount];
            byte[]       unk1         = new byte[itemCount];
            long[]       unk2         = new long[itemCount];
            int[]        unk3         = new int[itemCount];
            long[]       itemUid      = new long[itemCount];
            int[]        itemId       = new int[itemCount];
            EquipColor[] equipColor   = new EquipColor[itemCount];
            int[]        paletteId    = new int[itemCount];
            CoordF[]     hatXPosition = new CoordF[itemCount];
            CoordF[]     hatYPosition = new CoordF[itemCount];
            CoordF[]     hatZPosition = new CoordF[itemCount];
            CoordF[]     hatRotation  = new CoordF[itemCount];
            int[]        hatScale     = new int[itemCount];

            for (int i = 0; i < itemCount; i++)
            {
                quantity[i]   = packet.ReadShort(); // should always be one
                useVoucher[i] = packet.ReadBool();
                unk1[i]       = packet.ReadByte();  // just 0
                unk2[i]       = packet.ReadLong();  // just 0
                unk3[i]       = packet.ReadInt();   // also 0
                itemUid[i]    = packet.ReadLong();
                itemId[i]     = packet.ReadInt();
                equipColor[i] = packet.Read <EquipColor>();
                paletteId[i]  = packet.ReadInt();
                Item item = session.Player.GetEquippedItem(itemUid[i]);
                if (item == null)
                {
                    return;
                }

                if (item.ItemSlot == ItemSlot.CP)
                {
                    hatXPosition[i] = packet.Read <CoordF>(); // TODO: implement correct hat positioning
                    hatYPosition[i] = packet.Read <CoordF>();
                    hatZPosition[i] = packet.Read <CoordF>();
                    hatRotation[i]  = packet.Read <CoordF>();
                    hatScale[i]     = packet.ReadInt();
                }

                if (!HandleShopPay(session, beautyShop, useVoucher[i]))
                {
                    return;
                }

                item.Color = equipColor[i];
                session.FieldManager.BroadcastPacket(ItemExtraDataPacket.Update(session.FieldPlayer, item));
            }
        }
Exemplo n.º 7
0
        private static void HandleLoadShop(GameSession session, PacketReader packet)
        {
            int            npcId    = packet.ReadInt();
            BeautyCategory category = (BeautyCategory)packet.ReadByte();

            NpcMetadata beautyNpc = NpcMetadataStorage.GetNpc(npcId);

            if (beautyNpc == null)
            {
                return;
            }

            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(beautyNpc.ShopId);

            if (beautyShop == null)
            {
                return;
            }

            if (beautyShop.BeautyCategory == BeautyCategory.Dye)
            {
                if (beautyShop.BeautyType == BeautyShopType.Dye)
                {
                    session.Send(BeautyPacket.LoadDyeShop(beautyShop));
                    return;
                }
                session.Send(BeautyPacket.LoadBeautyShop(beautyShop));
                return;
            }

            if (beautyShop.BeautyCategory == BeautyCategory.Save)
            {
                session.Send(BeautyPacket.LoadSaveShop(beautyShop));
                session.Send(BeautyPacket.InitializeSaves());
                session.Send(BeautyPacket.LoadSaveWindow());
                session.Send(BeautyPacket.LoadSavedHairCount((short)session.Player.HairInventory.SavedHair.Count));
                if (session.Player.HairInventory.SavedHair.Count != 0)
                {
                    session.Player.HairInventory.SavedHair = session.Player.HairInventory.SavedHair.OrderBy(o => o.CreationTime).ToList();
                    session.Send(BeautyPacket.LoadSavedHairs(session.Player.HairInventory.SavedHair));
                }

                return;
            }

            List <BeautyItem> beautyItems = BeautyMetadataStorage.GetGenderItems(beautyShop.ShopId, session.Player.Gender);

            session.Send(BeautyPacket.LoadBeautyShop(beautyShop, beautyItems));
        }
Exemplo n.º 8
0
        private static void HandleDyeItem(GameSession session, PacketReader packet)
        {
            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(506);

            byte itemCount = packet.ReadByte();

            short[]      quantity   = new short[itemCount];
            bool[]       useVoucher = new bool[itemCount];
            byte[]       unk1       = new byte[itemCount];
            long[]       unk2       = new long[itemCount];
            int[]        unk3       = new int[itemCount];
            long[]       itemUid    = new long[itemCount];
            int[]        itemId     = new int[itemCount];
            EquipColor[] equipColor = new EquipColor[itemCount];
            HatData[]    hatData    = new HatData[itemCount];

            for (int i = 0; i < itemCount; i++)
            {
                quantity[i]   = packet.ReadShort(); // should always be one
                useVoucher[i] = packet.ReadBool();
                unk1[i]       = packet.ReadByte();  // just 0
                unk2[i]       = packet.ReadLong();  // just 0
                unk3[i]       = packet.ReadInt();   // also 0
                itemUid[i]    = packet.ReadLong();
                itemId[i]     = packet.ReadInt();
                equipColor[i] = packet.Read <EquipColor>();
                Item item = session.Player.GetEquippedItem(itemUid[i]);
                if (item == null)
                {
                    return;
                }

                if (!HandleShopPay(session, beautyShop, useVoucher[i]))
                {
                    return;
                }

                if (item.ItemSlot == ItemSlot.CP)
                {
                    hatData[i]   = packet.Read <HatData>();
                    item.HatData = hatData[i];
                }

                item.Color = equipColor[i];
                Console.WriteLine(item.Color);
                session.FieldManager.BroadcastPacket(ItemExtraDataPacket.Update(session.FieldPlayer, item));
            }
        }
Exemplo n.º 9
0
        private static void HandleModifySkin(GameSession session, PacketReader packet)
        {
            byte      unk        = packet.ReadByte();
            SkinColor skinColor  = packet.Read <SkinColor>();
            bool      useVoucher = packet.ReadBool();

            BeautyMetadata beautyShop = BeautyMetadataStorage.GetShopById(501);

            if (!HandleShopPay(session, beautyShop, useVoucher))
            {
                return;
            }

            session.Player.SkinColor = skinColor;
            session.FieldManager.BroadcastPacket(SkinColorPacket.Update(session.FieldPlayer, skinColor));
        }