local GroupComponent = class("GroupComponent") function GroupComponent:initialize(entity) --群组ID self.GroupID = 0 --群组目前还存活的成员数量 self.CurGroupEntityCount = 0 --群组成员的ID列表 self.GroupEntityIDList = {} --群组领袖的ID self.LeaderEntityID = nil --与群组领袖的距离 self.ToLeaderDisSqr = nil --群组指令的ID self.GroupDecisionDataID = nil ----------------------------------------- --群组成员列表 self.GroupEntityList = {} --群组领袖 self.LeaderEntity = nil --群组指令 self.GroupDecisionData = nil end function GroupComponent:AddEntity(entity) table.insert(self.GroupEntityList, entity) table.insert(self.GroupEntityIDList, entity._logicInitData.EntityID) self.CurGroupEntityCount = self.CurGroupEntityCount + 1 --print("Add, CurGroupEntityCount", self.CurGroupEntityCount) end function GroupComponent:RemoveEntity(entity) table.removebyvalue(self.GroupEntityList, entity, true) table.removebyvalue(self.GroupEntityIDList, entity._logicInitData.EntityID, true) self.CurGroupEntityCount = self.CurGroupEntityCount - 1 --print("Remove, CurGroupEntityCount", self.CurGroupEntityCount) end function GroupComponent:SetGroupLeader(entity, leader) if leader then self.LeaderEntityID = leader._logicInitData.EntityID self.LeaderEntity = leader self.ToLeaderDisSqr = FP.V2.DistanceSqr(entity.components.move.LogicPos, leader.components.move.LogicPos) else self.LeaderEntityID = nil self.LeaderEntity = nil self.ToLeaderDisSqr = nil end end function GroupComponent:SetGroupDecisionData(decisionData) self.GroupDecisionData = decisionData if decisionData then self.GroupDecisionDataID = decisionData.ID else self.GroupDecisionDataID = nil end end -- 传入的 strideColumn, strideRow 单位必须是毫米, 在本方法内会统一转换为米 function GroupComponent:SetPhalanxInfo(index, dir, center, totalMemberCount, strideColumn, strideRow, rotateType, maxColumn) if not self.phalanxIndex then self.phalanxDir = FP.newV2(0,0) self.phalanxCenter = FP.newV2(0,0) self.phalanxStrideColumn = FP.newV1(0) self.phalanxStrideRow = FP.newV1(0) end self.phalanxIndex = index self.phalanxDir:Reset(dir) self.phalanxDir:Normalize() self.phalanxCenter:Reset(center) self.phalanxMemberCount = totalMemberCount self.phalanxStrideColumn:Reset(strideColumn):Div(1000) --列与列之间的间隔 self.phalanxStrideRow:Reset(strideRow):Div(1000) --行与行之间的间隔 self.maxColumn = maxColumn self.rotateType = rotateType end return GroupComponent