Exemple #1
0
        public void CancelAuction(Character chr, NPC auctioneer, uint auctionId)
        {
            if (!DoAuctioneerInteraction(chr, auctioneer))
            {
                return;
            }
            Auction auction;

            if (auctioneer.AuctioneerEntry.Auctions.TryGetAuction(auctionId, out auction))
            {
                if ((int)auction.OwnerLowId == (int)chr.EntityId.Low)
                {
                    ItemRecord recordById = ItemRecord.GetRecordByID(auction.ItemLowId);
                    if (recordById != null)
                    {
                        if ((int)auction.BidderLowId != (int)auction.OwnerLowId)
                        {
                            uint amount = CalcAuctionCut(auction.HouseFaction, auction.CurrentBid);
                            if (chr.Money < amount)
                            {
                                AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                                        AuctionAction.CancelAuction, AuctionError.NotEnoughMoney);
                                return;
                            }

                            auction.SendMail(MailAuctionAnswers.CancelledToBidder, auction.CurrentBid);
                            chr.SubtractMoney(amount);
                        }

                        auction.SendMail(MailAuctionAnswers.Cancelled, recordById);
                        auctioneer.AuctioneerEntry.Auctions.RemoveAuction(auction);
                        AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                                AuctionAction.CancelAuction, AuctionError.Ok);
                        auctioneer.AuctioneerEntry.Auctions.RemoveAuction(auction);
                    }
                    else
                    {
                        AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                                AuctionAction.CancelAuction, AuctionError.ItemNotFound);
                    }
                }
                else
                {
                    AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                            AuctionAction.CancelAuction, AuctionError.ItemNotFound);
                }
            }
            else
            {
                AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                        AuctionAction.CancelAuction, AuctionError.ItemNotFound);
            }
        }
Exemple #2
0
        public void AuctionPlaceBid(Character chr, NPC auctioneer, uint auctionId, uint bid)
        {
            if (!DoAuctioneerInteraction(chr, auctioneer))
            {
                return;
            }
            Auction auction = null;

            if (!auctioneer.AuctioneerEntry.Auctions.TryGetAuction(auctionId, out auction))
            {
                AuctionHandler.SendAuctionCommandResult(chr.Client, null,
                                                        AuctionAction.PlaceBid, AuctionError.InternalError);
            }
            else
            {
                AuctionError error = AuctionBidChecks(auction, chr, bid);
                if (error != AuctionError.Ok)
                {
                    AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                            AuctionAction.PlaceBid, error);
                }
                else if (bid < auction.BuyoutPrice || auction.BuyoutPrice == 0U)
                {
                    if (auction.BidderLowId == (long)(ulong)chr.EntityId)
                    {
                        chr.SubtractMoney(bid - auction.CurrentBid);
                    }
                    else
                    {
                        chr.SubtractMoney(bid);
                        SendOutbidMail(auction, bid);
                    }

                    auction.BidderLowId = chr.EntityId.Low;
                    auction.CurrentBid  = bid;
                    AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                            AuctionAction.PlaceBid, AuctionError.Ok);
                }
                else
                {
                    if (auction.BidderLowId == (long)(ulong)chr.EntityId)
                    {
                        chr.SubtractMoney(auction.BuyoutPrice - auction.CurrentBid);
                    }
                    else
                    {
                        chr.SubtractMoney(auction.BuyoutPrice);
                        if ((int)auction.BidderLowId != (int)auction.OwnerLowId)
                        {
                            SendOutbidMail(auction, auction.BuyoutPrice);
                        }
                    }

                    auction.BidderLowId = chr.EntityId.Low;
                    auction.CurrentBid  = auction.BuyoutPrice;
                    SendAuctionSuccessfullMail(auction);
                    SendAuctionWonMail(auction);
                    AuctionHandler.SendAuctionCommandResult(chr.Client, auction,
                                                            AuctionAction.PlaceBid, AuctionError.Ok);
                    auctioneer.AuctioneerEntry.Auctions.RemoveAuction(auction);
                }
            }
        }
Exemple #3
0
        public void AuctionPlaceBid(Character chr, NPC auctioneer, uint auctionId, uint bid)
        {
            if (!DoAuctioneerInteraction(chr, auctioneer))
            {
                return;
            }

            Auction auction = null;

            if (!auctioneer.AuctioneerEntry.Auctions.TryGetAuction(auctionId, out auction))
            {
                AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.PlaceBid, AuctionError.InternalError);
                return;
            }

            var msg = AuctionBidChecks(auction, chr, bid);

            if (msg != AuctionError.Ok)
            {
                AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.PlaceBid, msg);
                return;
            }

            if (bid < auction.BuyoutPrice || (auction.BuyoutPrice == 0))
            {
                if (auction.BidderLowId == chr.EntityId)
                {
                    chr.Money -= (bid - auction.CurrentBid);
                }
                else
                {
                    chr.Money -= bid;

                    // Send a mail to the outbid character with their bid money
                    SendOutbidMail(auction, bid);
                }

                auction.BidderLowId = chr.EntityId.Low;
                auction.CurrentBid  = bid;

                AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.PlaceBid, AuctionError.Ok);
            }
            else
            {
                // This is a buyout
                if (auction.BidderLowId == chr.EntityId)
                {
                    chr.Money -= (auction.BuyoutPrice - auction.CurrentBid);
                }
                else
                {
                    chr.Money -= auction.BuyoutPrice;
                    if (auction.BidderLowId != auction.OwnerLowId)
                    {
                        // Someone had already bid on this item, send them a rejection letter
                        SendOutbidMail(auction, auction.BuyoutPrice);
                    }
                }
                auction.BidderLowId = chr.EntityId.Low;
                auction.CurrentBid  = auction.BuyoutPrice;

                SendAuctionSuccessfullMail(auction);
                SendAuctionWonMail(auction);

                AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.PlaceBid, AuctionError.Ok);

                auctioneer.AuctioneerEntry.Auctions.RemoveAuction(auction);
            }
        }
