public void Fill(int cntNpc, int cntMonster) { Vector3 center = RectIdxToCenterPos(_idx); bool bAvailable = false; SceneEntityPosAgent agent; System.Random rand = new System.Random(); for (int i = 0; i < cntNpc; i++) { Vector3 point = !PeGameMgr.randomMap ? GetEntityPoint(center, out bAvailable) : GetNpcPointInRndTer(center, out bAvailable); if (bAvailable) { if (VFDataRTGen.IsTownConnectionType(Mathf.RoundToInt(point.x), Mathf.RoundToInt(point.z))) { agent = NpcEntityCreator.CreateAgent(point); agent.spInfo = _rndNpcAgentInfo; _posRndNpcAgents.Add(agent); // npc entity would not be destroyed by scene } else { if (rand.NextDouble() < 0.25) { agent = NpcEntityCreator.CreateAgent(point); agent.spInfo = _rndNpcAgentInfo; _posRndNpcAgents.Add(agent); // npc entity would not be destroyed by scene } } } } for (int i = 0; i < cntMonster; i++) { Vector3 point = GetEntityPoint(center, out bAvailable); if (bAvailable && null == AIErodeMap.IsInErodeArea2D(point)) { _posRndMonsterAgents.Add(MonsterEntityCreator.CreateAgent(point)); } } SceneMan.AddSceneObjs(_posRndNpcAgents); SceneMan.AddSceneObjs(_posRndMonsterAgents); if (PeGameMgr.IsStory) { _posFixedMonsterIds = AISpawnPoint.Find(center.x - EntityCreationRadius, center.z - EntityCreationRadius, center.x + EntityCreationRadius, center.z + EntityCreationRadius); if (_posFixedMonsterIds.Count > 0) { SceneEntityCreatorArchiver.Instance.AddFixedSpawnPointToScene(_posFixedMonsterIds); } } else if (PeGameMgr.IsSingleAdventure) { SceneEntityPosRect.AddProcedualBossSpawnPointToScene(_idx); } }
public static void AddProcedualBossSpawnPointToScene(IntVector2 idxPosRect) { #if false // (256*2)*(256*2) one int idxX = idxPosRect.x >> 1; int idxY = idxPosRect.y >> 1; int idx = ((idxPosRect.y - (idxY << 1)) << 1) + (idxPosRect.y - (idxY << 1)); int idxMax = 4; int seed = RandomMapConfig.RandSeed + idxX * 722 + idxY; // Magic code System.Random rnd4BossGen = new System.Random(seed); int idx0 = rnd4BossGen.Next(idxMax); if (idx != idx0) { return; } #else // (256*4)*(256*4) one int idxX = idxPosRect.x >> 2; int idxY = idxPosRect.y >> 2; int idx = ((idxPosRect.y - (idxY << 2)) << 2) + (idxPosRect.x - (idxX << 2)); int idxMax = 16; int seed = RandomMapConfig.RandSeed + idxY * 722 + idxX; // Magic code System.Random rnd4BossGen = new System.Random(seed); int idx0 = rnd4BossGen.Next(idxMax); int idx1 = rnd4BossGen.Next(idxMax); while (idx1 == idx0) { idx1 = rnd4BossGen.Next(idxMax); } if (idx != idx0 && idx != idx1) { return; } #endif rnd4BossGen = new System.Random(seed + idx); float dx = (float)rnd4BossGen.NextDouble(); float dy = (float)rnd4BossGen.NextDouble(); Vector3 pos = new Vector3((dx + idxPosRect.x) * 2 * SceneEntityPosRect.EntityCreationRadius, SceneEntityPosAgent.PosYTBD, (dy + idxPosRect.y) * 2 * SceneEntityPosRect.EntityCreationRadius); if (null == AIErodeMap.IsInScaledErodeArea2D(pos, 1.2f)) { SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos); agent.spInfo = new MonsterEntityCreator.AgentInfo((float)rnd4BossGen.NextDouble()); SceneMan.AddSceneObj(agent); Debug.Log("<color=red>Boss Spawn Point</color>" + pos); } }
private void Init4FixedSpawnPoint() { foreach (KeyValuePair <int, AISpawnPoint> pair in AISpawnPoint.s_spawnPointData) { AISpawnPoint pt = pair.Value; int protoId = pt.resId; if (pt.isGroup) { protoId |= EntityProto.IdGrpMask; } FixedSpawnPointInfo info = new FixedSpawnPointInfo(); info._bActive = pt.active; info._needCD = pt.refreshtime; info._agent = MonsterEntityCreator.CreateAgent(pt.Position, protoId, Vector3.one, Quaternion.Euler(pt.euler)); info._agent.spInfo = new AgentInfo(pair.Key); info._agent.FixPos = pt.fixPosition; _fixedSpawnPointInfos[pair.Key] = info; } }
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); }
IEnumerator RefreshTowerMission() { _idxWave = 0; _uiData.CurWavesRemaining = _spData._waveDatas.Count; _uiData.TotalWaves = _spData._waveDatas.Count; while (_idxWave < _spData._waveDatas.Count) { while (PreTime > 0) { yield return(new WaitForSeconds(TimeStep)); PreTime -= TimeStep; } PreTime = 0; Vector3 dir = _forward; Vector3 center = _position; int m = _idxWave; AISpawnTDWavesData.TDWaveData wd = _spData._waveDatas[m]; if (Pathea.PeGameMgr.IsStory) { StroyManager.Instance.PushStoryList(wd._plotID); } int nMonsterTypes = wd._monsterTypes.Count; for (int n = 0; n < nMonsterTypes; n++) { int spType = wd._monsterTypes[n]; int minAngle = wd._minDegs[n]; int maxAngle = wd._maxDegs[n]; int spCount = UnityEngine.Random.Range(wd._minNums[n], wd._maxNums[n]); for (int i = 0; i < spCount; i++) { Vector3 pos; if (spType == 520 || spType == 521) //Special code for airborne monsters { pos = center; } else { if (isSweep) { pos = AiUtil.GetRandomPosition(center, 80, 100, dir, minAngle, maxAngle); transform.position = center + ((center - pos) * 1000); } else { pos = AiUtil.GetRandomPosition(center, 20, 80, dir, minAngle, maxAngle); } pos.y = SceneEntityPosAgent.PosYTBD; // let posagent to set y } SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, EncodeBcnMonsterProtoId(spType, _spData._dif, _spData._spawnType)); agent.spInfo = new MonsterEntityCreator.AgentInfo(this); agent.canRide = false; if (handerNewEntity != null) { handerNewEntity(agent); } _agents.Add(agent); SceneMan.AddSceneObj(agent); } } if (handlerNewWave != null) { handlerNewWave(_spData, _idxWave); } _uiData.CurWavesRemaining--; _idxWave++; if (_idxWave < _spData._waveDatas.Count) { int cdTime = _spData._timeToCool; while (cdTime > 0) { yield return(new WaitForSeconds(1)); cdTime--; } PreTime = (float)_spData._waveDatas[_idxWave]._delayTime; } } ; }
public bool Start() { MissionCommonData data = MissionManager.GetMissionCommonData(MissionId); for (int i = 0; i < data.m_TargetIDList.Count; i++) { if (data.m_TargetIDList[i] == TargetId) { _idxTarId = i; break; } } if (_idxTarId == -1) { return(false); } _data = MissionManager.GetTypeMonsterData(TargetId); if (_data == null) { return(false); } Vector3 referToPos; switch (_data.m_mr.refertoType) { case ReferToType.None: referToPos = PeCreature.Instance.mainPlayer.position; break; case ReferToType.Player: referToPos = PeCreature.Instance.mainPlayer.position; break; case ReferToType.Town: VArtifactUtil.GetTownPos(_data.m_mr.referToID, out referToPos); break; case ReferToType.Npc: referToPos = EntityMgr.Instance.Get(MissionManager.Instance.m_PlayerMission.adId_entityId[_data.m_mr.referToID]).position; break; default: referToPos = PeCreature.Instance.mainPlayer.position; break; } if (referToPos == Vector3.zero) { return(false); } if (PeGameMgr.IsSingle || PeGameMgr.IsTutorial) { if (_data.type == 2) { DoodadEntityCreator.commonDeathEvent += OnMonsterDeath; } else { MonsterEntityCreator.commonDeathEvent += OnMonsterDeath; } } GenMonsterInMission = !PeGameMgr.IsStory; if (GenMonsterInMission) { #if DbgNearGen Vector2 v2 = Vector2.zero; #else Vector2 v2 = UnityEngine.Random.insideUnitCircle.normalized * _data.m_mr.radius1; #endif Vector3 center = referToPos + new Vector3(v2.x, 0.0f, v2.y); //for (int i = 0; i < _data.m_MonsterList.Count; i++) { // int num = _data.m_MonsterList[i].type; // int protoId = _data.m_MonsterList[i].npcs[UnityEngine.Random.Range(0, _data.m_MonsterList[i].npcs.Count)]; // for (int j = 0; j < num; j++) { // Vector3 pos = AiUtil.GetRandomPosition (center, 0, _data.m_mr.radius2); // pos.y = SceneEntityPosAgent.PosYTBD; // let posagent to set y // SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, protoId); // agent.spInfo = new MonsterEntityCreator.AgentInfo(EntityMonsterBeacon.GetSpBeacon4MonsterKillTask()); // _agents.Add (agent); // SceneMan.AddSceneObj (agent); // } //} for (int i = 0; i < _data.m_CreMonList.Count; i++) { for (int j = 0; j < _data.m_CreMonList[i].monNum; j++) { Vector3 pos = AiUtil.GetRandomPosition(center, 0, _data.m_mr.radius2); pos.y = SceneEntityPosAgent.PosYTBD; // let posagent to set y int protoId = _data.m_CreMonList[i].monID; if (_data.m_CreMonList[i].type == 1) { protoId |= EntityProto.IdGrpMask; } SceneEntityPosAgent agent = MonsterEntityCreator.CreateAgent(pos, protoId); agent.spInfo = new MonsterEntityCreator.AgentInfo(EntityMonsterBeacon.GetSpBeacon4MonsterKillTask()); agent.canRide = false; _agents.Add(agent); SceneMan.AddSceneObj(agent); } } } return(true); }