New and improved. Now it states the champion's name and tells you how far away the secret is. It also stops detecting secrets that have been triggered. It also takes into account the elevation of the secret when determining the distance. Only shows the distance to the closest secret instead of the first one it finds. Every point is Earth magic increases your detection range.
Code: Select all
defineSpell{
name = "find_secret",
uiName = "Find Secret",
skill = "earth_magic",
requirements = {"concentration", 1},
gesture = 8,
manaCost = 5,
icon = 14,
spellIcon = 13,
description = "Reveals if a secret is nearby. Every point is Earth Magic increases your maximum detection range.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local secretfound = false
local count = 3 + skillLevel
local dist = -1
for fx = x - count, x + count do
for fy = y - count, y + count do
for i in party.map:entitiesAt(fx,fy) do
if i:getComponent("secret") then
if i.secret:isEnabled() then
--convert tile distance into meters by multiplying by 3
local xdist = (x - i.x) * 3
local ydist = (y - i.y) * 3
local zdist = (elevation - i.elevation) * 3
local sdist = math.floor(0.5 + math.sqrt(xdist^2 + ydist^2 + zdist^2))
--Only keeps the lowest distance
if sdist < dist or dist == -1 then
dist = sdist
end
secretfound = true
end
end
end
end
end
if secretfound == true then
playSound("generic_spell")
if dist == 0 then
--This part may never be seen if the secret is activated when the party stands on it, but added just in case.
hudPrint("You are standing on a secret.")
else
hudPrint(champion:getName().." senses that the nearest secret is "..dist.." meters away.")
end
else
hudPrint(champion:getName().." can not detect any secrets nearby.")
playSound("spell_fizzle")
end
end,
}
SpoilerShow
Code: Select all
defineSpell{
name = "find_secret",
uiName = "Find Secret",
skill = "earth_magic",
requirements = {"concentration", 1},
gesture = 8,
manaCost = 5,
icon = 14,
spellIcon = 13,
description = "Reveals if a secret is nearby.",
onCast = function(champion, x, y, direction, elevation, skillLevel)
local secretfound = false
local count = 0
repeat
for fx = x - count, x + count do
for fy = y - count, y + count do
for i in party.map:entitiesAt(fx,fy) do
if i:getComponent("secret") then
secretfound = true
playSoundAt("generic_spell", i.level, i.x, i.y)
break
end
end
end
end
count = count + 1
until secretfound == true or count >= 5
if secretfound == true then
if count == 1 then
hudPrint("You are standing on a secret")
else
hudPrint("A secret is nearby.")
end
else
hudPrint("You can not detect any secrets nearby.")
playSound("spell_fizzle")
end
end,
}