// Takes the given amount of damage public virtual int takeDamage(ref AttackInfo info, ref Unit instigator, ref BattleMap map) { // Variables int oldHealth= health; int amount= info.damage; if((float)(Start.rng.NextDouble())<= info.accuracy) { amount= instigator.onDealtDamage(health, amount, this, ref map); if((float)(Start.rng.NextDouble())<= info.criticalChance) { // Animate Critical Console.WriteLine("Critical Hit!"); info.criticalHit= true; amount= instigator.onCriticalHit(health, amount, this, ref map); amount= onHitByCritical(health, amount, this, ref map); } else { // Animate regular } amount= onTakeDamage(oldHealth, health, amount, ref instigator, ref map); health-= amount; } else { Console.WriteLine("Missed!"); // Animate Miss info.missed= true; onDodgedAttack(amount, ref instigator, ref map); instigator.onMissedAttack(amount, this, ref map); } if(health== 0) map.removeUnit(map.getFullUnitID(mapPos)); return health; }