public static bool CanOutFromPolice(Game g) { var p = g.Curr; bool rollDouble = p.LastRoll[0] == p.LastRoll[1]; if (rollDouble) return true; if (p.IsBot && BotBrain.ShouldGoFromPolice(g)) { g.Tlogp("step.PoliceOut", "заплатил 500 k$, чтобы выйти", "you paid 500 k$ to out"); PlayerAction.Pay(g, 500000); return true; } else { p.Police++; if (p.Police == 4) { g.Tlogp("ProcessPolice.PoliceOut", "заплатите 500 k$, чтобы выйти", "you need pay 500 k$ to out"); g.PayAmount = 500000; g.ToPay(false); return true; } else { g.Tlogp("ProcessPolice.PoliceCatch", "вы можете заплатить и выйти ", "you can pay 500 k$ and out"); return false; } } return false; }
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 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 PayToPolice(Game g) { var p = g.Curr; var cell = g.Cells[p.Pos]; if (p.CaughtByPolice) { g.Tlogp("PlayerAction.Pay.PayPolice", "заплатил за выход", "you paid for exit"); if (p.Police == 4) { if (Pay(g, 500000)) { p.Police = 0; g.Curr.Step(); PlayerStep.ProcessPosition(g); } } else { p.Police = 0; Pay(g, 500000); g.ToBeginRound(); } } }
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 bool MakeTrade(Game g, string userName, bool isYes) { if (g.CurrTrade.to.Id == g.GetPlayer(userName).Id && isYes) { GameManager.MakeTrade(g); return true; } else { GameManager.AddToRejectedTrades(g); g.Tlogp("PlayerAction.Trade.AddToRej", "к игнорируемым {0}", "added to rejected trades {0}", g.CurrTrade.ToString()); g.ToBeginRound(); 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 ProcessRandom(Game g, Player p) { var c = g.LastRandomCard; //get money if (c.RandomGroup == 1) { p.Money += c.Money; g.Tlogp("ProcessRandom.Random1.GetMoney", "получите {0}", "get money = {0}", c.Money.PrintMoney()); g.ToRandomCell(); } //go to cell if (c.RandomGroup == 2 || c.RandomGroup == 3) { g.MoveToCell(); } //pay each player if (c.RandomGroup == 4) { g.Tlogp("ProcessRandom.PayEachPlayer", "заплатите каждому игроку 500K", "pay each player 500K"); g.PayAmount = c.Money * (g.pcount - 1); g.Players.Where(x => x.Id != p.Id).ToList().ForEach(x => x.Money += c.Money); g.ToPay(); } //key to out from police if (c.RandomGroup == 5) { p.FreePoliceKey++; g.ToRandomCell(); } if (c.RandomGroup == -1) { g.Tlogp("ProcessRandom.PayBank", "заплатите банку", "pay to bank"); g.ToPay(c.Money); } //pay for each house and hotel if (c.RandomGroup == 15) { g.Tlogp("ProcessRandom.FixHouses", "Отремонтируйте ваши здания – $100K за дом, $400K за отель", "You are assessed for street repairs – $100K per house, $400K per hotel"); var hh = g.Map.GetHotelsAndHousesCount(p.Id); g.PayAmount = hh[0] * 400000 + hh[1] * 100000; g.ToPay(); } }
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; }