From cc7feea039f3fb05b9674af14c6c55cddeb0dd54 Mon Sep 17 00:00:00 2001 From: Fang Date: Thu, 20 Jul 2023 16:20:11 +0800 Subject: [PATCH] review --- lua/app/common/data_manager.lua | 3 +- lua/app/global/global_func.lua | 2 +- .../battle/component/battle_unit_comp.lua | 2 +- .../helper/battle_skill_condition_handle.lua | 2 +- lua/app/ui/hero/cell/attr_cell.lua | 42 ++- lua/app/userdata/battle/battle_base_data.lua | 18 +- lua/app/userdata/equip/equip_data.lua | 132 +------- lua/app/userdata/equip/equip_entity.lua | 22 +- lua/app/userdata/hero/hero_entity.lua | 284 ++++++++++++------ 9 files changed, 254 insertions(+), 253 deletions(-) diff --git a/lua/app/common/data_manager.lua b/lua/app/common/data_manager.lua index 27a22f00..48a4ed08 100644 --- a/lua/app/common/data_manager.lua +++ b/lua/app/common/data_manager.lua @@ -137,9 +137,10 @@ function DataManager:initWithServerData(data) self.DailyChallengeData:init(data.chapter_daily_challenge) self.DungeonData:initDungeonGold(data.chapter_gold_challenge) self.DungeonData:initDungeonShards(data.chapter_shards_challenge) + self.EquipData:init(data.heroes_equips) + -- HeroData要在EquipData之后初始化,依赖装备的属性数据 self.HeroData:init(data.bag.heroes) self.BagData:init(data.bag) - self.EquipData:init(data.heroes_equips) self.FormationData:init(data.fight_info) self.DungeonData:initDungeonWeapon(data.chapter_weapon_challenge) self.DungeonData:initDungeonArmor(data.chapter_armor_challenge) diff --git a/lua/app/global/global_func.lua b/lua/app/global/global_func.lua index 36aef444..3307ebf9 100644 --- a/lua/app/global/global_func.lua +++ b/lua/app/global/global_func.lua @@ -429,7 +429,7 @@ function GFunc.getBuffDesc(buffName, effectNum) end function GFunc.getAttrDesc(attrName, attrNum) - attrNum = attrNum // 100 .. "%" + attrNum = attrNum // 100 return I18N:getTextWithOtherKey("attr", "name", attrName, "desc", attrNum) end diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index a3085979..92496c0b 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -1728,7 +1728,7 @@ function BattleUnitComp:takeDamageOrCure(atker, num, effectType, effectStatus, d local team = self.battleController:getOtherSideTeam(self.side) team:checkPassiveEvent(BattleConst.PASSIVE_EVENT.ON_DEAD_BY_BURN) end - if self.unitEntity:getAttrValue(BattleConst.ATTR_NAME.BLEED) > 0 then + if self.unitEntity:getTotalAttrValue(BattleConst.ATTR_NAME.BLEED) > 0 then local team = self.battleController:getOtherSideTeam(self.side) team:checkPassiveEvent(BattleConst.PASSIVE_EVENT.ON_DEAD_WITH_BLEED) end diff --git a/lua/app/module/battle/helper/battle_skill_condition_handle.lua b/lua/app/module/battle/helper/battle_skill_condition_handle.lua index 6db6c14f..306d56c3 100644 --- a/lua/app/module/battle/helper/battle_skill_condition_handle.lua +++ b/lua/app/module/battle/helper/battle_skill_condition_handle.lua @@ -19,7 +19,7 @@ local function _judgeTargetAttr(buffCondition, conditionRel, target, battleContr if buffCondition.attr == "hpp" then attrNum = target.unitEntity:getHpPercent() * DEFAULT_FACTOR else - attrNum = target.unitEntity:getAttrValue(buffCondition.attr) + attrNum = target.unitEntity:getTotalAttrValue(buffCondition.attr) end return BattleSkillConditionHandle._strOperatorOverloading(buffCondition.op, attrNum, buffCondition.v) end diff --git a/lua/app/ui/hero/cell/attr_cell.lua b/lua/app/ui/hero/cell/attr_cell.lua index 59fe7d8a..849b06f2 100644 --- a/lua/app/ui/hero/cell/attr_cell.lua +++ b/lua/app/ui/hero/cell/attr_cell.lua @@ -46,22 +46,18 @@ function AttrCell:showHp() self.imgIcon:setSprite(GConst.ATLAS_PATH.HERO, "hero_attribute_2") self.txDesc:setText(I18N:getGlobalText(I18N.GlobalConst.ATTR_HP)) - local totalBaseValue = 0 - totalBaseValue = totalBaseValue + self.heroEntity:getAttrValue(self.attrName) - totalBaseValue = totalBaseValue + self.weaponEntity:getHp() - totalBaseValue = totalBaseValue + DataManager.EquipData:getTotalArmorHp(self.heroEntity:getCfgId()) - local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then value = self.heroEntity:getCfgHp(self.heroEntity:getLv()) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then value = self.weaponEntity:getHp() - value = value + totalBaseValue * self.weaponEntity:getHpPercent() // DEFAULT_FACTOR elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_ARMOR then - value = DataManager.EquipData:getTotalArmorHp(self.heroEntity:getCfgId()) - value = value + totalBaseValue * DataManager.EquipData:getTotalArmorHpPercent(self.heroEntity:getCfgId()) // DEFAULT_FACTOR + value = value + self.hatEntity:getHp() + value = value + self.clothesEntity:getHp() + value = value + self.beltEntity:getHp() + value = value + self.handguardEntity:getHp() elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_SKIN then end @@ -73,22 +69,18 @@ function AttrCell:showAtk() self.imgIcon:setSprite(GConst.ATLAS_PATH.HERO, "hero_attribute_1") self.txDesc:setText(I18N:getGlobalText(I18N.GlobalConst.ATTR_ATK)) - local totalBaseValue = 0 - totalBaseValue = totalBaseValue + self.heroEntity:getAttrValue(self.attrName) - totalBaseValue = totalBaseValue + self.weaponEntity:getHp() - totalBaseValue = totalBaseValue + DataManager.EquipData:getTotalArmorAttack(self.heroEntity:getCfgId()) - local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then value = self.heroEntity:getCfgAtk(self.heroEntity:getLv()) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then value = self.weaponEntity:getAttack() - value = value + totalBaseValue * self.weaponEntity:getAtkPercent() // DEFAULT_FACTOR elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_ARMOR then - value = DataManager.EquipData:getTotalArmorAttack(self.heroEntity:getCfgId()) - value = value + totalBaseValue * DataManager.EquipData:getTotalArmorAttackPercent(self.heroEntity:getCfgId()) // DEFAULT_FACTOR + value = value + self.hatEntity:getAttack() + value = value + self.clothesEntity:getAttack() + value = value + self.beltEntity:getAttack() + value = value + self.handguardEntity:getAttack() elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_SKIN then end @@ -102,7 +94,7 @@ function AttrCell:showNormalHurt() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_ARMOR then @@ -123,7 +115,7 @@ function AttrCell:showSkillHurt() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_ARMOR then @@ -144,7 +136,7 @@ function AttrCell:showCrit() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then value = self.weaponEntity:getCritPercent() @@ -162,7 +154,7 @@ function AttrCell:showCritAtk() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then value = self.weaponEntity:getCritHurtPercent() @@ -180,7 +172,7 @@ function AttrCell:showNormalHurtp() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_ARMOR then @@ -201,7 +193,7 @@ function AttrCell:showSkillHurtp() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_ARMOR then @@ -222,7 +214,7 @@ function AttrCell:showCured() local value = 0 if self.nodeType == GConst.HeroConst.ATTR_SHOW_TOTAL then - value = self.heroEntity:getAttrValue(self.attrName) + value = self.heroEntity:getTotalAttrValue(self.attrName) elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_BASE then elseif self.nodeType == GConst.HeroConst.ATTR_SHOW_WEAPON then value = self.weaponEntity:getHealPercent() diff --git a/lua/app/userdata/battle/battle_base_data.lua b/lua/app/userdata/battle/battle_base_data.lua index b9d4b0c9..7bed81c7 100644 --- a/lua/app/userdata/battle/battle_base_data.lua +++ b/lua/app/userdata/battle/battle_base_data.lua @@ -687,10 +687,10 @@ function BattleBaseData:initHeroData(formation) ---- 攻击力 for matchType, attrName in pairs(GConst.MATCH_ATTACK_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) local atkAddName = GConst.MATCH_ATTACK_ADD_NAME[matchType] if atkAddName then - unitData.attr[attrName] = unitData.attr[attrName] + heroEntity:getAttrValue(atkAddName) + unitData.attr[attrName] = unitData.attr[attrName] + heroEntity:getTotalAttrValue(atkAddName) end unitData.attr[attrName] = unitData.attr[attrName] // DEFAULT_FACTOR @@ -698,37 +698,37 @@ function BattleBaseData:initHeroData(formation) ---- 暴击率 for matchType, attrName in pairs(GConst.MATCH_CRIT_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end ---- 暴击伤害 for matchType, attrName in pairs(GConst.MATCH_CRIT_TIME_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end ---- 治疗效果 for matchType, attrName in pairs(GConst.MATCH_CURED_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end ---- 普攻增伤固定值 for matchType, attrName in pairs(GConst.MATCH_NORMAL_HURT_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end ---- 普攻增伤百分比 for matchType, attrName in pairs(GConst.MATCH_NORMAL_HURTP_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end ---- 技能增伤固定值 for matchType, attrName in pairs(GConst.MATCH_SKILL_HURT_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end ---- 技能增伤百分比 for matchType, attrName in pairs(GConst.MATCH_SKILL_HURTP_NAME) do - unitData.attr[attrName] = heroEntity:getAttrValue(attrName) + unitData.attr[attrName] = heroEntity:getTotalAttrValue(attrName) end local skillInfo = skillCfg[skillId] diff --git a/lua/app/userdata/equip/equip_data.lua b/lua/app/userdata/equip/equip_data.lua index 326b4d53..906cba66 100644 --- a/lua/app/userdata/equip/equip_data.lua +++ b/lua/app/userdata/equip/equip_data.lua @@ -22,62 +22,6 @@ function EquipData:init(data) self:addEquip(heroId, part, level) end end - self:updateHeroValue() -end - --- 更新英雄数值 -function EquipData:updateHeroValue() - if not self.equips then - return - end - - for heroId, equip in pairs(self.equips) do - local heroEntity = DataManager.HeroData:getHeroById(heroId) - for part, level in pairs(equip) do - self:addAttrValue(heroEntity, part) - end - end -end - -function EquipData:addAttrValue(heroEntity, part, isDeduct) - local equipEntity = self:getEquip(heroEntity:getCfgId(), part) - - local hp = equipEntity:getHp() - local atk = equipEntity:getAttack() - local normalHurt = equipEntity:getNormalHurt() - local skillHurt = equipEntity:getSkillHurt() - local critPer = equipEntity:getCritPercent() - local critHurtPer = equipEntity:getCritHurtPercent() - local normalHurtPer = equipEntity:getNormalHurtPercent() - local skillHurtPer = equipEntity:getSkillHurtPercent() - local healPer = equipEntity:getHealPercent() - - heroEntity:addAttrValue(GConst.MATCH_HP_NAME[heroEntity:getMatchType()], isDeduct and -hp or hp) - heroEntity:addAttrValue(GConst.MATCH_ATTACK_NAME[heroEntity:getMatchType()], isDeduct and -atk or atk) - heroEntity:addAttrValue(GConst.MATCH_NORMAL_HURT_NAME[heroEntity:getMatchType()], isDeduct and -normalHurt or normalHurt) - heroEntity:addAttrValue(GConst.MATCH_SKILL_HURT_NAME[heroEntity:getMatchType()], isDeduct and -skillHurt or skillHurt) - heroEntity:addAttrValue(GConst.MATCH_CRIT_NAME[heroEntity:getMatchType()], isDeduct and -critPer or critPer) - heroEntity:addAttrValue(GConst.MATCH_CRIT_TIME_NAME[heroEntity:getMatchType()], isDeduct and -critHurtPer or critHurtPer) - heroEntity:addAttrValue(GConst.MATCH_NORMAL_HURTP_NAME[heroEntity:getMatchType()], isDeduct and -normalHurtPer or normalHurtPer) - heroEntity:addAttrValue(GConst.MATCH_SKILL_HURTP_NAME[heroEntity:getMatchType()], isDeduct and -skillHurtPer or skillHurtPer) - heroEntity:addAttrValue(GConst.MATCH_CURED_NAME[heroEntity:getMatchType()], isDeduct and -healPer or healPer) - - local printStr = "" - if not isDeduct then - printStr = printStr .. "增加装备数值:"..heroEntity:getCfgId().."-"..part .. "\n" - else - printStr = printStr .. "减去装备数值:"..heroEntity:getCfgId().."-"..part .. "\n" - end - printStr = printStr .. "生命:".. hp .. "\n" - printStr = printStr .. "攻击力:".. atk .. "\n" - printStr = printStr .. "普攻增伤:".. normalHurt .. "\n" - printStr = printStr .. "技能增伤:".. skillHurt .. "\n" - printStr = printStr .. "暴击率:".. critPer .. "\n" - printStr = printStr .. "暴击伤害百分比:".. critHurtPer .. "\n" - printStr = printStr .. "普攻增伤百分比:".. normalHurtPer .. "\n" - printStr = printStr .. "技能增伤百分比:".. skillHurtPer .. "\n" - printStr = printStr .. "治疗加成百分比:".. healPer .. "\n" - Logger.logHighlight(printStr) end function EquipData:setDirty() @@ -114,6 +58,10 @@ function EquipData:createEntity(heroId, part, level) return EquipEntity:create(heroId, part, level) end +function EquipData:getAllEquips() + return self.equips +end + function EquipData:getEquip(id, part) if not self.equips[id] then self.equips[id] = {} @@ -124,84 +72,14 @@ function EquipData:getEquip(id, part) return self.equips[id][part] end --- 获取英雄所有防具(不包含武器)生命固定值 -function EquipData:getTotalArmorHp(heroId) - local hatEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HAT) - local clothesEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.CLOTHES) - local beltEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.BELT) - local handguardEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HANDGUARD) - - local result = 0 - result = result + hatEntity:getHp() - result = result + clothesEntity:getHp() - result = result + beltEntity:getHp() - result = result + handguardEntity:getHp() - - return result -end - --- 获取英雄所有防具(不包含武器)攻击力固定值 -function EquipData:getTotalArmorAttack(heroId) - local hatEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HAT) - local clothesEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.CLOTHES) - local beltEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.BELT) - local handguardEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HANDGUARD) - - local result = 0 - result = result + hatEntity:getAttack() - result = result + clothesEntity:getAttack() - result = result + beltEntity:getAttack() - result = result + handguardEntity:getAttack() - - return result -end - --- 获取英雄所有防具(不包含武器)生命加成 -function EquipData:getTotalArmorHpPercent(heroId) - local hatEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HAT) - local clothesEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.CLOTHES) - local beltEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.BELT) - local handguardEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HANDGUARD) - - local result = 0 - result = result + hatEntity:getHpPercent() - result = result + clothesEntity:getHpPercent() - result = result + beltEntity:getHpPercent() - result = result + handguardEntity:getHpPercent() - - return result -end - --- 获取英雄所有防具(不包含武器)攻击力固定值 -function EquipData:getTotalArmorAttackPercent(heroId) - local hatEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HAT) - local clothesEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.CLOTHES) - local beltEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.BELT) - local handguardEntity = self:getEquip(heroId, GConst.EquipConst.PART_TYPE.HANDGUARD) - - local result = 0 - result = result + hatEntity:getAtkPercent() - result = result + clothesEntity:getAtkPercent() - result = result + beltEntity:getAtkPercent() - result = result + handguardEntity:getAtkPercent() - - return result -end - -- 装备升级 function EquipData:onUpgradeEquip(heroId, part) local entity = self:getEquip(heroId, part) if not entity then return end - - local last = entity:getLastLevelEntity() - if last then - self:addAttrValue(DataManager.HeroData:getHeroById(heroId), part, true) - end entity:onLevelUp() - self:addAttrValue(DataManager.HeroData:getHeroById(heroId), part) - + DataManager.HeroData:getHeroById(heroId):setEquipAttrDirty() EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.EQUIP_UPGRADE_SUCCESS) end diff --git a/lua/app/userdata/equip/equip_entity.lua b/lua/app/userdata/equip/equip_entity.lua index 1bc1a346..7cd55d4a 100644 --- a/lua/app/userdata/equip/equip_entity.lua +++ b/lua/app/userdata/equip/equip_entity.lua @@ -28,22 +28,36 @@ function EquipEntity:getPart() return self.cfg.part end --- 获取部位生命值 -function EquipEntity:getHp() +-- 获取部位基础生命值 +function EquipEntity:getBaseHp() if self.cfg.armor_hp and self.cfg.armor_hp[self.level] then return self.cfg.armor_hp[self.level] end return 0 end --- 获取部位攻击力 -function EquipEntity:getAttack() +-- 获取部位加成后生命值 +function EquipEntity:getHp() + local result = self:getBaseHp() + result = result + DataManager.HeroData:getHeroById(self:getHeroId()):getTotalBaseHp() * self:getHpPercent() // DEFAULT_FACTOR + return result +end + +-- 获取部位基础攻击力 +function EquipEntity:getBaseAttack() if self.cfg.armor_atk and self.cfg.armor_atk[self.level] then return self.cfg.armor_atk[self.level] end return 0 end +-- 获取部位加成后攻击力 +function EquipEntity:getAttack() + local result = self:getBaseAttack() + result = result + DataManager.HeroData:getHeroById(self:getHeroId()):getTotalBaseAtk() * self:getAtkPercent() // DEFAULT_FACTOR + return result +end + -- 获取部位普攻伤害 function EquipEntity:getNormalHurt() if self.cfg.normal_hurt_add and self.cfg.normal_hurt_add[self.level] then diff --git a/lua/app/userdata/hero/hero_entity.lua b/lua/app/userdata/hero/hero_entity.lua index c103dcc0..db119246 100644 --- a/lua/app/userdata/hero/hero_entity.lua +++ b/lua/app/userdata/hero/hero_entity.lua @@ -2,28 +2,170 @@ local HeroEntity = class("HeroEntity", BaseData) local ATTR_NAME = GConst.BattleConst.ATTR_NAME function HeroEntity:ctor(cfgId, lv, collectionLevel) - self.id = cfgId self.cfgId = cfgId self.data.lv = lv self.data.collectionLevel = collectionLevel - self.attrDirty = false + self.baseAttrDirty = false + self.equipAttrDirty = false self.config = ConfigManager:getConfig("hero")[self.cfgId] self.beginLv = self.config.begin_lv -- 初始等级 - - self.baseAttrOriginal = {} - self.allAttr = {} - self:initAttr() - self:updateAttr() end function HeroEntity:initAttr() - self:setAttrValue(ATTR_NAME.HP, 0) - self:setAttrValue(ATTR_NAME.ATK, 0) - self:setAttrValue(ATTR_NAME.ATK_RED, 0) - self:setAttrValue(ATTR_NAME.ATK_YELLOW, 0) - self:setAttrValue(ATTR_NAME.ATK_GREEN, 0) - self:setAttrValue(ATTR_NAME.ATK_BLUE, 0) - self:setAttrValue(ATTR_NAME.ATK_PURPLE, 0) + self.baseAttrOriginal = {} + self.equipAttr = {} + self.allAttr = {} + + self:setTotalAttrValue(ATTR_NAME.HP, 0) + self:setTotalAttrValue(ATTR_NAME.ATK, 0) + self:setTotalAttrValue(ATTR_NAME.ATK_RED, 0) + self:setTotalAttrValue(ATTR_NAME.ATK_YELLOW, 0) + self:setTotalAttrValue(ATTR_NAME.ATK_GREEN, 0) + self:setTotalAttrValue(ATTR_NAME.ATK_BLUE, 0) + self:setTotalAttrValue(ATTR_NAME.ATK_PURPLE, 0) + self:setEquipAttrValue(GConst.MATCH_HP_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_ATTACK_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_NORMAL_HURT_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_SKILL_HURT_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_CRIT_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_CRIT_TIME_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_NORMAL_HURTP_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_SKILL_HURTP_NAME[self:getMatchType()], 0) + self:setEquipAttrValue(GConst.MATCH_CURED_NAME[self:getMatchType()], 0) + + self:updateAllAttr() +end + +function HeroEntity:setBaseAttrDirty() + self.baseAttrDirty = true +end + +function HeroEntity:setEquipAttrDirty() + self.equipAttrDirty = true +end + +function HeroEntity:getAllAttr() + if self.allAttr == nil then + self:initAttr() + end + if self.baseAttrDirty == true then + self.baseAttrDirty = false + self:updateBaseAttr() + self:updateTotalAttr() + end + if self.equipAttrDirty == true then + self.equipAttrDirty = false + self:updateEquipAttr() + self:updateTotalAttr() + end + return self.allAttr +end + +-- 更新所有属性 +function HeroEntity:updateAllAttr() + self:updateBaseAttr() + self:updateEquipAttr() + self:updateTotalAttr() +end + +-- 更新英雄基础属性 +function HeroEntity:updateBaseAttr() + self.baseAttrOriginal[ATTR_NAME.HP] = self:getCfgHp() + self.baseAttrOriginal[ATTR_NAME.ATK_RED] = 0 + self.baseAttrOriginal[ATTR_NAME.ATK_YELLOW] = 0 + self.baseAttrOriginal[ATTR_NAME.ATK_GREEN] = 0 + self.baseAttrOriginal[ATTR_NAME.ATK_BLUE] = 0 + self.baseAttrOriginal[ATTR_NAME.ATK_PURPLE] = 0 + self.baseAttrOriginal[GConst.MATCH_ATTACK_NAME[self.config.position]] = self:getCfgAtk() +end + +-- 更新装备属性 +function HeroEntity:updateEquipAttr() + local equips = DataManager.EquipData:getAllEquips()[self:getCfgId()] + if not equips then + return + end + + local hp,atk,normalHurt,skillHurt,critPer,critHurtPer,normalHurtPer,skillHurtPer,healPer = 0 + for part, equipEntity in pairs(equips) do + if equipEntity:getLevel() <= 0 then + return + end + + hp = equipEntity:getHp() + atk = equipEntity:getAttack() + normalHurt = equipEntity:getNormalHurt() + skillHurt = equipEntity:getSkillHurt() + critPer = equipEntity:getCritPercent() + critHurtPer = equipEntity:getCritHurtPercent() + normalHurtPer = equipEntity:getNormalHurtPercent() + skillHurtPer = equipEntity:getSkillHurtPercent() + healPer = equipEntity:getHealPercent() + + self:addEquipAttrValue(GConst.MATCH_HP_NAME[self:getMatchType()], hp) + self:addEquipAttrValue(GConst.MATCH_ATTACK_NAME[self:getMatchType()], atk) + self:addEquipAttrValue(GConst.MATCH_NORMAL_HURT_NAME[self:getMatchType()], normalHurt) + self:addEquipAttrValue(GConst.MATCH_SKILL_HURT_NAME[self:getMatchType()], skillHurt) + self:addEquipAttrValue(GConst.MATCH_CRIT_NAME[self:getMatchType()], critPer) + self:addEquipAttrValue(GConst.MATCH_CRIT_TIME_NAME[self:getMatchType()], critHurtPer) + self:addEquipAttrValue(GConst.MATCH_NORMAL_HURTP_NAME[self:getMatchType()], normalHurtPer) + self:addEquipAttrValue(GConst.MATCH_SKILL_HURTP_NAME[self:getMatchType()], skillHurtPer) + self:addEquipAttrValue(GConst.MATCH_CURED_NAME[self:getMatchType()], healPer) + + if EDITOR_MODE then + local printStr = "" + printStr = printStr .. "更新装备数值:"..self:getCfgId().."-"..part .. "\n" + printStr = printStr .. "生命:".. hp .. "\n" + printStr = printStr .. "攻击力:".. atk .. "\n" + printStr = printStr .. "普攻增伤:".. normalHurt .. "\n" + printStr = printStr .. "技能增伤:".. skillHurt .. "\n" + printStr = printStr .. "暴击率:".. critPer .. "\n" + printStr = printStr .. "暴击伤害百分比:".. critHurtPer .. "\n" + printStr = printStr .. "普攻增伤百分比:".. normalHurtPer .. "\n" + printStr = printStr .. "技能增伤百分比:".. skillHurtPer .. "\n" + printStr = printStr .. "治疗加成百分比:".. healPer .. "\n" + Logger.logHighlight(printStr) + end + end +end + +function HeroEntity:setEquipAttrValue(name, value) + self.equipAttr[name] = value +end + +function HeroEntity:addEquipAttrValue(name, value) + self.equipAttr[name] = self.equipAttr[name] + value +end + +-- 更新总属性 +function HeroEntity:updateTotalAttr() + for k, v in pairs(self.baseAttrOriginal) do + self:setTotalAttrValue(k, v) + end + for k, v in pairs(self.equipAttr) do + self:addTotalAttrValue(k, v) + end +end + +function HeroEntity:setTotalAttrValue(name, value) + self.allAttr[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) +end + +function HeroEntity:getTotalAttrValue(name) + if self.allAttr == nil then + self:initAttr() + end + if not self.allAttr[name] then + return 0 + end + -- Logger.logHighlight("get "..name..":"..GFunc.decryptNumber(self.allAttr[name])) + return GFunc.decryptNumber(self.allAttr[name]) end function HeroEntity:setLv(lv) @@ -35,7 +177,7 @@ function HeroEntity:setLv(lv) end self.data.lv = lv ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP, lv) - self:setDirty() + self:setAttrDirty() end function HeroEntity:getCfgId() @@ -46,16 +188,6 @@ function HeroEntity:getLv() return self.data.lv end --- 获取英雄已领取图鉴点数的等级 -function HeroEntity:getCollectionLevel() - return self.data.collectionLevel -end - --- 更新英雄图鉴已领取等级 -function HeroEntity:updateCollectionLevel() - self.data.collectionLevel = self:getLv() -end - function HeroEntity:getQlt() return self.config.qlt end @@ -68,38 +200,21 @@ function HeroEntity:getMatchType() return self.config.position end +-- 获取英雄已领取图鉴点数的等级 +function HeroEntity:getCollectionLevel() + return self.data.collectionLevel +end + +-- 更新英雄图鉴已领取等级 +function HeroEntity:updateCollectionLevel() + self.data.collectionLevel = self:getLv() +end + -- 英雄每级可领取图鉴点数 function HeroEntity:getCollectionPoint() return self.config.collection_point end -function HeroEntity:setAttrDirty() - self.attrDirty = true -end - -function HeroEntity:getAllAttr() - if self.attrDirty == true then - self.attrDirty = false - self:updateAttr() - end - return self.allAttr -end - -function HeroEntity:updateAttr() - self:updateBaseAttr() - self:updateAllAttr() -end - -function HeroEntity:updateBaseAttr() - self.baseAttrOriginal[ATTR_NAME.HP] = self:getCfgHp() - self.baseAttrOriginal[ATTR_NAME.ATK_RED] = 0 - self.baseAttrOriginal[ATTR_NAME.ATK_YELLOW] = 0 - self.baseAttrOriginal[ATTR_NAME.ATK_GREEN] = 0 - self.baseAttrOriginal[ATTR_NAME.ATK_BLUE] = 0 - self.baseAttrOriginal[ATTR_NAME.ATK_PURPLE] = 0 - self.baseAttrOriginal[GConst.MATCH_ATTACK_NAME[self.config.position]] = self:getCfgAtk() -end - function HeroEntity:getCfgHp(lv) lv = lv or self.data.lv if lv > self:getMaxLv() then @@ -132,43 +247,16 @@ function HeroEntity:getIsShowUnlcokChapter() return self.config.is_show == 1 end -function HeroEntity:updateAllAttr() - for k, v in pairs(self.baseAttrOriginal) do - self:setAttrValue(k, v) - end -end - -function HeroEntity:setAttrValue(name, value) - self.allAttr[name] = GFunc.encryptNumber(value or 0) -end - -function HeroEntity:addAttrValue(name, add) - -- Logger.logHighlight("add "..name..":"..add) - local before = self:getAttrValue(name) - self.allAttr[name] = GFunc.encryptNumber(before + add or 0) -end - -function HeroEntity:getAttrValue(name) - if not self.allAttr[name] then - return 0 - end - -- Logger.logHighlight("get "..name..":"..GFunc.decryptNumber(self.allAttr[name])) - return GFunc.decryptNumber(self.allAttr[name]) -end - function HeroEntity:getAtk() - local atkAddName = GConst.MATCH_ATTACK_ADD_NAME[self:getMatchType()] local atkName = GConst.MATCH_ATTACK_NAME[self:getMatchType()] - return self:getAttrValue(atkName) + self:getAttrValue(atkAddName) + local atkAddName = GConst.MATCH_ATTACK_ADD_NAME[self:getMatchType()] + return self:getTotalAttrValue(atkName) + self:getTotalAttrValue(atkAddName) end function HeroEntity:getHp() - local atkAddName = GConst.MATCH_HP_ADD_NAME[self:getMatchType()] - return self:getAttrValue(GConst.BattleConst.ATTR_NAME.HP) + self:getAttrValue(atkAddName) -end - -function HeroEntity:setDirty() - self.attrDirty = true + local hpName = GConst.MATCH_HP_NAME[self:getMatchType()] + local hpAddName = GConst.MATCH_HP_ADD_NAME[self:getMatchType()] + return self:getTotalAttrValue(hpName) + self:getTotalAttrValue(hpAddName) end function HeroEntity:isMaxLv() @@ -317,4 +405,32 @@ function HeroEntity:getActiveRogueSkills() return list end +-- 获取总基础生命值(英雄+装备) +function HeroEntity:getTotalBaseHp() + local result = 0 + result = result + self:getTotalAttrValue(GConst.MATCH_HP_NAME[self:getMatchType()]) + -- 武器 + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.WEAPON):getBaseHp() + -- 防具 + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.HAT):getBaseHp() + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.CLOTHES):getBaseHp() + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.BELT):getBaseHp() + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.HANDGUARD):getBaseHp() + return result +end + +-- 获取总基础攻击值(英雄+装备) +function HeroEntity:getTotalBaseAtk() + local result = 0 + result = result + self:getTotalAttrValue(GConst.MATCH_HP_NAME[self:getMatchType()]) + -- 武器 + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.WEAPON):getBaseAttack() + -- 防具 + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.HAT):getBaseAttack() + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.CLOTHES):getBaseAttack() + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.BELT):getBaseAttack() + result = result + DataManager.EquipData:getEquip(self:getCfgId(), GConst.EquipConst.PART_TYPE.HANDGUARD):getBaseAttack() + return result +end + return HeroEntity \ No newline at end of file