IEnumerator RefreshAgents() { while (true) { if (PETools.PEUtil.SqrMagnitudeH(PeCreature.Instance.mainPlayer.position, Center) <= _playerRadius * _playerRadius) { int n = GetEntitiesCnt(); if (n < _maxCntOfMonsters && _posOfMonsters != null && _posOfMonsters.Length > 0 && _protoIdsOfMonsters != null && _protoIdsOfMonsters.Length > 0) { Vector3 pos = GetSpawnPos(); int protoId = GetProtoId(); if (PeGameMgr.IsAdventure) { SceneDoodadLodCmpt lod = GetComponentInParent <SceneDoodadLodCmpt> (); if (lod != null && lod.Index >= 0) { int allyId = VArtifactTownManager.Instance.GetTownByID(lod.Index).AllyId; int playerId = VATownGenerator.Instance.GetPlayerId(allyId); int allyColor = VATownGenerator.Instance.GetAllyColor(allyId); MonsterEntityCreator.CreateAdMonster(protoId, pos, allyColor, playerId); } } else { MonsterEntityCreator.CreateMonster(protoId, pos); } // } } yield return(new WaitForSeconds(UnityEngine.Random.Range(_timeIntervalMinMax.x, _timeIntervalMinMax.y))); } }
IEnumerator Exec() { while (true) { switch (_step) { case Step.FadeIn: if (_tAirborne.position.y > _dstPos.y) { _tAirborne.position -= _spdDown * Vector3.up; } else { _lastTime = -1.0f; _spdWave = 0.0f; _step = Step.Running; } break; case Step.Running: float a = _coefWave * (transform.position.y + _endHeight - _tAirborne.position.y); // assume weight == 1 _spdWave += a; _tAirborne.position += _spdWave * Vector3.up; if (_agents.Count > 0 && Time.realtimeSinceStartup > _lastTime + _itvCreate) { Transform tSpawn = _tAirborne.Find("CreatMonster"); _agents[0].Pos = tSpawn != null ? tSpawn.position : _tAirborne.position; _agents[0].protoId &= ~EntityProto.IdAirborneAllMask; MonsterEntityCreator.CreateMonster(_agents[0]); _agents.RemoveAt(0); _lastTime = Time.realtimeSinceStartup; } break; case Step.FadeOut: if (_tAirborne.position.y < _dstPos.y) { _tAirborne.position += _spdDown * Vector3.up; } else { Destroy(gameObject); } break; } yield return(0); } }
void UpdatePlayerUpperAir() { if (!PeGameMgr.IsMulti && Entity == PeCreature.Instance.mainPlayer) { if (carrier == null || !(carrier is HelicopterController)) { m_UpperAir = false; } else { float baseHeight = PeMappingMgr.Instance.GetTerrainHeight(Entity.position); bool isHeight = Entity.position.y - baseHeight > 30.0f; bool isRunning = carrier.rigidbody != null && carrier.rigidbody.velocity.sqrMagnitude > 1f * 1f; m_UpperAir = isHeight && isRunning; } } if (!m_UpperAir) { m_UpperAirStartTime = 0.0f; } else { if (m_UpperAirStartTime < PETools.PEMath.Epsilon) { m_UpperAirStartTime = Time.time; } } if (m_UpperAir && m_UpperAirStartTime > 0.0f) { if (Time.time - m_UpperAirStartTime > 10.0f) { m_UpperAirStartTime = Time.time; float randomValue = UnityEngine.Random.value; if (randomValue < 0.015f) { Vector3 position = PETools.PEUtil.GetRandomPosition(Entity.position, 25.0f, 35.0f); MonsterEntityCreator.CreateMonster(73, position); Debug.Log("Spawn caelum rex in upper air : " + randomValue + " time : " + Time.time); } } } }
IEnumerator TryCreateEntityUnstatic() { _step = EStep.InCreating; int n = 0; while (n++ < MaxTimes) { if (CheckSetAvailablePos()) { switch (_type) { case EntityType.EntityType_Npc: NpcEntityCreator.CreateNpc(this); break; case EntityType.EntityType_Monster: MonsterEntityCreator.CreateMonster(this); break; } if (entity != null) { spInfo.OnSuceededToCreate(this); } else { //if(protoId >= 0){ // Airborne monster would go here to remove its agent // Debug.LogWarning("[EntityPosAgent]:Failed to create entity "+_type.ToString()+protoId); //} spInfo.OnFailedToCreate(this); } break; } yield return(new WaitForSeconds(OneWait)); } if (n >= MaxTimes) { Debug.LogWarning("[EntityPosAgent]:Failed to create entity " + _type.ToString() + protoId + " during " + n * OneWait); } _step = EStep.Created; }