Example #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);
            }
            }
        }
Example #2
0
        public void End_Match(bool foundWinner = false)
        {
            bool   failed      = false;
            string matchResult = "";

            if (foundWinner)
            {
                LMS_Rank     lmsRank       = null;
                PlayerObject winningPlayer = null;
                for (int i = 0; i < CurrentMap.Players.Count; i++)
                {
                    PlayerObject player = CurrentMap.Players[i];
                    if (player == null ||
                        player.Dead)
                    {
                        continue;
                    }
                    for (int x = 0; x < PlayerRanks.Count; x++)
                    {
                        if (player.Name == PlayerRanks[x].Player.Name &&
                            winningPlayer == null &&
                            lmsRank == null)
                        {
                            winningPlayer = player;
                            lmsRank       = PlayerRanks[x];
                        }
                    }
                }
                if (winningPlayer != null &&
                    lmsRank != null)
                {
                    //  TODO Reward players (send by mail)
                    matchResult = string.Format("{0} is the Victor of the match!", winningPlayer.Name);

                    winningPlayer.Teleport(Envir.GetMap(winningPlayer.BindMapIndex), winningPlayer.BindLocation, true, 0);
                    winningPlayer.InLMSBR = false;
                    List <LMS_RewardInfo> rewards = CreateRewards(1, winningPlayer);
                    if (rewards != null &&
                        rewards.Count > 0)
                    {
                        winningPlayer.ReceiveChat(string.Format("Victory is yours! Prize(s) will be sent via mail!"), ChatType.Hint);
                        List <UserItem> items = new List <UserItem>();
                        for (int i = 0; i < rewards.Count; i++)
                        {
                            if (rewards[i].ItemReward == null)
                            {
                                SMain.EnqueueDebugging(string.Format("Null reward"));
                                continue;
                            }
                            ItemInfo iInfo = Envir.GetItemInfo(rewards[i].ItemReward.Index);
                            if (iInfo == null)
                            {
                                SMain.EnqueueDebugging(string.Format("Null item info"));
                                continue;
                            }
                            UserItem item = Envir.CreateFreshItem(iInfo);
                            if (item != null)
                            {
                                items.Add(item);
                            }
                        }
                        MailInfo mail = new MailInfo(winningPlayer.Info.Index)
                        {
                            Items   = items,
                            Message = string.Format("Congratulations on winning the match! here is your prize(s)"),
                            Sender  = string.Format("LMS"),
                            MailID  = ++Envir.NextMailID
                        };
                        mail.Send();
                    }
                    SMain.EnqueueDebugging(string.Format("[LMS BR] Map {0} {1} wins the Match, made {2} kills.", CurrentMap.Info.Title, winningPlayer.Name, lmsRank.Kills));
                }
                else
                {
                    failed = true;
                }
            }
            if ((failed && foundWinner) || !foundWinner)
            {
                if (CurrentMap.Players.Count > 0)
                {
                    string[] finalPlayers = new string[CurrentMap.Players.Count];
                    if (finalPlayers.Length >= 1)
                    {
                        int index = 0;
                        for (int i = 0; i < CurrentMap.Players.Count; i++)
                        {
                            PlayerObject player = CurrentMap.Players[i];
                            if (player.Dead ||
                                player.IsGM)
                            {
                                continue;
                            }
                            finalPlayers[index] = player.Name;
                            player.Teleport(Envir.GetMap(player.BindMapIndex), player.BindLocation);
                            player.InLMSBR = failed;
                            index++;
                        }
                        Array.Resize(ref finalPlayers, index);
                    }
                    matchResult = "Stalemate, Players ";
                    for (int i = 0; i < finalPlayers.Length; i++)
                    {
                        matchResult += string.Format("{0}{1} ", finalPlayers[i], i - 1 <= finalPlayers.Length ? "," : " have drawn the match!");
                    }
                }
            }

            if (matchResult.Length > 0)
            {
                Envir.Broadcast(new ServerPackets.Chat {
                    Message = matchResult, Type = ChatType.Announcement
                });
            }
            StartTime        = 0;
            EndTime          = 0;
            SignedupPlayers  = new List <PlayerObject>();
            CircleLocations  = new List <Point>();
            PlayerRanks      = new List <LMS_Rank>();
            StartingLocation = Info.StartingLocation;
            Stage            = 0;
            Finished         = false;
            Started          = false;
        }
Example #3
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);
        }