Ejemplo n.º 1
0
    private static UGC HandleCreateUGCItem(PacketReader packet, GameSession session, long characterId, long accountId, UGCType type)
    {
        long   unk      = packet.ReadLong(); // some kind of UID
        int    itemId   = packet.ReadInt();
        int    amount   = packet.ReadInt();
        string itemName = packet.ReadUnicodeString();

        packet.ReadByte();
        long cost       = packet.ReadLong();
        bool useVoucher = packet.ReadBool();

        UgcDesignMetadata metadata = UgcDesignMetadataStorage.GetItem(itemId);

        if (metadata is null)
        {
            return(null);
        }

        if (useVoucher)
        {
            Item voucher = session.Player.Inventory.GetAllByTag("FreeDesignCoupon").FirstOrDefault();
            if (voucher is null)
            {
                return(null);
            }

            session.Player.Inventory.ConsumeItem(session, voucher.Uid, 1);
        }
        else
        {
            switch (metadata.CurrencyType)
            {
            case CurrencyType.Meso when !session.Player.Wallet.Meso.Modify(-cost):
                return(null);

            case CurrencyType.Meret when !session.Player.Account.Meret.Modify(-cost):
                return(null);
            }
        }

        Item item = new(itemId, amount, metadata.Rarity);

        item.Ugc.UpdateItem(itemName, characterId, session.Player.Name, accountId, metadata.SalePrice, type);
        DatabaseManager.Items.Update(item);
        return(item.Ugc);
    }
Ejemplo n.º 2
0
    private static void HandleCreateUGCItem(GameSession session, PacketReader packet)
    {
        packet.ReadLong();
        packet.ReadByte();
        packet.ReadByte();
        packet.ReadByte();
        packet.ReadInt();
        long accountId   = packet.ReadLong();
        long characterId = packet.ReadLong();

        packet.ReadLong();
        packet.ReadInt();
        packet.ReadShort();
        packet.ReadShort();
        long   unk      = packet.ReadLong(); // some kind of UID
        int    itemId   = packet.ReadInt();
        int    amount   = packet.ReadInt();
        string itemName = packet.ReadUnicodeString();

        packet.ReadByte();
        long cost       = packet.ReadLong();
        bool useVoucher = packet.ReadBool();

        UgcDesignMetadata metadata = UgcDesignMetadataStorage.GetItem(itemId);

        if (metadata is null)
        {
            return;
        }

        if (useVoucher)
        {
            Item voucher = session.Player.Inventory.Items.Values.FirstOrDefault(x => x.Tag == "FreeDesignCoupon");
            if (voucher is null)
            {
                return;
            }
            session.Player.Inventory.ConsumeItem(session, voucher.Uid, 1);
        }
        else
        {
            switch (metadata.CurrencyType)
            {
            case CurrencyType.Meso when !session.Player.Wallet.Meso.Modify(-cost):
                session.SendNotice("You don't have enough mesos.");
                return;

            case CurrencyType.Meret when !session.Player.Account.Meret.Modify(-cost):
                session.SendNotice("You don't have enough merets.");
                return;
            }
        }

        Item item = new(itemId, 1)
        {
            Rarity = metadata.Rarity,
            UGC    = new(itemName, characterId, session.Player.Name, accountId, metadata.SalePrice)
        };

        DatabaseManager.Items.Update(item);

        session.Send(UgcPacket.CreateUGC(true, item.UGC));
    }