public static void ChangeFace(GameSession session, int faceId, out Item previousFace, out Item newFace)
    {
        Random random = Random.Shared;

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

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

        newFace = new(faceId)
        {
            Color              = EquipColor.Argb(color, indexColor, palette.PaletteId),
            IsEquipped         = true,
            OwnerCharacterId   = session.Player.CharacterId,
            OwnerCharacterName = session.Player.Name
        };
        Dictionary <ItemSlot, Item> cosmetics = session.Player.Inventory.Cosmetics;

        //Remove old face
        if (cosmetics.Remove(ItemSlot.FA, out previousFace))
        {
            previousFace.Slot = -1;
            DatabaseManager.Items.Delete(previousFace.Uid);
            session.FieldManager.BroadcastPacket(EquipmentPacket.UnequipItem(session.Player.FieldPlayer, previousFace));
        }

        cosmetics[ItemSlot.FA] = newFace;
    }
}
Beispiel #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));
        }
    public static void ChangeHair(GameSession session, int hairId, out Item previousHair, out Item newHair)
    {
        Random random = Random.Shared;

        //Grab a preset hair and length of hair
        ItemCustomizeMetadata customize = ItemMetadataStorage.GetMetadata(hairId).Customize;
        int         indexPreset         = random.Next(customize.HairPresets.Count);
        HairPresets chosenPreset        = customize.HairPresets[indexPreset];

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

        //Grab random back hair length
        double chosenBackLength = random.NextDouble() *
                                  (customize.HairPresets[indexPreset].MaxScale - customize.HairPresets[indexPreset].MinScale) + customize.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];

        newHair = new(hairId)
        {
            Color              = EquipColor.Argb(color, indexColor, palette.PaletteId),
            HairData           = new((float)chosenBackLength, (float)chosenFrontLength, chosenPreset.BackPositionCoord, chosenPreset.BackPositionRotation, chosenPreset.FrontPositionCoord, chosenPreset.FrontPositionRotation),
            IsEquipped         = true,
            OwnerCharacterId   = session.Player.CharacterId,
            OwnerCharacterName = session.Player.Name
        };
        Dictionary <ItemSlot, Item> cosmetics = session.Player.Inventory.Cosmetics;

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

        cosmetics[ItemSlot.HR] = newHair;
    }