feat: add basic ennemy attack system

Fix #8
This commit is contained in:
Kazhnuz 2020-08-05 09:25:38 +02:00
parent b1a7bdc2af
commit ed70bb6550
10 changed files with 153 additions and 19 deletions

View file

@ -8,6 +8,8 @@ return {
turns = 2,
hudHeight = 24,
behaviour = "random",
behaviourAlt = "random",
giveExp = 20,
giveRings = 30,

View file

@ -10,6 +10,8 @@ return {
targetNumber = 1, -- 0 for targeting all ennemies
targetEnnemies = true,
isSpecial = false,
choregraphy = { -- the main attack choregraphy
{"goTo", "none", "target", -0.4, 0, 0.5, true},
{"sendDamage", "none", 120, 100, false, false},

View file

@ -15,7 +15,7 @@ function Ennemy:draw()
self:drawSprite(0, -self.z)
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
local height = 32

View file

@ -18,22 +18,15 @@ function HeroFighter:new(owner, character, id)
self.statusbar = StatusBar(self.abstract, self.turnSystem.scene)
self:initVoices()
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)
HeroFighter.super.update(self, dt)
if (self.selection ~= nil) then
self.selection:update(dt)
end
@ -111,11 +104,6 @@ function HeroFighter:goBackToMenu()
self.selection = nil
end
function HeroFighter:finishAction()
self.action = nil
self:setInactive()
end
-- LIFE functions
function HeroFighter:setHP(value, relative)
HeroFighter.super.setHP(self, value, relative)

View file

@ -18,6 +18,8 @@ function FighterParent:new(owner, isHero, id)
self.isActive = false
self.isAlive = true
self.action = nil
end
-- LIFE handling functions
@ -77,10 +79,10 @@ function FighterParent:createActor()
end
function FighterParent:update(dt)
counter = counter + dt
if (counter > 1) then
counter = 0
self:setInactive()
if (self.action ~= nil) then
if (self.action.isStarted) then
self.action:update(dt)
end
end
end
@ -111,6 +113,11 @@ function FighterParent:startAction()
end
function FighterParent:finishAction()
self.action = nil
self:setInactive()
end
function FighterParent:getUniqueIdentificator()
local side = 1
if (isHero == false) then

View file

@ -0,0 +1,5 @@
local folder = "scenes.battlesystem.controllers.fighters.systems.behaviours."
return {
["random"] = require(folder .. "random")
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -2,6 +2,9 @@ local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
local VillainFighter = FighterParent:extend()
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 ENNEMY_LINE = 11;
@ -19,7 +22,6 @@ function VillainFighter:updateAssets(dt)
self.hpbar:update(dt)
end
function VillainFighter:getAbstract()
return game.ennemies:getEnnemyData(self.category, self.name)
end
@ -30,9 +32,42 @@ function VillainFighter:createActor()
end
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
function VillainFighter:endAction()
end