Exemplo n.º 1
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.º 2
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.º 3
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));
        }