feat: add the basic action selection system
This commit is contained in:
parent
eb1113064d
commit
9ece46fbb5
7 changed files with 139 additions and 26 deletions
|
@ -3,6 +3,7 @@ local HeroFighter = FighterParent:extend()
|
||||||
|
|
||||||
local StatusBar = require "scenes.battlesystem.gui.statusbar"
|
local StatusBar = require "scenes.battlesystem.gui.statusbar"
|
||||||
local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection"
|
local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection"
|
||||||
|
local actionList = require "scenes.battlesystem.controllers.fighters.systems.actions"
|
||||||
|
|
||||||
local POSITIONS = {3, 1, 5}
|
local POSITIONS = {3, 1, 5}
|
||||||
local HEROES_LINE = 3;
|
local HEROES_LINE = 3;
|
||||||
|
@ -13,15 +14,19 @@ function HeroFighter:new(owner, character, id)
|
||||||
|
|
||||||
self.statusbar = StatusBar(self)
|
self.statusbar = StatusBar(self)
|
||||||
|
|
||||||
self.currentAction = ""
|
self.action = nil
|
||||||
self.actionArgument = ""
|
|
||||||
self.target = nil
|
|
||||||
|
|
||||||
self.selection = nil
|
self.selection = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:updateAssets(dt)
|
function HeroFighter:updateAssets(dt)
|
||||||
self.statusbar:update(dt)
|
self.statusbar:update(dt)
|
||||||
|
|
||||||
|
if (self.action ~= nil) then
|
||||||
|
if (self.action.isStarted) then
|
||||||
|
self.action:update(dt)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:update(dt)
|
function HeroFighter:update(dt)
|
||||||
|
@ -41,9 +46,7 @@ end
|
||||||
|
|
||||||
function HeroFighter:startAction()
|
function HeroFighter:startAction()
|
||||||
core.debug:print("cbs/heroFighter", "launching the action menu")
|
core.debug:print("cbs/heroFighter", "launching the action menu")
|
||||||
self.currentAction = ""
|
self.action = nil
|
||||||
self.actionArgument = ""
|
|
||||||
self.target = nil
|
|
||||||
self.turnSystem.scene.menu:set( self )
|
self.turnSystem.scene.menu:set( self )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,14 +59,35 @@ function HeroFighter:doNothing()
|
||||||
self:setInactive()
|
self:setInactive()
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:attack()
|
function HeroFighter:doBasicAction(action)
|
||||||
self.currentAction = "attack"
|
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)
|
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:doBasicAction("attack")
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:receiveTarget(target)
|
function HeroFighter:receiveTarget(target)
|
||||||
self.selection = nil
|
self.selection = nil
|
||||||
self:setInactive()
|
if (self.action ~= nil) then
|
||||||
|
self.action:start()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:goBackToMenu()
|
function HeroFighter:goBackToMenu()
|
||||||
|
@ -71,6 +95,10 @@ function HeroFighter:goBackToMenu()
|
||||||
self.selection = nil
|
self.selection = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function HeroFighter:finishAction()
|
||||||
|
self:setInactive()
|
||||||
|
end
|
||||||
|
|
||||||
-- DRAW FUNCTIONS
|
-- DRAW FUNCTIONS
|
||||||
function HeroFighter:drawIcon(x, y)
|
function HeroFighter:drawIcon(x, y)
|
||||||
local iconID = 1
|
local iconID = 1
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -10,8 +10,6 @@ local SubMenuWidget = BattleWidget:extend()
|
||||||
local BackMenuWidget = BattleWidget:extend()
|
local BackMenuWidget = BattleWidget:extend()
|
||||||
local SkillWidget = BattleWidget:extend()
|
local SkillWidget = BattleWidget:extend()
|
||||||
|
|
||||||
local AttackWidget = ActionWidget:extend()
|
|
||||||
|
|
||||||
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
||||||
local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
|
local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
|
||||||
local MENU_ITEM_NUMBER = 6
|
local MENU_ITEM_NUMBER = 6
|
||||||
|
@ -40,7 +38,7 @@ end
|
||||||
|
|
||||||
function MenuConstructor:buildBaseMenu(character)
|
function MenuConstructor:buildBaseMenu(character)
|
||||||
CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||||
AttackWidget(character, "BaseMenu")
|
ActionWidget(character, "BaseMenu", "attack")
|
||||||
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
|
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
|
||||||
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
|
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
|
||||||
ActionWidget(character, "BaseMenu", "defend")
|
ActionWidget(character, "BaseMenu", "defend")
|
||||||
|
@ -221,22 +219,9 @@ function ActionWidget:new(character, menu_name, action)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ActionWidget:sendCharacterData()
|
function ActionWidget:sendCharacterData()
|
||||||
self.character:doNothing()
|
self.character:doBasicAction(self.actionType)
|
||||||
end
|
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
|
-- SubMenuWidget
|
||||||
-- A simple widget to change menu
|
-- A simple widget to change menu
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue