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