From 325964a47b180c03417c12bd04f87377fab8d361 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 25 Aug 2019 10:38:06 +0200 Subject: [PATCH] feat(cbs): add targeting support to skills --- .../scenes/battlesystem/actors/hero.lua | 3 +- .../scenes/battlesystem/cursor.lua | 67 +++++++++++++++++-- .../scenes/battlesystem/menu.lua | 13 +++- .../scenes/battlesystem/world.lua | 4 +- 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua index 006a581..8cf88c4 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/hero.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/hero.lua @@ -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') diff --git a/sonic-radiance.love/scenes/battlesystem/cursor.lua b/sonic-radiance.love/scenes/battlesystem/cursor.lua index 7848c78..ad3223a 100644 --- a/sonic-radiance.love/scenes/battlesystem/cursor.lua +++ b/sonic-radiance.love/scenes/battlesystem/cursor.lua @@ -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) diff --git a/sonic-radiance.love/scenes/battlesystem/menu.lua b/sonic-radiance.love/scenes/battlesystem/menu.lua index d7b8167..b20a30d 100644 --- a/sonic-radiance.love/scenes/battlesystem/menu.lua +++ b/sonic-radiance.love/scenes/battlesystem/menu.lua @@ -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") diff --git a/sonic-radiance.love/scenes/battlesystem/world.lua b/sonic-radiance.love/scenes/battlesystem/world.lua index 0fe87aa..c9fe393 100644 --- a/sonic-radiance.love/scenes/battlesystem/world.lua +++ b/sonic-radiance.love/scenes/battlesystem/world.lua @@ -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