public ActionResult Show() { Combat.Log.Clear(); Generate generate = new Generate(Request); UnitFactory.StartUnitFactory(); DateTime startTime = DateTime.Now; Attackers attackers = new Attackers(generate); Defenders defenders = new Defenders(generate); int turns = attackers.Units.Count.BiggerThan(defenders.Units.Count)? attackers.Units.Count : defenders.Units.Count; int rounds = ReadIntFromRequest("rounds"); generate.HeroesPowers(turns, attackers, defenders); int i = 1; while (i <= rounds && defenders.Units.Count + defenders.Heroes.Count > 0 && attackers.Units.Count + attackers.Heroes.Count > 0) { Combat.Log.Add(string.Format("<h2>Round {0}</h2><p>Atacando: {1} unidades</p><p>Defendendo: {2} unidades</p>", i, attackers.Units.Count, defenders.Units.Count)); Combat.StartCombat(turns, attackers, defenders); #region LOG Combat.Log.Add(attackers.PV()); Combat.Log.Add(defenders.PV()); generate.RoundReport(i, attackers, defenders); #endregion #region RESET generate.RoundResetUnitLives(attackers.Units); generate.RoundResetUnitLives(defenders.Units); attackers.ResetHeroes(); defenders.ResetHeroes(); #endregion turns = attackers.Units.Count.BiggerThan(defenders.Units.Count)? attackers.Units.Count : defenders.Units.Count; generate.HeroesPowers(turns, attackers, defenders); i++; } DateTime finishTime = DateTime.Now; TimeSpan ts = finishTime.Subtract(startTime); ViewData["TimeSpent"] = ts; ViewData["Rounds"] = rounds; return View(); }
//private static void round_OnRoundExecution() //{ // Round.IsRunning = true; // System.Threading.Thread.Sleep(20000); // Round.IsRunning = false; //} private void round_OnRoundExecution() { Round.IsRunning = true; Game.Log.Clear(); World davi = World.Load(1); World golias = World.Load(2); Attackers attackers = new Attackers(); Defenders defenders = new Defenders(); int number = 1; attackers.Units = new List<Unit>(); Unit unit = null; Unit baseUnit = null; foreach (WorldUnits worldUnit in davi.Units) { baseUnit = Unit.Find(worldUnit.UnitId); if (baseUnit != null) { for (int j = 0; j < worldUnit.Quantity; j++) { unit = (Unit)baseUnit.Clone(); unit.Number = number; unit.PositionInCombat = Unit.CombatPosition.attacker; attackers.Units.Add(unit); number += 1; } } } number = 1; defenders.Units = new List<Unit>(); unit = null; baseUnit = null; foreach (WorldUnits worldUnit in golias.Units) { baseUnit = Unit.Find(worldUnit.UnitId); if (baseUnit != null) { for (int j = 0; j < worldUnit.Quantity; j++) { unit = (Unit)baseUnit.Clone(); unit.Number = number; unit.PositionInCombat = Unit.CombatPosition.defender; defenders.Units.Add(unit); number += 1; } } } attackers.Units = Util.ScrambleList<Unit>(attackers.Units); defenders.Units = Util.ScrambleList<Unit>(defenders.Units); Hero hero = null; attackers.Heroes = new List<Hero>(); hero = Hero.Find(davi.HeroId); hero.SetPowers(); attackers.Heroes.Add(hero); defenders.Heroes = new List<Hero>(); hero = Hero.Find(golias.HeroId); hero.SetPowers(); defenders.Heroes.Add(hero); int turns = attackers.Units.Count.BiggerThan(defenders.Units.Count) ? attackers.Units.Count : defenders.Units.Count; int rounds = 1; //round will be always one! refactor later HeroesPowers(turns, attackers, defenders); int i = 1; while (i <= rounds && defenders.Units.Count + defenders.Heroes.Count > 0 && attackers.Units.Count + attackers.Heroes.Count > 0) { Game.Log.Add(string.Format("<h2>Round {0}</h2><p>Atacando: {1} unidades</p><p>Defendendo: {2} unidades</p>", i, attackers.Units.Count, defenders.Units.Count)); Game.StartCombat(turns, attackers, defenders); #region LOG Game.Log.Add(attackers.PV()); Game.Log.Add(defenders.PV()); RoundReport(i, attackers, defenders); #endregion //#region RESET //generate.RoundResetUnitLives(attackers.Units); //generate.RoundResetUnitLives(defenders.Units); //attackers.ResetHeroes(); //defenders.ResetHeroes(); //#endregion turns = attackers.Units.Count.BiggerThan(defenders.Units.Count) ? attackers.Units.Count : defenders.Units.Count; HeroesPowers(turns, attackers, defenders); i++; } Round.IsRunning = false; CombatLog l = new CombatLog() { Log = string.Join("<br/>", Game.Log.ToArray()), CombatId = 1 }; l.Save(); }