63 lines
1.8 KiB
Lua
63 lines
1.8 KiB
Lua
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
|
|
if (isSpecial) then
|
|
damages = damages * stats:get(stats.POWER)
|
|
else
|
|
damages = damages * stats:get(stats.ATTACK)
|
|
end
|
|
return damages
|
|
end
|
|
|
|
function BattleUtils.computeReceivingDamages(base, stats, isSpecial, isDefending)
|
|
local damages = base
|
|
if (isSpecial) then
|
|
damages = damages / stats:get(stats.MIND)
|
|
else
|
|
damages = damages / stats:get(stats.DEFENSE)
|
|
end
|
|
|
|
if (isDefending) then
|
|
damages = damages * CONSTS.DAMAGE.DEFFACTOR
|
|
end
|
|
|
|
return damages
|
|
end
|
|
|
|
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)
|
|
end
|
|
|
|
return BattleUtils
|