From 6e93a11fefef8212176ec2ae323ec1576f4a25c5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 8 Aug 2021 16:00:45 +0200 Subject: [PATCH] feat: add statuses stat effect --- .../datas/gamedata/statuses.lua | 38 +++++++++++++++++++ .../datas/parsers/choregraphystep.lua | 1 + .../game/abstractmobs/parent.lua | 14 +++++++ .../controllers/fighters/parent.lua | 25 +++++++++++- .../systems/choregraphy/mixins/wrappers.lua | 10 +++++ .../systems/choregraphy/step/init.lua | 1 + .../systems/choregraphy/step/sendStatus.lua | 17 +++++++++ 7 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/datas/gamedata/statuses.lua create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/sendStatus.lua diff --git a/sonic-radiance.love/datas/gamedata/statuses.lua b/sonic-radiance.love/datas/gamedata/statuses.lua new file mode 100644 index 0000000..10d0b27 --- /dev/null +++ b/sonic-radiance.love/datas/gamedata/statuses.lua @@ -0,0 +1,38 @@ +return { + hidden = { + {"evasion", 30}, + }, + focus = { + {"critical", 30}, + }, + shielded = { + {"armor", 20} + }, + hyper = { + {"damage", 25}, + {"critical", 20} + }, + lucky = { + {"evasion", 20}, + {"luck", 20}, + }, + regen = { + {"hpregen", 8} + }, + poison = { + {"hpregen", -15} + }, + weakened = { + {"damage", -20} + }, + vulnerable = { + {"armor", -20} + }, + cursed = { + {"evasion", 0}, + {"luck", -30} + }, + distracted = { + {"accuracy", -30} + } +} \ No newline at end of file diff --git a/sonic-radiance.love/datas/parsers/choregraphystep.lua b/sonic-radiance.love/datas/parsers/choregraphystep.lua index 05860c1..0823fc1 100644 --- a/sonic-radiance.love/datas/parsers/choregraphystep.lua +++ b/sonic-radiance.love/datas/parsers/choregraphystep.lua @@ -5,6 +5,7 @@ return { ["addGFX"] = {'sprite', "origin", "x", "y", "z", "affectedByDirection", 'blockProcess'}, ["playSFX"] = {"sfx"}, ["sendDamage"] = {"power", "type", "element", "isSpecial"}, + ["sendStatus"] = {"status", "duration", "force"}, ["goTo"] = {"who", "origin", "x", "y", "duration", "blockProcess"}, ["goTo3D"] = {"who", "origin", "x", "y", "z", "duration", "blockProcess"}, ["setAnimation"] = {"who", "animation", "blockProcess"}, diff --git a/sonic-radiance.love/game/abstractmobs/parent.lua b/sonic-radiance.love/game/abstractmobs/parent.lua index b03b27f..61f2ee1 100644 --- a/sonic-radiance.love/game/abstractmobs/parent.lua +++ b/sonic-radiance.love/game/abstractmobs/parent.lua @@ -2,6 +2,8 @@ local Serializable = require "birb.classes.serializable" local AbstractMobParent = Serializable:extend() local StatManager = require "game.abstractmobs.statmanager" +local statutStatList = require "datas.gamedata.statuses" + function AbstractMobParent:new(serializeFields, listSerializable, statManager) local statManager = statManager or StatManager self:initBasicElements() @@ -67,6 +69,18 @@ function AbstractMobParent:getStats() return self.stats end +function AbstractMobParent:getStatutsStat(statName) + local stat = 0 + for statut, _ in pairs(self.statuts) do + for _, statutStat in ipairs(statutStatList[statut]) do + if (statutStat[1] == statName) then + stat = stat + statutStat[2] + end + end + end + return stat +end + -- STATUT HANDLING function AbstractMobParent:addStatut(name, duration) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index 6ab0fc9..8cd7f73 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -82,6 +82,12 @@ function FighterParent:sendDamageToAll(listTarget, value, type, element, isSpeci end end +function FighterParent:sendStatusToAll(listTarget, status, duration, force) + for _, target in ipairs(listTarget) do + self:sendStatus(target, status, duration, force) + end +end + function FighterParent:getTargets(ourSide) if (self.isHero == ourSide) then return self.turnSystem.player:getTargets(true) @@ -102,6 +108,19 @@ function FighterParent:sendDamage(target, value, type, element, isSpecial) end end +function FighterParent:sendStatus(target, status, duration, force) + core.debug:print("cbs/battler", "Sending status " .. status .." at " .. target.name) + if ((not force) or battleutils.rollDice(self:getStat(STATS.ACCURACY))) then + target:receiveStatus(status, duration, force) + end +end + +function FighterParent:receiveStatus(status, duration, force) + if (force or (not battleutils.rollDice(self:getStat(STATS.LUCK)))) then + self.abstract:addStatut(status, duration) + end +end + function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho) local damages = battleutils.computeReceivingDamages(value, self, isSpecial, self.isDefending) damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes()) @@ -178,7 +197,11 @@ function FighterParent:getNbrActionPerTurn() end function FighterParent:getStat(statname) - return (self.abstract.stats:get(statname) * self:getStatBonusValue(statname)) + local stat = (self.abstract.stats:get(statname) * self:getStatBonusValue(statname)) + self.abstract:getStatutsStat(statname) + if (self.abstract:haveStatuts("cursed") and (statname == "evasion")) then + return math.max(0, stat) + end + return stat end function FighterParent:getStatBonusValue(statname) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua index a6fd761..b6e4200 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/mixins/wrappers.lua @@ -46,6 +46,16 @@ function InfosMixin:sendDamage(power, type, element, isSpecial) end end +function InfosMixin:sendStatus(status, duration, force) + if (self.fighter.isAlive) then + if (self.target ~= nil) then + self.fighter:sendStatus(self.target, status, duration, force) + else + self.fighter:sendStatus(self.targetList, status, duration, force) + end + end +end + function InfosMixin:haveFrameSignal(signal) return self.actor:haveFrameSignal(signal) end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua index b2c2525..68c8953 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/init.lua @@ -11,6 +11,7 @@ actions["jumpBack"] = require(baseURI .. "jumpBack") actions["jump"] = require(baseURI .. "jump") actions["playSFX"] = require(baseURI .. "playSFX") actions["sendDamage"] = require(baseURI .. "sendDamage") +actions["sendStatus"] = require(baseURI .. "sendStatus") actions["setAnimation"] = require(baseURI .. "setAnimation") actions["setAnimSpeed"] = require(baseURI .. "setAnimSpeed") actions["wait"] = require(baseURI .. "wait") diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/sendStatus.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/sendStatus.lua new file mode 100644 index 0000000..1681383 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/choregraphy/step/sendStatus.lua @@ -0,0 +1,17 @@ +local StepParent = require "scenes.battlesystem.controllers.fighters.systems.choregraphy.step.parent" +local SendStatus = StepParent:extend() + +function SendStatus:new(system, args) + SendStatus.super.new(self, system, args) +end + +function SendStatus:start() + local status = self.arguments.status + local force = self.arguments.force + local duration = self.arguments.duration + + self.choregraphy:sendStatus(status, duration, force) + self:finish() +end + +return SendStatus