feat(cbs): add targeting support to skills
This commit is contained in:
parent
be4504ff2b
commit
325964a47b
4 changed files with 79 additions and 8 deletions
|
@ -220,7 +220,8 @@ function Hero:receiveSignal(action_type, id)
|
|||
--self:changeAnimation("hit1")
|
||||
self:attack()
|
||||
elseif (action_type == "skill") then
|
||||
self:useSkill(id)
|
||||
self.world.cursor:unset( )
|
||||
self:useSkill(id, self.world.cursor.x, self.world.cursor.y)
|
||||
elseif (action_type == "cursorMove") then
|
||||
self:changeAnimation("walk", true)
|
||||
self:goTo(self.world.cursor.x, self.world.cursor.y, 'cursorMove')
|
||||
|
|
|
@ -21,18 +21,63 @@ function Cursor:new(world)
|
|||
self.grid = maputils.newEmptyMap()
|
||||
end
|
||||
|
||||
function Cursor:set(x, y, signal)
|
||||
function Cursor:set(x, y, signal, subSignal)
|
||||
self.x = math.max(math.min(x, 12), 1)
|
||||
self.y = math.max(math.min(y, 07), 1)
|
||||
self.initialx = self.x
|
||||
self.initialy = self.y
|
||||
self.tx = self.x
|
||||
self.ty = self.y
|
||||
|
||||
self.isActive = true
|
||||
self.signal = signal or ""
|
||||
self:placeInGrid()
|
||||
|
||||
self.isActive = true
|
||||
self.signal = signal or ""
|
||||
self.subSignal = subSignal or ""
|
||||
|
||||
self.world:setActiveGridFromGrid(self.grid)
|
||||
end
|
||||
|
||||
function Cursor:placeInGrid()
|
||||
while (self.grid[self.y][self.x] == 0) do
|
||||
core.debug:print("cursor", "testing position " .. self.x .. " " .. self.y)
|
||||
-- On teste d'abord les position > initialx
|
||||
if self.x >= self.initialx then
|
||||
if self.x >= 12 then
|
||||
-- cependant, si on est au maximum, on se place juste avant
|
||||
self.x = self.initialx - 1
|
||||
else
|
||||
self.x = self.x + 1
|
||||
end
|
||||
else
|
||||
if self.x <= 1 then
|
||||
-- cependant, si on est au minimum, on doit tester une autre ligne
|
||||
self.x = self.initialx
|
||||
if self.y >= self.initialy then
|
||||
-- on test d'abord les positions en dessous de la position initiales
|
||||
if self.y >= 7 then
|
||||
self.y = self.initialy - 1
|
||||
else
|
||||
self.y = self.y + 1
|
||||
end
|
||||
else
|
||||
if self.y <= 1 then
|
||||
core.debug:error("cursor", "map was empty")
|
||||
else
|
||||
self.y = self.y - 1
|
||||
end
|
||||
end
|
||||
else
|
||||
-- sinon, on test les positions avant
|
||||
self.x = self.x - 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.tx = self.x
|
||||
self.ty = self.y
|
||||
end
|
||||
|
||||
function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
|
||||
self.grid = maputils.newEmptyMap()
|
||||
|
||||
|
@ -53,6 +98,20 @@ function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
|
|||
self.world:setActiveGridFromGrid(self.grid)
|
||||
end
|
||||
|
||||
function Cursor:setGridIgnoreActor(ox, oy, shape, size, direction)
|
||||
self.grid = maputils.newEmptyMap()
|
||||
|
||||
for y, line in ipairs(self.grid) do
|
||||
for x, case in ipairs(line) do
|
||||
if maputils.isInMask(x, y, ox, oy, shape, size, direction) then
|
||||
self.grid[y][x] = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.world:setActiveGridFromGrid(self.grid)
|
||||
end
|
||||
|
||||
function Cursor:testPoint(x, y, whitelistedActor)
|
||||
if ((self.world:getActorInCase(x, y) == nil) or
|
||||
(self.world:getActorInCase(x, y) == whitelistedActor) and (whitelistedActor ~= nil)) and
|
||||
|
@ -121,7 +180,7 @@ function Cursor:update(dt)
|
|||
end
|
||||
|
||||
if (keys["A"].isPressed) then
|
||||
self.world:sendSignalToCurrentBattler(self.signal)
|
||||
self.world:sendSignalToCurrentBattler(self.signal, self.subSignal)
|
||||
end
|
||||
|
||||
self.tweens:update(dt)
|
||||
|
|
|
@ -267,8 +267,19 @@ end
|
|||
function SkillWidget:action()
|
||||
self.scene.world:resetActiveGrid()
|
||||
self.scene.world:resetEffectGrid()
|
||||
|
||||
if self.skilldata ~= nil then
|
||||
self.character:receiveSignal("skill", self.actionType)
|
||||
if self.skilldata.target == nil then
|
||||
self.character:useSkill(self.actionType, self.character.x, self.character.y)
|
||||
else
|
||||
local x = self.character.x + self.skilldata.target[1]
|
||||
local y = self.character.y + self.skilldata.target[2]
|
||||
local shape = self.skilldata.target[3]
|
||||
local size = self.skilldata.target[4]
|
||||
local direction = self.character.direction
|
||||
self.scene.world.cursor:setGridIgnoreActor(x, y, shape, size, direction)
|
||||
self.scene.world.cursor:set(self.character.x, self.character.y, "skill", self.actionType)
|
||||
end
|
||||
else
|
||||
core.debug:warning("cbs/menu", "skill " .. self.actionType .. " doesn't exist")
|
||||
self.character:receiveSignal("none")
|
||||
|
|
|
@ -274,8 +274,8 @@ function World:finishBattle()
|
|||
self.scene:finishBattle()
|
||||
end
|
||||
|
||||
function World:sendSignalToCurrentBattler(signal)
|
||||
self.actionlist[self.turns.current].actor:receiveSignal(signal)
|
||||
function World:sendSignalToCurrentBattler(signal, subSignal)
|
||||
self.actionlist[self.turns.current].actor:receiveSignal(signal, subSignal)
|
||||
end
|
||||
|
||||
-- ACTIVEGRID FUNCTIONS
|
||||
|
|
Loading…
Reference in a new issue