--需要替换的数据--- local ReplaceComponent = class("ReplaceComponent") function ReplaceComponent:initialize(entity, heroAppearanceId, expModelID, paramData)--heroAppearanceId 时装ID self.Entity = entity self.baseComp = entity.components.base -- 真正的ECS架构是不允许这样的 self.replaceModelLog = {} --记录替换的顺序 self.replaceModelDataDic = {} --目前仅仅是外观用 key = 被替换的modelID ,value = 新modeldata self.skinPsReplaceDic = {} -- 技能特效被替换的字典 key = 被替换的modelID ,value = {SkinReplaceData } self.buffEffectResourceDic = {} --buff特效替换 key = modelID ,value = {[buff] = buffPath} --当前逻辑模型的替换skillPs数据 self.curModelSkinPsDic = nil --当前逻辑模型的替换buff 数据 self.curModelBuffEffectResourceDic = nil local originModelID = entity._logicInitData._modelData.ID if paramData and paramData.CharacterType == LuaConst.CharacterType.Adjutant then local heroData = DataSheetManager.HeroData:GetDataByID(paramData.AdjutantOriginID) originModelID = heroData.ModelID end if heroAppearanceId then local heroAppearanceData = DataSheetManager.HeroAppearance:GetDataByID(heroAppearanceId) if heroAppearanceData == nil then logging.error(LTAG.ERROR, "[策划注意]:不存在模型时装 :", heroAppearanceId) return end local replaceModelID = heroAppearanceData.BattleModel self:SetReplaceModel(originModelID,replaceModelID) self:AddReplaceSkinPS(originModelID, heroAppearanceData.SkinPsReplaceID, heroAppearanceData.BlackRoomPath, heroAppearanceData.VictoryPose) elseif expModelID then self:SetReplaceModel(originModelID,expModelID) end -- 神兵替换相关 ↓ local magicWeaponID = entity._logicInitData.MagicWeaponID if magicWeaponID and magicWeaponID > 0 then local isSuccess, weaponAppearance = DataSheetManager.WeaponAppearance:TryGetDataByID(magicWeaponID) if isSuccess and weaponAppearance.SkinPsReplaceID > 0 then self:AddReplaceSkinPS(originModelID, weaponAppearance.SkinPsReplaceID, weaponAppearance.BlackRoomPath) end end -- 神兵替换相关 ↑ -- 非时装的buff特效替换(不区分model,只和entity有关,优先级低于时装) self.extraBuffEffectResourceDic = nil -- key = buffID ,value = 特效path end --替换模型外观 function ReplaceComponent:SetReplaceModel(sourceID,replaceModelID) table.insert(self.replaceModelLog,{typeStr = "model",oId = sourceID,rId = replaceModelID}) if replaceModelID == 0 then -- 还原为最初的模型 self.replaceModelDataDic[sourceID] = nil else local replaceModelData = DataSheetManager.MonsterModelData:GetDataByID(replaceModelID) self.replaceModelDataDic[sourceID] = replaceModelData end end -- 这个的功能:获取表现得模型 。case:当穿戴时装时,外显是时装,逻辑数据还是用baseComp.CurModelData的。 function ReplaceComponent:GetCurExpModelData() if not self.replaceModelDataDic then return self.baseComp.CurModelData end local curModelData = self.baseComp.CurModelData return self.replaceModelDataDic[curModelData.ID] or curModelData end -- 获取武将未小变身的模型(武将原始modelID或者时装ID) function ReplaceComponent:GetHeroOriginalModelID() local modelID = self.baseComp.CurCharacterData.ModelID if not self.replaceModelDataDic then return modelID end local modelData = self.replaceModelDataDic[modelID] return modelData and modelData.ID or modelID end --添加 替换技能特效 function ReplaceComponent:AddReplaceSkinPS(modelID, skinReplaceID, blackRoomPath, victoryPose) --小黑屋相关 if not string.isNilOrEmpty(blackRoomPath) then self.blackRoomReplacePath = blackRoomPath end --胜利动画特效 if not string.isNilOrEmpty(victoryPose) then self.replaceVictoryPose = victoryPose end if not skinReplaceID or skinReplaceID <= 0 then return end local replaceData = DataSheetManager.SkinReplaceData:GetDataByID(skinReplaceID) if replaceData == nil then logging.error(LTAG.ERROR , "【时装策划】 特效替换表SkinReplaceData没有发现数据 id = ",skinReplaceID) return end table.insert(self.replaceModelLog,{typeStr = "battlePs",modelID = modelID, replaceData = replaceData}) --技能特效相关 local skinPsReplaceDic = self.skinPsReplaceDic[modelID] if skinPsReplaceDic == nil then skinPsReplaceDic = {} self.skinPsReplaceDic[modelID] = skinPsReplaceDic end local skillKeyPosList = replaceData.SkillKeyPos for i,skillPos in ipairs(skillKeyPosList) do skinPsReplaceDic[skillPos] = replaceData end -- buff特效相关 local buffEffectResourceDic = self.buffEffectResourceDic[modelID] if buffEffectResourceDic == nil then buffEffectResourceDic = {} self.buffEffectResourceDic[modelID] = buffEffectResourceDic end local buffs = replaceData.BuffID for i,buffID in ipairs(buffs) do buffEffectResourceDic[buffID] = replaceData.ReplaceBuffPath[i] end --为额外需要的模型也使用这套替换规则(注意:这数据都是浅拷贝,目前数据不会被特殊改变,故不复制多份数据。) local extModels = replaceData.ApplyExtraModelID for i,extModelID in ipairs(extModels) do self.skinPsReplaceDic[extModelID] = skinPsReplaceDic self.buffEffectResourceDic[extModelID] = buffEffectResourceDic end -- 为额外的模型换模型外显 local replaceModels = replaceData.ModelID for i,replaceModelID in ipairs(replaceModels) do local replaceModelData = DataSheetManager.MonsterModelData:GetDataByID(replaceData.ReplaceModelID[i]) self.replaceModelDataDic[replaceModelID] = replaceModelData end self:UpdateCurModelCacheData() end --删除 替换技能特效 function ReplaceComponent:RemoveReplaceSkinPS(modelID, skinReplaceID) if not skinReplaceID or skinReplaceID <= 0 then return end local replaceData = DataSheetManager.SkinReplaceData:GetDataByID(skinReplaceID) if replaceData == nil then logging.error(LTAG.ERROR , "【时装策划】 特效替换表SkinReplaceData没有发现数据 id = ",skinReplaceID) return end for index = #self.replaceModelLog,1,-1 do local log = self.replaceModelLog[index] if log.typeStr == "battlePs" and log.modelID == modelID and log.replaceData == replaceData then table.remove(self.replaceModelLog,index) end end --技能特效相关 local skinPsReplaceDic = self.skinPsReplaceDic[modelID] if skinPsReplaceDic then local skillKeyPosList = replaceData.SkillKeyPos for i,skillPos in ipairs(skillKeyPosList) do skinPsReplaceDic[skillPos] = nil end end -- buff特效相关 local buffEffectResourceDic = self.buffEffectResourceDic[modelID] if buffEffectResourceDic then local buffs = replaceData.BuffID for i,buffID in ipairs(buffs) do buffEffectResourceDic[buffID] = nil end end end function ReplaceComponent:UpdateCurModelCacheData() local curModelID = self.baseComp.CurModelData.ID self.curModelSkinPsDic = self.skinPsReplaceDic[curModelID] self.curModelBuffEffectResourceDic = self.buffEffectResourceDic[curModelID] end function ReplaceComponent:SetExtraBuffEffectResourceDic(buffID, value) if self.extraBuffEffectResourceDic == nil then self.extraBuffEffectResourceDic = {} end self.extraBuffEffectResourceDic[buffID] = value end function ReplaceComponent:GetCurModelBuffResource(buffData) local str = nil if self.curModelBuffEffectResourceDic then str = self.curModelBuffEffectResourceDic[buffData.BuffID] end if str == nil then if self.extraBuffEffectResourceDic then str = self.extraBuffEffectResourceDic[buffData.BuffID] or buffData.BuffResource else str = buffData.BuffResource end end return str end --在子弹发射时调用,以节约性能 function ReplaceComponent:GetCurModelHitResource(skillId,hitResourceStr) local str = hitResourceStr if self.curModelSkinPsDic then local curReplaceData = self:GetCurReplaceData(skillId) if curReplaceData then local hitResources = curReplaceData.HitResource local replaceHitResources = curReplaceData.ReplaceHitResource for i,path in ipairs(hitResources) do if path == hitResourceStr then return replaceHitResources[i] end end end end return str end --获取召唤怪的模型 function ReplaceComponent:GetCurModelCallMonsterModelID(skillId,callMonsterID) if self.curModelSkinPsDic then local curReplaceData = self:GetCurReplaceData(skillId) if curReplaceData then local callMonsterIDs = curReplaceData.CallMonsterID local replaceCallMonsterModels = curReplaceData.ReplaceCallMonsterModel -- 目前只是给召唤怪换个皮 ,如果换技能特效,则新加一个字段进行控制。 for i,monsterID in ipairs(callMonsterIDs) do if monsterID == callMonsterID then return replaceCallMonsterModels[i] end end end end return nil end -- todo: 等屈勇写好高些的字符串替换后,这个函数要使用。 function ReplaceComponent:GetReplaceSkillPath(skillId,resourcePath) if self.curModelSkinPsDic then local curReplaceData = self:GetCurReplaceData(skillId) if curReplaceData then local result = string.gsub(resourcePath,curReplaceData.SkillPath,curReplaceData.ReplaceSkillPath) return result end end return resourcePath end -- 小黑屋:小黑屋和模型绑定 function ReplaceComponent:GetReplaceBlackRoomEffect(blackRoom) if self.blackRoomReplacePath then return self.blackRoomReplacePath end return blackRoom end -- 胜利动画特效(包含着个timeline) function ReplaceComponent:GetVictoryPose(victoryPose) if self.replaceVictoryPose then return self.replaceVictoryPose end return victoryPose end function ReplaceComponent:GetCurReplaceData(skillId) if skillId == nil then return nil end local skillData = self.Entity:GetSkillData(skillId) local keyPos = nil if skillData.ID == skillData.BelongTo then keyPos = skillData.KeyPosition else local belongToSkillData = self.Entity:GetSkillData(skillData.BelongTo) keyPos = belongToSkillData.KeyPosition end local curReplaceData = self.curModelSkinPsDic[keyPos] return curReplaceData end return ReplaceComponent