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