示例#1
0
    private static void HandleBeautyVoucher(GameSession session, PacketReader packet)
    {
        long itemUid = packet.ReadLong();

        Player player  = session.Player;
        Item   voucher = player.Inventory.GetByUid(itemUid);

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

        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(voucher.Function.Id);

        if (beautyShop == null)
        {
            return;
        }

        List <BeautyShopItem> beautyItems = DatabaseManager.BeautyShopItems.FindAllByShopIdAndGender(beautyShop.Id, player.Gender);

        player.ShopId = beautyShop.Id;
        session.Send(BeautyPacket.LoadBeautyShop(beautyShop, beautyItems));
        player.Inventory.ConsumeItem(session, voucher.Uid, 1);
    }
示例#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;
        }

        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(session.Player.ShopId);

        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.Player.FieldPlayer, removeItem));
        }

        cosmetics[removeItem.ItemSlot] = hair;

        session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(session.Player.FieldPlayer, hair, hair.ItemSlot));
        session.Send(BeautyPacket.ChangetoSavedHair());
    }
示例#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.Inventory.GetEquippedItem(beautyItemUid);

        if (beautyItem.ItemSlot is ItemSlot.CP) // This should only work with the mirror shop
        {
            HatData hatData = packet.Read <HatData>();
            beautyItem.HatData = hatData;
            session.FieldManager.BroadcastPacket(ItemExtraDataPacket.Update(session.Player.FieldPlayer, beautyItem));
            return;
        }

        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(session.Player.ShopId);

        if (beautyShop is null)
        {
            return;
        }

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

        beautyItem.Color = equipColor;
        ModifyBeauty(session, packet, beautyItem);
    }
示例#4
0
    public static PacketWriter LoadDyeShop(BeautyShop beautyShop)
    {
        PacketWriter pWriter = PacketWriter.Of(SendOp.Beauty);

        pWriter.Write(BeautyPacketMode.LoadDyeShop);
        WriteBeautyShop(pWriter, beautyShop);
        return(pWriter);
    }
示例#5
0
    private static bool PayWithShopTokenCost(GameSession session, BeautyShop beautyShop)
    {
        int cost = beautyShop.CurrencyCost;

        if (beautyShop.SpecialCost != 0)
        {
            cost = beautyShop.SpecialCost;
        }

        return(Pay(session, beautyShop.CurrencyType, cost, beautyShop.RequiredItemId));
    }
示例#6
0
    private static void HandleLoadShop(GameSession session, PacketReader packet)
    {
        int            npcId    = packet.ReadInt();
        BeautyCategory category = (BeautyCategory)packet.ReadByte();

        NpcMetadata beautyNpc = NpcMetadataStorage.GetNpcMetadata(npcId);

        if (beautyNpc == null)
        {
            return;
        }

        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(beautyNpc.ShopId);

        if (beautyShop == null)
        {
            return;
        }

        session.Player.ShopId = beautyNpc.ShopId;

        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 <BeautyShopItem> beautyItems = DatabaseManager.BeautyShopItems.FindAllByShopIdAndGender(beautyShop.Id, session.Player.Gender);

        session.Send(BeautyPacket.LoadBeautyShop(beautyShop, beautyItems));
    }
    public BeautyShop FindById(int id)
    {
        dynamic data = QueryFactory.Query(TableName).Where("id", id).Get().FirstOrDefault();

        if (data == null)
        {
            return(null);
        }

        BeautyShop shop = ReadShop(data);

        return(shop);
    }
示例#8
0
    private static bool PayWithVoucher(GameSession session, BeautyShop shop)
    {
        string voucherTag = ""; // using an Item's tag to search for any applicable voucher

        switch (shop.BeautyType)
        {
        case BeautyShopType.Hair:
            if (shop.BeautyCategory == BeautyCategory.Special)
            {
                voucherTag = "beauty_hair_special";
                break;
            }

            voucherTag = "beauty_hair";
            break;

        case BeautyShopType.Face:
            voucherTag = "beauty_face";
            break;

        case BeautyShopType.Makeup:
            voucherTag = "beauty_makeup";
            break;

        case BeautyShopType.Skin:
            voucherTag = "beauty_skin";
            break;

        case BeautyShopType.Dye:
            voucherTag = "beauty_itemcolor";
            break;

        default:
            Logger.Warning($"Unknown Beauty Shop: {shop.BeautyType}");
            session.Send(NoticePacket.Notice("Unknown Beauty Shop", NoticeType.FastText));
            return(false);
        }

        Item voucher = session.Player.Inventory.GetAllByTag(voucherTag).FirstOrDefault();

        if (voucher == null)
        {
            session.Send(NoticePacket.Notice(SystemNotice.ErrorItemNotFound, NoticeType.FastText));
            return(false);
        }

        session.Send(BeautyPacket.UseVoucher(voucher.Id, 1));
        session.Player.Inventory.ConsumeItem(session, voucher.Uid, 1);
        return(true);
    }
