public virtual bool ContainsImprovement(Type type) { return(HeavyUnit.ContainsImprovement(type)); }
public ActionResult DoSpecialAction(int position, IArmy myArmy, IArmy enemyArmy, Random random = null) { if (random == null) { random = new Random(); } double probability = random.NextDouble(); //для улучшения сгенерированная вероятность должна принадлежать промежутку [0, ImprovementHeavyUnitProbability) if (probability >= ImprovementHeavyUnitProbability) { return(ActionResult.Empty); } int[] availibleForImprovement = GetAvailibleForImprovement(position, myArmy).ToArray(); if (availibleForImprovement.Length == 0) { return(ActionResult.Empty); } int index = availibleForImprovement[random.Next(0, availibleForImprovement.Length)]; int action = random.Next(0, 4); IHeavyInfantry unit = myArmy.GetUnit(index) as IHeavyInfantry; switch (action) { case 0: if (unit.ContainsImprovement(typeof(HelmetDecorator))) { return(ActionResult.Empty); } unit = new HelmetDecorator(unit); myArmy.ReplaceUnit(unit, index); break; case 1: if (unit.ContainsImprovement(typeof(HorseDecorator))) { return(ActionResult.Empty); } unit = new HorseDecorator(unit); myArmy.ReplaceUnit(unit, index); break; case 2: if (unit.ContainsImprovement(typeof(ShieldDecorator))) { return(ActionResult.Empty); } unit = new ShieldDecorator(unit); myArmy.ReplaceUnit(unit, index); break; case 3: if (unit.ContainsImprovement(typeof(SwordDecorator))) { return(ActionResult.Empty); } unit = new SwordDecorator(unit); myArmy.ReplaceUnit(unit, index); break; default: return(ActionResult.Empty); } return(new ActionResult(this, unit, ActionResultType.Improvement)); }