Ejemplo n.º 1
0
        public bool LoadFromDB(SQLFields fields)
        {
            _marketId = fields.Read <uint>(0);

            // Invalid MarketID
            BlackMarketTemplate templ = Global.BlackMarketMgr.GetTemplateByID(_marketId);

            if (templ == null)
            {
                Log.outError(LogFilter.Misc, "Black market auction {0} does not have a valid id.", _marketId);
                return(false);
            }

            _currentBid       = fields.Read <ulong>(1);
            _secondsRemaining = (uint)(fields.Read <uint>(2) - Global.BlackMarketMgr.GetLastUpdate());
            _numBids          = fields.Read <uint>(3);
            _bidder           = fields.Read <ulong>(4);

            // Either no bidder or existing player
            if (_bidder != 0 && ObjectManager.GetPlayerAccountIdByGUID(ObjectGuid.Create(HighGuid.Player, _bidder)) == 0) // Probably a better way to check if player exists
            {
                Log.outError(LogFilter.Misc, "Black market auction {0} does not have a valid bidder (GUID: {1}).", _marketId, _bidder);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void BuildItemsResponse(BlackMarketRequestItemsResult packet, Player player)
        {
            packet.LastUpdateID = (int)_lastUpdate;
            foreach (var pair in _auctions)
            {
                BlackMarketTemplate templ = pair.Value.GetTemplate();

                BlackMarketItem item = new();
                item.MarketID  = pair.Value.GetMarketId();
                item.SellerNPC = templ.SellerNPC;
                item.Item      = templ.Item;
                item.Quantity  = templ.Quantity;

                // No bids yet
                if (pair.Value.GetNumBids() == 0)
                {
                    item.MinBid       = templ.MinBid;
                    item.MinIncrement = 1;
                }
                else
                {
                    item.MinIncrement = pair.Value.GetMinIncrement(); // 5% increment minimum
                    item.MinBid       = pair.Value.GetCurrentBid() + item.MinIncrement;
                }

                item.CurrentBid       = pair.Value.GetCurrentBid();
                item.SecondsRemaining = pair.Value.GetSecondsRemaining();
                item.HighBid          = (pair.Value.GetBidder() == player.GetGUID().GetCounter());
                item.NumBids          = pair.Value.GetNumBids();

                packet.Items.Add(item);
            }
        }
Ejemplo n.º 3
0
        public void LoadTemplates()
        {
            uint oldMSTime = Time.GetMSTime();

            // Clear in case we are reloading
            _templates.Clear();

            SQLResult result = DB.World.Query("SELECT marketId, sellerNpc, itemEntry, quantity, minBid, duration, chance, bonusListIDs FROM blackmarket_template");

            if (result.IsEmpty())
            {
                Log.outInfo(LogFilter.ServerLoading, "Loaded 0 black market templates. DB table `blackmarket_template` is empty.");
                return;
            }

            do
            {
                BlackMarketTemplate templ = new BlackMarketTemplate();

                if (!templ.LoadFromDB(result.GetFields())) // Add checks
                {
                    continue;
                }

                AddTemplate(templ);
            } while (result.NextRow());

            Log.outInfo(LogFilter.ServerLoading, "Loaded {0} black market templates in {1} ms.", _templates.Count, Time.GetMSTimeDiffToNow(oldMSTime));
        }
Ejemplo n.º 4
0
        public void SendAuctionWonMail(BlackMarketEntry entry, SQLTransaction trans)
        {
            // Mail already sent
            if (entry.GetMailSent())
            {
                return;
            }

            uint       bidderAccId;
            ObjectGuid bidderGuid = ObjectGuid.Create(HighGuid.Player, entry.GetBidder());
            Player     bidder     = Global.ObjAccessor.FindConnectedPlayer(bidderGuid);
            // data for gm.log
            string bidderName = "";
            bool   logGmTrade;

            if (bidder)
            {
                bidderAccId = bidder.GetSession().GetAccountId();
                bidderName  = bidder.GetName();
                logGmTrade  = bidder.GetSession().HasPermission(RBACPermissions.LogGmTrade);
            }
            else
            {
                bidderAccId = Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(bidderGuid);
                if (bidderAccId == 0) // Account exists
                {
                    return;
                }

                logGmTrade = Global.AccountMgr.HasPermission(bidderAccId, RBACPermissions.LogGmTrade, Global.WorldMgr.GetRealmId().Index);

                if (logGmTrade && !Global.CharacterCacheStorage.GetCharacterNameByGuid(bidderGuid, out bidderName))
                {
                    bidderName = Global.ObjectMgr.GetCypherString(CypherStrings.Unknown);
                }
            }

            // Create item
            BlackMarketTemplate templ = entry.GetTemplate();
            Item item = Item.CreateItem(templ.Item.ItemID, templ.Quantity, ItemContext.BlackMarket);

            if (!item)
            {
                return;
            }

            if (templ.Item.ItemBonus.HasValue)
            {
                foreach (uint bonusList in templ.Item.ItemBonus.Value.BonusListIDs)
                {
                    item.AddBonuses(bonusList);
                }
            }

            item.SetOwnerGUID(bidderGuid);

            item.SaveToDB(trans);

            // Log trade
            if (logGmTrade)
            {
                Log.outCommand(bidderAccId, "GM {0} (Account: {1}) won item in blackmarket auction: {2} (Entry: {3} Count: {4}) and payed gold : {5}.",
                               bidderName, bidderAccId, item.GetTemplate().GetName(), item.GetEntry(), item.GetCount(), entry.GetCurrentBid() / MoneyConstants.Gold);
            }

            if (bidder)
            {
                bidder.GetSession().SendBlackMarketWonNotification(entry, item);
            }

            new MailDraft(entry.BuildAuctionMailSubject(BMAHMailAuctionAnswers.Won), entry.BuildAuctionMailBody())
            .AddItem(item)
            .SendMailTo(trans, new MailReceiver(bidder, entry.GetBidder()), new MailSender(entry), MailCheckMask.Copied);

            entry.MailSent();
        }
Ejemplo n.º 5
0
 public void AddTemplate(BlackMarketTemplate templ)
 {
     _templates[templ.MarketID] = templ;
 }