feat: add battle stats
This commit is contained in:
parent
d4698ab101
commit
4c46e510d0
6 changed files with 101 additions and 10 deletions
|
@ -9,6 +9,15 @@ CONST.MIND = "mind"
|
|||
CONST.TECHNIC = "technic"
|
||||
CONST.SPEED = "speed"
|
||||
|
||||
CONST.DAMAGE = "damage"
|
||||
CONST.ACCURACY = "accuracy"
|
||||
CONST.EVASION = "evasion"
|
||||
CONST.LUCK = "luck"
|
||||
CONST.ARMOR = "armor"
|
||||
CONST.CRITICAL = "critical"
|
||||
CONST.HPREGEN = "hpregen"
|
||||
CONST.PPREGEN = "ppregen"
|
||||
|
||||
CONST.RANK_E = 10
|
||||
CONST.RANK_D = 25
|
||||
CONST.RANK_C = 40
|
||||
|
@ -18,6 +27,7 @@ CONST.RANK_S = 100
|
|||
CONST.MULT_HP = 4.5
|
||||
|
||||
CONST.LIST = {CONST.HPMAX, CONST.PPMAX, CONST.ATTACK, CONST.POWER, CONST.DEFENSE, CONST.MIND, CONST.TECHNIC, CONST.SPEED}
|
||||
CONST.BATTLELIST = {CONST.ACCURACY, CONST.EVASION, CONST.LUCK, CONST.DAMAGE, CONST.ARMOR, CONST.CRITICAL, CONST.HPREGEN, CONST.PPREGEN}
|
||||
|
||||
CONST.SIMPLENAME = {}
|
||||
CONST.SIMPLENAME[CONST.HPMAX] = "HP"
|
||||
|
@ -41,4 +51,23 @@ CONST.MULT_HP = 7.5
|
|||
CONST.SALT_HP = 35
|
||||
CONST.MULT_MP = 1.5
|
||||
|
||||
local function createBattleStat(name, valueHero, valueEnnemy)
|
||||
CONST.BATTLESTAT.HERO[name] = valueHero
|
||||
CONST.BATTLESTAT.ENNEMI[name] = valueEnnemy or valueHero
|
||||
end
|
||||
|
||||
CONST.BATTLESTAT = {}
|
||||
CONST.BATTLESTAT.HERO = {}
|
||||
CONST.BATTLESTAT.ENNEMI = {}
|
||||
createBattleStat("accuracy", 100)
|
||||
createBattleStat("evasion", 0)
|
||||
createBattleStat("luck", 66, 40)
|
||||
createBattleStat("damage", 0)
|
||||
createBattleStat("armor", 0)
|
||||
createBattleStat("critical", 0)
|
||||
createBattleStat("hpregen", -10)
|
||||
createBattleStat("ppregen", 10)
|
||||
|
||||
CONST.ARMOR_AND_DAMAGE_RATIO = .5
|
||||
|
||||
return CONST
|
||||
|
|
|
@ -6,7 +6,7 @@ function CharacterStatManager:new(owner)
|
|||
end
|
||||
|
||||
function CharacterStatManager:computeStat(statname, ignoreEquip)
|
||||
local stat = self.owner:getLevelStat(statname) + self.owner:getEquipStats(statname, ignoreEquip)
|
||||
local stat = self:getBaseStat(statname) + self.owner:getEquipStats(statname, ignoreEquip)
|
||||
return stat
|
||||
end
|
||||
|
||||
|
@ -16,4 +16,12 @@ function CharacterStatManager:predictStat(statname, category, name)
|
|||
return self:computeStat(statname, category) + boost
|
||||
end
|
||||
|
||||
function CharacterStatManager:getBaseStat(statname)
|
||||
if (self:isBattleStat(statname)) then
|
||||
return self:getBattleStat(statname)
|
||||
else
|
||||
return self.owner:getLevelStat(statname)
|
||||
end
|
||||
end
|
||||
|
||||
return CharacterStatManager
|
|
@ -2,7 +2,7 @@ local StatManager = require "game.abstractmobs.statmanager"
|
|||
local EnnemyStatManager = StatManager:extend()
|
||||
|
||||
function EnnemyStatManager:new(owner)
|
||||
EnnemyStatManager.super.new(self, owner)
|
||||
EnnemyStatManager.super.new(self, owner, "ENNEMI")
|
||||
self.pvFactor = 1
|
||||
self.statFactor = 1
|
||||
end
|
||||
|
@ -15,10 +15,16 @@ end
|
|||
function EnnemyStatManager:computeStat(statname)
|
||||
local stat = self.owner.data.stats[statname]
|
||||
|
||||
if (self:isBattleStat(statname)) then
|
||||
return self:getBattleStat(statname)
|
||||
end
|
||||
|
||||
if statname == EnnemyStatManager.HPMAX then
|
||||
return stat * self.pvFactor
|
||||
elseif (statname ~= EnnemyStatManager.PPMAX) then
|
||||
return stat * self.statFactor
|
||||
else
|
||||
return stat
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,8 +11,10 @@ StatManager.MIND = CONST.MIND
|
|||
StatManager.TECHNIC = CONST.TECHNIC
|
||||
StatManager.SPEED = CONST.SPEED
|
||||
|
||||
function StatManager:new(owner)
|
||||
function StatManager:new(owner, battleStatType)
|
||||
local battleStatType = battleStatType or "HERO"
|
||||
self.owner = owner
|
||||
self.battleStats = CONST.BATTLESTAT[battleStatType]
|
||||
end
|
||||
|
||||
function StatManager:get(statname)
|
||||
|
@ -23,4 +25,12 @@ function StatManager:computeStat(statname)
|
|||
return self.list[statname]
|
||||
end
|
||||
|
||||
function StatManager:isBattleStat(statname)
|
||||
return utils.table.contain(CONST.BATTLELIST, statname)
|
||||
end
|
||||
|
||||
function StatManager:getBattleStat(statname)
|
||||
return self.battleStats[statname]
|
||||
end
|
||||
|
||||
return StatManager
|
|
@ -11,6 +11,13 @@ function BattleUtils.computeLaunchingDamages(base, fighter, isSpecial)
|
|||
else
|
||||
damages = damages * fighter:getStat(STATS.ATTACK)
|
||||
end
|
||||
|
||||
damages = damages * BattleUtils.computerArmorAndDamage(fighter:getStat(STATS.DAMAGE))
|
||||
|
||||
if (BattleUtils.rollDice(fighter:getStat(STATS.CRITICAL))) then
|
||||
damages = damages * 2
|
||||
end
|
||||
|
||||
return damages
|
||||
end
|
||||
|
||||
|
@ -22,6 +29,8 @@ function BattleUtils.computeReceivingDamages(base, fighter, isSpecial, isDefendi
|
|||
damages = damages / fighter:getStat(STATS.DEFENSE)
|
||||
end
|
||||
|
||||
damages = damages * BattleUtils.computerArmorAndDamage(fighter:getStat(STATS.ARMOR), true)
|
||||
|
||||
if (isDefending) then
|
||||
damages = damages * CONSTS.DAMAGE.DEFFACTOR
|
||||
end
|
||||
|
@ -57,9 +66,19 @@ function BattleUtils.applyResistences(damages, element, resistsList)
|
|||
return damages
|
||||
end
|
||||
|
||||
function BattleUtils.isAttackSuccess(statutList)
|
||||
local accuracy = 100
|
||||
return (math.random(100) <= accuracy)
|
||||
function BattleUtils.rollDice(stat)
|
||||
local stat = stat or 100
|
||||
return (math.random(100) <= stat)
|
||||
end
|
||||
|
||||
function BattleUtils.computerArmorAndDamage(stat, isNegative)
|
||||
if (isNegative) then
|
||||
stat = stat * -1
|
||||
end
|
||||
if (stat < 0) then
|
||||
stat = stat * STATS.ARMOR_AND_DAMAGE_RATIO
|
||||
end
|
||||
return (100 + (stat))/100
|
||||
end
|
||||
|
||||
return BattleUtils
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
local FighterParent = Object:extend()
|
||||
|
||||
local battleutils = require "game.utils.battle"
|
||||
local STATS = require "datas.consts.stats"
|
||||
|
||||
function FighterParent:new(owner, isHero, id)
|
||||
self.owner = owner
|
||||
|
@ -78,7 +79,12 @@ function FighterParent:sendDamage(target, value, type, element, isSpecial)
|
|||
local damage = battleutils.computeLaunchingDamages(value, self, isSpecial)
|
||||
|
||||
core.debug:print("cbs/battler", "Sending " .. damage .." damage at " .. target.name)
|
||||
return target:receiveDamage(damage, type, element, isSpecial, self)
|
||||
if (battleutils.rollDice(self:getStat(STATS.ACCURACY))) then
|
||||
return target:receiveDamage(damage, type, element, isSpecial, self)
|
||||
else
|
||||
target.actor:avoidedAttack()
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho)
|
||||
|
@ -87,11 +93,11 @@ function FighterParent:receiveDamage(value, type, element, isSpecial, fromWho)
|
|||
damages = battleutils.applyResistences(damages, element, self.abstract:getResistences())
|
||||
damages = battleutils.applyWeaknesses(damages, element, self.abstract:getWeaknesses())
|
||||
|
||||
if (battleutils.isAttackSuccess(nil)) then
|
||||
self:applyDamage(damages)
|
||||
else
|
||||
if (battleutils.rollDice(self:getStat(STATS.EVASION))) then
|
||||
self.actor:avoidedAttack()
|
||||
return false
|
||||
else
|
||||
self:applyDamage(damages)
|
||||
end
|
||||
|
||||
return true
|
||||
|
@ -134,8 +140,21 @@ function FighterParent:setActive()
|
|||
self:startAction()
|
||||
end
|
||||
|
||||
function FighterParent:applyRegen()
|
||||
local regenStat = self:getStat(STATS.HPREGEN)
|
||||
if (regenStat ~= 0) then
|
||||
self:setHP(regenStat*self:getStat(STATS.HPMAX)/100, true)
|
||||
end
|
||||
|
||||
local regenStat = self:getStat(STATS.PPREGEN)
|
||||
if (regenStat ~= 0) then
|
||||
self:setPP(regenStat*self:getStat(STATS.PPMAX)/100, true)
|
||||
end
|
||||
end
|
||||
|
||||
function FighterParent:setInactive()
|
||||
self.isActive = false
|
||||
self:applyRegen()
|
||||
self.turnSystem:endAction()
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue