heroes-of-nerevelon/lib/spell/target_test.lua
PeaAshMeter d84fc4a7c2 Add path preview and refactor spells with new Spell API
- Add path preview support to Spell with update and draw methods
- Refactor spell:cast to always return a Task
- Simplify spell.new constructor and apply distance constraint uniformly
- Replace walk spell with new Spell-based implementation supporting path
  preview
- Remove debug print from target_test.lua
2026-03-18 03:53:27 +03:00

28 lines
1.1 KiB
Lua

--- @alias SpellTargetTest fun(caster: Character, targetPosition: Vec3) : boolean
return {
-- любой тайл
any = function() return true end,
-- тайл, где находится кастующий
caster = function(caster, targetPosition)
local targetCharacterId = Tree.level.characterGrid:get(targetPosition)
return caster.id == targetCharacterId
end,
-- тайл, где находится любой персонаж
character = function(caster, targetPosition)
local targetCharacterId = Tree.level.characterGrid:get(targetPosition)
return not not targetCharacterId
end,
-- тайл в пределах окружности в нашей кривой метрике
--- @param radius number
distance = function(radius)
return function(caster, targetPosition)
return caster:try(Tree.behaviors.positioned, function(p)
local dist = math.max(math.abs(p.position.x - targetPosition.x),
math.abs(p.position.y - targetPosition.y))
return dist <= radius
end)
end
end
}