local BaseComponent = class("BaseComponent") local EventSystem = require('Event/EventSystem') local HeroFeature = {ID = 0, IsLookIK = false, IgnoreBlock = false,IgnoreShoveOthers = false , AmBuff = 0, CantBeAim = false, BeSkillAim = true, CantBeTrigger = 0, SpecialGroupID = {1}, BeHitNotRotate = false, CantTriggerLevelItem = false, IsHitFlash = true ,HeadHpUIType = 1,InteractIDs = {}, VisualPriority = 50000, AsCalledNotCullingPs = true} local AdjutantFeature = {ID = -1, IsLookIK = false, IgnoreBlock = false, IgnoreShoveOthers = false ,AmBuff = 0, CantBeAim = true, BeSkillAim = false ,CantBeTrigger = 1, SpecialGroupID = {1}, BeHitNotRotate = true, CantTriggerLevelItem = true, IsHitFlash = true,HeadHpUIType = 0,InteractIDs = {}, VisualPriority = 50000, AsCalledNotCullingPs = true} function BaseComponent:initialize(entity) self.Pause = false self.CurCharacterData = entity._logicInitData._characterData self.AllCharacterData = {} self.AllCharacterData[self.CurCharacterData.ID] = self.CurCharacterData self:SetCurModelData(entity._logicInitData._modelData) self.Entity = entity self.DominatedEntityList = {} self:SetMonsterFeature() --是否是第一次active self.IsFirstActive = true --是否是第一次active且添加完了bornBuff后 self.IsFirstActiveDone = false --是否处于激活状态,激活状态的Entity,才会运行常规逻辑,比如运动、碰撞检测(被子弹打)等 self.IsActive = false -- 隐藏时,需要继续update更新(一般是强制某个entity隐藏时才设置为true,其他情况一律是false或者nil) self.HidingNeedUpdate = nil -- 有时为false end function BaseComponent:SetActive(active , hidingNeedUpdate, activeType) if self.IsActive ~= active then self.IsActive = active if self.IsActive then if self.IsFirstActive then -- 首次active self.IsFirstActive = false --这个要先调 SystemManager.OnBorn(self.Entity) self.IsFirstActiveDone = true end if not (activeType == LuaConst.EActiveType.OFF_DRIVE) then BattleEventSystem.OnEntityActive(self.Entity) end end end if self.HidingNeedUpdate ~= nil or hidingNeedUpdate ~= nil then EventSystem.Dispatch(EventID.Player_HidingUpdate, self.Entity.EntityID ,hidingNeedUpdate) end self.HidingNeedUpdate = hidingNeedUpdate end -- CurModelData 大变身、小变身 会调用 。 主城换特殊模型(和尚)、主城换时装、战斗默认穿时装 不会调用。 function BaseComponent:SetCurModelData(modelData) if self.CurModelData ~= modelData then self.CurModelData = modelData if self.CurModelData then if self.CurModelData.ModelSoundID > 0 then self.CurModelSoundData = DataSheetManager.ModelSoundData:GetDataByID(self.CurModelData.ModelSoundID) end self.shoveRadius = FP.newV1(math.max(self.CurModelData.ShoveDiameterX,self.CurModelData.ShoveDiameterZ)):Mul(0.5) self.averageRadius = FP.newV1((self.CurModelData.ShoveDiameterX + self.CurModelData.ShoveDiameterZ)):Mul(self.CurModelData.ModelScale):Mul(0.5) self.boundingCircleRadius = FP.newV1(math.max(self.CurModelData.ShoveDiameterX,self.CurModelData.ShoveDiameterZ)):Mul(self.CurModelData.ModelScale):Div(2) self.isArealSmall = FP.newV1(self.CurModelData.ShoveDiameterX):Mul(self.CurModelData.ModelScale) <= FP.Const.One and FP.newV1(self.CurModelData.ShoveDiameterZ):Mul(self.CurModelData.ModelScale) <= FP.Const.One end end end function BaseComponent:SetMonsterFeature() local characterType = self.Entity._logicInitData.CharacterType if characterType == LuaConst.CharacterType.Hero or characterType == LuaConst.CharacterType.Illusion then self.CurMonsterFeature = HeroFeature elseif characterType == LuaConst.CharacterType.Adjutant then self.CurMonsterFeature = AdjutantFeature elseif characterType == LuaConst.CharacterType.NPC then self.CurMonsterFeature = DataSheetManager.MonsterFeatureData:GetDataByID(self.CurCharacterData.NPCType) else self.CurMonsterFeature = DataSheetManager.MonsterFeatureData:GetDataByID(self.CurCharacterData.MonsterType) end if self.CurMonsterFeature == nil then logging.error(LTAG.ERROR ,"[策划注意] :数据表中配置NPCType或 MonsterType 错误! 怪物id = :" ,self.CurCharacterData.ID) end end function BaseComponent:GetAverageRadius() return self.averageRadius or FP.Const.One end function BaseComponent:GetShoveRadius() return self.shoveRadius or FP.Const.One end function BaseComponent:GetBoundingCircleRadius() return self.boundingCircleRadius or FP.Const.One end function BaseComponent:GetDominatedEntityCount() return #self.DominatedEntityList end function BaseComponent:GetAdoptedIndex() return self.AdoptedIndex end function BaseComponent:OnAdopt(dominatedEntity) local masterEntity = self.Entity:GetMasterEntity() if masterEntity then masterEntity.components.base:OnAdopt(dominatedEntity) else self.DominatedEntityList[#self.DominatedEntityList + 1] = dominatedEntity end end function BaseComponent:OnAdopted(masterEntity) masterEntity = masterEntity:GetMasterEntity() or masterEntity self.AdoptedIndex = masterEntity.components.base:GetDominatedEntityCount() end function BaseComponent:OnDominatedEntityDead(dominatedEntity) local deadIndex = nil for i,v in ipairs(self.DominatedEntityList) do if deadIndex then v.components.base:OnOlderSiblingDead() else if v == dominatedEntity then deadIndex = i end end end table.remove(self.DominatedEntityList,deadIndex) end function BaseComponent:OnOlderSiblingDead() if self.AdoptedIndex then self.AdoptedIndex = self.AdoptedIndex - 1 end end --长宽是否都小于1m function BaseComponent:IsAreaSmall() return self.isArealSmall end --自己被别的单位投技抓取后 function BaseComponent:AfterBeGrabbed(graber) self.Graber = graber end --自己从被抓取的状态中解放出来后 function BaseComponent:AfterFreeFromGrab(graber) if self.Graber == graber then self.Graber = nil end end --自己抓取别人之后 function BaseComponent:AfterGrabOther(grabbedEntity) self.GrabbedEntity = grabbedEntity --未完成HYW now now now now这里在抓取多个单位时会是bug隐患 end --自己把别人从抓取中释放后 function BaseComponent:AfterRealseGrabOther(grabbedEntity) if self.GrabbedEntity == grabbedEntity then self.GrabbedEntity = nil end end return BaseComponent