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:changeAnimation("hit1")
|
||||||
self:attack()
|
self:attack()
|
||||||
elseif (action_type == "skill") then
|
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
|
elseif (action_type == "cursorMove") then
|
||||||
self:changeAnimation("walk", true)
|
self:changeAnimation("walk", true)
|
||||||
self:goTo(self.world.cursor.x, self.world.cursor.y, 'cursorMove')
|
self:goTo(self.world.cursor.x, self.world.cursor.y, 'cursorMove')
|
||||||
|
|
|
@ -21,18 +21,63 @@ function Cursor:new(world)
|
||||||
self.grid = maputils.newEmptyMap()
|
self.grid = maputils.newEmptyMap()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cursor:set(x, y, signal)
|
function Cursor:set(x, y, signal, subSignal)
|
||||||
self.x = math.max(math.min(x, 12), 1)
|
self.x = math.max(math.min(x, 12), 1)
|
||||||
self.y = math.max(math.min(y, 07), 1)
|
self.y = math.max(math.min(y, 07), 1)
|
||||||
|
self.initialx = self.x
|
||||||
|
self.initialy = self.y
|
||||||
self.tx = self.x
|
self.tx = self.x
|
||||||
self.ty = self.y
|
self.ty = self.y
|
||||||
|
|
||||||
self.isActive = true
|
self:placeInGrid()
|
||||||
self.signal = signal or ""
|
|
||||||
|
self.isActive = true
|
||||||
|
self.signal = signal or ""
|
||||||
|
self.subSignal = subSignal or ""
|
||||||
|
|
||||||
self.world:setActiveGridFromGrid(self.grid)
|
self.world:setActiveGridFromGrid(self.grid)
|
||||||
end
|
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)
|
function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
|
||||||
self.grid = maputils.newEmptyMap()
|
self.grid = maputils.newEmptyMap()
|
||||||
|
|
||||||
|
@ -53,6 +98,20 @@ function Cursor:setGrid(ox, oy, shape, size, direction, whitelistedEntity)
|
||||||
self.world:setActiveGridFromGrid(self.grid)
|
self.world:setActiveGridFromGrid(self.grid)
|
||||||
end
|
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)
|
function Cursor:testPoint(x, y, whitelistedActor)
|
||||||
if ((self.world:getActorInCase(x, y) == nil) or
|
if ((self.world:getActorInCase(x, y) == nil) or
|
||||||
(self.world:getActorInCase(x, y) == whitelistedActor) and (whitelistedActor ~= nil)) and
|
(self.world:getActorInCase(x, y) == whitelistedActor) and (whitelistedActor ~= nil)) and
|
||||||
|
@ -121,7 +180,7 @@ function Cursor:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (keys["A"].isPressed) then
|
if (keys["A"].isPressed) then
|
||||||
self.world:sendSignalToCurrentBattler(self.signal)
|
self.world:sendSignalToCurrentBattler(self.signal, self.subSignal)
|
||||||
end
|
end
|
||||||
|
|
||||||
self.tweens:update(dt)
|
self.tweens:update(dt)
|
||||||
|
|
|
@ -267,8 +267,19 @@ end
|
||||||
function SkillWidget:action()
|
function SkillWidget:action()
|
||||||
self.scene.world:resetActiveGrid()
|
self.scene.world:resetActiveGrid()
|
||||||
self.scene.world:resetEffectGrid()
|
self.scene.world:resetEffectGrid()
|
||||||
|
|
||||||
if self.skilldata ~= nil then
|
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
|
else
|
||||||
core.debug:warning("cbs/menu", "skill " .. self.actionType .. " doesn't exist")
|
core.debug:warning("cbs/menu", "skill " .. self.actionType .. " doesn't exist")
|
||||||
self.character:receiveSignal("none")
|
self.character:receiveSignal("none")
|
||||||
|
|
|
@ -274,8 +274,8 @@ function World:finishBattle()
|
||||||
self.scene:finishBattle()
|
self.scene:finishBattle()
|
||||||
end
|
end
|
||||||
|
|
||||||
function World:sendSignalToCurrentBattler(signal)
|
function World:sendSignalToCurrentBattler(signal, subSignal)
|
||||||
self.actionlist[self.turns.current].actor:receiveSignal(signal)
|
self.actionlist[self.turns.current].actor:receiveSignal(signal, subSignal)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ACTIVEGRID FUNCTIONS
|
-- ACTIVEGRID FUNCTIONS
|
||||||
|
|
Loading…
Reference in a new issue