// Talent Trigger Handler.
// Worthless Bums 2012.


function checkActiveTalents (%monster)
{//echo("checkSquadActiveTalents()");
	checkLeaderActiveTalents(%monster);
	checkScoutActiveTalents(%monster);
	checkGrenadierActiveTalents(%monster);
	checkSupportActiveTalents(%monster);
	checkEngineerActiveTalents(%monster);
}
function checkLeaderActiveTalents (%monster)
{//echo("checkLeaderActiveTalents()");
	// Check for Leader active talents.
	if ($squadTagged)
	{
		%monster.evasion -= $taggedEvasionReduction;
		if (%monster.evasion < 0)
		{
			%monster.evasion = 0;
		}
	}
	if ($squadTactics)
	{
		%monster.armorRating -= $tacticsEvasionReduction;
		if (%monster.armorRating < 0)
		{
			%monster.armorRating = 0;
		}
	}
}
function checkScoutActiveTalents (%monster)
{//echo("checkScoutActiveTalents()");
	// Reduce monster AP if the active character is the Scout and has the Called Shot talent active.
	if ($squadCalledShot)
	{//echo("CALLED SHOT DETECTED!");
		%monster.currentActionPoints -= $caledShotAPDeduction;
		if (%monster.currentActionPoints > 0)
		{
			%monster.currentActionPoints = 0;
		}
	}
	// Stun monster if the active character is the Scout and has the Trick Shot talent active.
	if ($squadTrickShot)
	{//echo("TRICK SHOT DETECTED!");
		$squadTrickShot = false;
		%monster.currentActionPoints = 0;
		createStunAnimation(%monsterIndex);
	}
	// Shatter monster's temporary defensive bonuses if the active character is the Scout and has the Charge Shot talent active.
	if ($squadChargeShot)
	{//echo("CHARGE SHOT DETECTED!");
		$squadChargeShot = false;
		%monster.currentActionPoints = 0;
	}
}
function checkGrenadierActiveTalents (%monster)
{//echo("checkGrenadierrActiveTalents()");
	if ($squadShrapnel)
	{//echo("SHRPANEL DETECTED!");
		$squadShrapnel = false;
	}
	if ($squadGutShot)
	{//echo("GUT SHOT DETECTED!");
		$squadGutShot = false;
	}
	if ($squadFlank)
	{//echo("FLANK DETECTED!");
		$squadFlank = false;
		%cardinalCount = getCardinalSquadMemberCount(%monster.xIndex, %monster.yIndex);
		if (%cardinalCount > 0)
		{
			%cardinalCount--;
		}
		if (%cardinalCount > 0)
		{
			%damage = %cardinalCount * 20;
			if (%damage > %monster.currentHealth)
			{
				%monster.currentHealth = 0;
			}
			else
			{
				%monster.currentHealth -= %damage;
			}
			schedule(750, 0, "objectHit", %monster, %damage);
		}
	}
	if ($squadPincer)
	{//echo("PINCER DETECTED!");
		$squadPincer = false;
		%monster.armor -= $pincerARReduction;
		if (%monster.armor < 0)
		{
			%monster.armor = 0;
		}
	}
	if ($squadAmbush)
	{//echo("AMBUSH DETECTED!");
		$squadAmbush = false;
		if (isObject(%monster.sleepAnimation))
		{
			%monster.safeDelete();
		}
	}
	if ($squadAssault)
	{//echo("ASSAULT DETECTED!");
		$squadAssault = false;
		%direction = getDirectionBetweenUnits($playerSquad[$activeCharacter], %monster);
		knockBackUnit(%monster, %direction);
	}
	if ($squadNapalm)
	{//echo("NAPALM DETECTED!");
		$squadNapalm = false;
		createFireEffectOnObject(%monster);
	}
}
function checkSupportActiveTalents (%monster)
{//echo("checkSupportActiveTalents()");
	if ($squadBunkerDown)
	{//echo("BUNKER DOWN!");
		//$squadBunkerDown = false;		// Don't unflag here - should last entire turn!
	}
	if ($squadSprayFire)
	{//echo("SPRAY FIRE!");
		$squadSprayFire = false;
	}
	if ($squadBulwark)
	{//echo("BULWARK!");
		$squadBulwark = false;
	}
	if ($squadPointBlank)
	{//echo("POINT BLANK!");
		$squadPointBlank = false;
		%removeArmor = mRound(%monster.armorRating * ((100 - $pointBlankArmorReduction) / 100));
		%monster.armorRating -= %removeArmor;
		if (%monster.armorRating < 0)
		{
			%monster.armorRating = 0;
		}
		scrollInfoText(%monster, "-" @ %removeArmor @ " armor!");
	}
	if ($squadPerforate)
	{//echo("PERFORATE!");
		$squadPerforate = false;
		if (%monster.armorRating > 0)
		{
			%monster.armorRating--;
		}
	}
	if ($squadDismantle)
	{//echo("DISMANTLE!");
		$squadDismantle = false;
		if (%monster.currentActionPoints > 0)
		{
			%monster.currentActionPoints--;
			%monsterIndex = getMonsterIndex(%monster);
			if (%monsterIndex != -1)
			{
				updateMonsterFloatingActionPointText(%monsterIndex);
			}
		}
	}
	if ($squadDoubleTap)
	{//echo("DOUBLE TAP!");
		$squadDoubleTap = false;
	}
	if ($squadHailMary)
	{//echo("HAIL MARY!");
		$squadHailMary = false;
	}
}
function checkEngineerActiveTalents (%monster)
{//echo("checkEngineerActiveTalents()");
	if ($squadMagFist)
	{//echo("MAG FIST!");
		$squadMagFist = false;
		setMonsterFacing(getReverseDirection(%monster.facing), %monster);
	}
}