static bool ParseAgentInfo(SceneEntityPosAgent agent, out EntityGrp grp, out EntityMonsterBeacon bcn, ref float exScale, ref int colorType, ref int playerId, ref int buffId) // bValidAgent { AgentInfo info = agent.spInfo as AgentInfo; grp = info != null ? info._grp : null; bcn = info != null ? info._bcn : null; colorType = info != null?info._colorType:-1; playerId = info != null?info._playerId:-1; buffId = info != null?info._buffId:0; if (bcn != null) { agent.protoId = MonsterEntityCreator.GetMonsterProtoIDForBeacon(agent.protoId, agent.Pos, ref exScale); if ((agent.protoId & EntityProto.IdAirborneAllMask) != 0) { bcn.AddAirborneReq(agent); return(false); } } if (0 > agent.protoId) { agent.protoId = (info == null || info._bsRate < 0) ? GetMonsterProtoID(agent.Pos, ref exScale) : GetBossMonsterProtoID(agent.Pos, info._bsRate, ref exScale); } return(agent.protoId >= 0); }
void Awake() { m_Grp = GetComponent <EntityGrp>(); if (m_Grp != null) { m_Grp.handlerMonsterCreated += OnMemberCreated; } }
public static void OnMonsterAdd(int id, AiNetwork ai, Pathea.PeEntity entity) { EntityGrp grpEntity = Pathea.EntityMgr.Instance.Get(id) as EntityGrp; if (null != grpEntity) { grpEntity.OnMemberCreated(entity); } }
EntityGrp CreateMonsterGroup(SpawnPoint grp_sp, MonsterSpawnPoint[] points, MonsterSpawnArea area) { int noid = Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId(); EntityGrp grp = EntityMgr.Instance.Create(noid, sMonsterGroupPath, Vector3.zero, Quaternion.identity, Vector3.one) as EntityGrp; if (grp == null) { Debug.LogError("Load Prefab Error"); return(null); } grp._protoId = grp_sp.Prototype; grp._cntMin = area.AmountPerSocial; grp._cntMax = area.AmountPerSocial; for (int i = 0; i < points.Length; i++) { MonsterSpawnPoint sp = points[i]; Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId(); SceneEntityAgent agent = new SceneEntityAgent(sp, false, area, null); agent.ScenarioId = area.ID; grp.scenarioId = area.ID; agent.entityGp = grp; sp.agent = agent; AddMstDeadAgent(agent); if (!sp.isDead) { SceneMan.AddSceneObj(agent); } } return(grp); }
protected override void OnPEInstantiate(uLink.NetworkMessageInfo info) { _id = info.networkView.initialData.Read <int>(); _externId = info.networkView.initialData.Read <int>(); authId = info.networkView.initialData.Read <int>(); _tdId = info.networkView.initialData.Read <int>(); _dungeonId = info.networkView.initialData.Read <int>(); _colorType = info.networkView.initialData.Read <int>(); _playerId = info.networkView.initialData.Read <int>(); _buffId = info.networkView.initialData.Read <int>(); _aiList.Clear(); EntityGrp.CreateMonsterGroup(ExternId & ~Pathea.EntityProto.IdGrpMask, transform.position, _colorType, _playerId, Id, _buffId); Pathea.PeEntity entity = Pathea.EntityMgr.Instance.Get(Id); if (null == entity) { return; } OnSpawned(entity.GetGameObject()); }
public static EntityGrp CreateMonsterGroup(int grpProtoId, Vector3 center, int colorType, int playerId, int entityId = -1, int buffId = 0) { int noid = -1 == entityId?Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId() : entityId; #if DbgMonsterGroup MonsterGroupProtoDb.Item item = new MonsterGroupProtoDb.Item(); item.protoID = 3; item.cntMinMax = new int[] { 3, 5 }; item.radiusDesc = new float[] { 15f, 1.5f }; item.subProtoID = new int[0]; #else MonsterGroupProtoDb.Item item = MonsterGroupProtoDb.Get(grpProtoId); if (item == null) { return(null); } #endif int cnt = 0; EntityGrp grp = EntityMgr.Instance.Create(noid, PeEntityCreator.GroupPrefabPath, center, Quaternion.identity, Vector3.one) as EntityGrp; if (grp == null) { return(null); } grp._grpProtoId = grpProtoId; // Random part grp._protoId = item.protoID; grp._cntMin = item.cntMinMax [0]; grp._cntMax = item.cntMinMax [1]; grp._atkMin = item.atkMinMax [0]; grp._atkMax = item.atkMinMax [1]; grp._radius = item.radiusDesc [0]; grp._sqrRejectRadius = item.radiusDesc.Length > 1 ? (item.radiusDesc [1] * item.radiusDesc [1]) : 1; cnt = UnityEngine.Random.Range(grp._cntMin, grp._cntMax); if (grp._protoId > 0) { Vector3 pos = Vector3.zero; for (int i = 0; i < cnt; i++) { if (grp.GetRandPos(center, ref pos, 5)) { SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, grp._protoId); agent.ScenarioId = grp.scenarioId; agent.spInfo = new MonsterEntityCreator.AgentInfo(grp, colorType, playerId, buffId); grp._lstAgents.Add(agent); } } } // Layout part cnt = item.subProtoID != null ? item.subProtoID.Length : 0; for (int i = 0; i < cnt; i++) { if (item.subProtoID[i] > 0) { SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(item.subPos[i] + center, item.subProtoID[i], item.subScl[i], Quaternion.Euler(item.subRot[i])); agent.ScenarioId = grp.scenarioId; agent.spInfo = new MonsterEntityCreator.AgentInfo(grp, colorType, playerId, buffId); grp._lstAgents.Add(agent); } } grp.StartCoroutine(grp.AddMemberAgents()); //postpond member creation to avoid performance spike //SceneMan.AddSceneObjs (grp._lstAgents); return(grp); }
public abstract void OnGrpCreated(EntityGrp grp);
public static bool IsHaveSpecialHatred(PeEntity me, PeEntity ennemy, out int ignoreOrHighHatred) //不会成为目标:1 优先成为目标:2 正常处理:0 冉哥用 { ignoreOrHighHatred = 0; if (ennemy == null || ennemy.aliveEntity == null) { return(false); } if (ennemy.aliveEntity.SpecialHatredData.Count == 0) { return(false); } List <int> targets = new List <int>(ennemy.aliveEntity.SpecialHatredData.Keys); if (me.entityProto.proto == EEntityProto.Monster) { if (targets.Contains(me.entityProto.protoId)) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[me.entityProto.protoId]; return(true); } else if (targets.Contains(allMonsters)) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[allMonsters]; return(true); } foreach (var item in targets) { if (item / 1000 != 8 || item == allMonsters) { continue; } if (ennemy.aliveEntity.SpecialHatredData[item] == 3) { continue; } PeEntity mon = SceneEntityCreatorArchiver.Instance.GetEntityByFixedSpId(item % fixMonsBase); if (mon != null) { if (mon is EntityGrp) { EntityGrp eg = mon as EntityGrp; foreach (var item1 in eg.memberAgents) { if (!(item1 is SceneEntityPosAgent)) { continue; } if ((item1 as SceneEntityPosAgent).entity == me) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[item]; return(true); } } } else if (mon == me) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[item]; return(true); } } } } else if (me.entityProto.proto == EEntityProto.Npc || me.entityProto.proto == EEntityProto.RandomNpc) { if (targets.Contains(me.Id)) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[me.Id]; return(true); } else if (targets.Contains(allNpcs)) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[allNpcs]; return(true); } for (int i = 0; i < ServantLeaderCmpt.mMaxFollower; i++) { NpcCmpt nc = ServantLeaderCmpt.Instance.GetServant(i); if (nc != null) { PeEntity npcEntity = nc.Entity; if (npcEntity != null && npcEntity == me) { if (targets.Contains(25001 + i)) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[25001 + i]; return(true); } else if (targets.Contains(25010)) { ignoreOrHighHatred = ennemy.aliveEntity.SpecialHatredData[25010]; return(true); } //targets.Add(25001 + i); //if (!targets.Contains(25010)) // targets.Add(25010); } } } } ignoreOrHighHatred = 0; return(false); }
public AgentInfo(EntityGrp grp, int colorType = -1, int playerId = -1, int buffId = 0) { _grp = grp; _colorType = colorType; _playerId = playerId; _buffId = buffId; }
public static void CreateMonster(SceneEntityPosAgent agent) // treat proid as type in monsterBesiegeSpawn { agent.entity = null; // Compute agent.protoId EntityGrp grp; EntityMonsterBeacon bcn; float exScale = -1.0f; int colorType = -1; int playerId = -1; int buffId = 0; if (!ParseAgentInfo(agent, out grp, out bcn, ref exScale, ref colorType, ref playerId, ref buffId)) { return; } if (NetworkInterface.IsClient) { NetworkManager.WaitCoroutine(PlayerNetwork.RequestCreateAi(agent.protoId, agent.Pos, null == grp ? -1 : grp.Id, null == bcn ? -1 : bcn.Id, -1, colorType, playerId, buffId)); return; } // If grp need network sync, put this statement down if ((agent.protoId & EntityProto.IdGrpMask) != 0) { agent.entity = EntityGrp.CreateMonsterGroup(agent.protoId & ~EntityProto.IdGrpMask, agent.Pos, colorType, playerId, -1, buffId); return; } Vector3 pos = new Vector3(agent.Pos.x, agent.Pos.y, agent.Pos.z); MonsterProtoDb.Item protoData = MonsterProtoDb.Get(agent.protoId); if (protoData != null && bcn == null && !agent.FixPos) // exclude fixpos { float hOffset = protoData.hOffset; if (hOffset < 0.0f) { float depth = VFVoxelWater.self.UpToWaterSurface(agent.Pos.x, agent.Pos.y, agent.Pos.z); if (depth <= 0) { Debug.LogError("[SceneEntityCreator]Failed to create water monster becasue not in water:" + agent.protoId); return; } pos.y += depth + hOffset; } else if (hOffset > 2.0f) { float depth = VFVoxelWater.self.UpToWaterSurface(agent.Pos.x, agent.Pos.y, agent.Pos.z); if (depth <= 0) { RaycastHit hitinfo; float rayLen = 128.0f; if (Physics.Raycast(pos + rayLen * Vector3.up, Vector3.down, out hitinfo, rayLen, SceneMan.DependenceLayer)) // avoid from birds genterating in cave { pos.y = hitinfo.point.y; } pos.y += hOffset; } else { pos.y += depth + hOffset; } } else { float depth = VFVoxelWater.self.UpToWaterSurface(agent.Pos.x, agent.Pos.y, agent.Pos.z); if (depth <= 0) { pos.y += hOffset; } else { Debug.LogError("[SceneEntityCreator]Failed to create land monster becasue in water:" + agent.protoId); return; } } } int id = Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId(); // not save agent.entity = PeEntityCreator.Instance.CreateMonster(id, agent.protoId, pos, agent.Rot, agent.Scl, exScale, colorType, buffId); if (null == agent.entity) { Debug.LogError("[SceneEntityCreator]Failed to create monster:" + agent.protoId); return; } agent.entity.monster.Ride(agent.canRide); //colorType,playerId //if(colorType>=0) // PeEntityCreator.InitMonsterSkinRandom(agent.entity,colorType); if (playerId >= 0) { agent.entity.SetAttribute(AttribType.DefaultPlayerID, playerId); } if (commonCreateEvent != null) { commonCreateEvent(agent.entity); } if (grp != null) { grp.OnMemberCreated(agent.entity); } if (bcn != null) { bcn.OnMonsterCreated(agent.entity); } return; }