local rune = Spell("rune")

local corpseIds = {3058, 3059, 3060, 3061, 3064, 3065, 3066}
local removalLimit = 500

function rune.onCastSpell(creature, variant, isHotkey)
	local position = variant:getPosition()
	local tile = Tile(position)
	if tile then
		local items = tile:getItems()
		if items then
			for i, item in ipairs(items) do
				if item:getType():isMovable() and item:getUniqueId() > 65535 and item:getActionId() == 0 and not table.contains(corpseIds, item:getId()) then
					item:remove()
				end

				if i == removalLimit then
					break
				end
			end
		end
	end

	creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
	position:sendMagicEffect(CONST_ME_POFF)
	return true
end

rune:group("support")
rune:id(78)
rune:name("Desintegrate")
rune:runeId(2310)
rune:allowFarUse(false)
rune:charges(3)
rune:level(21)
rune:magicLevel(4)
rune:cooldown(2 * 1000)
rune:groupCooldown(2 * 1000)
rune:range(1)
rune:register()