function Start()
	sleep(5);
    startThread(checkWinAttacker);
	startThread(checkWinDefender);
	startThread(castVulnerability);
	sleep(5);
	EnableAutoFinish(nil);
end;

function castVulnerability()
    local manaSave = GetUnitManaPoints(GetAttackerHero());
    combatSetPause(1);
    SetUnitManaPoints(GetAttackerHero(), 500);
    sleep(1);
    unitCastSpellVulnerability();
    sleep(5);
    SetUnitManaPoints(GetAttackerHero(), manaSave);
    combatSetPause(nil);
end;

function unitCastSpellVulnerability()
	local creaturesList = GetAttackerCreatures();
	for i, target in creaturesList do
		startThread(unitCastSpellVulnerToTarget, target);
	end;
end;

function unitCastSpellVulnerToTarget(target)
    UnitCastAimedSpell(GetAttackerHero(), 12, target);
    sleep(10);
    UnitCastAimedSpell(GetAttackerHero(), 277, target);
end;

function checkWinAttacker()
	repeat sleep(1); until length(GetDefenderCreatures()) == 0;

	sleep(30);
	Finish(ATTACKER);
end;

function checkWinDefender()
	repeat sleep(1); until length(GetAttackerCreatures()) == 0;
	
	sleep(30);
	Finish(DEFENDER);
end;