Exemple #4
0
        public void CancelAuction(Character chr, NPC auctioneer, uint auctionId)
        {
            if (!DoAuctioneerInteraction(chr, auctioneer))
            {
                return;
            }

            Auction auction;

            if (auctioneer.AuctioneerEntry.Auctions.TryGetAuction(auctionId, out auction))
            {
                if (auction.OwnerLowId == chr.EntityId.Low)
                {
                    var itemRecord = ItemRecord.GetRecordByID(auction.ItemLowId);
                    if (itemRecord != null)
                    {
                        if (auction.BidderLowId != auction.OwnerLowId)
                        {
                            // someone has bid on the item already, his money must be returned
                            // and the cancelling player must be charged the auctionhouse's cut
                            var auctionhouseCut = CalcAuctionCut(auction.HouseFaction, auction.CurrentBid);
                            if (chr.Money < auctionhouseCut)
                            {
                                // the player is no-good for the money, the auction cannot be cancelled
                                AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.CancelAuction, AuctionError.NotEnoughMoney);
                                return;
                            }

                            //var bidder = WorldMgr.GetCharacter(auction.BidderLowId);
                            //if (bidder != null)
                            //{
                            // send bidder a notification?
                            //}
                            auction.SendMail(MailAuctionAnswers.CancelledToBidder, auction.CurrentBid);
                            chr.Money -= auctionhouseCut;
                        }

                        // return the item to the seller via mail
                        auction.SendMail(MailAuctionAnswers.Cancelled, itemRecord);
                        auctioneer.AuctioneerEntry.Auctions.RemoveAuction(auction);
                    }
                    else
                    {
                        // auction contains a non-existant item
                        AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.CancelAuction, AuctionError.ItemNotFound);
                        return;
                    }
                }
                else
                {
                    // trying to cancel someone else's auction -- CHEATER!
                    AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.CancelAuction, AuctionError.ItemNotFound);
                    return;
                }
            }
            else
            {
                // auction not found -- CHEATER?
                AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.CancelAuction, AuctionError.ItemNotFound);
                return;
            }

            AuctionHandler.SendAuctionCommandResult(chr.Client, auction, AuctionAction.CancelAuction, AuctionError.Ok);
            auctioneer.AuctioneerEntry.Auctions.RemoveAuction(auction);
        }
Exemple #5
0
        public void AuctionSellItem(Character chr, NPC auctioneer, EntityId itemId, uint bid, uint buyout, uint time, uint stackSize)
        {
            if (!DoAuctioneerInteraction(chr, auctioneer))
            {
                return;
            }

            var item = chr.Inventory.GetItem(itemId, false);

            var msg = AuctionCheatChecks(auctioneer, item, bid, time);

            if (msg == AuctionError.Ok)
            {
                // Check that character has enough money to cover the deposit
                var houseFaction = auctioneer.AuctioneerEntry.LinkedHouseFaction;
                var deposit      = GetAuctionDeposit(item, houseFaction, time);
                if (chr.Money < deposit)
                {
                    AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.SellItem, AuctionError.NotEnoughMoney);
                    return;
                }

                if (item.Amount > stackSize)
                {
                    item = item.Split((int)stackSize);
                }

                if (item == null)
                {
                    AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.SellItem, AuctionError.ItemNotFound);
                    return;
                }


                // Charge the deposit to the character
                chr.Money -= deposit;


                // Create the new Auction and add it to the list.

                var newAuction = new Auction
                {
                    BidderLowId    = 0,
                    BuyoutPrice    = buyout,
                    CurrentBid     = bid,
                    Deposit        = deposit,
                    HouseFaction   = houseFaction,
                    ItemLowId      = item.EntityId.Low,
                    ItemTemplateId = item.Template.Id,
                    OwnerLowId     = chr.EntityId.Low,
                    TimeEnds       = DateTime.Now.AddMinutes(time),
                    IsNew          = true
                };



                //save new auction to database and add item to items container
                RealmServer.IOQueue.AddMessage(new Util.Threading.Message(() =>
                {
                    ItemRecord record  = item.Record;
                    record.IsAuctioned = true;
                    record.Save();
                    auctioneer.AuctioneerEntry.Auctions.AddAuction(
                        newAuction);
                    AuctionItems.Add(newAuction.ItemLowId, record);
                    item.Remove(false);
                    AuctionListOwnerItems(chr, auctioneer);
                }));

                // Send the all-good message
                AuctionHandler.SendAuctionCommandResult(chr.Client, newAuction, AuctionAction.SellItem, AuctionError.Ok);
            }
            else
            {
                AuctionHandler.SendAuctionCommandResult(chr.Client, null, AuctionAction.SellItem, msg);
            }
        }