Example #1
0
    public static void BlackMarketCancellation(BlackMarketListing listing)
    {
        long deposit = 0;

        if (TimeInfo.Now() > listing.ExpiryTimestamp)
        {
            deposit = listing.Deposit;
        }

        string senderName    = "<ms2><v key=\"s_blackmarket_mail_to_sender\" /></ms2>";
        string title         = "<ms2><v key=\"s_blackmarket_mail_to_cancel_title\" /></ms2>";
        string body          = "<ms2><v key=\"s_blackmarket_mail_to_cancel_content\" /></ms2>";
        string addParameter1 = $"<ms2><v item=\"{listing.Item.Id}\" ></v></ms2>";
        string addParameter2 = "<ms2>" +
                               "<v key=\"s_blackmarket_mail_to_cancel_direct\" ></v>" +
                               $"<v item=\"{listing.Item.Id}\" ></v>" +
                               $"<v str=\"{listing.ListedQuantity}\" ></v>" +
                               $"<v money=\"{listing.Price * listing.ListedQuantity}\" ></v>" +
                               $"<v money=\"{listing.Price}\" ></v>" +
                               $"<v money=\"{deposit}\" ></v>" +
                               "</ms2>";

        Mail mail = new(MailType.BlackMarketListingCancel, listing.OwnerCharacterId, 0, senderName, title, body, addParameter1, addParameter2, new()
        {
            listing.Item
        }, deposit, 0);

        GameServer.MailManager.AddMail(mail);
        SendNotification(mail);
    }
Example #2
0
    private static void SendBlackMarketSoldMail(BlackMarketListing listing, Item item, long price, bool removeListing)
    {
        Script   script        = ScriptLoader.GetScript("Functions/calcBlackMarketCostRate");
        DynValue scriptResults = script.RunFunction("calcBlackMarketCostRate");
        float    salesFeeRate  = (float)scriptResults.Number;
        long     tax           = (long)(salesFeeRate * (item.Amount * price));
        long     revenue       = item.Amount * price - tax;

        string senderName    = "<ms2><v key=\"s_blackmarket_mail_to_sender\" /></ms2>";
        string title         = "<ms2><v key=\"s_blackmarket_mail_to_seller_title\" /></ms2>";
        string body          = "<ms2><v key=\"s_blackmarket_mail_to_seller_content\" /></ms2>";
        string addParameter1 = $"<ms2><v item=\"{item.Id}\" ></v></ms2>";
        string addParameter2 =
            $"<ms2><v item=\"{item.Id}\" ></v><v str=\"{item.Amount}\" ></v><v money=\"{price * item.Amount}\" ></v><v money=\"{price}\" ></v><v money=\"{tax}\" ></v><v str=\"{salesFeeRate * 100}%\" ></v><v money=\"{revenue}\" ></v></ms2>";

        if (removeListing)
        {
            revenue      += listing.Deposit;
            body          = "<ms2><v key=\"s_blackmarket_mail_to_seller_content_soldout\" /></ms2>";
            addParameter2 =
                $"<ms2><v item=\"{item.Id}\" ></v><v str=\"{item.Amount}\" ></v><v money=\"{price * item.Amount}\" ></v><v money=\"{price}\" ></v><v money=\"{tax}\" ></v><v str=\"{salesFeeRate * 100}%\" ></v><v money=\"{listing.Deposit}\" ></v><v money=\"{revenue}\" ></v></ms2>";
        }

        Mail mail = new(MailType.BlackMarketSale, listing.OwnerCharacterId, 0, senderName, title, body, addParameter1, addParameter2, new(), revenue, 0);

        GameServer.MailManager.AddMail(mail);
        SendNotification(mail);
    }
Example #3
0
    public static PacketWriter CreateListing(BlackMarketListing listing)
    {
        PacketWriter pWriter = PacketWriter.Of(SendOp.BLACK_MARKET);

        pWriter.Write(BlackMarketPacketMode.CreateListing);
        WriteListing(pWriter, listing);
        return(pWriter);
    }
Example #4
0
    public static void BlackMarketTransaction(Item item, BlackMarketListing listing, long recipientCharacterId, long price, bool removeListing)
    {
        // Create mail for purchaser
        SendBlackMarketPurchaseMail(item, recipientCharacterId, price);

        // Create mail for seller
        SendBlackMarketSoldMail(listing, item, price, removeListing);
    }
Example #5
0
    public static PacketWriter CancelListing(BlackMarketListing listing, bool isSold)
    {
        PacketWriter pWriter = PacketWriter.Of(SendOp.BLACK_MARKET);

        pWriter.Write(BlackMarketPacketMode.CancelListing);
        pWriter.WriteLong(listing.Id);
        pWriter.WriteBool(isSold);
        return(pWriter);
    }
Example #6
0
    private static void HandlePurchase(GameSession session, PacketReader packet)
    {
        long listingId = packet.ReadLong();
        int  amount    = packet.ReadInt();

        BlackMarketListing listing = GameServer.BlackMarketManager.GetListingById(listingId);

        if (listing == null)
        {
            return;
        }

        if (listing.OwnerAccountId == session.Player.AccountId)
        {
            session.Send(BlackMarketPacket.Error((int)BlackMarketError.CannotPurchaseOwnItems));
            return;
        }

        if (listing.Item.Amount < amount)
        {
            session.Send(BlackMarketPacket.Error((int)BlackMarketError.QuantityNotAvailable));
            return;
        }

        if (!session.Player.Wallet.Meso.Modify(-listing.Price * amount))
        {
            return;
        }

        Item purchasedItem;
        bool removeListing = false;

        if (listing.Item.Amount == amount)
        {
            purchasedItem = listing.Item;
            GameServer.BlackMarketManager.RemoveListing(listing);
            DatabaseManager.BlackMarketListings.Delete(listing.Id);
            removeListing = true;
        }
        else
        {
            listing.Item.Amount -= amount;
            Item newItem = new(listing.Item)
            {
                Amount = amount
            };
            newItem.Uid   = DatabaseManager.Items.Insert(newItem);
            purchasedItem = newItem;
        }

        purchasedItem.DecreaseTradeCount();

        MailHelper.BlackMarketTransaction(purchasedItem, listing, session.Player.CharacterId, listing.Price, removeListing);
        session.Send(BlackMarketPacket.Purchase(listingId, amount));
    }
