From 487d14dece9f9df5c15c166e19637cdfecf8e1bc Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 9 May 2021 15:08:46 +0200 Subject: [PATCH] feat: make aerial ennemies able to avoir attacks --- .../controllers/fighters/parent.lua | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index 8fdc974..3ed84c0 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -2,6 +2,8 @@ local FighterParent = Object:extend() local counter = 0 +local AERIAL_ACCURACY_FACTOR = 0 + function FighterParent:new(owner, isHero, id) self.owner = owner self.turnSystem = owner.turnSystem @@ -82,11 +84,12 @@ function FighterParent:sendDamage(target, value, accuracy, isSpecial, isAerial) core.debug:print("cbs/battler", "Sending " .. value .." damage at " .. target.name) - target:receiveDamage(value, accuracy, isSpecial, isAerial, self) + return target:receiveDamage(value, accuracy, isSpecial, isAerial, self) end function FighterParent:receiveDamage(value, accuracy, isSpecial, isAerial, fromWho) local stats = self:getStats() + local isSuccess = true if (isSpecial) then value = value / stats.mind @@ -94,13 +97,27 @@ function FighterParent:receiveDamage(value, accuracy, isSpecial, isAerial, fromW value = value / stats.defense end - core.debug:print("cbs/fighter", "Taken " .. value .. " damage" ) - if (self.isDefending) then - self:setHP(value * -0.66, true) - else - self:setHP(value * -1, true) - self.actor:getHurt() + print(self.abstract.data.isArieal) + + if (self.abstract.data.isAerial and not isAerial) then + accuracy = accuracy * AERIAL_ACCURACY_FACTOR end + + isSuccess = (math.random(100) <= accuracy) + + if (isSuccess) then + core.debug:print("cbs/fighter", "Taken " .. value .. " damage" ) + if (self.isDefending) then + self:setHP(value * -0.66, true) + else + self:setHP(value * -1, true) + self.actor:getHurt() + end + else + self.actor:avoidedAttack() + end + + return isSuccess end function FighterParent:getAbstract()