feat(cbs): initial implementation of damage system

This commit is contained in:
Kazhnuz 2019-08-15 15:06:13 +02:00
parent c7a24a2bf3
commit 45c58bcbcd
5 changed files with 73 additions and 0 deletions

View file

@ -32,4 +32,37 @@ function Battler:validateAction()
end
function Battler:sendDamage(x, y, value, accuracy, isSpecial, isAerial)
local stats = self:getStats()
local value = value / 10
if (isSpecial) then
value = value * stats.power
else
value = value * stats.attack
end
core.debug:print("battler", "sending " .. value .." damage at position <" .. x .. ";" .. y .. ">")
local fromEnnemy = self.isEnnemy
local other = self.world:getActorInCase(x, y)
if (other ~= nil) then
core.debug:print("battler", "sending damage to actor at position <" .. x .. ";" .. y .. ">")
other:receiveDamage(value, accuracy, isSpecial, isAerial, fromWho)
end
end
function Battler:receiveDamage(value, accuracy, isSpecial, isAerial)
local stats = self:getStats()
if (fromEnnemy ~= self.isEnnemy) then
if (isSpecial) then
value = value / stats.mind
else
value = value / stats.defense
end
core.debug:print("battler", "taken " .. value .. " damage" )
self:setHP(value * -1, true)
end
end
return Battler

View file

@ -43,6 +43,17 @@ function Ennemy:receiveDatas()
self.data = game.ennemies:getEnnemyData(self.ennid)
end
function Ennemy:setHP(value, relative)
if (relative) then
value = self.hp + value
end
self.hp = value
if (self.hp <= 0) then
self:destroy()
end
end
function Ennemy:getStats()
return self.data.stats
end

View file

@ -186,16 +186,31 @@ end
function Hero:animationEnded(animation)
if (animation == "hit1") then
self:sendDamage(self.x + self.direction, self.y, 33, 100, false, false)
self:changeAnimation("hit2")
elseif (animation == "hit2") then
self:sendDamage(self.x + self.direction, self.y, 33, 100, false, false)
self:changeAnimation("hit3")
elseif (animation == "hit3") then
self:sendDamage(self.x + self.direction, self.y, 33, 100, false, false)
core.debug:print("cbs/hero", "normal combo finished, switching actor")
self:changeAnimation("idle")
self.world:switchActiveBattler( )
end
end
-- STATS FUNCTIONS
-- Handle character stats and stuff
function Hero:setHP(value, relative)
if (relative) then
local hp = game.characters.list[self.charid].stats.hp
value = hp + value
end
game.characters.list[self.charid].stats.hp = value
end
-- DRAW FUNCTIONS
-- Draw everything related to the hero

View file

@ -23,6 +23,7 @@ function Parent:new(world, x, y, z)
self.isHero = false
self.isActor = false
self.isEnnemy = false
self.isDestroyed = false
self:register()
end
@ -31,6 +32,11 @@ function Parent:register()
self.world:registerActor(self)
end
function Parent:destroy()
self.world:destroyActor(self)
self.destroyed = true
end
function Parent:update(dt)
self:updateSprite(dt)
end

View file

@ -63,6 +63,14 @@ function World:registerActor(actor)
actor.id = self.globalID
end
function World:destroyActor(actorToDestroy)
for i, actor in ipairs(self.actors) do
if actor == actorToDestroy then
table.remove(self.actors, i)
end
end
end
-- INFO FUNCTIONS
-- Get info from the world