示例#9
0
    private static void HandleModifySkin(GameSession session, PacketReader packet)
    {
        byte      unk        = packet.ReadByte();
        SkinColor skinColor  = packet.Read <SkinColor>();
        bool      useVoucher = packet.ReadBool();

        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(session.Player.ShopId);

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

        session.Player.SkinColor = skinColor;
        session.FieldManager.BroadcastPacket(SkinColorPacket.Update(session.Player.FieldPlayer, skinColor));
    }
示例#10
0
    private static void HandleDyeItem(GameSession session, PacketReader packet)
    {
        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(session.Player.ShopId);

        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.Inventory.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];
            session.FieldManager.BroadcastPacket(ItemExtraDataPacket.Update(session.Player.FieldPlayer, item));
        }
    }
示例#11
0
 public static void WriteBeautyShop(PacketWriter pWriter, BeautyShop beautyShop)
 {
     pWriter.Write(beautyShop.BeautyCategory);
     pWriter.WriteInt(beautyShop.Id);
     pWriter.Write(beautyShop.BeautyType);
     pWriter.WriteInt(beautyShop.VoucherId);
     pWriter.WriteByte();
     pWriter.WriteInt();
     pWriter.WriteInt(beautyShop.UniqueId);
     pWriter.WriteByte();
     pWriter.Write(beautyShop.CurrencyType);
     pWriter.WriteInt();
     pWriter.WriteInt(beautyShop.SpecialCost);
     pWriter.WriteString();
     pWriter.Write(beautyShop.CurrencyType);
     pWriter.WriteInt(beautyShop.RequiredItemId);
     pWriter.WriteInt(beautyShop.CurrencyCost);
     pWriter.WriteString();
 }
示例#12
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(beautyItemId)
        {
            Color              = equipColor,
            IsEquipped         = true,
            OwnerCharacterId   = session.Player.CharacterId,
            OwnerCharacterName = session.Player.Name
        };
        BeautyShop beautyShop = DatabaseManager.BeautyShops.FindById(session.Player.ShopId);

        if (beautyShop is null)
        {
            return;
        }

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

        ModifyBeauty(session, packet, beautyItem);
    }
示例#13
0
    public static PacketWriter LoadBeautyShop(BeautyShop beautyShop, List <BeautyShopItem> items)
    {
        PacketWriter pWriter = PacketWriter.Of(SendOp.Beauty);

        pWriter.Write(BeautyPacketMode.LoadBeautyShop);
        WriteBeautyShop(pWriter, beautyShop);
        pWriter.WriteByte(30);
        pWriter.WriteByte(6);
        pWriter.WriteShort((short)items.Count);
        foreach (BeautyShopItem item in items)
        {
            pWriter.WriteInt(item.ItemId);
            pWriter.Write(item.Flag);
            pWriter.WriteShort(item.RequiredLevel);
            pWriter.WriteInt(item.RequiredAchievementId);
            pWriter.WriteByte(item.RequiredAchievementGrade);
            pWriter.Write(item.CurrencyType);
            pWriter.WriteInt(item.RequiredItemId);
            pWriter.WriteInt(item.CurrencyCost);
            pWriter.WriteString();
        }
        return(pWriter);
    }
示例#14
0
    private static void HandleRandomHair(GameSession session, PacketReader packet)
    {
        int  shopId     = packet.ReadInt();
        bool useVoucher = packet.ReadBool();

        BeautyShop            beautyShop  = DatabaseManager.BeautyShops.FindById(shopId);
        List <BeautyShopItem> beautyItems = DatabaseManager.BeautyShopItems.FindAllByShopIdAndGender(beautyShop.Id, session.Player.Gender);

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

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

        BeautyHelper.ChangeHair(session, chosenHair.ItemId, out Item previousHair, out Item newHair);

        session.FieldManager.BroadcastPacket(EquipmentPacket.EquipItem(session.Player.FieldPlayer, newHair, ItemSlot.HR));
        session.Send(BeautyPacket.RandomHairOption(previousHair, newHair));
    }
示例#15
0
    private static bool PayWithShopItemTokenCost(GameSession session, int beautyItemId, BeautyShop beautyShop)
    {
        BeautyShopItem item = beautyShop.Items.FirstOrDefault(x => x.ItemId == beautyItemId);

        return(item != null && Pay(session, item.CurrencyType, item.CurrencyCost, item.RequiredItemId));
    }
示例#16
0
 private static bool HandleShopPay(GameSession session, BeautyShop shop, bool useVoucher)
 {
     return(useVoucher ? PayWithVoucher(session, shop) : PayWithShopTokenCost(session, shop));
 }