Exemplo n.º 1
0
		private bool EncounterExecuteAttack(Ship attacker, Ship defender, bool fleeing)
		{
			bool hit = false;

			// On beginner level, if you flee, you will escape unharmed.
			// Otherwise, Fighter skill attacker is pitted against pilot skill defender; if defender
			// is fleeing the attacker has a free shot, but the chance to hit is smaller
			// JAF - if the opponent is disabled and attacker has targeting system, they WILL be hit.
			if (!(Difficulty == Difficulty.Beginner && defender.CommandersShip && fleeing) &&
				(attacker.CommandersShip && OpponentDisabled && attacker.HasGadget(GadgetType.TargetingSystem) ||
				Functions.GetRandom(attacker.Fighter + (int)defender.Size) >=
				(fleeing ? 2 : 1) * Functions.GetRandom(5 + defender.Pilot / 2)))
			{
				// If the defender is disabled, it only takes one shot to destroy it completely.
				if (attacker.CommandersShip && OpponentDisabled)
					defender.Hull = 0;
				else
				{
					int attackerLasers = attacker.WeaponStrength(WeaponType.PulseLaser, WeaponType.MorgansLaser);
					int attackerDisruptors = attacker.WeaponStrength(WeaponType.PhotonDisruptor, WeaponType.QuantumDistruptor);

					if (defender.Type == ShipType.Scarab)
					{
						attackerLasers -= attacker.WeaponStrength(WeaponType.BeamLaser, WeaponType.MilitaryLaser);
						attackerDisruptors -= attacker.WeaponStrength(WeaponType.PhotonDisruptor, WeaponType.PhotonDisruptor);
					}

					int attackerWeapons = attackerLasers + attackerDisruptors;

					int disrupt = 0;

					// Attempt to disable the opponent if they're not already disabled, their shields are down,
					// we have disabling weapons, and the option is checked.
					if (defender.Disableable && defender.ShieldCharge == 0 && !OpponentDisabled &&
						Options.DisableOpponents && attackerDisruptors > 0)
					{
						disrupt = Functions.GetRandom(attackerDisruptors * (100 + 2 * attacker.Fighter) / 100);
					}
					else
					{
						int damage = attackerWeapons == 0 ? 0 :
							Functions.GetRandom(attackerWeapons * (100 + 2 * attacker.Fighter) / 100);

						if (damage > 0)
						{
							hit = true;

							// Reactor on board -- damage is boosted!
							if (defender.ReactorOnBoard)
								damage *= (int)(1 + ((int)Difficulty + 1) * (Difficulty < Difficulty.Normal ? 0.25 : 0.33));

							// First, shields are depleted
							for (int i = 0; i < defender.Shields.Length && defender.Shields[i] != null && damage > 0; i++)
							{
								int applied = Math.Min(defender.Shields[i].Charge, damage);
								defender.Shields[i].Charge -= applied;
								damage -= applied;
							}

							// If there still is damage after the shields have been depleted,
							// this is subtracted from the hull, modified by the engineering skill
							// of the defender.
							// JAF - If the player only has disabling weapons, no damage will be done to the hull.
							if (damage > 0)
							{
								damage = Math.Max(1, damage - Functions.GetRandom(defender.Engineer));

								disrupt = damage * attackerDisruptors / attackerWeapons;

								// Only that damage coming from Lasers will deplete the hull.
								damage -= disrupt;

								// At least 2 shots on Normal level are needed to destroy the hull
								// (3 on Easy, 4 on Beginner, 1 on Hard or Impossible). For opponents,
								// it is always 2.
								damage = Math.Min(damage, defender.HullStrength /
									(defender.CommandersShip ? Math.Max(1, Difficulty.Impossible - Difficulty) : 2));

								// If the hull is hardened, damage is halved.
								if (QuestStatusScarab == SpecialEvent.StatusScarabDone)
									damage /= 2;

								defender.Hull = Math.Max(0, defender.Hull - damage);
							}
						}
					}

					// Did the opponent get disabled? (Disruptors are 3 times more effective against the ship's
					// systems than they are against the shields).
					if (defender.Hull > 0 && defender.Disableable && Functions.GetRandom(100) <
						disrupt * Consts.DisruptorSystemsMultiplier * 100 / defender.Hull)
						OpponentDisabled = true;

					// Make sure the Scorpion doesn't get destroyed.
					if (defender.Type == ShipType.Scorpion && defender.Hull == 0)
					{
						defender.Hull = 1;
						OpponentDisabled = true;
					}
				}
			}

			return hit;
		}