Advertisement
Guest User

ShootTo

a guest
Sep 6th, 2015
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.81 KB | None | 0 0
  1. public void ShootTo(PlayersUnitsManager enemy)
  2.         {
  3.  
  4. #if TRACE
  5.             Hits = 0;
  6.             DamageGiven = 0;
  7.             DamageOnShield = 0;
  8. #endif
  9.  
  10.             for (int iUnit = 0; iUnit < _AliveUnitsCount; iUnit++)
  11.             {
  12.  
  13.                 var unit = _AliveUnits[iUnit];
  14.  
  15.  
  16.                 int iRapidFire;
  17.                 do
  18.                 {
  19.  
  20.                     Unit uSelectedUnit = enemy._AliveUnits[_Random.Next(enemy._AliveUnitsCount)];
  21.  
  22. #if TRACE
  23.                     //Debug.WriteLine("Attackers: {0} shooting to {1}", Infos.UnitInfos[unit.ID].Name, Infos.UnitInfos[uSelectedUnit.ID].Name);
  24.                     Hits++;
  25. #endif
  26.  
  27.                     // Assume UnitStatus == Status.Alive e iDamage != 0 -> unit.Attack < uSelectedUnit.ShieldUnit
  28.                     if (uSelectedUnit.UnitStatus == Status.Alive && unit.Attack != 0)
  29.                     {
  30.  
  31. #if TRACE
  32.                         DamageGiven += unit.Attack;
  33. #endif
  34.  
  35.                         // Everything on the shield
  36.                         if (uSelectedUnit.Shield >= unit.Attack)
  37.                         {
  38.  
  39.                             // Discretized shield
  40.                             var shieldDmg = (int)(((int)(unit.Attack / uSelectedUnit.ShieldUnit)) * uSelectedUnit.ShieldUnit);
  41.  
  42.                             uSelectedUnit.Shield -= shieldDmg;
  43. #if TRACE
  44.                             DamageOnShield += shieldDmg;
  45. #endif
  46.  
  47.                             // Only if HP is less than 70%
  48.                             if (uSelectedUnit.HP <= (int)((double)uSelectedUnit.MaxHP * 0.7f))
  49.                             {
  50.                                 // Roll a dice on lost HP                      
  51.                                 if (_Random.Next(uSelectedUnit.MaxHP) < (uSelectedUnit.MaxHP - uSelectedUnit.HP))
  52.                                 {
  53.                                     uSelectedUnit.UnitStatus = Status.Exploded;
  54.                                 }
  55.                             }
  56.  
  57.                         }
  58.                         // Otherwise some on shield and some on HP
  59.                         else
  60.                         {
  61.                             int realDamage = unit.Attack - uSelectedUnit.Shield;
  62. #if TRACE
  63.                             DamageOnShield += uSelectedUnit.Shield;
  64. #endif
  65.  
  66.                             uSelectedUnit.Shield = 0;
  67.                             uSelectedUnit.HP -= realDamage;
  68.  
  69.                             // If HP is below 0, I thinks it's exploded!
  70.                             if (uSelectedUnit.HP <= 0)
  71.                             {
  72.                                 uSelectedUnit.UnitStatus = Status.Exploded;
  73.                             }
  74.                             // Otherwise calculate explosion probability
  75.                             else
  76.                             {
  77.                                 // Only if HP is below 70%
  78.                                 if (uSelectedUnit.HP <= (int)((double)uSelectedUnit.MaxHP * 0.7f))
  79.                                 {
  80.                                     // Roll a dice on lost HP                      
  81.                                     if (_Random.Next(uSelectedUnit.MaxHP) < (uSelectedUnit.MaxHP - uSelectedUnit.HP))
  82.                                     {
  83.  
  84.                                         uSelectedUnit.UnitStatus = Status.Exploded;
  85.                                     }
  86.                                 }
  87.                             }
  88.  
  89.                         }
  90.  
  91.                     }
  92.  
  93.                     iRapidFire = Infos.UnitInfos[unit.ID].RapidFires[uSelectedUnit.ID];
  94.  
  95.                     // More than before!
  96.                     if (iRapidFire == 0) break;
  97.  
  98.                     // Let's repeat until rapidfire tells us so
  99.                 } while (_Random.Next(iRapidFire) < (iRapidFire - 1));
  100.             }
  101.  
  102.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement