--角色实体 local Entity = class("Entity") --加载需要的模块 local LogicInitData = require "Battle/Logic/Entity/LogicInitData" local ExpEntity = require "Battle/Expression/ExpEntity/ExpEntity" local MoveComponent = require "Battle/Logic/Entity/Component/MoveComponent" local HitComponent = require "Battle/Logic/Entity/Component/HitComponent" local AnimComponent = require "Battle/Logic/Entity/Component/AnimComponent" local AIBaseComponent = require "Battle/Logic/Entity/Component/AIBaseComponent" local SkillBaseComponent = require "Battle/Logic/Entity/Component/SkillBaseComponent" local TimeScaleComponent = require "Battle/Logic/Entity/Component/TimeScaleComponent" local AdjutantComponent = require "Battle/Logic/Entity/Component/AdjutantComponent" local BaseComponent = require "Battle/Logic/Entity/Component/BaseComponent" local AttrComponent = require "Battle/Logic/Entity/Component/AttrComponent" local TargetComponent = require "Battle/Logic/Entity/Component/TargetComponent" local PatrolComponent = require "Battle/Logic/Entity/Component/PatrolComponent" local BuffComponent = require "Battle/Logic/Entity/Component/BuffComponent" local RecordComponent = require "Battle/Logic/Entity/Component/RecordComponent" local GroupComponent = require "Battle/Logic/Entity/Component/GroupComponent" local PathComponent = require "Battle/Logic/Entity/Component/PathComponent" local AutoFightComponent = require "Battle/Logic/Entity/Component/AutoFightComponent" local ReviveComponent = require "Battle/Logic/Entity/Component/ReviveComponent" local DriveComponent = require "Battle/Logic/Entity/Component/DriveComponent" local InteractComponent = require "Battle/Logic/Entity/Component/InteractComponent" local DeadComponent = require "Battle/Logic/Entity/Component/DeadComponent" local ReplaceComponent = require "Battle/Logic/Entity/Component/ReplaceComponent" local StratagemSkillComponent = require "Battle/Logic/Entity/Component/StratagemSkillComponent" local BuffSkillComponent = require "Battle/Logic/Entity/Component/BuffSkillComponent" local BattlePropComponent = require "Battle/Logic/Entity/Component/BattlePropComponent" local VisualFieldComponent = require "Battle/Logic/Entity/Component/VisualFieldComponent" local PetComponent = require "Battle/Logic/Entity/Component/PetComponent" local WeaponSoulComponent = require "Battle/Logic/Entity/Component/WeaponSoulComponent" local FP=FP local MonsterBeTriggerType_OnlyMaster = LuaConst.MonsterBeTriggerType.OnlyMaster local MonsterBeTriggerType_None = LuaConst.MonsterBeTriggerType.None --[[ 初始化 --]] function Entity:initialize(paramData, entityID) --注意这里的entityID可能为nil self:InitData(paramData) --初始化数据 self:InitCachedDataBeforeInitComponent() --初始化一些早期就要使用的缓存数据 self:InitComponent(paramData) --初始化组件 LogicUpdateManager.AddEntity(self, entityID) self.EntityID = self._logicInitData.EntityID --这样缓存一下,减少访问消耗 --缓存是安全的,因为EntityID在LogicUpdateManager.AddEntity一定会确定并且永不更改 self:InitEvent(paramData) --初始化事件 if self._logicInitData.MasterEntity then self._logicInitData.MasterEntity:SetLastSlave(self) end self:initialized() self:InitExpEntity(paramData) --初始化表现 if not paramData.IsPreload then self:OnActive() end end --初始化一些缓存数据, 该方法时间更早,主要初始化一些Component初始化需要的数据 function Entity:InitCachedDataBeforeInitComponent() self.PlayerID = self._logicInitData.PlayerIDInRoom self.CampID = self._logicInitData.EntityCampID local characterType = self:GetCharacterType() self.isMonster = characterType == LuaConst.CharacterType.Monster self.isNpc = characterType == LuaConst.CharacterType.NPC self.isHero = characterType == LuaConst.CharacterType.Hero and not self._logicInitData.isStatue self.isAdjuntant = characterType == LuaConst.CharacterType.Adjutant self.isIllusion = characterType == LuaConst.CharacterType.Illusion self.originCharacterData = self._logicInitData._characterData if self.isHero and self.originCharacterData.HeroNumData then self.professionType = self.originCharacterData.HeroNumData.TypeID self.kindomType = self.originCharacterData.HeroNumData.Kingdom self.genderType = self.originCharacterData.HeroNumData.Sexual end local isSuccess, retinueDataCfg = DataSheetManager.RetinueData:TryGetDataByID(self.originCharacterData.ID) self.retinueData = retinueDataCfg if self.isMonster and self.retinueData then self.isRetinue = true --是否是随从 if self.retinueData.UseDevelopOfHeroID then self.useDevelopOfHero = true --是否是英雄外观的随从(CharacterType依然是Monster) end local masterEntity = self:GetMasterEntity() if masterEntity then masterEntity:OnRetinueInitCachedDataBeforeInitComponent(self) end end self.needBatchPosDir = true -- 是否统一更新表现的位置和方向 end function Entity:OnRetinueInitCachedDataBeforeInitComponent(retinueEntity) self.retinueList = self.retinueList or {} table.insert(self.retinueList, retinueEntity) end function Entity:HasValidRetinueOfCharacterID(characterID) if self.retinueList then for i,retinueEntity in ipairs(self.retinueList) do if retinueEntity:GetCharacterID() == characterID and retinueEntity:IsAlive() and retinueEntity:IsActive() then return true end end end return false end function Entity:initialized() if not self.isPickupItem then self.components.aiBase:OnEntityInitialized(self) self.components.move:OnEntityInitialized(self) if self.components.pet then self.components.pet:OnEntityInitialized(self) end end --需要在initialize最后时间点处理事务的component,在这里接过去 self:InitCachedDataAfterInitialized() end --初始化一些缓存数据 function Entity:InitCachedDataAfterInitialized() --缓存数据可以在这里初始化, 这里的时间点是initialized末尾 --self.isCachedDataInited = true end function Entity:InitCachedDataAfterBaseComponentInit() --缓存数据可以在这里初始化, 这里的时间点是BaseComponent初始化后, 其他Component初始化前 local monsterFeature = self.components.base.CurMonsterFeature self.isPickupItem = monsterFeature.IsPickupItem if self.isPickupItem then self.pickUpItemLifeFrameLeft = monsterFeature.PickUpItemLifeFrame > 0 and monsterFeature.PickUpItemLifeFrame or 99999999 end self.isBoss = self.isMonster and monsterFeature.ShowBossUI self.isElite = self.isMonster and monsterFeature.HeadHpUIType == 4 and (not monsterFeature.ShowBossUI)--这个要后调 self.isVehicle = self.components.base.CurCharacterData.DriveParamID > 0 self.isOpenShoveRotate = self.components.base.CurModelData.OpenShoveRotate self.shoveOffsetZ = self.components.base.CurModelData.ForwardShoveOffset self.isMinion = self.isMonster and not self.isBoss and not self.isElite self.isOnlyTriggerByMaster = monsterFeature.CantBeTrigger == MonsterBeTriggerType_OnlyMaster self.isNotTriggerByOthers = self.isOnlyTriggerByMaster or monsterFeature.CantBeTrigger == MonsterBeTriggerType_None self.featureID = monsterFeature.ID end --[[ 初始化数据 --]] function Entity:InitData(paramData) self._logicInitData = LogicInitData:new(paramData) end --[[ 初始化组件 --]] function Entity:InitComponent(paramData) self.components = {} if self:CheckType(LuaConst.CharacterType.NPC) then self.components.base = BaseComponent:new(self) self:InitCachedDataAfterBaseComponentInit() self.components.attr = AttrComponent:new(self, paramData.AttrTable) self.components.move = MoveComponent:new(self, paramData.Pos, paramData.Forward) self.components.anim = AnimComponent:new(self) self.components.aiBase = AIBaseComponent:new(self) self.components.timeScale = TimeScaleComponent:new(self) self.components.patrol = PatrolComponent:new(self, paramData.Pos, paramData.BornItemID) self.components.record = RecordComponent:new(self) self.components.path = PathComponent:new(self) self.components.autoFight = AutoFightComponent:new(self) self.components.interact = InteractComponent:new(self) self.components.replace = ReplaceComponent:new(self) self.components.visualField = VisualFieldComponent:new(self) else self.components.base = BaseComponent:new(self) self:InitCachedDataAfterBaseComponentInit() if self.isPickupItem then self.components.attr = AttrComponent:new(self, paramData.AttrTable, paramData.AttrID, paramData.InitHP) self.components.move = MoveComponent:new(self, paramData.Pos, paramData.Forward ,paramData.SkipFindFinalPos) self.components.anim = AnimComponent:new(self) self.components.record = RecordComponent:new(self) self.components.replace = ReplaceComponent:new(self, paramData.HeroAppearance, paramData.ExpModelID, paramData) self.components.interact = InteractComponent:new(self) else self.components.attr = AttrComponent:new(self, paramData.AttrTable, paramData.AttrID, paramData.InitHP) self.components.move = MoveComponent:new(self, paramData.Pos, paramData.Forward ,paramData.SkipFindFinalPos) self.components.hit = HitComponent:new(self) self.components.anim = AnimComponent:new(self) self.components.aiBase = AIBaseComponent:new(self) self.components.skillBase = SkillBaseComponent:new(self) self.components.timeScale = TimeScaleComponent:new(self) self.components.adjutant = AdjutantComponent:new(self) self.components.target = TargetComponent:new(self) self.components.patrol = PatrolComponent:new(self, paramData.Pos, paramData.BornItemID) self.components.buff = BuffComponent:new(self) self.components.record = RecordComponent:new(self) self.components.revive = ReviveComponent:new(self) self.components.group = GroupComponent:new(self) self.components.path = PathComponent:new(self) self.components.autoFight = AutoFightComponent:new(self) self.components.drive = DriveComponent:new(self) self.components.dead = DeadComponent:new(self) self.components.interact = InteractComponent:new(self) self.components.replace = ReplaceComponent:new(self, paramData.HeroAppearance, paramData.ExpModelID, paramData) self.components.stratagem = StratagemSkillComponent:new(self, paramData.StratagemSkill) self.components.buffSkill = BuffSkillComponent:new(self) self.components.battleProp = BattlePropComponent:new(self) self.components.visualField = VisualFieldComponent:new(self) if self._logicInitData.PetID and self._logicInitData.PetID > 0 and LevelManager.CurLevelCanUsePet() then self.components.pet = PetComponent:new(self) end if self._logicInitData.WeaponSoulInfo and self._logicInitData.WeaponSoulInfo.isActive and not LevelManager.IsTown then self.components.weaponSoul = WeaponSoulComponent:new(self) end end end end --[[ 初始化模型 --]] function Entity:InitExpEntity(paramData) --表现层 if self.ExpEntity == nil then self.ExpEntity = ExpEntity:new() self.ExpEntity:Init(self, paramData, true) else self.ExpEntity:Init(self, paramData, false) end end --[[ 初始化事件 ]]-- function Entity:InitEvent(paramData) self:InitEventOfBornItemID(paramData.BornItemID) -- 以下都是和关卡无关的。有些怪的出生是通过其他方式召唤的 self.Event_EntityIDHPChanged = self.EntityID .. EventID._EntityIDHPChanged self.exclusiveBattleEventDic = {} for eventID,v in pairs(LuaConst.EntityExclusiveEventDic) do --pairs safe self.exclusiveBattleEventDic[eventID] = self.EntityID .. "_" .. eventID end end function Entity:InitEventOfBornItemID(itemID) if itemID then self.Event_EntityDead = itemID..EventID._EntityDead self.Event_EntityVisited = itemID..EventID._EntityVisited self.Event_EntityAIMessage = itemID..EventID._EntityAIMessage self.Event_EntityHPChanged = itemID..EventID._EntityHPChanged self.Event_EntityAMChanged = itemID..EventID._EntityAMChanged self.Event_EntitySAChanged = itemID..EventID._EntitySAChanged self.Event_EntityRevive = itemID..EventID._EntityRevive if self.components.interact:HasInteractData() then self.Event_EntityInteracted = itemID..EventID._EntityInteracted end end end function Entity:SyncFinish() self:OnSyncFinished() end function Entity:OnActive() SystemManager.Active(self) end function Entity:OnSyncFinished() --需要在同步结束时间点做事情的component,在这里接过去。这个只会有一部分entity会响应,其他entity不会sync,所以也不会响应这里 self.components.autoFight:OnEntitySyncFinished(self) self:InitCacheDataAfterSyncFinish() end function Entity:InitCacheDataAfterSyncFinish() self.name = self._logicInitData.Name --如果一个人没有teamID,则teamID为PlayerID。 这样不会带来混淆,因为组队的队伍ID是一个很长的string,playerID则是唯一的number self.teamID = (self._logicInitData.TeamID ~= nil and self._logicInitData.TeamID ~= "") and self._logicInitData.TeamID or self:GetPlayerID() self.teamLeaderName = (self._logicInitData.TeamLeaderName ~= nil and self._logicInitData.TeamLeaderName ~= "") and self._logicInitData.TeamLeaderName or self._logicInitData.Name self.isTeamLeader = self.teamLeaderName == self._logicInitData.Name end function Entity:HasBuffComponent() return self.components.buff ~= nil end function Entity:CheckType(type) return self._logicInitData.CharacterType == type end --PlayerID是玩家的index,值从1开始,1、2、3 function Entity:GetPlayerID() return self._logicInitData.PlayerIDInRoom end function Entity:SetTeamID(value) self._logicInitData.TeamID = value self.teamID = (self._logicInitData.TeamID ~= nil and self._logicInitData.TeamID ~= "") and self._logicInitData.TeamID or self:GetPlayerID() --如果一个人没有teamID,则teamID为PlayerID。 这样不会带来混淆,因为组队的队伍ID是一个很长的string,playerID则是唯一的number end --返回TeamID,当有组队时,返回队伍ID,是一个很长的string。没有组队时,直接返回playerID function Entity:GetTeamID() return self.teamID end function Entity:GetGuildID() return self._logicInitData.GuildID end function Entity:HasGuild() return type(self._logicInitData.GuildID) == "string" and self._logicInitData.GuildID ~= "" end function Entity:HasTeam() return LevelPlayerManager.IsTeamId(self:GetTeamID()) end function Entity:GetTeamLeaderName() return self.teamLeaderName end --只有同步玩法才生效,其他玩法调用就是错的 function Entity:IsTeamLeader() return self.isTeamLeader end --这个方法调用频次太高,每帧上千次,所以调用都优化为裸调用了,尽可能不要调用这个方法,因为EntityID不会改变,裸调用也没问题 function Entity:GetEntityID() --return self._logicInitData.EntityID return self.EntityID end function Entity:GetFightMode() return self.components.target.FightMode end function Entity:SetLastSlave(slaveEntity) self.lastSlave = slaveEntity end function Entity:GetLastSlave() return self.lastSlave end --设置Entity在LevelPlayerManager.PlayersEntityTable的元素里的index function Entity:SetIndex(index) self.index = index end --自己是否是玩家的主单位。(主单位:玩家多武将同时上场时候,是玩家镜头跟随着的单位、玩家操作的单位。其他时候就是当前唯一active的hero单位) function Entity:IsMainEntityOfPlayer() return self.index == 1 end function Entity:IsMasterEntity(otherEntity) return otherEntity and otherEntity:GetMasterEntity() == self end --返回根主人(位于主从关系链根节点的主人,即最顶层的那个主人,这个主人一定是没有MasterEntity的单位) --可能返回nil,单位可以没有MasterEntity function Entity:GetMasterEntity() return self._logicInitData.RootMasterEntity -- local master = self._logicInitData.MasterEntity -- while(master) do -- if not master._logicInitData.MasterEntity then -- break -- end -- master = master._logicInitData.MasterEntity -- end -- return master end --返回直接主人(处于主从关系链的上层的第1个Entity) function Entity:GetDirectMasterEntity() return self._logicInitData.MasterEntity end -- 返回最原始的entity (最终的Master,再看最终master是否被其他entity控制);GWS注意:self被A驾驶,A一定是最终entity;目前不支持 A是由B召唤的(司机不能是被召唤的) function Entity:GetOriginEntity() local originEntity = nil local masterEntity = self._logicInitData.RootMasterEntity or self local driveComp = masterEntity.components.drive if driveComp then originEntity = driveComp:GetLastDriver() or masterEntity else originEntity = masterEntity end return originEntity end --可传入LuaConst.AttrType、LuaConst.RealtimeAttrType --返回FP对象,是引用,修改这个引用会直接修改属性值 --如果不存在属性,会返回nil function Entity:GetAttrValue(attrType) return self.components.attr:GetAttrValue(attrType) end function Entity:GetHp() return self:GetAttrValue(LuaConst.RealtimeAttrType.hp) end function Entity:GetMaxHp() return self:GetAttrValue(LuaConst.AttrType.hplmt) end --返回number function Entity:GetAttrValueNum(attrType) return self.components.attr:GetAttrValueNum(attrType) end --attrType是string类型的,比如hp、atk这种,value可以是FP,也可以是number --如果attrType指定的属性不存在,会新建属性 function Entity:SetAttrBaseValue(attrType,value) self.components.attr:SetAttrBaseValue(attrType,value) end function Entity:AttrAdd(attrType,value) self.components.attr:AttrAdd(attrType,value) end function Entity:AttrSub(attrType,value) self.components.attr:AttrSub(attrType,value) end function Entity:AttrMul(attrType,value) self.components.attr:AttrMul(attrType,value) end function Entity:AttrDiv(attrType,value) self.components.attr:AttrDiv(attrType,value) end function Entity:IsActive() return self.components.base.IsActive end function Entity:IsValid() local baseComp = self.components.base return (baseComp.IsActive or baseComp.HidingNeedUpdate) and self.components.attr:IsAlive() end function Entity:IsRealActive() local baseComp = self.components.base return baseComp.IsActive or baseComp.HidingNeedUpdate end function Entity:CanRideHorse() if self.isHero and not LevelManager.CurLevelCanRideHorse() then return false end --没有马 if self._logicInitData.HorseModelData == nil then return false end if not self.components.buff:CheckHasBuffState(LuaConst.SpecialBuffs.CanRide) then return false end if self.components.aiBase.CurStateType == LuaConst.StateType.Interact then return false end return true end function Entity:IsAlive() return self.isNpc or self.components.attr:IsAlive() end function Entity:IsBorned() return not self.components.base.IsFirstActive --这个值会在born之后被设为false end --返回初始CharacterData(指一开始的,变身之前的CharacterData) function Entity:GetOriginCharacterData() return self.originCharacterData end function Entity:GetCharacterType() return self._logicInitData.CharacterType end function Entity:GetFeatureID() return self.featureID end function Entity:IsMonster() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isMonster end function Entity:IsHero() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isHero end function Entity:IsIllusion() return self.isIllusion end function Entity:IsBoss() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isBoss end --是否是精英怪 function Entity:IsElite() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isElite end --是否是小兵(非boss也非精英怪的monster) function Entity:IsMinion() return self.isMinion end function Entity:IsAdjutant() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isAdjuntant end --是否是载具 function Entity:IsVehicle() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isVehicle end function Entity:IsMasterHero() local masterEntity = self:GetMasterEntity() return masterEntity and masterEntity.isHero end function Entity:GetKindomType() return self.kindomType end function Entity:GetProfessionType() return self.professionType end function Entity:GetGenderType() return self.genderType end --返回初始的CharacterID function Entity:GetCharacterID() return self._logicInitData.CharacterID --不可缓存,因为会变身 end --返回当前的CharacterID,如果大变身,会返回变身后的ID function Entity:GetCurCharacterID() return self.components.base.CurCharacterData.ID end --返回当前是否正处于大变身中 function Entity:IsAvatarChanged() return self.components and self.components.base and self.components.base.CurCharacterData and self._logicInitData._characterData and self.components.base.CurCharacterData ~= self._logicInitData._characterData end function Entity:CheckHasBuffState(buffID) local buffComp = self.components.buff if buffComp then return buffComp:CheckHasBuffState(buffID) end return false end function Entity:HasBuff(buffID) local buffComp = self.components.buff if buffComp then return buffComp:HasBuff(buffID) end return false end function Entity:GetLastLogicPos() return self.components.move.LastLogicPos end --返回队伍号 --相同队伍号的单位互为友军,不同队伍号的单位互为敌军 function Entity:GetCampID() return self.CampID --如果未来单位的阵营会变化,则需要同时修改 self.CampID end function Entity:GetLogicPos() return self.components.move.LogicPos end function Entity:GetLogicPosY() return self.components.move.LogicPosY end --长宽是否都小于1m function Entity:IsAreaSmall() return self.components.base:IsAreaSmall() end function Entity:IsOpenShoveRotate() -- if not self.isCachedDataInited then -- logging.error(LTAG.ERROR, "HYW : 致命错误,缓存数据未初始化,访问过早!") -- end return self.isOpenShoveRotate end --返回单位的挤压旋转,仅用于挤压、碰撞的运算,跟逻辑旋转可能不一致 function Entity:GetShoveRotate() local rotate = FP.Const.Zero if not self:IsAreaSmall() then --太小的Entity就不要算挤压旋转了 if self:IsOpenShoveRotate() then --是否开启挤压旋转。默认不开启 --rotate = FP.Math.Radian(FP.V2.Angle(FP.Const.Vector2_Right, self.components.move.LogicRotateDir)) rotate = FP.Math.Radian(self.components.move:GetLogicRotateAngle()) end end return rotate end function Entity:GetShoveOffsetZ() return self.shoveOffsetZ end --返回上一帧的 单位的挤压旋转,仅用于挤压、碰撞的运算,跟逻辑旋转可能不一致 function Entity:GetLastShoveRotate() local rotate = FP.Const.Zero if not self:IsAreaSmall() then --太小的Entity就不要算挤压旋转了 if self:IsOpenShoveRotate() then --是否开启挤压旋转。默认不开启 --local angle = FP.V2.Angle(FP.Const.Vector2_Right, self.components.move.LastLogicRotateDir) rotate = FP.Math.Radian(self.components.move:GetLastLogicRotateAngle()) end end return rotate end function Entity:SetLogicPos(pos) self.components.move:SetLogicPos(pos) end function Entity:SetLogicRotateDir(dir) return self.components.move:SetLogicRotateDir(dir) end function Entity:GetLogicRotateDir() return self.components.move:GetLogicRotateDir() end --设置战力 --不同的关卡会有不同的设置规则,有的关卡设置的是单个hero的战力,有的关卡设置的是整个队伍的总站里 function Entity:SetGs(gs) self.components.attr:SetGs(gs) end local loopWatcher = 0 --返回战力 function Entity:GetGs() --new↓ loopWatcher = loopWatcher + 1 if loopWatcher < 10 then local originEntity = self:GetOriginEntity() if self == originEntity then loopWatcher = 0 return self.components.attr:GetGs() else return originEntity:GetGs() end else loopWatcher = 0 return self.components.attr:GetGs() end --new↑ --return self.components.attr:GetGs() --old end --返回官职 function Entity:GetOp() return self._logicInitData.OfficialPosition end function Entity:GetPetIDAndStage() return self._logicInitData.PetID, self._logicInitData.PetStage end function Entity:GetPetSkillID() return self._logicInitData.PetSkillId end function Entity:IsPlayerSelf() return self._logicInitData.IsPlayerSelf end function Entity:AddInteractEntity(entity) self.components.interact:AddInteractEntity(entity) end function Entity:RemoveInteractEntity(entity) return self.components.interact:RemoveInteractEntity(entity) end -- 副单位自动战斗的强制AI,比LevelFunction中的SideHeroDefaultAI 优先级高 function Entity:SetSideHeroForceAiID(aiID) self.sideHeroForceAiID = aiID end function Entity:GetSideHeroForceAiID() return self.sideHeroForceAiID end --自身或者自己的主人,或者驾驶我的司机是playerself function Entity:SelfAndMasterIsPlayerSelf() local masterEntity = self._logicInitData.MasterEntity while(masterEntity) do if masterEntity._logicInitData.MasterEntity then masterEntity = masterEntity._logicInitData.MasterEntity else return masterEntity._logicInitData.IsPlayerSelf end end if self._logicInitData.IsPlayerSelf then return true else local driver = self.components.drive and self.components.drive.BeDrivedByEntity or nil if driver and driver._logicInitData.IsPlayerSelf then return true end end return false end function Entity:SetHorseData(horseID,horseAppearanceID) if horseAppearanceID and horseAppearanceID > 0 then local horseAppearanceData = DataSheetManager.HorseAppearance:GetDataByID(horseAppearanceID) if horseAppearanceData then self:SetHorseModelData(horseAppearanceData.HorseModelID) else logging.error(LTAG.ERROR, "【策划错误】:马外显表中没有发现id:",horseAppearanceID) end else local horseData = DataSheetManager.HorseData:GetDataByHorseID(horseID) if horseData then self:SetHorseModelData(horseData.HorseModelID) else logging.error(LTAG.ERROR, "【策划错误】:马表中没有发现id:",horseID) end end end function Entity:SetHorseModelData(horseModelID) local horseModelData = DataSheetManager.HorseModelData:GetDataByHorseModelID(horseModelID) if horseModelData then self._logicInitData.HorseModelData = horseModelData local horseMoveData = DataSheetManager.HorseMoveData:GetDataByID(horseModelData.MoveID); if horseMoveData then self._logicInitData.HorseMoveData = horseMoveData self:SetAttrBaseValue(LuaConst.AttrType.ridespd,horseMoveData.MaxSpd) self:SetAttrBaseValue(LuaConst.AttrType.rideangvel,horseMoveData.MaxAngleSpd) self:SetAttrBaseValue(LuaConst.AttrType.ridespdacc,horseMoveData.SpdAccele) self:SetAttrBaseValue(LuaConst.AttrType.ridespddec,horseMoveData.SpdDecele) self:SetAttrBaseValue(LuaConst.AttrType.ridegear,horseMoveData.SpdGear) self:SetAttrBaseValue(LuaConst.AttrType.rideangacc,horseMoveData.AngleAccele) self:SetAttrBaseValue(LuaConst.AttrType.rideheadacc,horseMoveData.HeadAccele) self:SetAttrBaseValue(LuaConst.AttrType.rideheaddec,horseMoveData.HeadStopDecele) end else logging.error(LTAG.ERROR, "【策划错误】:马model表中没有发现id:",horseModelID) end end function Entity:SetPetData(petId, petStage, petName, petSkill, isLineUp, aptitudeSum, runeSkillLevelSum) self._logicInitData.PetID = petId self._logicInitData.PetStage = petStage self._logicInitData.PetName = petName self._logicInitData.PetSkillId = petSkill self._logicInitData.PetIsLineUp = isLineUp self._logicInitData.PetRuneSkillLevelSum = runeSkillLevelSum self._logicInitData.PetAptitudeSum = aptitudeSum if petId and petId > 0 then if self.components.pet == nil then self.components.pet = PetComponent:new(self) self.components.pet:OnEntityInitialized(self) else self.components.pet:InitData() end else self.components.pet = nil end end function Entity:GetSkillData(skillID) if (self.isHero or self.isAdjuntant) and self.components.record and self.components.record.overrideSkillDataDic[skillID] then --认为只有hero才会重写Data return self.components.record.overrideSkillDataDic[skillID] else --非英雄且非副将单位,直接返回数据表静态值 return DataSheetManager.SkillData:GetDataByID(skillID) end end function Entity:GetCallData(callID) if self.isAdjuntant then --副将返回主将的(副将相关数据的覆盖是覆盖主将,并且副将也查询的是主将) return self._logicInitData.MasterEntity:GetCallData(callID) end if self.isHero and self.components.record.overrideCallDataDic[callID] then --认为只有hero才会重写Data return self.components.record.overrideCallDataDic[callID] else --非英雄且非副将单位,直接返回数据表静态值 return DataSheetManager.CallBulletData:GetDataByID(callID) end end function Entity:GetMissileData(missileID) if self.isAdjuntant then --副将返回主将的(副将相关数据的覆盖是覆盖主将,并且副将也查询的是主将) return self._logicInitData.MasterEntity:GetMissileData(missileID) end if self.isHero and self.components.record.overrideMissileDataDic[missileID] then --认为只有hero才会重写Data return self.components.record.overrideMissileDataDic[missileID] else --非英雄且非副将单位,直接返回数据表静态值 return DataSheetManager.MissileData:GetDataByID(missileID) end end function Entity:GetTrackerData(trackerID) if self.isAdjuntant then --副将返回主将的(副将相关数据的覆盖是覆盖主将,并且副将也查询的是主将) return self._logicInitData.MasterEntity:GetTrackerData(trackerID) end if self.isHero and self.components.record.overrideTrackerDataDic[trackerID] then --认为只有hero才会重写Data return self.components.record.overrideTrackerDataDic[trackerID] else --非英雄且非副将单位,直接返回数据表静态值 return DataSheetManager.TrackerData:GetDataByID(trackerID) end end return Entity