示例#1
0
        public bool MakeBid(uint myBid)
        {
            //  Range Check
            if (myBid <= 0 || myBid > uint.MaxValue)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Bid amount {0} out of range.", myBid));
                return(false);
            }
            //  Sellers cannot bid on their own items
            if (IsSeller)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Cannot bid on own item.", AuctionIndex));
                return(false);
            }
            AuctionHouseInfo ListedItem = Envir.GetAuction(AuctionIndex);

            //  Can't find the Auction
            if (ListedItem == null)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : {0} Index was not found.", AuctionIndex));
                return(false);
            }
            //  The Auctions ended
            if (SMain.Envir.Time > ListedItem.ListEndTime)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : {0} Auction has already finished.", AuctionIndex));
                return(false);
            }
            //  The Item up for Auction doesn't exist
            if (ListedItem.ListedItem == null)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : {0} Item not found.", AuctionIndex));
                return(false);
            }
            //  Bidder was the previous bidder
            if (ListedItem.HighestBidderIndex == PlayerIndex)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Already made bid."));
                return(false);
            }
            PlayerObject bidder = Envir.GetPlayer((uint)PlayerIndex);

            //  Can't find the player
            if (bidder == null)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer not found {0}.", PlayerIndex));
                return(false);
            }
            //  Can't find the players account
            if (bidder.Account == null)
            {
                SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Account not found {0}.", PlayerIndex));
                return(false);
            }
            uint   gold    = 0;
            string message = "";

            //  Switch between the currency
            switch (ListedItem.CurrencyType)
            {
            default:
            case CurrencyType.Gold:
            {
                //  Bid was more than the Account has
                if (bidder.Account.Gold < myBid)
                {
                    SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Not enough gold {0}.", myBid - bidder.Account.Gold));
                    return(false);
                }
                //  Bid was too low
                if (myBid <= ListedItem.CurrentBid + 1000)
                {
                    SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Bid is too low {0}.", myBid - ListedItem.CurrentBid));
                    return(false);
                }
                if (!FirstBid && !GoldRetrived)
                {
                    gold = MyBid;
                    //  Message contents.
                    message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid);
                    //  Create the mail
                    MailInfo mail = new MailInfo(PlayerIndex, true)
                    {
                        MailID  = ++Envir.NextMailID,
                        Sender  = "AuctionHouse",
                        Message = message,
                        Gold    = gold,
                    };
                    GoldRetrived = true;
                }

                MyBid = myBid;

                if (myBid >= bidder.Account.Gold)
                {
                    myBid = bidder.Account.Gold;
                }

                bidder.Account.Gold -= myBid;
                bidder.Enqueue(new S.LoseGold {
                        Gold = myBid
                    });

                ListedItem.CurrentBid         = myBid;
                ListedItem.HighestBidderIndex = PlayerIndex;

                GoldRetrived = false;

                bidder.ReceiveChat(string.Format("You bid {0:#,###,###,###} for {1}{2} has been placed.", MyBid, ListedItem.ListedItem.FriendlyName, ListedItem.ListedItem.Count >= 1 ? string.Format("[{0}]", ListedItem.ListedItem.Count) : ""), ChatType.System);
                if (FirstBid)
                {
                    FirstBid = false;
                }
                return(true);
            }

            case CurrencyType.Credits:
            {
                if (bidder.Account.Credit < myBid)
                {
                    SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Not enough credit {0}.", myBid - bidder.Account.Credit));
                    return(false);
                }
                //  Only allow Increments of 1k
                if (myBid <= ListedItem.CurrentBid + 5)
                {
                    SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Bid is too low {0}.", myBid - ListedItem.CurrentBid));
                    return(false);
                }
                if (!FirstBid && !GoldRetrived)
                {
                    gold = MyBid;
                    //  Message contents.
                    message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid);
                    //  Create the mail
                    MailInfo mail = new MailInfo(PlayerIndex, true)
                    {
                        MailID  = ++Envir.NextMailID,
                        Sender  = "AuctionHouse",
                        Message = message,
                        Gold    = gold,
                    };
                    GoldRetrived = true;
                }

                MyBid = myBid;

                if (myBid >= bidder.Account.Credit)
                {
                    myBid = bidder.Account.Credit;
                }

                bidder.Account.Credit -= myBid;
                bidder.Enqueue(new S.LoseCredit {
                        Credit = myBid
                    });

                ListedItem.CurrentBid         = myBid;
                ListedItem.HighestBidderIndex = PlayerIndex;
                GoldRetrived = false;

                bidder.ReceiveChat(string.Format("You bid {0:#,###,###,###} for {1}{2} has been placed.", MyBid, ListedItem.ListedItem.FriendlyName, ListedItem.ListedItem.Count >= 1 ? string.Format("[{0}]", ListedItem.ListedItem.Count) : ""), ChatType.System);
                if (FirstBid)
                {
                    FirstBid = false;
                }
                return(true);
            }

            case CurrencyType.Pearl:
            {
                if (bidder.Info.PearlCount < myBid)
                {
                    SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Not enough pearl {0}.", myBid - bidder.Info.PearlCount));
                    return(false);
                }
                //  Only allow Increments of 1k
                if (myBid <= ListedItem.CurrentBid + 1)
                {
                    SMain.EnqueueDebugging(string.Format("[MakeBid(uint myBid)]Auction House Error : Buyer Bid is too low {0}.", myBid - ListedItem.CurrentBid));
                    return(false);
                }
                if (!FirstBid && !GoldRetrived)
                {
                    gold = MyBid;
                    //  Message contents.
                    message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid);
                    //  Create the mail
                    MailInfo mail = new MailInfo(PlayerIndex, true)
                    {
                        MailID  = ++Envir.NextMailID,
                        Sender  = "AuctionHouse",
                        Message = message,
                        Gold    = gold,
                    };
                    GoldRetrived = true;
                }

                MyBid = myBid;

                if (myBid >= bidder.Info.PearlCount)
                {
                    myBid = (uint)bidder.Info.PearlCount;
                }

                bidder.Info.PearlCount -= (int)myBid;

                ListedItem.CurrentBid         = myBid;
                ListedItem.HighestBidderIndex = PlayerIndex;

                GoldRetrived = false;

                bidder.ReceiveChat(string.Format("You bid {0:#,###,###,###} Pearl{2} for {1}{3} has been placed.", MyBid, ListedItem.ListedItem.FriendlyName, MyBid > 1 ? "s" : "", ListedItem.ListedItem.Count >= 1 ? string.Format("[{0}]", ListedItem.ListedItem.Count) : ""), ChatType.System);
                if (FirstBid)
                {
                    FirstBid = false;
                }
                return(true);
            }
            }
        }
