feat: add resistences and weaknesses
This commit is contained in:
parent
534517f0f3
commit
98af0eda2a
9 changed files with 121 additions and 6 deletions
42
sonic-radiance.love/datas/gamedata/battles/elements.lua
Normal file
42
sonic-radiance.love/datas/gamedata/battles/elements.lua
Normal file
|
@ -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 = {}
|
||||
}
|
||||
}
|
22
sonic-radiance.love/datas/gamedata/battles/protectypes.lua
Normal file
22
sonic-radiance.love/datas/gamedata/battles/protectypes.lua
Normal file
|
@ -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"}
|
||||
},
|
||||
}
|
|
@ -13,6 +13,9 @@ return {
|
|||
canGoSuper = true,
|
||||
canBreakCraft = false,
|
||||
|
||||
weakTo = {},
|
||||
resists = {},
|
||||
|
||||
icon = 3,
|
||||
charset = "perso",
|
||||
charId = 3,
|
||||
|
|
|
@ -13,6 +13,9 @@ return {
|
|||
canGoSuper = true,
|
||||
canBreakCraft = false,
|
||||
|
||||
weakTo = {"water"},
|
||||
resists = {"wind"},
|
||||
|
||||
icon = 1,
|
||||
charset = "perso",
|
||||
charId = 1,
|
||||
|
|
|
@ -13,6 +13,9 @@ return {
|
|||
canGoSuper = true,
|
||||
canBreakCraft = false,
|
||||
|
||||
weakTo = {"light"},
|
||||
resists = {"earth"},
|
||||
|
||||
icon = 2,
|
||||
charset = "perso",
|
||||
charId = 2,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,13 +27,34 @@ 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
|
||||
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)
|
||||
local accuracy = 100
|
||||
return (math.random(100) <= accuracy)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue