public override void Attack(AbstractUnit anotherUnit, float damage) { int indexEntityAttack = Random.Range(1, entityCount); Entity entityAttack = GetEntity(indexEntityAttack); float coef = GetEfficientCoef(this, anotherUnit); int efficientCoef = GetEfficiencyType(coef); if (anotherUnit.GetNumberAlive() > 0) { int indexEntityDefense = Random.Range(0, entityCount); Entity entityDefense = anotherUnit.GetEntity(indexEntityDefense); if (entityAttack == null || entityDefense == null) { return; } int life = entityAttack.Attack(entityDefense, (int)(-1 * entityAttack.GetStrength() * damage * coef), efficientCoef); if (life == 0) { anotherUnit.PopEntity(indexEntityDefense); } } else if (anotherUnit.GetNumberAlive() == 0) { if (entityAttack != null) { entityAttack.Attack(anotherUnit.GetEntity(0), -100, efficientCoef); anotherUnit.PopEntity(0); // Le leader est attrapé unitTarget = null; //important pour indiquer à l'IA de commencer de nouvelles recherches } } }
public override void Attack(AbstractUnit anotherUnit, float damage) { int indexEntityAttack = Random.Range(1, entityCount); Entity entityAttack = GetEntity(indexEntityAttack); float coef = GetEfficientCoef(this, anotherUnit); int efficientCoef = GetEfficiencyType(coef); if (anotherUnit.GetNumberAlive() > 0) { int indexEntityDefense = Random.Range(0, entityCount); Entity entityDefense = anotherUnit.GetEntity(indexEntityDefense); if (entityAttack == null || entityDefense == null) { return; } int life = entityAttack.Attack(entityDefense, (int)(-1 * entityAttack.GetStrength() * damage * coef), efficientCoef); if (life == 0) { GameSingleton.Instance.GetPlayer().currentScore += (int) (GetEfficientCoef(this, anotherUnit) * 200f * anotherUnit.brain.MultiplierScore); // ajouter les types complexes anotherUnit.PopEntity(indexEntityDefense); } } else if (anotherUnit.GetNumberAlive() == 0) { if (entityAttack != null) { unitTarget = null; //important pour indiquer à l'IA de commencer de nouvelles recherches } } }