405 lines
9.6 KiB
Lua
405 lines
9.6 KiB
Lua
local BattleConst = require "app/module/battle/battle_const"
|
|
|
|
local BattleUnitEntity = require "app/userdata/battle/team/battle_unit_entity"
|
|
|
|
local BattleTeamEntity = class("BattleTeamEntity", BaseData)
|
|
|
|
local MATCH_ATTACK_NAME = GConst.MATCH_ATTACK_NAME
|
|
local MATCH_DMG_ADDITION_NAME = BattleConst.MATCH_DMG_ADDITION_NAME
|
|
local MATCH_DEC_DMG_NAME = BattleConst.MATCH_DEC_DMG_NAME
|
|
local MATCH_DMG_DEC_NAME = BattleConst.MATCH_DMG_DEC_NAME
|
|
local MATCH_WEAKNESS_NAME = BattleConst.MATCH_WEAKNESS_NAME
|
|
local DEFAULT_FACTOR = BattleConst.DEFAULT_FACTOR
|
|
local BUFF_NAME = BattleConst.BUFF_NAME
|
|
local ATTR_NAME = BattleConst.ATTR_NAME
|
|
|
|
function BattleTeamEntity:ctor()
|
|
self.members = {}
|
|
self.membersCount = 0
|
|
self.counterAttackCount = 0 -- 反击次数
|
|
end
|
|
|
|
function BattleTeamEntity:init(side, data)
|
|
self.side = side
|
|
if self.baseAttr then
|
|
for k, v in pairs(self.baseAttr) do
|
|
self.baseAttr[k] = 0
|
|
end
|
|
else
|
|
self.baseAttr = {}
|
|
end
|
|
if self.attr then
|
|
for k, v in pairs(self.attr) do
|
|
self.attr[k] = 0
|
|
end
|
|
else
|
|
self.attr = {}
|
|
end
|
|
self.isDead = false
|
|
self.stunCount = 0
|
|
self.lethargyCount = 0
|
|
self.frozenCount = 0
|
|
self.limitAll = 0
|
|
self.activeSkillLimit = 0
|
|
self.shieldHp = 0
|
|
self.undeadHp = 0
|
|
if data then
|
|
table.sort(data.units, function(a, b)
|
|
if a.level == b.level then
|
|
if a.qlt == b.qlt then
|
|
return a.id < b.id
|
|
else
|
|
return a.qlt > b.qlt
|
|
end
|
|
else
|
|
return a.level > b.level
|
|
end
|
|
end)
|
|
self.mainHero = nil
|
|
for i, unitData in ipairs(data.units) do
|
|
local unit = BattleUnitEntity:create()
|
|
unit:init(unitData, side, self)
|
|
self:addBaseAttr(unitData.attr)
|
|
self.members[unitData.matchType] = unit
|
|
self.membersCount = self.membersCount + 1
|
|
if self.mainHero == nil then
|
|
unit:setIsMainUnit(true)
|
|
self.mainHero = unit
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function BattleTeamEntity:addUnit(unitData)
|
|
local unit = BattleUnitEntity:create()
|
|
unit:init(unitData, self.side, self)
|
|
self:addBaseAttr(unitData.attr)
|
|
self.members[unitData.matchType] = unit
|
|
self.membersCount = self.membersCount + 1
|
|
if self.mainHero == nil then
|
|
unit:setIsMainUnit(true)
|
|
self.mainHero = unit
|
|
end
|
|
return unit
|
|
end
|
|
|
|
function BattleTeamEntity:addBaseAttr(unitAttr)
|
|
for k, v in pairs(unitAttr) do
|
|
self.baseAttr[k] = (self.baseAttr[k] or 0) + v
|
|
self.attr[k] = (self.attr[k] or 0) + v
|
|
end
|
|
end
|
|
|
|
function BattleTeamEntity:addAttr(name, num, isPercent)
|
|
local addNum = 0
|
|
if isPercent then
|
|
if self.attr[name] then
|
|
-- 百分比加减属性的时候如果是减少属性,则先取正数做计算,在减去此结果, 否则在做整除运算的时候,正数和负数整除后的绝对值会不一致
|
|
-- 例如150 // 100 = 1, -150 // 100 = -2, 导致添加和移除的时候计算的属性值不一样
|
|
if num < 0 then
|
|
if self.baseAttr[name] then
|
|
addNum = self.baseAttr[name] * -num // DEFAULT_FACTOR
|
|
self.attr[name] = self.attr[name] - addNum
|
|
else
|
|
addNum = self.attr[name] * -num // DEFAULT_FACTOR
|
|
self.attr[name] = self.attr[name] - addNum
|
|
end
|
|
addNum = -addNum
|
|
else
|
|
if self.baseAttr[name] then
|
|
addNum = self.baseAttr[name] * num // DEFAULT_FACTOR
|
|
self.attr[name] = self.attr[name] + addNum
|
|
else
|
|
addNum = self.attr[name] * num // DEFAULT_FACTOR
|
|
self.attr[name] = self.attr[name] + addNum
|
|
end
|
|
end
|
|
end
|
|
else
|
|
addNum = num
|
|
local currNum = self.attr[name] or 0
|
|
self.attr[name] = currNum + num
|
|
end
|
|
return addNum
|
|
end
|
|
|
|
function BattleTeamEntity:setAttr(name, num)
|
|
self.attr[name] = num
|
|
end
|
|
|
|
function BattleTeamEntity:getAllMembers()
|
|
return self.members
|
|
end
|
|
|
|
function BattleTeamEntity:getMembersCount()
|
|
return self.membersCount
|
|
end
|
|
|
|
function BattleTeamEntity:getHp()
|
|
return self.attr.hp
|
|
end
|
|
|
|
function BattleTeamEntity:getMaxHp()
|
|
return self.attr.max_hp
|
|
end
|
|
|
|
function BattleTeamEntity:getHpPercent()
|
|
return self.attr.hp / self.attr.max_hp
|
|
end
|
|
|
|
function BattleTeamEntity:getAtk(matchType)
|
|
return self.attr[MATCH_ATTACK_NAME[matchType]] or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getDmgAddition(matchType)
|
|
return (self.attr.dmg_addition_all or 0) + (self.attr[MATCH_DMG_ADDITION_NAME[matchType]] or 0)
|
|
end
|
|
|
|
function BattleTeamEntity:getDmgDec(matchType)
|
|
return (self.attr.dmg_dec_all or 0) + (self.attr[MATCH_DMG_DEC_NAME[matchType]] or 0)
|
|
end
|
|
|
|
function BattleTeamEntity:getDecDmg(matchType)
|
|
return (self.attr.dec_dmg_all or 0) + (self.attr[MATCH_DEC_DMG_NAME[matchType]] or 0)
|
|
end
|
|
|
|
function BattleTeamEntity:getWeakness(matchType)
|
|
return (self.attr.weakness_all or 0) + (self.attr[MATCH_WEAKNESS_NAME[matchType]] or 0)
|
|
end
|
|
|
|
function BattleTeamEntity:getCrittime()
|
|
return self.attr.crittime or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getCrit()
|
|
return self.attr.crit or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getCureAddition()
|
|
return self.attr.cure_addition or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getCureDec()
|
|
return self.attr.cure_dec or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getBeDmgToHeal()
|
|
return self.attr.be_dmg_to_heal or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getBeSucked()
|
|
return self.attr.be_sucked or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getUndeadHp()
|
|
return self.undeadHp
|
|
end
|
|
|
|
function BattleTeamEntity:setUndeadHp(hp)
|
|
self.undeadHp = hp
|
|
end
|
|
|
|
function BattleTeamEntity:getNormalAttackAddCount()
|
|
return self.attr[ATTR_NAME.NORMAL_ATTACK_COUNT] or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getThorns()
|
|
return self.attr[ATTR_NAME.THORNS] or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getExpTime()
|
|
return self.attr.exp_time or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getFirstHand()
|
|
return self.attr.first_hand or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getDeathSummon()
|
|
return self.attr.death_summon or 0
|
|
end
|
|
|
|
function BattleTeamEntity:addMaxHp(num)
|
|
local hpBefore = self.attr.hp
|
|
local currPercent = hpBefore * DEFAULT_FACTOR // self.attr.max_hp
|
|
self.attr.max_hp = self.attr.max_hp + self.baseAttr.max_hp * num // DEFAULT_FACTOR
|
|
self.attr.hp = currPercent*self.attr.max_hp//DEFAULT_FACTOR
|
|
if self.attr.hp <= 0 and hpBefore > 0 then
|
|
self.attr.hp = 1
|
|
end
|
|
end
|
|
|
|
function BattleTeamEntity:addLimit(name, buffEffect)
|
|
if name == BUFF_NAME.STUN then
|
|
self.stunCount = self.stunCount + 1
|
|
elseif name == BUFF_NAME.LETHARGY then
|
|
if buffEffect.result then
|
|
return
|
|
end
|
|
self.lethargyCount = self.lethargyCount + 1
|
|
elseif name == BUFF_NAME.FROZEN then
|
|
if buffEffect.result then
|
|
return
|
|
end
|
|
self.frozenCount = self.frozenCount + 1
|
|
end
|
|
self.limitAll = self.limitAll + 1
|
|
end
|
|
|
|
function BattleTeamEntity:removeLimit(name)
|
|
if name == BUFF_NAME.STUN then
|
|
self.stunCount = self.stunCount - 1
|
|
elseif name == BUFF_NAME.LETHARGY then
|
|
self.lethargyCount = self.lethargyCount - 1
|
|
elseif name == BUFF_NAME.FROZEN then
|
|
self.frozenCount = self.frozenCount - 1
|
|
end
|
|
self.limitAll = self.limitAll - 1
|
|
end
|
|
|
|
function BattleTeamEntity:getIsLimit()
|
|
return self.limitAll > 0
|
|
end
|
|
|
|
function BattleTeamEntity:getActiveSkillLimit()
|
|
return self.activeSkillLimit > 0
|
|
end
|
|
|
|
function BattleTeamEntity:addActiveSkillLimit(name)
|
|
self.activeSkillLimit = self.activeSkillLimit + 1
|
|
end
|
|
|
|
function BattleTeamEntity:removeActiveSkillLimit(name)
|
|
self.activeSkillLimit = self.activeSkillLimit - 1
|
|
end
|
|
|
|
function BattleTeamEntity:getIsStun()
|
|
return self.stunCount > 0
|
|
end
|
|
|
|
function BattleTeamEntity:getIsLethargy()
|
|
return self.lethargyCount > 0
|
|
end
|
|
|
|
function BattleTeamEntity:getIsFrozen()
|
|
return self.frozenCount > 0
|
|
end
|
|
|
|
function BattleTeamEntity:addShield(num)
|
|
self.shieldHp = self.shieldHp + num
|
|
end
|
|
|
|
function BattleTeamEntity:getShieldHp()
|
|
return self.shieldHp
|
|
end
|
|
|
|
function BattleTeamEntity:getShieldRebound()
|
|
return self.attr.shield_rebound or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getBlock()
|
|
return self.attr.block or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getCounterAttack()
|
|
return self.attr.counterattack or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getSkillHurt()
|
|
return self.attr.skill_hurt or 0
|
|
end
|
|
|
|
function BattleTeamEntity:getAttrValue(attrName)
|
|
return self.attr[attrName] or 0
|
|
end
|
|
|
|
function BattleTeamEntity:takeDamageOrCure(num)
|
|
if self.isDead then
|
|
return 0
|
|
end
|
|
if num < 0 then -- 是伤害的话处理一下护盾
|
|
num = self:handleShield(num)
|
|
if num >= 0 then -- 这次伤害被抵消了
|
|
return 0
|
|
end
|
|
end
|
|
local hpBefore = self.attr.hp
|
|
self.attr.hp = self.attr.hp + num
|
|
local hurtEventNum = 0
|
|
if self:getUndeadHp() > 0 and self.attr.hp <= 0 then
|
|
self.attr.hp = self:getUndeadHp()
|
|
num = self:getUndeadHp() - hpBefore
|
|
end
|
|
if self.attr.hp <= 0 then -- 死了
|
|
hurtEventNum = -hpBefore
|
|
self.attr.hp = 0
|
|
self:die()
|
|
elseif self.attr.hp < self.attr.max_hp then
|
|
hurtEventNum = num
|
|
else -- 满血了
|
|
-- 这是加血
|
|
hurtEventNum = self.attr.max_hp - hpBefore
|
|
self.attr.hp = self.attr.max_hp
|
|
end
|
|
return hurtEventNum
|
|
end
|
|
|
|
function BattleTeamEntity:handleShield(damageNum)
|
|
self.shieldHp = self.shieldHp + damageNum
|
|
if self.shieldHp >= 0 then
|
|
return 0
|
|
else
|
|
damageNum = self.shieldHp
|
|
self.shieldHp = 0
|
|
return damageNum
|
|
end
|
|
end
|
|
|
|
function BattleTeamEntity:getCounterAttackCount()
|
|
return self.counterAttackCount or 0
|
|
end
|
|
|
|
function BattleTeamEntity:addCounterAttackCount(count)
|
|
count = count or 1
|
|
self.counterAttackCount = self.counterAttackCount + count
|
|
end
|
|
|
|
function BattleTeamEntity:clearCounterAttackCount()
|
|
self.counterAttackCount = 0
|
|
end
|
|
|
|
function BattleTeamEntity:getRecordData(name)
|
|
if self.recordData == nil then
|
|
self.recordData = {}
|
|
end
|
|
return self.recordData[name]
|
|
end
|
|
|
|
function BattleTeamEntity:setRecordData(name, value)
|
|
if self.recordData == nil then
|
|
self.recordData = {}
|
|
end
|
|
self.recordData[name] = value
|
|
end
|
|
|
|
function BattleTeamEntity:clearRecordData()
|
|
if self.recordData then
|
|
for k, v in pairs(self.recordData) do
|
|
self.recordData[k] = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
function BattleTeamEntity:die()
|
|
if self.isDead then
|
|
return
|
|
end
|
|
self.isDead = true
|
|
self:clearRecordData()
|
|
end
|
|
|
|
function BattleTeamEntity:getIsDead()
|
|
return self.isDead
|
|
end
|
|
|
|
return BattleTeamEntity |