属性
This commit is contained in:
parent
6d8dc21bfb
commit
bd30d1737c
@ -388,6 +388,12 @@ end
|
||||
-- endregion
|
||||
|
||||
-- region 属性相关
|
||||
function HeroData:setAllHeroesDitry()
|
||||
for k,v in pairs(self.heroes) do
|
||||
v:setAttrDirty()
|
||||
end
|
||||
end
|
||||
|
||||
function HeroData:getAttrByMatchType(matchType, attrType)
|
||||
self.allAtkpAttr[matchType] = self.allAtkpAttr[matchType] or {}
|
||||
return self.allAtkpAttr[matchType][attrType] or 0
|
||||
@ -396,6 +402,7 @@ end
|
||||
function HeroData:setHeroAttr(heroId, attr)
|
||||
self.allAtkpAttrByHero[heroId] = attr
|
||||
self:calcAttr()
|
||||
self:setAllHeroesDitry()
|
||||
end
|
||||
|
||||
function HeroData:calcAttr()
|
||||
|
||||
@ -13,7 +13,10 @@ function HeroEntity:ctor(cfgId, lv, skin, star)
|
||||
self.baseAttrOriginal = {}
|
||||
self.starAttr = {}
|
||||
self.skinAttr = {}
|
||||
self.allBaseAttr = {}
|
||||
self.allAttr = {}
|
||||
self.attrDirty = true
|
||||
self.attrBaseDirty = true
|
||||
end
|
||||
|
||||
-- region 属性
|
||||
@ -26,24 +29,24 @@ function HeroEntity:initAttr()
|
||||
self:setTotalAttrValue(ATTR_NAME.ATK_BLUE, 0)
|
||||
self:setTotalAttrValue(ATTR_NAME.ATK_PURPLE, 0)
|
||||
|
||||
self:updateAllAttr()
|
||||
self:_updateAllBaseAttr()
|
||||
end
|
||||
|
||||
function HeroEntity:onBaseAttrChange()
|
||||
self:updateBaseAttr()
|
||||
self:updateTotalAttr()
|
||||
self:_updateBaseAttr()
|
||||
self:_updateTotalAttr()
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
function HeroEntity:onStarAttrChange()
|
||||
self:updateStarAttr()
|
||||
self:updateTotalAttr()
|
||||
self:_updateStarAttr()
|
||||
self:_updateTotalAttr()
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
function HeroEntity:onSkinAttrChange()
|
||||
self:updateSkinAttr()
|
||||
self:updateTotalAttr()
|
||||
self:_updateSkinAttr()
|
||||
self:_updateTotalAttr()
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
@ -51,24 +54,30 @@ function HeroEntity:setDirty()
|
||||
self.data.isDirty = not self.data.isDirty
|
||||
end
|
||||
|
||||
function HeroEntity:setAttrDirty()
|
||||
self.attrDirty = true
|
||||
end
|
||||
|
||||
function HeroEntity:setBaseAttrDirty()
|
||||
self.attrBaseDirty = true
|
||||
end
|
||||
|
||||
function HeroEntity:getAllAttr()
|
||||
if self.attrDirty == true then
|
||||
self.attrDirty = false
|
||||
self:_updateAllAttr()
|
||||
end
|
||||
return self.allAttr
|
||||
end
|
||||
|
||||
-- 更新所有属性
|
||||
function HeroEntity:updateAllAttr()
|
||||
self:updateBaseAttr()
|
||||
self:updateStarAttr()
|
||||
self:updateSkinAttr()
|
||||
self:updateTotalAttr()
|
||||
|
||||
if self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] ~= nil then
|
||||
local attr = {}
|
||||
attr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] = self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]]
|
||||
-- self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] = nil
|
||||
DataManager.HeroData:setHeroAttr(self:getCfgId(), attr)
|
||||
-- 更新所有属性(包括其他英雄的加成)
|
||||
function HeroEntity:_updateAllAttr()
|
||||
self.allAttr = {}
|
||||
self.allBaseAttr = self:_getAllBaseAttr()
|
||||
for k, v in pairs(self.allBaseAttr) do
|
||||
self.allAttr[k] = v
|
||||
end
|
||||
|
||||
self.allAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] = nil
|
||||
-- 攻击力(百分比)
|
||||
local atkType = GConst.MATCH_ATTACK_NAME[self:getMatchType()]
|
||||
local atkpType = GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]
|
||||
@ -78,8 +87,30 @@ function HeroEntity:updateAllAttr()
|
||||
end
|
||||
end
|
||||
|
||||
function HeroEntity:_getAllBaseAttr()
|
||||
if self.attrBaseDirty == true then
|
||||
self.attrBaseDirty = false
|
||||
self:_updateAllBaseAttr()
|
||||
end
|
||||
return self.allBaseAttr
|
||||
end
|
||||
|
||||
-- 更新所有属性(自己)
|
||||
function HeroEntity:_updateAllBaseAttr()
|
||||
self:_updateBaseAttr()
|
||||
self:_updateStarAttr()
|
||||
self:_updateSkinAttr()
|
||||
self:_updateTotalAttr()
|
||||
|
||||
if self.allBaseAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] ~= nil then
|
||||
local attr = {}
|
||||
attr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]] = self.allBaseAttr[GConst.MATCH_ALL_ATKP_NAME[self:getMatchType()]]
|
||||
DataManager.HeroData:setHeroAttr(self:getCfgId(), attr)
|
||||
end
|
||||
end
|
||||
|
||||
-- 更新英雄基础属性
|
||||
function HeroEntity:updateBaseAttr()
|
||||
function HeroEntity:_updateBaseAttr()
|
||||
self.baseAttrOriginal[ATTR_NAME.HP] = self:getCfgHp()
|
||||
self.baseAttrOriginal[ATTR_NAME.ATK_RED] = 0
|
||||
self.baseAttrOriginal[ATTR_NAME.ATK_YELLOW] = 0
|
||||
@ -90,7 +121,7 @@ function HeroEntity:updateBaseAttr()
|
||||
end
|
||||
|
||||
-- 更新皮肤属性
|
||||
function HeroEntity:updateStarAttr()
|
||||
function HeroEntity:_updateStarAttr()
|
||||
self.starAttr = {}
|
||||
for i = 1, self.data.star do
|
||||
local attr = self:getStarAttrCfg()[i]
|
||||
@ -103,28 +134,28 @@ function HeroEntity:getStarAttr()
|
||||
end
|
||||
|
||||
-- 更新皮肤属性
|
||||
function HeroEntity:updateSkinAttr()
|
||||
function HeroEntity:_updateSkinAttr()
|
||||
self.skinAttr = {}
|
||||
|
||||
local hp = DataManager.SkinData:getHp(self)
|
||||
local atk = DataManager.SkinData:getAttack(self)
|
||||
local normalHurt = DataManager.SkinData:getNormalHurt(self)
|
||||
local skillHurt = DataManager.SkinData:getSkillHurt(self)
|
||||
local critPer = DataManager.SkinData:getCritPercent(self)
|
||||
local critHurtPer = DataManager.SkinData:getCritHurtPercent(self)
|
||||
local normalHurtPer = DataManager.SkinData:getNormalHurtPercent(self)
|
||||
local skillHurtPer = DataManager.SkinData:getSkillHurtPercent(self)
|
||||
local healPer = DataManager.SkinData:getHealPercent(self)
|
||||
-- local hp = DataManager.SkinData:getHp(self)
|
||||
-- local atk = DataManager.SkinData:getAttack(self)
|
||||
-- local normalHurt = DataManager.SkinData:getNormalHurt(self)
|
||||
-- local skillHurt = DataManager.SkinData:getSkillHurt(self)
|
||||
-- local critPer = DataManager.SkinData:getCritPercent(self)
|
||||
-- local critHurtPer = DataManager.SkinData:getCritHurtPercent(self)
|
||||
-- local normalHurtPer = DataManager.SkinData:getNormalHurtPercent(self)
|
||||
-- local skillHurtPer = DataManager.SkinData:getSkillHurtPercent(self)
|
||||
-- local healPer = DataManager.SkinData:getHealPercent(self)
|
||||
|
||||
self.skinAttr[GConst.MATCH_HP_NAME[self:getMatchType()]] = hp
|
||||
self.skinAttr[GConst.MATCH_ATTACK_NAME[self:getMatchType()]] = atk
|
||||
self.skinAttr[GConst.MATCH_NORMAL_HURT_NAME[self:getMatchType()]] = normalHurt
|
||||
self.skinAttr[GConst.MATCH_SKILL_HURT_NAME[self:getMatchType()]] = skillHurt
|
||||
self.skinAttr[GConst.MATCH_CRIT_NAME[self:getMatchType()]] = critPer
|
||||
self.skinAttr[GConst.MATCH_CRIT_TIME_NAME[self:getMatchType()]] = critHurtPer
|
||||
self.skinAttr[GConst.MATCH_NORMAL_HURTP_NAME[self:getMatchType()]] = normalHurtPer
|
||||
self.skinAttr[GConst.MATCH_SKILL_HURTP_NAME[self:getMatchType()]] = skillHurtPer
|
||||
self.skinAttr[GConst.MATCH_CURED_NAME[self:getMatchType()]] = healPer
|
||||
-- self.skinAttr[GConst.MATCH_HP_NAME[self:getMatchType()]] = hp
|
||||
-- self.skinAttr[GConst.MATCH_ATTACK_NAME[self:getMatchType()]] = atk
|
||||
-- self.skinAttr[GConst.MATCH_NORMAL_HURT_NAME[self:getMatchType()]] = normalHurt
|
||||
-- self.skinAttr[GConst.MATCH_SKILL_HURT_NAME[self:getMatchType()]] = skillHurt
|
||||
-- self.skinAttr[GConst.MATCH_CRIT_NAME[self:getMatchType()]] = critPer
|
||||
-- self.skinAttr[GConst.MATCH_CRIT_TIME_NAME[self:getMatchType()]] = critHurtPer
|
||||
-- self.skinAttr[GConst.MATCH_NORMAL_HURTP_NAME[self:getMatchType()]] = normalHurtPer
|
||||
-- self.skinAttr[GConst.MATCH_SKILL_HURTP_NAME[self:getMatchType()]] = skillHurtPer
|
||||
-- self.skinAttr[GConst.MATCH_CURED_NAME[self:getMatchType()]] = healPer
|
||||
|
||||
-- if EDITOR_MODE then
|
||||
-- local printStr = ""
|
||||
@ -143,8 +174,8 @@ function HeroEntity:updateSkinAttr()
|
||||
end
|
||||
|
||||
-- 更新总属性
|
||||
function HeroEntity:updateTotalAttr()
|
||||
self.allAttr = {}
|
||||
function HeroEntity:_updateTotalAttr()
|
||||
self.allBaseAttr = {}
|
||||
for k, v in pairs(self.baseAttrOriginal) do
|
||||
self:setTotalAttrValue(k, v)
|
||||
end
|
||||
@ -158,25 +189,25 @@ end
|
||||
|
||||
function HeroEntity:setTotalAttrValue(name, value)
|
||||
-- Logger.logHighlight("set "..name..":"..value)
|
||||
self.allAttr[name] = GFunc.encryptNumber(value or 0)
|
||||
self.allBaseAttr[name] = GFunc.encryptNumber(value or 0)
|
||||
end
|
||||
|
||||
function HeroEntity:addTotalAttrValue(name, add)
|
||||
-- Logger.logHighlight("add "..name..":"..add)
|
||||
local before = self:getTotalAttrValue(name)
|
||||
self.allAttr[name] = GFunc.encryptNumber(before + (add or 0))
|
||||
self.allBaseAttr[name] = GFunc.encryptNumber(before + (add or 0))
|
||||
end
|
||||
|
||||
function HeroEntity:getTotalAttrValue(name)
|
||||
if table.nums(self.allAttr) <= 0 then
|
||||
if table.nums(self.allBaseAttr) <= 0 then
|
||||
self:initAttr()
|
||||
end
|
||||
|
||||
if not self.allAttr[name] then
|
||||
if not self.allBaseAttr[name] then
|
||||
return 0
|
||||
end
|
||||
-- Logger.logHighlight("get "..name..":"..GFunc.decryptNumber(self.allAttr[name]))
|
||||
return GFunc.decryptNumber(self.allAttr[name])
|
||||
-- Logger.logHighlight("get "..name..":"..GFunc.decryptNumber(self.allBaseAttr[name]))
|
||||
return GFunc.decryptNumber(self.allBaseAttr[name])
|
||||
end
|
||||
|
||||
-- 获取总基础生命值(英雄+装备+皮肤)
|
||||
@ -250,7 +281,7 @@ function HeroEntity:setLv(lv, onlyChangeLv)
|
||||
return
|
||||
end
|
||||
self.data.lv = lv
|
||||
self:updateAllAttr()
|
||||
self:_updateAllBaseAttr()
|
||||
self:setDirty()
|
||||
|
||||
if not onlyChangeLv then
|
||||
@ -599,6 +630,7 @@ end
|
||||
|
||||
function HeroEntity:onHeroStarUp()
|
||||
self.data.star = self.data.star + 1
|
||||
self:setBaseAttrDirty()
|
||||
self:setDirty()
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user