From 6818a441dfebfa9d2d115046ac485b2922c31e9e Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 May 2021 08:33:41 +0200 Subject: [PATCH 1/5] chore: extract battle aglorythm in battleutils --- sonic-radiance.love/datas/cbs.lua | 4 ++ .../game/utils/battle/init.lua | 38 +++++++++++++ .../controllers/fighters/parent.lua | 53 +++++++------------ 3 files changed, 60 insertions(+), 35 deletions(-) diff --git a/sonic-radiance.love/datas/cbs.lua b/sonic-radiance.love/datas/cbs.lua index 7d1028e..cbafe36 100644 --- a/sonic-radiance.love/datas/cbs.lua +++ b/sonic-radiance.love/datas/cbs.lua @@ -3,4 +3,8 @@ local CONST = {} CONST.ACCURACY = 100 CONST.ATKWRONGTYPE = 0.66 +CONST.DAMAGE = {} +CONST.DAMAGE.DIVISOR = 10 +CONST.DAMAGE.DEFFACTOR = 0.66 + return CONST \ No newline at end of file diff --git a/sonic-radiance.love/game/utils/battle/init.lua b/sonic-radiance.love/game/utils/battle/init.lua index 42bdf43..5f05529 100644 --- a/sonic-radiance.love/game/utils/battle/init.lua +++ b/sonic-radiance.love/game/utils/battle/init.lua @@ -1,3 +1,41 @@ local BattleUtils = {} +local CONSTS = require "datas.cbs" + +function BattleUtils.computeLaunchingDamages(base, stats, isSpecial) + local damages = base / CONSTS.DAMAGE.DIVISOR + if (isSpecial) then + damages = damages * stats.power + else + damages = damages * stats.attack + end + return damages +end + +function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending) + local damages = base + if (isSpecial) then + damages = damages / stats.mind + else + damages = damages / stats.defense + end + + if (isDefending) then + damages = damages * CONSTS.DAMAGE.DEFFACTOR + end + + return damages +end + +function BattleUtils.applyProtectTypes(value, type, protectype) + if (utils.table.contain(protectype, "aerial") and type == "basic") then + value = value * CONSTS.ATKWRONGTYPE + end + return value +end + +function BattleUtils.isAttackSuccess(statutList) + local accuracy = 100 + return (math.random(100) <= accuracy) +end return BattleUtils diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index ea64b2d..c990bae 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -1,6 +1,7 @@ local FighterParent = Object:extend() local CONST = require "datas.cbs" +local battleutils = require "game.utils.battle" function FighterParent:new(owner, isHero, id) self.owner = owner @@ -75,50 +76,32 @@ function FighterParent:haveProtecType(type) end function FighterParent:sendDamage(target, value, type, element, isSpecial) - local stats = self:getStats() - local value = value / 10 + local damage = battleutils.computeLaunchingDamages(value, self:getStats(), isSpecial) - if (isSpecial) then - value = value * stats.power - else - value = value * stats.attack - end - - core.debug:print("cbs/battler", "Sending " .. value .." damage at " .. target.name) - - return target:receiveDamage(value, type, element, isSpecial, self) + core.debug:print("cbs/battler", "Sending " .. damage .." damage at " .. target.name) + return target:receiveDamage(damage, type, element, isSpecial, self) end function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho) - local accuracy = 100 - local stats = self:getStats() - local isSuccess = true + local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending) + damages = battleutils.applyProtectTypes(damages, type, self:getProtecTypes()) - if (isSpecial) then - value = value / stats.mind - else - value = value / stats.defense - end - - if (self:haveProtecType("aerial") and type == "basic") then - value = value * CONST.ATKWRONGTYPE - 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 + if (battleutils.isAttackSuccess(nil)) then + self:applyDamage(damages) else self.actor:avoidedAttack() + return false end - return isSuccess + return true +end + +function FighterParent:applyDamage(damage) + core.debug:print("cbs/fighter", "Taken " .. damage .. " damage" ) + self:setHP(damage * -1, true) + if (not self.isDefending) then + self.actor:getHurt() + end end function FighterParent:getAbstract() From 8c9f814370493bd7dd9fb794f3ecedfd7df617a3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 May 2021 08:36:06 +0200 Subject: [PATCH 2/5] fix: fix a crash --- .../scenes/battlesystem/controllers/fighters/parent.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index c990bae..5786fd4 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -84,7 +84,7 @@ end function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho) local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending) - damages = battleutils.applyProtectTypes(damages, type, self:getProtecTypes()) + damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes()) if (battleutils.isAttackSuccess(nil)) then self:applyDamage(damages) From e9c9cbb8e3ad1b67d7893b2cb5635202da7be9d3 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 May 2021 08:38:09 +0200 Subject: [PATCH 3/5] chore: put const files in a single folder --- sonic-radiance.love/datas/{cbs.lua => consts/battle.lua} | 0 sonic-radiance.love/datas/{ => consts}/stats.lua | 0 sonic-radiance.love/datas/gamedata/characters/amy/stats.lua | 2 +- sonic-radiance.love/datas/gamedata/characters/sonic/stats.lua | 2 +- sonic-radiance.love/datas/gamedata/characters/tails/stats.lua | 2 +- sonic-radiance.love/game/abstractmobs/character/levels.lua | 2 +- sonic-radiance.love/game/utils/battle/init.lua | 2 +- sonic-radiance.love/game/utils/characters.lua | 2 +- .../scenes/battlesystem/controllers/fighters/parent.lua | 2 +- .../scenes/overworld/screens/mainmenu/character/statpage.lua | 2 +- sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua | 2 +- 11 files changed, 9 insertions(+), 9 deletions(-) rename sonic-radiance.love/datas/{cbs.lua => consts/battle.lua} (100%) rename sonic-radiance.love/datas/{ => consts}/stats.lua (100%) diff --git a/sonic-radiance.love/datas/cbs.lua b/sonic-radiance.love/datas/consts/battle.lua similarity index 100% rename from sonic-radiance.love/datas/cbs.lua rename to sonic-radiance.love/datas/consts/battle.lua diff --git a/sonic-radiance.love/datas/stats.lua b/sonic-radiance.love/datas/consts/stats.lua similarity index 100% rename from sonic-radiance.love/datas/stats.lua rename to sonic-radiance.love/datas/consts/stats.lua diff --git a/sonic-radiance.love/datas/gamedata/characters/amy/stats.lua b/sonic-radiance.love/datas/gamedata/characters/amy/stats.lua index 5879ee4..f1d7862 100644 --- a/sonic-radiance.love/datas/gamedata/characters/amy/stats.lua +++ b/sonic-radiance.love/datas/gamedata/characters/amy/stats.lua @@ -1,4 +1,4 @@ -local CONST = require "datas.stats" +local CONST = require "datas.consts.stats" return { hpmax = CONST.RANK_A, -- diff --git a/sonic-radiance.love/datas/gamedata/characters/sonic/stats.lua b/sonic-radiance.love/datas/gamedata/characters/sonic/stats.lua index b685137..96d3630 100644 --- a/sonic-radiance.love/datas/gamedata/characters/sonic/stats.lua +++ b/sonic-radiance.love/datas/gamedata/characters/sonic/stats.lua @@ -1,4 +1,4 @@ -local CONST = require "datas.stats" +local CONST = require "datas.consts.stats" return { hpmax = CONST.RANK_B, -- diff --git a/sonic-radiance.love/datas/gamedata/characters/tails/stats.lua b/sonic-radiance.love/datas/gamedata/characters/tails/stats.lua index 2e54926..3c38b84 100644 --- a/sonic-radiance.love/datas/gamedata/characters/tails/stats.lua +++ b/sonic-radiance.love/datas/gamedata/characters/tails/stats.lua @@ -1,4 +1,4 @@ -local CONST = require "datas.stats" +local CONST = require "datas.consts.stats" return { hpmax = CONST.RANK_C, -- diff --git a/sonic-radiance.love/game/abstractmobs/character/levels.lua b/sonic-radiance.love/game/abstractmobs/character/levels.lua index e3e127a..954c4c7 100644 --- a/sonic-radiance.love/game/abstractmobs/character/levels.lua +++ b/sonic-radiance.love/game/abstractmobs/character/levels.lua @@ -1,7 +1,7 @@ local CharacterLevel = Object:extend() local charutils = require "game.utils.characters" -local STATS = require "datas.stats" +local STATS = require "datas.consts.stats" function CharacterLevel:initLevel() self.level = self.data.startlevel diff --git a/sonic-radiance.love/game/utils/battle/init.lua b/sonic-radiance.love/game/utils/battle/init.lua index 5f05529..bbf9582 100644 --- a/sonic-radiance.love/game/utils/battle/init.lua +++ b/sonic-radiance.love/game/utils/battle/init.lua @@ -1,5 +1,5 @@ local BattleUtils = {} -local CONSTS = require "datas.cbs" +local CONSTS = require "datas.consts.battle" function BattleUtils.computeLaunchingDamages(base, stats, isSpecial) local damages = base / CONSTS.DAMAGE.DIVISOR diff --git a/sonic-radiance.love/game/utils/characters.lua b/sonic-radiance.love/game/utils/characters.lua index e9e4390..8c11059 100644 --- a/sonic-radiance.love/game/utils/characters.lua +++ b/sonic-radiance.love/game/utils/characters.lua @@ -1,6 +1,6 @@ local CharUtils = {} -local CONST = require "datas.stats" +local CONST = require "datas.consts.stats" function CharUtils.getExpValue(level) return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO ) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index 5786fd4..bafa8d9 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -1,6 +1,6 @@ local FighterParent = Object:extend() -local CONST = require "datas.cbs" +local CONST = require "datas.consts.battle" local battleutils = require "game.utils.battle" function FighterParent:new(owner, isHero, id) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua index e8aa0c2..fa120ac 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/statpage.lua @@ -8,7 +8,7 @@ local const = require "scenes.overworld.screens.mainmenu.const" local EquipMenu = menu.ListMenu:extend() local EquipWidget = menu.DualTextWidget:extend() -local STATS = require "datas.stats" +local STATS = require "datas.consts.stats" function StatPage:new(view, character) self.statBox = gui.newTextBox("assets/gui/dialogbox.png", const.CHARPAGESIZE, 40 + 32) diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua index 7615561..28f134b 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/equip.lua @@ -10,7 +10,7 @@ local baseCharacterWidget = require "scenes.overworld.screens.mainmenu.common.ch local CharacterMenu = baseCharacterMenu:extend() local CharacterWidget = baseCharacterWidget:extend() -local STATS = require "datas.stats" +local STATS = require "datas.consts.stats" local DESC_SIZE = 32 * 6 From 534517f0f339994324508dcaa8b613cb33575d20 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 May 2021 08:48:05 +0200 Subject: [PATCH 4/5] chore: kill game.skills --- sonic-radiance.love/game/init.lua | 2 - sonic-radiance.love/game/skills.lua | 47 ------------------- .../fighters/systems/actions/parent.lua | 2 +- .../fighters/systems/actions/skill.lua | 2 +- .../fighters/systems/ennemyaction.lua | 2 +- .../scenes/battlesystem/menus/widgets.lua | 2 +- .../scenes/debug/viewers/choregraphy/init.lua | 10 ++-- .../screens/mainmenu/character/skillpage.lua | 2 +- 8 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 sonic-radiance.love/game/skills.lua diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 3c62c6a..a4fae2a 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -28,7 +28,6 @@ local Serializer = require "birb.classes.serializable.serializer" local Game = Serializer:extend() local Characters = require "game.characters" local Ennemies = require "game.ennemies" -local Skills = require "game.skills" local Loot = require "game.loot" local CBSCore = require "game.battle" local Difficulty = require "game.difficulty" @@ -92,7 +91,6 @@ function Game:reset() self.characters = Characters(self) self.ennemies = Ennemies(self) - self.skills = Skills(self) self.loot = Loot(self) self.cbs = CBSCore(self) self.difficulty = Difficulty(self) diff --git a/sonic-radiance.love/game/skills.lua b/sonic-radiance.love/game/skills.lua deleted file mode 100644 index 4af25ca..0000000 --- a/sonic-radiance.love/game/skills.lua +++ /dev/null @@ -1,47 +0,0 @@ -local SkillManager = Object:extend() - -function SkillManager:new(controller) - self.controller = controller -end - -function SkillManager:getSkillData(skillname) - if core.datas:exists("skills", skillname) then - return core.datas:get("skills", skillname) - end -end - -function SkillManager:skillDataExists(skillname) - return core.datas:exists("skills", skillname) -end - -function SkillManager:getEnnemySkillData(skillname) - if core.datas:exists("badskills", skillname) then - return core.datas:get("badskills", skillname) - end -end - -function SkillManager:ennemySkillDataExists(skillname) - return core.datas:exists("badskills", skillname) -end - -function SkillManager:getActionArguments(choregraphyAction) - local choregraphyData = require "datas.gamedata.skills" - local args = {} - args.name = choregraphyAction[1] - args.condition = choregraphyAction[2] - local actionData = choregraphyData.actions[args.name] - if actionData ~= nil then - args.type = actionData[1] - local argumentList = actionData[2] - for i, argData in ipairs(choregraphyAction) do - if i > 2 then - local argName = argumentList[i-2] or "" - args[argName] = argData - end - end - end - - return args -end - -return SkillManager diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua index 467b7ac..3371346 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/parent.lua @@ -17,7 +17,7 @@ function ActionParent:update(dt) end function ActionParent:loadChoregraphy(skillname) - local skill = game.skills:getSkillData(skillname) + local skill = core.datas:get("skills", skillname) self.choregraphy = ChoregraphySystem(self, skill.choregraphy) end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/skill.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/skill.lua index e7a4a08..b0dfcff 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/skill.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/actions/skill.lua @@ -2,7 +2,7 @@ local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.a local SkillAction = ActionParent:extend() function SkillAction:new(fighter, skill) - self.data = game.skills:getSkillData(skill) + self.data = core.datas:get("skills", skill) SkillAction.super.new(self, fighter) end diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/ennemyaction.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/ennemyaction.lua index 72e343d..e06fb8c 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/ennemyaction.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/ennemyaction.lua @@ -2,7 +2,7 @@ local ActionParent = require "scenes.battlesystem.controllers.fighters.systems.a local EnnemyAction = ActionParent:extend() function EnnemyAction:new(fighter, skill) - self.data = game.skills:getEnnemySkillData(skill) + self.data = core.datas:get("badskills", skill) EnnemyAction.super.new(self, fighter) end diff --git a/sonic-radiance.love/scenes/battlesystem/menus/widgets.lua b/sonic-radiance.love/scenes/battlesystem/menus/widgets.lua index c39975a..4ec7d51 100644 --- a/sonic-radiance.love/scenes/battlesystem/menus/widgets.lua +++ b/sonic-radiance.love/scenes/battlesystem/menus/widgets.lua @@ -96,7 +96,7 @@ function widgets.SkillWidget:new(character, menu_name, skill) self.skillname = skill local label2 = "00" - self.skilldata = game.skills:getSkillData(skill) + self.skilldata = core.datas:get("skills", skill) if self.skilldata ~= nil then label2 = self.skilldata.cost or 0 diff --git a/sonic-radiance.love/scenes/debug/viewers/choregraphy/init.lua b/sonic-radiance.love/scenes/debug/viewers/choregraphy/init.lua index 133afe7..39262a5 100644 --- a/sonic-radiance.love/scenes/debug/viewers/choregraphy/init.lua +++ b/sonic-radiance.love/scenes/debug/viewers/choregraphy/init.lua @@ -35,7 +35,7 @@ function ChoregraphyViewer:buildCharacterMenu() self:addSubMenu("characters", "MainMenu", "Rivals") for k, character in pairs(game.characters.list) do self:addSubMenu(k, "characters", character.fullname) - menu.HeroChoregraphyWidget(self, k, game.skills:getSkillData("attack")) + menu.HeroChoregraphyWidget(self, k, core.datas:get("skills", "attack")) self:buildSkillMenu(k) end end @@ -51,8 +51,8 @@ function ChoregraphyViewer:buildEnnemySkillMenu(category, ennemy) self:addSubMenu(ennemy, category, ennemy) local data = core.datas:get("ennemies", ennemy) for j,skillName in ipairs(data.skills) do - if (game.skills:ennemySkillDataExists(skillName)) then - menu.EnnemyChoregraphyWidget(self, category, ennemy, game.skills:getEnnemySkillData(skillName)) + if (core.datas:exists("badskills", skillName)) then + menu.EnnemyChoregraphyWidget(self, category, ennemy, core.datas:get("badskills", skillName)) end end end @@ -64,8 +64,8 @@ function ChoregraphyViewer:buildSkillMenu(charName) local skillName = skill[1] if (skillTreated[skillName] ~= true) then skillTreated[skillName] = true - if (game.skills:skillDataExists(skillName)) then - menu.HeroChoregraphyWidget(self, charName, game.skills:getSkillData(skillName)) + if (core.datas:exists("skills", skillName)) then + menu.HeroChoregraphyWidget(self, charName, core.datas:get("skills", skillName)) end end end diff --git a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua index 17220ec..db4681c 100644 --- a/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua +++ b/sonic-radiance.love/scenes/overworld/screens/mainmenu/character/skillpage.lua @@ -60,7 +60,7 @@ end function SkillWidget:new(page, skill) self.page = page - self.skillData = game.skills:getSkillData(skill) + self.skillData = core.datas:get("skills", skill) SkillWidget.super.new(self, self.page.view.scene, "equip", self.skillData.fullname, utils.math.numberToString(self.skillData.cost, 2)) end From 98af0eda2a947cb66644b90e4e9754f5ebc36fde Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 May 2021 10:06:20 +0200 Subject: [PATCH 5/5] feat: add resistences and weaknesses --- .../datas/gamedata/battles/elements.lua | 42 +++++++++++++++++++ .../datas/gamedata/battles/protectypes.lua | 22 ++++++++++ .../datas/gamedata/characters/amy/init.lua | 3 ++ .../datas/gamedata/characters/sonic/init.lua | 3 ++ .../datas/gamedata/characters/tails/init.lua | 3 ++ .../game/abstractmobs/character/datas.lua | 8 ++++ .../game/abstractmobs/ennemy.lua | 11 +++++ .../game/utils/battle/init.lua | 32 +++++++++++--- .../controllers/fighters/parent.lua | 3 +- 9 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 sonic-radiance.love/datas/gamedata/battles/elements.lua create mode 100644 sonic-radiance.love/datas/gamedata/battles/protectypes.lua diff --git a/sonic-radiance.love/datas/gamedata/battles/elements.lua b/sonic-radiance.love/datas/gamedata/battles/elements.lua new file mode 100644 index 0000000..3ec5f5b --- /dev/null +++ b/sonic-radiance.love/datas/gamedata/battles/elements.lua @@ -0,0 +1,42 @@ +return { + ["none"] = { + fullname = "None", + weakTo = {}, + resists = {} + }, + ["water"] = { + fullname = "Water", + weakTo = {"light"}, + resists = {"fire", "water"} + }, + ["fire"] = { + fullname = "Fire", + weakTo = {"water"}, + resists = {"ice", "fire"} + }, + ["ice"] = { + fullname = "Fire", + weakTo = {"fire"}, + resists = {"wind", "ice"} + }, + ["wind"] = { + fullname = "Fire", + weakTo = {"ice"}, + resists = {"earth", "wind"} + }, + ["earth"] = { + fullname = "Fire", + weakTo = {"wind"}, + resists = {"light", "earth"} + }, + ["light"] = { + fullname = "Fire", + weakTo = {"earth"}, + resists = {"water", "light"} + }, + ["chaos"] = { + fullname = "Chaos", + weakTo = {"chaos"}, + resists = {} + } +} \ No newline at end of file diff --git a/sonic-radiance.love/datas/gamedata/battles/protectypes.lua b/sonic-radiance.love/datas/gamedata/battles/protectypes.lua new file mode 100644 index 0000000..222ce6f --- /dev/null +++ b/sonic-radiance.love/datas/gamedata/battles/protectypes.lua @@ -0,0 +1,22 @@ +return { + ["basic"] = { + resistTo = {}, + backDamage = {} + }, + ["aerial"] = { + resistTo = {"basic"}, + backDamage = {} + }, + ["shielded"] = { + resistTo = {"basic", "projectile"}, + backDamage = {} + }, + ["spiked"] = { + resistTo = {"basic", "aerial"}, + backDamage = {"basic", "aerial"} + }, + ["backspiked"] = { + resistTo = {"aerial"}, + backDamage = {"aerial"} + }, +} \ No newline at end of file diff --git a/sonic-radiance.love/datas/gamedata/characters/amy/init.lua b/sonic-radiance.love/datas/gamedata/characters/amy/init.lua index ab50f27..0621f24 100644 --- a/sonic-radiance.love/datas/gamedata/characters/amy/init.lua +++ b/sonic-radiance.love/datas/gamedata/characters/amy/init.lua @@ -13,6 +13,9 @@ return { canGoSuper = true, canBreakCraft = false, + weakTo = {}, + resists = {}, + icon = 3, charset = "perso", charId = 3, diff --git a/sonic-radiance.love/datas/gamedata/characters/sonic/init.lua b/sonic-radiance.love/datas/gamedata/characters/sonic/init.lua index cc1a34b..80f68cc 100644 --- a/sonic-radiance.love/datas/gamedata/characters/sonic/init.lua +++ b/sonic-radiance.love/datas/gamedata/characters/sonic/init.lua @@ -13,6 +13,9 @@ return { canGoSuper = true, canBreakCraft = false, + weakTo = {"water"}, + resists = {"wind"}, + icon = 1, charset = "perso", charId = 1, diff --git a/sonic-radiance.love/datas/gamedata/characters/tails/init.lua b/sonic-radiance.love/datas/gamedata/characters/tails/init.lua index eca83a7..56b76a6 100644 --- a/sonic-radiance.love/datas/gamedata/characters/tails/init.lua +++ b/sonic-radiance.love/datas/gamedata/characters/tails/init.lua @@ -13,6 +13,9 @@ return { canGoSuper = true, canBreakCraft = false, + weakTo = {"light"}, + resists = {"earth"}, + icon = 2, charset = "perso", charId = 2, diff --git a/sonic-radiance.love/game/abstractmobs/character/datas.lua b/sonic-radiance.love/game/abstractmobs/character/datas.lua index 14a4aa1..d688f71 100644 --- a/sonic-radiance.love/game/abstractmobs/character/datas.lua +++ b/sonic-radiance.love/game/abstractmobs/character/datas.lua @@ -7,4 +7,12 @@ function CharacterData:getCommonData() self.turns = self.data.turns end +function CharacterData:getWeaknesses() + return self.data.weakTo +end + +function CharacterData:getResistences() + return self.data.resists +end + return CharacterData diff --git a/sonic-radiance.love/game/abstractmobs/ennemy.lua b/sonic-radiance.love/game/abstractmobs/ennemy.lua index a49e55c..7005bd2 100644 --- a/sonic-radiance.love/game/abstractmobs/ennemy.lua +++ b/sonic-radiance.love/game/abstractmobs/ennemy.lua @@ -1,6 +1,7 @@ local AbstractMobParent = require "game.abstractmobs.parent" local AbstractEnnemy = AbstractMobParent:extend() +local elements = require "datas.gamedata.battles.elements" function AbstractEnnemy:new(directory, name) self.simplename = name @@ -8,6 +9,16 @@ function AbstractEnnemy:new(directory, name) self.super.new(self) end +function AbstractEnnemy:getWeaknesses() + local elementData = elements[self.data.element] or elements["none"] + return elementData.weakTo +end + +function AbstractEnnemy:getResistences() + local elementData = elements[self.data.element] or elements["none"] + return elementData.resists +end + function AbstractEnnemy:haveProtecType(protectype) return utils.table.contain(self.data.protectypes, protectype) end diff --git a/sonic-radiance.love/game/utils/battle/init.lua b/sonic-radiance.love/game/utils/battle/init.lua index bbf9582..a6bde26 100644 --- a/sonic-radiance.love/game/utils/battle/init.lua +++ b/sonic-radiance.love/game/utils/battle/init.lua @@ -1,5 +1,6 @@ local BattleUtils = {} local CONSTS = require "datas.consts.battle" +local protectypes = require "datas.gamedata.battles.protectypes" function BattleUtils.computeLaunchingDamages(base, stats, isSpecial) local damages = base / CONSTS.DAMAGE.DIVISOR @@ -26,11 +27,32 @@ function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending return damages end -function BattleUtils.applyProtectTypes(value, type, protectype) - if (utils.table.contain(protectype, "aerial") and type == "basic") then - value = value * CONSTS.ATKWRONGTYPE - end - return value +function BattleUtils.applyProtectTypes(value, type, protectypeList) + for _, protectype in ipairs(protectypeList) do + local protecttypeData = protectypes[protectype] + if protecttypeData ~= nil then + if (utils.table.contain(protecttypeData.resistTo, type)) then + value = value * CONSTS.ATKWRONGTYPE + end + else + core.debug:warning("battleutils", "protectype " .. protectype .. " doesn't exists ") + end + end + return value +end + +function BattleUtils.applyWeaknesses(damages, element, weaknessList) + if (utils.table.contain(weaknessList, element)) then + damages = damages * 1.2 + end + return damages +end + +function BattleUtils.applyResistences(damages, element, resistsList) + if (utils.table.contain(resistsList, element)) then + damages = damages * 0.8 + end + return damages end function BattleUtils.isAttackSuccess(statutList) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua index bafa8d9..ed7e734 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/parent.lua @@ -1,6 +1,5 @@ local FighterParent = Object:extend() -local CONST = require "datas.consts.battle" local battleutils = require "game.utils.battle" function FighterParent:new(owner, isHero, id) @@ -85,6 +84,8 @@ end function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho) local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending) damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes()) + damages = battleutils.applyResistences(damages, element, self.abstract:getResistences()) + damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses()) if (battleutils.isAttackSuccess(nil)) then self:applyDamage(damages)