示例#2
0
        public bool BuyNow()
        {
            //  Sellers cannot bid on their own items
            if (IsSeller)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Cannot bid on own item.", AuctionIndex));
                return(false);
            }
            AuctionHouseInfo ListedItem = Envir.GetAuction(AuctionIndex);

            //  Can't find the Auction
            if (ListedItem == null)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Index was not found.", AuctionIndex));
                return(false);
            }
            if (ListedItem.Sold)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction has already finished or been purchased.", AuctionIndex));
                return(false);
            }
            if (!ListedItem.CanBuyNow)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction is not Buy now.", AuctionIndex));
                return(false);
            }
            if (ListedItem.BuyNowPrice <= 0 || ListedItem.BuyNowPrice > uint.MaxValue)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction Buy now price out of range.", AuctionIndex));
                return(false);
            }
            //  The Auctions ended
            if (SMain.Envir.Time > ListedItem.ListEndTime)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Auction has already finished.", AuctionIndex));
                return(false);
            }
            //  The Item up for Auction doesn't exist
            if (ListedItem.ListedItem == null)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Item not found.", AuctionIndex));
                return(false);
            }
            PlayerObject bidder = Envir.GetPlayer((uint)PlayerIndex);

            //  Can't find the player
            if (bidder == null)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Buyer not found {0}.", PlayerIndex));
                return(false);
            }
            //  Can't find the players account
            if (bidder.Account == null)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Buyer Account not found {0}.", PlayerIndex));
                return(false);
            }
            PlayerObject seller = Envir.GetPlayer((uint)ListedItem.SellersIndex);

            if (seller == null)
            {
                SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : Sellers Account not found {0}.", PlayerIndex));
                return(false);
            }
            uint            gold    = 0;
            string          message = "";
            List <UserItem> items   = new List <UserItem>();

            switch (ListedItem.CurrencyType)
            {
            default:
            case CurrencyType.Gold:
            {
                if (bidder.Account.Gold < ListedItem.BuyNowPrice)
                {
                    SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Player does not have enough gold.", AuctionIndex));
                    return(false);
                }
                gold = ListedItem.BuyNowPrice;

                if (gold >= bidder.Account.Gold)
                {
                    gold = bidder.Account.Gold;
                }

                bidder.Account.Gold -= gold;
                bidder.Enqueue(new S.LoseGold {
                        Gold = gold
                    });
                items.Add(ListedItem.ListedItem);
                message = string.Format("You purchased {0} from {1} for {2:#,###,###,###}.", ListedItem.ListedItem.FriendlyName, seller.Name, ListedItem.BuyNowPrice);
                MailInfo mail = new MailInfo(PlayerIndex, false)
                {
                    Gold    = 0,
                    Message = message,
                    Items   = items,
                    Sender  = "AuctionHouse",
                    MailID  = ++Envir.NextMailID
                };
                mail.Send();
                mail = null;
                items.Add(ListedItem.ListedItem);
                message = string.Format("{0} purchased {1} from you for {2:#,###,###,###}.", bidder.Name, ListedItem.ListedItem.FriendlyName, ListedItem.BuyNowPrice);
                mail    = new MailInfo(PlayerIndex, false)
                {
                    Gold    = ListedItem.BuyNowPrice - (uint)Functions.GetPercentage(ListedItem.Commission, (int)ListedItem.BuyNowPrice),
                    Message = message,
                    Sender  = "AuctionHouse",
                    MailID  = ++Envir.NextMailID
                };
                mail.Send();
                mail = null;
                //  End it.
                ListedItem.ListedItem         = null;
                ListedItem.CurrentBid         = gold;
                ListedItem.HighestBidderIndex = PlayerIndex;
                ListedItem.ListEndTime        = Envir.Time;
                ListedItem.Sold = true;
                GoldRetrived    = true;

                /*
                 * gold = MyBid;
                 * //  Message contents.
                 * message = string.Format("{0:#,###,###,###} Gold has been returned to you.", MyBid);
                 * //  Create the mail
                 * MailInfo mail = new MailInfo(PlayerIndex, true)
                 * {
                 *  MailID = ++Envir.NextMailID,
                 *  Sender = "AuctionHouse",
                 *  Message = message,
                 *  Gold = gold,
                 * };
                 */
            }
            break;

            case CurrencyType.Credits:
            {
                if (bidder.Account.Credit < ListedItem.BuyNowPrice)
                {
                    SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Player does not have enough credits.", AuctionIndex));
                    return(false);
                }
            }
            break;

            case CurrencyType.Pearl:
            {
                if (bidder.Info.PearlCount < ListedItem.BuyNowPrice)
                {
                    SMain.EnqueueDebugging(string.Format("[BuyNow()]Auction House Error : {0} Player does not have enough pearls.", AuctionIndex));
                    return(false);
                }
            }
            break;
            }
            return(true);
        }