Example #7
0
            /* Write */
            public long CreateBlackMarketListing(BlackMarketListing listing)
            {
                var dbListing = new Maple2.Sql.Model.BlackMarketListing();

                // Perform lookup for item if it exists, so we UPDATE instead of ADD
                dbListing.Item         = context.Item.Find(listing.Item.Id) ?? new Maple2.Sql.Model.Item();
                dbListing.Item.OwnerId = 100; // 100 = BlackMarket

                storage.blackMarketListingConverter.ToModel(listing, dbListing);
                context.BlackMarketListing.Add(dbListing);
                return(context.TrySaveChanges() ? dbListing.Id : -1);
            }
Example #8
0
 public long Insert(BlackMarketListing listing)
 {
     return(QueryFactory.Query(TableName).InsertGetId <long>(new
     {
         listing_timestamp = listing.ListedTimestamp,
         expiry_timestamp = listing.ExpiryTimestamp,
         price = listing.Price,
         deposit = listing.Deposit,
         listed_quantity = listing.ListedQuantity,
         item_uid = listing.Item.Uid,
         owner_account_id = listing.OwnerAccountId,
         owner_character_id = listing.OwnerCharacterId
     }));
 }
Example #9
0
 private static void WriteListing(PacketWriter pWriter, BlackMarketListing listing)
 {
     pWriter.WriteLong(listing.Id);
     pWriter.WriteLong(listing.ListedTimestamp);
     pWriter.WriteLong(listing.ListedTimestamp);
     pWriter.WriteLong(listing.ExpiryTimestamp);
     pWriter.WriteInt(listing.Item.Amount);
     pWriter.WriteInt();
     pWriter.WriteLong(listing.Price);
     pWriter.WriteByte(); // discontinued bool
     pWriter.WriteLong(listing.Item.Uid);
     pWriter.WriteInt(listing.Item.Id);
     pWriter.WriteByte((byte)listing.Item.Rarity);
     pWriter.WriteLong(listing.OwnerAccountId);
     pWriter.WriteItem(listing.Item);
 }
Example #10
0
    private static void HandleCancelListing(GameSession session, PacketReader packet)
    {
        long listingId = packet.ReadLong();

        BlackMarketListing listing = GameServer.BlackMarketManager.GetListingById(listingId);

        if (listing == null)
        {
            return;
        }

        if (listing.OwnerCharacterId != session.Player.CharacterId)
        {
            return;
        }

        DatabaseManager.BlackMarketListings.Delete(listingId);
        GameServer.BlackMarketManager.RemoveListing(listing);
        session.Send(BlackMarketPacket.CancelListing(listing, false));
        MailHelper.BlackMarketCancellation(listing);
    }
Example #11
0
    private static void SendBlackMarketSoldMail(BlackMarketListing listing, Item item, long price, bool removeListing)
    {
        float salesFeeRate = float.Parse(ConstantsMetadataStorage.GetConstant("BlackMarketSalesFeeRate"));
        long  tax          = (long)(salesFeeRate * (item.Amount * price));
        long  revenue      = item.Amount * price - tax;

        string senderName    = "<ms2><v key=\"s_blackmarket_mail_to_sender\" /></ms2>";
        string title         = "<ms2><v key=\"s_blackmarket_mail_to_seller_title\" /></ms2>";
        string body          = "<ms2><v key=\"s_blackmarket_mail_to_seller_content\" /></ms2>";
        string addParameter1 = $"<ms2><v item=\"{item.Id}\" ></v></ms2>";
        string addParameter2 = $"<ms2><v item=\"{item.Id}\" ></v><v str=\"{item.Amount}\" ></v><v money=\"{price * item.Amount}\" ></v><v money=\"{price}\" ></v><v money=\"{tax}\" ></v><v str=\"{salesFeeRate * 100}%\" ></v><v money=\"{revenue}\" ></v></ms2>";

        if (removeListing)
        {
            revenue      += listing.Deposit;
            body          = "<ms2><v key=\"s_blackmarket_mail_to_seller_content_soldout\" /></ms2>";
            addParameter2 = $"<ms2><v item=\"{item.Id}\" ></v><v str=\"{item.Amount}\" ></v><v money=\"{price * item.Amount}\" ></v><v money=\"{price}\" ></v><v money=\"{tax}\" ></v><v str=\"{salesFeeRate * 100}%\" ></v><v money=\"{listing.Deposit}\" ></v><v money=\"{revenue}\" ></v></ms2>";
        }

        Mail mail = new(MailType.BlackMarketSale, listing.OwnerCharacterId, 0, senderName, title, body, addParameter1, addParameter2, new(), revenue, 0);

        GameServer.MailManager.AddMail(mail);
        SendNotification(mail);
    }
 public void RemoveListing(BlackMarketListing listing)
 {
     Listings.Remove(listing.Id);
 }
 public void AddListing(BlackMarketListing listing)
 {
     Listings.Add(listing.Id, listing);
 }