print("BOSS FIGHT!");
SetUnitManaPoints(GetDefenderHero(), 2 * GetUnitMaxManaPoints(GetDefenderHero()));
count = 0;

function Start()
	EnableDynamicBattleMode(1);
	first_creatures = GetCreatures(DEFENDER);
	AddCreature(DEFENDER, 85, 25, 9, 1);
	AddCreature(DEFENDER, 86, 25, 9, 10);
	AddCreature(DEFENDER, 87, 25, 9, 3);
	AddCreature(DEFENDER, 88, 25, 9, 8);
end;

function DefenderHeroMove(hero)
	count = count + 1;
	if GetUnitManaPoints(hero) > 100 then
		creatures = GetCreatures(DEFENDER);
		if count == 1 then
			for i, creature in first_creatures do
				startThread(cast, hero, 40, creature);
			end;
			return not nil
		end;
		if count == 2 then
			startThread(firewalls, hero);
			return not nil
		end;
		if count == 3 then
			UnitCastGlobalSpell(hero, 213);
			return not nil
		end;
		if count == 4 then
			for i, creature in creatures do
				startThread(cast, hero, 31, creature);
			end;
			return not nil
		end;
		if count == 5 then
			startThread(mines, hero);
			return not nil
		end;
		if count == 7 then
			UnitCastGlobalSpell(hero, 235);
			return not nil
		end;
		if count == 8 then
			UnitCastGlobalSpell(hero, 43);
			return not nil
		end;
		if count == 9 then
			UnitCastGlobalSpell(hero, 35);
			return not nil
		end;
		if count == 10 then
			startThread(mines, hero);
			return not nil
		end;
		if count == 11 then
			UnitCastGlobalSpell(hero, 212);
			return not nil
		end;
		if count == 12 then
			UnitCastGlobalSpell(hero, 210);
			return not nil
		end;
		if count == 13 then
			startThread(mines, hero);
			return not nil
		end;
		if count > 15 then
			UnitCastGlobalSpell(hero, 35);
			return not nil
		end;
		return nil
	end;
	return nil
end;

function cast(hero, spell, target)
	UnitCastAimedSpell(hero, spell, target);
	print("casting spell "..spell);
end;

function firewalls(hero)
	UnitCastAreaSpell(hero, 236, 2, 2);
	UnitCastAreaSpell(hero, 236, 2, 5);
	UnitCastAreaSpell(hero, 236, 2, 7);
	UnitCastAreaSpell(hero, 236, 2, 9);
	UnitCastAreaSpell(hero, 236, 3, 2);
	UnitCastAreaSpell(hero, 236, 3, 5);
	UnitCastAreaSpell(hero, 236, 3, 7);
	UnitCastAreaSpell(hero, 236, 3, 9);
end;

function mines(hero)
	UnitCastAreaSpell(hero, 38, 5, 2);
	UnitCastAreaSpell(hero, 38, 5, 5);
	UnitCastAreaSpell(hero, 38, 5, 8);
	UnitCastAreaSpell(hero, 38, 10, 2);
	UnitCastAreaSpell(hero, 38, 10, 5);
	UnitCastAreaSpell(hero, 38, 10, 8);
end;