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; }