public static void CheckAuctionWinner(Game g) { var count = g.Players.Count(x => x.InAuction); if (count == 0 || (g.currAuction.LastBiddedPlayer != null && count == 1)) g.currAuction.IsFinished = true; if (g.currAuction.IsFinished) { var last = g.currAuction.LastBiddedPlayer; if (last != null) { if (BotBrain.MortgageSell(g, last, g.currAuction.currBid)) { g.Tlog("Game.CheckAuctionWinner.Winner", "@p{0} выиграл", "@p{0} winner", last.Id); //set winner GameManager.SetAuctionWinner(g); } } //g.Tlog("Game.CheckAuctionWinner.FinishStepForBot", "FinishStepForBot", "FinishStepForBot"); g.FinishStep(); } }
public static void MakeStep(Game g, bool needRoll = true) { //g.logp("rolls {0} {1}", g.LastRoll); if (g.State != GameState.BeginStep) return; var p = g.Curr; if (p.IsBot && BotBrain.BeforeRollMakeBotAction(g)) return; g.CleanTimeOut(); if (needRoll) GameManager.MakeRoll(g); bool CanGo = true; if (p.Pos == 10 && p.Police > 0) { CanGo = CanOutFromPolice(g); if (p.Police == 4) return; } if (CanGo) { var NotTrippleRoll = g.Curr.Step(); if (NotTrippleRoll) { ProcessPosition(g); } else { g.Tlogp("step.TripleRoll", "вы выкинули тройной дубль, вас задержала милиция", "you roll triple, go to POLICE"); g.FinishStep(); } } else { g.FinishStep(); } }
public static void Buy(Game g) { if (g.State != GameState.CanBuy) return; var p = g.Curr; var cell = g.CurrCell; if (cell.IsLand) { if (cell.Owner == null) { //--buy var ff = BotBrain.FactorOfBuy(g, p, cell); bool needBuy = ff >= 1; if (p.IsBot) { if (ff >= 1 && p.Money < cell.Cost) needBuy = BotBrain.MortgageSell(g, cell.Cost); } else { if (p.Money < cell.Cost) { g.ToCantPay(); return; } } if (needBuy) { g.Map.SetOwner(p, cell); g.Tlogp("PlayerAction.Bought", "вы купили {0} за {1}", "You bought {0} for {1}", cell.Name, cell.Cost.PrintMoney()); g.FinishStep(string.Format("bought_{0}_f({1})", cell.Id, ff)); } else { g.ToAuction(); } } } }
public static bool Pay(Game g, bool needFinish = true) { //if (g.State != GameState.NeedPay) return ; var curr = g.Curr; var amount = g.PayAmount; //if (amount == 0) return true; var ok = curr.IsBot ? BotBrain.MortgageSell(g, curr, amount) : curr.Money > amount; if (ok) { curr.Money -= amount; if (g.PayToUserId.HasValue) { var to = g.GetPlayer(g.PayToUserId.Value); to.Money += amount; g.PayToUserId = null; } if (needFinish) g.FinishStep("paid_" + g.PayAmount.PrintMoney()); else g.SetState(GameState.BeginStep); g.PayAmount = 0; return true; } else { g.Tlogp("PlayerAction.PayAmount", "не хватает денег", "not enough money"); g.ToCantPay(); } return false; }
public static void MoveAfterRandom(Game g) { var c = g.LastRandomCard; var p = g.Curr; if (c.RandomGroup == 2 && c.Pos == 10) { p.Pos = 10; p.Police = 1; g.Tlogp("MoveAfterRandom.GoToPolice", "вы попали в тюрьму", "go To Police"); g.FinishStep(); } else { if (c.RandomGroup == 3) { g.Tlogp("MoveAfterRandom.Go3Back", "на три хода назад", "go 3 step back"); if (p.Pos > 3) p.Pos -= 3; } else { g.Tlogp("MoveAfterRandom.goToCell", "вам нужно на клетку {0}", "go To Cell {0}", c.Pos); if (p.Pos > c.Pos) { p.Money += 2000000; g.Tlogp("MoveAfterRandom.GoPass", "вы прошли через старт и получили 2M$", "get 2M$ "); } p.Pos = c.Pos; } PlayerStep.ProcessPosition(g); } }
public static void ProcessPosition(Game g) { var p = g.Curr; //general land var cell = g.Cells[p.Pos]; if (cell.IsLand) { ProcessLand(g, p, cell); } //interpol if (p.Pos == 30) { PlayerStep.MoveFrom30(g); //g.MoveToCell(); } // tax if (cell.Type == 6) { //g.logp(g.Text("ProcessPosition.PayTax", "заплатите налог", "you need pay tax ")); g.ToPay(cell.Rent); } //var offPos = new[] { 2, 7, 17, 22, 33, 36 }; if (cell.Type == 4) { g.Map.TakeRandomCard(); g.FixAction("random"); ProcessRandom(g, p); } else if (p.Pos == 20 || p.Pos == 0 || (p.Pos == 10 && p.Police == 0)) g.FinishStep("cell_" + p.Pos); }
public static void ProcessLand(Game g, Player p, CellInf cell) { if (cell.Owner == null) { g.ToCanBuy(); } else if (cell.Owner != p.Id) { if (cell.IsMortgage) { g.Tlogp("ProcessLand.CellIsMortgaged", "земля {0} заложена", "land {0} is mortgaged ", cell.Name); g.FinishStep("cell_mortgaged"); } else { //pay rent g.PayToUserId = cell.Owner.Value; g.ToPay(cell.Rent); } } else if (cell.Owner == p.Id) { g.Tlogp("ProcessLand.MyCell", "ваше поле {0}", "your cell {0} ", cell.Name); g.FinishStep("mycell"); } }
public static void MoveFrom30(Game g) { var p = g.Curr; if (p.Pos == 30) { p.Pos = 10; p.Police = 1; g.Tlogp("ProcessPosition.Police30", "вас задержал интерпол", "go to POLICE"); g.FinishStep(); } }
public static string Go(Game g, string act, string userName) { string res = ""; if (act == "ok") g.FinishStep(); if (g.Curr.CaughtByPolice) { if (act == "policekey") { g.Curr.FreePoliceKey--; g.Curr.Police = 0; g.ToBeginRound(); } else PlayerAction.PayToPolice(g); } if (g.State == GameState.CanBuy || g.State == GameState.CantPay) { if (act == "auc") { g.ToAuction(); res = GameRender.RenderAuction(g, userName); } else { PlayerAction.Buy(g); } } if (g.State == GameState.Auction) { if (act == "auc_y") { PlayerAction.MakeAuctionYes(g, userName); } else if (act == "auc_no") { PlayerAction.MakeAuctionNo(g, userName); } //LogicBot.CheckAuctionJob(g); } if (g.State == GameState.NeedPay) PlayerAction.Pay(g); if (g.State == GameState.CantPay) { PlayerAction.Pay(g); if (g.Curr.IsBot) { g.Tlogp("LeaveGame", "вы банкрот и покидаете игру", "you are bankrupt"); GameManager.LeaveGame(g, g.Curr.Name); } else { res = g.Text("go.CannotPay", "у вас нет денег, попробуйте заложить или продать <br />", "you dont have money,try mortage <br />"); res += "<br />" + GameRender.UIParts("ButtonPay"); } //PlayerAction.Pay(g); } if (g.State == GameState.Trade) { PlayerAction.MakeTrade(g, userName, act == "tr_y"); } if (g.State == GameState.MoveToCell) { if (g.Curr.Pos == 30) PlayerStep.MoveFrom30(g); else PlayerStep.MoveAfterRandom(g); } if (g.State == GameState.EndStep) { g.FinishRound(); } return res; }