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,
|
canGoSuper = true,
|
||||||
canBreakCraft = false,
|
canBreakCraft = false,
|
||||||
|
|
||||||
|
weakTo = {},
|
||||||
|
resists = {},
|
||||||
|
|
||||||
icon = 3,
|
icon = 3,
|
||||||
charset = "perso",
|
charset = "perso",
|
||||||
charId = 3,
|
charId = 3,
|
||||||
|
|
|
@ -13,6 +13,9 @@ return {
|
||||||
canGoSuper = true,
|
canGoSuper = true,
|
||||||
canBreakCraft = false,
|
canBreakCraft = false,
|
||||||
|
|
||||||
|
weakTo = {"water"},
|
||||||
|
resists = {"wind"},
|
||||||
|
|
||||||
icon = 1,
|
icon = 1,
|
||||||
charset = "perso",
|
charset = "perso",
|
||||||
charId = 1,
|
charId = 1,
|
||||||
|
|
|
@ -13,6 +13,9 @@ return {
|
||||||
canGoSuper = true,
|
canGoSuper = true,
|
||||||
canBreakCraft = false,
|
canBreakCraft = false,
|
||||||
|
|
||||||
|
weakTo = {"light"},
|
||||||
|
resists = {"earth"},
|
||||||
|
|
||||||
icon = 2,
|
icon = 2,
|
||||||
charset = "perso",
|
charset = "perso",
|
||||||
charId = 2,
|
charId = 2,
|
||||||
|
|
|
@ -7,4 +7,12 @@ function CharacterData:getCommonData()
|
||||||
self.turns = self.data.turns
|
self.turns = self.data.turns
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CharacterData:getWeaknesses()
|
||||||
|
return self.data.weakTo
|
||||||
|
end
|
||||||
|
|
||||||
|
function CharacterData:getResistences()
|
||||||
|
return self.data.resists
|
||||||
|
end
|
||||||
|
|
||||||
return CharacterData
|
return CharacterData
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
local AbstractMobParent = require "game.abstractmobs.parent"
|
local AbstractMobParent = require "game.abstractmobs.parent"
|
||||||
|
|
||||||
local AbstractEnnemy = AbstractMobParent:extend()
|
local AbstractEnnemy = AbstractMobParent:extend()
|
||||||
|
local elements = require "datas.gamedata.battles.elements"
|
||||||
|
|
||||||
function AbstractEnnemy:new(directory, name)
|
function AbstractEnnemy:new(directory, name)
|
||||||
self.simplename = name
|
self.simplename = name
|
||||||
|
@ -8,6 +9,16 @@ function AbstractEnnemy:new(directory, name)
|
||||||
self.super.new(self)
|
self.super.new(self)
|
||||||
end
|
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)
|
function AbstractEnnemy:haveProtecType(protectype)
|
||||||
return utils.table.contain(self.data.protectypes, protectype)
|
return utils.table.contain(self.data.protectypes, protectype)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
local BattleUtils = {}
|
local BattleUtils = {}
|
||||||
local CONSTS = require "datas.consts.battle"
|
local CONSTS = require "datas.consts.battle"
|
||||||
|
local protectypes = require "datas.gamedata.battles.protectypes"
|
||||||
|
|
||||||
function BattleUtils.computeLaunchingDamages(base, stats, isSpecial)
|
function BattleUtils.computeLaunchingDamages(base, stats, isSpecial)
|
||||||
local damages = base / CONSTS.DAMAGE.DIVISOR
|
local damages = base / CONSTS.DAMAGE.DIVISOR
|
||||||
|
@ -26,11 +27,32 @@ function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending
|
||||||
return damages
|
return damages
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleUtils.applyProtectTypes(value, type, protectype)
|
function BattleUtils.applyProtectTypes(value, type, protectypeList)
|
||||||
if (utils.table.contain(protectype, "aerial") and type == "basic") then
|
for _, protectype in ipairs(protectypeList) do
|
||||||
value = value * CONSTS.ATKWRONGTYPE
|
local protecttypeData = protectypes[protectype]
|
||||||
end
|
if protecttypeData ~= nil then
|
||||||
return value
|
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
|
end
|
||||||
|
|
||||||
function BattleUtils.isAttackSuccess(statutList)
|
function BattleUtils.isAttackSuccess(statutList)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
local FighterParent = Object:extend()
|
local FighterParent = Object:extend()
|
||||||
|
|
||||||
local CONST = require "datas.consts.battle"
|
|
||||||
local battleutils = require "game.utils.battle"
|
local battleutils = require "game.utils.battle"
|
||||||
|
|
||||||
function FighterParent:new(owner, isHero, id)
|
function FighterParent:new(owner, isHero, id)
|
||||||
|
@ -85,6 +84,8 @@ end
|
||||||
function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho)
|
function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho)
|
||||||
local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending)
|
local damages = battleutils.computeReceivingDamages(value, self:getStats(), isSpecial, self.isDefending)
|
||||||
damages = battleutils.applyProtectTypes(damages, type, self.abstract:getProtecTypes())
|
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
|
if (battleutils.isAttackSuccess(nil)) then
|
||||||
self:applyDamage(damages)
|
self:applyDamage(damages)
|
||||||
|
|
Loading…
Reference in a new issue