local combatWarn = Combat()
combatWarn:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combatWarn:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)

local combat1, combat2, combat3, combat4, combat5, combat6 = Combat(), Combat(), Combat(), Combat(), Combat(), Combat()

local combats = { combat1, combat2, combat3, combat4, combat5, combat6 }

for _, combat in pairs(combats) do
	combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
	combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
	combat:setFormula(COMBAT_FORMULA_DAMAGE, 0, 700, 1500, 0)
end

arr = {
	{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
	{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
	{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
	{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
	{ 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}

arr1 = {
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}

arr2 = {
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0,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, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}

arr6 = {
	{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}

local area = createCombatArea(arr)
combatWarn:setArea(area)
combat1:setArea(createCombatArea(arr1))
combat2:setArea(createCombatArea(arr2))
combat3:setArea(createCombatArea(arr3))
combat4:setArea(createCombatArea(arr4))
combat5:setArea(createCombatArea(arr5))
combat6:setArea(createCombatArea(arr6))

local spell = Spell("instant")

local function eventRemoveFreeze(creatureid)
	local creature = Creature(creatureid)
	if not creature then
		return
	end

	if creature:isMoveLocked() then
		creature:setMoveLocked(false)
	end

	if creature:isDirectionLocked() then
		creature:setDirectionLocked(false)
	end
end

local function doCombat(combat, creatureId, var)
	local creature = Creature(creatureId)
	if not creature then
		return false
	end

	combat:execute(creature, var)
end

function spell.onCastSpell(creature, var)
	creature:setMoveLocked(true)
	creature:setDirectionLocked(true)

	combatWarn:execute(creature, var)
	addEvent(doCombat, 1000, combatWarn, creature:getId(), var)
	addEvent(doCombat, 2000, combatWarn, creature:getId(), var)
	addEvent(doCombat, 3000, combat1, creature:getId(), var)
	addEvent(doCombat, 3100, combat2, creature:getId(), var)
	addEvent(doCombat, 3200, combat3, creature:getId(), var)
	addEvent(doCombat, 3300, combat4, creature:getId(), var)
	addEvent(doCombat, 3400, combat5, creature:getId(), var)
	addEvent(doCombat, 3500, combat6, creature:getId(), var)

	addEvent(eventRemoveFreeze, 3800, creature:getId())
	return true
end

spell:name("fire wave delayed")
spell:words("###6050")
spell:isAggressive(true)
spell:blockWalls(true)
spell:needLearn(true)
spell:needDirection(true)
spell:register()
