From 9ece46fbb5036fdb83a221a8da84a0fafae0e535 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 19 Jul 2020 22:38:59 +0200 Subject: [PATCH] feat: add the basic action selection system --- .../controllers/fighters/character.lua | 46 +++++++++++++++---- .../fighters/systems/actions/attack.lua | 17 +++++++ .../fighters/systems/actions/defend.lua | 17 +++++++ .../fighters/systems/actions/flee.lua | 17 +++++++ .../fighters/systems/actions/init.lua | 9 ++++ .../fighters/systems/actions/parent.lua | 40 ++++++++++++++++ .../scenes/battlesystem/menu.lua | 19 +------- 7 files changed, 139 insertions(+), 26 deletions(-) create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/attack.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/defend.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/init.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua index 68d76f7..dc8d964 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua @@ -3,6 +3,7 @@ local HeroFighter = FighterParent:extend() local StatusBar = require "scenes.battlesystem.gui.statusbar" local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection" +local actionList = require "scenes.battlesystem.controllers.fighters.systems.actions" local POSITIONS = {3, 1, 5} local HEROES_LINE = 3; @@ -13,15 +14,19 @@ function HeroFighter:new(owner, character, id) self.statusbar = StatusBar(self) - self.currentAction = "" - self.actionArgument = "" - self.target = nil + self.action = nil self.selection = nil end function HeroFighter:updateAssets(dt) self.statusbar:update(dt) + + if (self.action ~= nil) then + if (self.action.isStarted) then + self.action:update(dt) + end + end end function HeroFighter:update(dt) @@ -41,9 +46,7 @@ end function HeroFighter:startAction() core.debug:print("cbs/heroFighter", "launching the action menu") - self.currentAction = "" - self.actionArgument = "" - self.target = nil + self.action = nil self.turnSystem.scene.menu:set( self ) end @@ -56,14 +59,35 @@ function HeroFighter:doNothing() self:setInactive() end +function HeroFighter:doBasicAction(action) + self.action = actionList[action](self) + self:verifyTargets() +end + +function HeroFighter:verifyTargets() + local needTarget, targetEnnemies = self.action:needTarget() + + if (needTarget) then + if (targetEnnemies) then + self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies) + else + self.selection = SelectionSystem(self, self.owner) + end + else + self.action:start() + end + +end + function HeroFighter:attack() - self.currentAction = "attack" - self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies) + self:doBasicAction("attack") end function HeroFighter:receiveTarget(target) self.selection = nil - self:setInactive() + if (self.action ~= nil) then + self.action:start() + end end function HeroFighter:goBackToMenu() @@ -71,6 +95,10 @@ function HeroFighter:goBackToMenu() self.selection = nil end +function HeroFighter:finishAction() + self:setInactive() +end + -- DRAW FUNCTIONS function HeroFighter:drawIcon(x, y) local iconID = 1 diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/attack.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/attack.lua new file mode 100644 index 0000000..84e83aa --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/attack.lua @@ -0,0 +1,17 @@ +local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent" +local AttackAction = ActionParent:extend() + +function AttackAction:new(fighter) + AttackAction.super.new(self, fighter) +end + +function AttackAction:needTarget() + return true, true +end + +function AttackAction:startAction() + core.debug:print("cbs/action", "Starting attack action") + self:finishAction() +end + +return AttackAction diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/defend.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/defend.lua new file mode 100644 index 0000000..10597b9 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/defend.lua @@ -0,0 +1,17 @@ +local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent" +local DefendAction = ActionParent:extend() + +function DefendAction:new(fighter) + DefendAction.super.new(self, fighter) +end + +function DefendAction:needTarget() + return false, false +end + +function DefendAction:startAction() + core.debug:print("cbs/action", "Starting defend action") + self:finishAction() +end + +return DefendAction diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua new file mode 100644 index 0000000..def62b6 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/flee.lua @@ -0,0 +1,17 @@ +local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent" +local FleeAction = ActionParent:extend() + +function FleeAction:new(fighter) + FleeAction.super.new(self, fighter) +end + +function FleeAction:needTarget() + return false, false +end + +function FleeAction:startAction() + core.debug:print("cbs/action", "Starting flee action") + self:finishAction() +end + +return FleeAction diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/init.lua new file mode 100644 index 0000000..daa2ac7 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/init.lua @@ -0,0 +1,9 @@ +local actions = {} + +actions.attack = require "scenes.battlesystem.controllers.fighters.systems.actions.attack" +--actions.skill = require "scenes.battlesystem.controllers.fighters.systems.actions.skill" +--actions.item = require "scenes.battlesystem.controllers.fighters.systems.actions.item" +actions.defend = require "scenes.battlesystem.controllers.fighters.systems.actions.defend" +actions.flee = require "scenes.battlesystem.controllers.fighters.systems.actions.flee" + +return actions diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua new file mode 100644 index 0000000..f802e25 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua @@ -0,0 +1,40 @@ +local ActionParent = Object:extend() + +function ActionParent:new(fighter) + self.fighter = fighter + self.target = nil + self.choregraphy = nil + + self.isStarted = false +end + +function ActionParent:update(dt) + if (self.choregraphy ~= nil) then + self.choregraphy:update(dt) + end +end + +function ActionParent:needTarget() + -- needTarget, targetEnnemies + return false, false +end + +function ActionParent:setTarget(target) + self.target = target +end + +function ActionParent:start() + self.isStarted = true + self:startAction() +end + +function ActionParent:startAction() + + self:finishAction() +end + +function ActionParent:finishAction() + self.fighter:finishAction() +end + +return ActionParent diff --git a/sonic-radiance.love/scenes/battlesystem/menu.lua b/sonic-radiance.love/scenes/battlesystem/menu.lua index cea0beb..44ebe20 100644 --- a/sonic-radiance.love/scenes/battlesystem/menu.lua +++ b/sonic-radiance.love/scenes/battlesystem/menu.lua @@ -10,8 +10,6 @@ local SubMenuWidget = BattleWidget:extend() local BackMenuWidget = BattleWidget:extend() local SkillWidget = BattleWidget:extend() -local AttackWidget = ActionWidget:extend() - local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110 local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17 local MENU_ITEM_NUMBER = 6 @@ -40,7 +38,7 @@ end function MenuConstructor:buildBaseMenu(character) CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y) - AttackWidget(character, "BaseMenu") + ActionWidget(character, "BaseMenu", "attack") SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu") SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu") ActionWidget(character, "BaseMenu", "defend") @@ -221,22 +219,9 @@ function ActionWidget:new(character, menu_name, action) end function ActionWidget:sendCharacterData() - self.character:doNothing() + self.character:doBasicAction(self.actionType) end --- AttackWidget --- The basic action widget - -function AttackWidget:new(character, menu_name) - self.actionType = "attack" - ActionWidget.super.new(self, character, menu_name, "attack", "") -end - -function AttackWidget:sendCharacterData() - self.character:attack() -end - - -- SubMenuWidget -- A simple widget to change menu