parent
b1a7bdc2af
commit
ed70bb6550
10 changed files with 153 additions and 19 deletions
|
@ -8,6 +8,8 @@ return {
|
||||||
turns = 2,
|
turns = 2,
|
||||||
|
|
||||||
hudHeight = 24,
|
hudHeight = 24,
|
||||||
|
behaviour = "random",
|
||||||
|
behaviourAlt = "random",
|
||||||
|
|
||||||
giveExp = 20,
|
giveExp = 20,
|
||||||
giveRings = 30,
|
giveRings = 30,
|
||||||
|
|
|
@ -10,6 +10,8 @@ return {
|
||||||
targetNumber = 1, -- 0 for targeting all ennemies
|
targetNumber = 1, -- 0 for targeting all ennemies
|
||||||
targetEnnemies = true,
|
targetEnnemies = true,
|
||||||
|
|
||||||
|
isSpecial = false,
|
||||||
|
|
||||||
choregraphy = { -- the main attack choregraphy
|
choregraphy = { -- the main attack choregraphy
|
||||||
{"goTo", "none", "target", -0.4, 0, 0.5, true},
|
{"goTo", "none", "target", -0.4, 0, 0.5, true},
|
||||||
{"sendDamage", "none", 120, 100, false, false},
|
{"sendDamage", "none", 120, 100, false, false},
|
||||||
|
|
|
@ -15,7 +15,7 @@ function Ennemy:draw()
|
||||||
self:drawSprite(0, -self.z)
|
self:drawSprite(0, -self.z)
|
||||||
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
||||||
|
|
||||||
self.owner:drawHUD(x - 12, y - self.owner.abstract.data.hudHeight)
|
self.owner:drawHUD(x - 12, y - self.owner.abstract.data.hudHeight - self.z)
|
||||||
|
|
||||||
if (self.isSelected) then
|
if (self.isSelected) then
|
||||||
local height = 32
|
local height = 32
|
||||||
|
|
|
@ -18,22 +18,15 @@ function HeroFighter:new(owner, character, id)
|
||||||
self.statusbar = StatusBar(self.abstract, self.turnSystem.scene)
|
self.statusbar = StatusBar(self.abstract, self.turnSystem.scene)
|
||||||
self:initVoices()
|
self:initVoices()
|
||||||
|
|
||||||
self.action = 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)
|
||||||
|
HeroFighter.super.update(self, dt)
|
||||||
if (self.selection ~= nil) then
|
if (self.selection ~= nil) then
|
||||||
self.selection:update(dt)
|
self.selection:update(dt)
|
||||||
end
|
end
|
||||||
|
@ -111,11 +104,6 @@ function HeroFighter:goBackToMenu()
|
||||||
self.selection = nil
|
self.selection = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:finishAction()
|
|
||||||
self.action = nil
|
|
||||||
self:setInactive()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- LIFE functions
|
-- LIFE functions
|
||||||
function HeroFighter:setHP(value, relative)
|
function HeroFighter:setHP(value, relative)
|
||||||
HeroFighter.super.setHP(self, value, relative)
|
HeroFighter.super.setHP(self, value, relative)
|
||||||
|
|
|
@ -18,6 +18,8 @@ function FighterParent:new(owner, isHero, id)
|
||||||
|
|
||||||
self.isActive = false
|
self.isActive = false
|
||||||
self.isAlive = true
|
self.isAlive = true
|
||||||
|
|
||||||
|
self.action = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- LIFE handling functions
|
-- LIFE handling functions
|
||||||
|
@ -77,10 +79,10 @@ function FighterParent:createActor()
|
||||||
end
|
end
|
||||||
|
|
||||||
function FighterParent:update(dt)
|
function FighterParent:update(dt)
|
||||||
counter = counter + dt
|
if (self.action ~= nil) then
|
||||||
if (counter > 1) then
|
if (self.action.isStarted) then
|
||||||
counter = 0
|
self.action:update(dt)
|
||||||
self:setInactive()
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -111,6 +113,11 @@ function FighterParent:startAction()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function FighterParent:finishAction()
|
||||||
|
self.action = nil
|
||||||
|
self:setInactive()
|
||||||
|
end
|
||||||
|
|
||||||
function FighterParent:getUniqueIdentificator()
|
function FighterParent:getUniqueIdentificator()
|
||||||
local side = 1
|
local side = 1
|
||||||
if (isHero == false) then
|
if (isHero == false) then
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
local folder = "scenes.battlesystem.controllers.fighters.systems.behaviours."
|
||||||
|
|
||||||
|
return {
|
||||||
|
["random"] = require(folder .. "random")
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
local BehaviourParent = Object:extend()
|
||||||
|
|
||||||
|
function BehaviourParent:new(fighter, skilldata, targetList, highestScore)
|
||||||
|
self.fighter = fighter
|
||||||
|
self.scoreList = {}
|
||||||
|
self.targetList = targetList
|
||||||
|
self.skilldata = skilldata
|
||||||
|
self.highestScore = highestScore
|
||||||
|
|
||||||
|
self:initScoreList()
|
||||||
|
self:calculateAllScores()
|
||||||
|
end
|
||||||
|
|
||||||
|
function BehaviourParent:initScoreList()
|
||||||
|
for i, target in ipairs(self.targetList) do
|
||||||
|
self.scoreList[target.name] = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BehaviourParent:calculateAllScores()
|
||||||
|
for i, target in ipairs(self.targetList) do
|
||||||
|
self.scoreList[target.name] = self:calculateScore(target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BehaviourParent:calculateScore(target)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
function BehaviourParent:getScore(target)
|
||||||
|
return self.scoreList[target.name]
|
||||||
|
end
|
||||||
|
|
||||||
|
function BehaviourParent:isBestTarget(target, bestTargetScore, isHighest)
|
||||||
|
if (bestTargetScore == nil) then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
if (isHighest) then
|
||||||
|
return (self:getScore(target) >= bestTargetScore)
|
||||||
|
else
|
||||||
|
return (self:getScore(target) <= bestTargetScore)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BehaviourParent:getTarget()
|
||||||
|
local bestTargetScore = nil
|
||||||
|
local finalTarget = nil
|
||||||
|
|
||||||
|
for i, target in ipairs(self.targetList) do
|
||||||
|
if (self:isBestTarget(target, bestTargetScore, self.isHighest)) then
|
||||||
|
finalTarget = target
|
||||||
|
bestTargetScore = self:getScore(target)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return finalTarget
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
return BehaviourParent
|
|
@ -0,0 +1,12 @@
|
||||||
|
local ParentBehaviour = require "scenes.battlesystem.controllers.fighters.systems.behaviours.parent"
|
||||||
|
local RandomBehaviour = ParentBehaviour:extend()
|
||||||
|
|
||||||
|
function RandomBehaviour:new(fighter, skilldata, targetList)
|
||||||
|
RandomBehaviour.super.new(self, fighter, skilldata, targetList, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
function RandomBehaviour:calculateScore(target)
|
||||||
|
return math.random(1, 200)
|
||||||
|
end
|
||||||
|
|
||||||
|
return RandomBehaviour
|
|
@ -0,0 +1,22 @@
|
||||||
|
local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.actions.parent"
|
||||||
|
local EnnemyAction = ActionParent:extend()
|
||||||
|
|
||||||
|
function EnnemyAction:new(fighter, skill)
|
||||||
|
self.data = game.skills:getEnnemySkillData(skill)
|
||||||
|
EnnemyAction.super.new(self, fighter)
|
||||||
|
end
|
||||||
|
|
||||||
|
function EnnemyAction:needTarget()
|
||||||
|
return (self.data.targetNumber == 1), self.data.targetEnnemies
|
||||||
|
end
|
||||||
|
|
||||||
|
function EnnemyAction:startAction()
|
||||||
|
core.debug:print("cbs/action", "Starting flee action")
|
||||||
|
self:loadChoregraphyFromSkill(self.data)
|
||||||
|
end
|
||||||
|
|
||||||
|
function EnnemyAction:getData()
|
||||||
|
return self.data
|
||||||
|
end
|
||||||
|
|
||||||
|
return EnnemyAction
|
|
@ -2,6 +2,9 @@ local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
|
||||||
local VillainFighter = FighterParent:extend()
|
local VillainFighter = FighterParent:extend()
|
||||||
|
|
||||||
local SimpleHPBar = require "game.modules.gui.simplehpbar"
|
local SimpleHPBar = require "game.modules.gui.simplehpbar"
|
||||||
|
local EnnemyAction = require "scenes.battlesystem.controllers.fighters.systems.ennemyaction"
|
||||||
|
local behaviourList = require "scenes.battlesystem.controllers.fighters.systems.behaviours"
|
||||||
|
|
||||||
|
|
||||||
local POSITIONS = {1, 3, 5}
|
local POSITIONS = {1, 3, 5}
|
||||||
local ENNEMY_LINE = 11;
|
local ENNEMY_LINE = 11;
|
||||||
|
@ -19,7 +22,6 @@ function VillainFighter:updateAssets(dt)
|
||||||
self.hpbar:update(dt)
|
self.hpbar:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function VillainFighter:getAbstract()
|
function VillainFighter:getAbstract()
|
||||||
return game.ennemies:getEnnemyData(self.category, self.name)
|
return game.ennemies:getEnnemyData(self.category, self.name)
|
||||||
end
|
end
|
||||||
|
@ -30,9 +32,42 @@ function VillainFighter:createActor()
|
||||||
end
|
end
|
||||||
|
|
||||||
function VillainFighter:startAction()
|
function VillainFighter:startAction()
|
||||||
|
core.debug:print("cbs/villainFighter", "choosing an action")
|
||||||
|
self.action = nil
|
||||||
|
self:selectAction()
|
||||||
|
end
|
||||||
|
|
||||||
|
function VillainFighter:selectAction()
|
||||||
|
if (#self.abstract.skills < 1) then
|
||||||
|
self:finishAction()
|
||||||
|
else
|
||||||
|
local skillId = math.floor(math.random(1, #self.abstract.skills))
|
||||||
|
local skill = self.abstract.skills[skillId]
|
||||||
|
self.action = EnnemyAction(self, skill)
|
||||||
|
self:verifyTargets()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function VillainFighter:verifyTargets()
|
||||||
|
local needTarget, targetEnnemies = self.action:needTarget()
|
||||||
|
|
||||||
|
if (needTarget) then
|
||||||
|
if (targetEnnemies) then
|
||||||
|
--fighter, skilldata, targetList
|
||||||
|
local Behaviour = behaviourList[self.abstract.data.behaviour]
|
||||||
|
local behav = Behaviour(self, self.action:getData(), self.owner.turnSystem.player:getTargets(true))
|
||||||
|
self.action:setTarget(behav:getTarget())
|
||||||
|
self.action:start()
|
||||||
|
else
|
||||||
|
--self.selection = SelectionSystem(self, self.owner, false)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.action:start()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function VillainFighter:endAction()
|
function VillainFighter:endAction()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue