Ejemplo n.º 1
0
 public override void UpdateTurn()
 {
     base.UpdateTurn();
     if (State == EState.IDLE)
     {
         Position position = LegacyLogic.Instance.WorldManager.Party.Position;
         Grid     grid     = LegacyLogic.Instance.MapLoader.Grid;
         for (Int32 i = m_invalidSpawners.Count - 1; i >= 0; i--)
         {
             Spawn spawn = m_invalidSpawners[i];
             if (spawn.ObjectType == EObjectType.MONSTER && spawn.InSpawnRange(position) && !m_spawnObjects.Contains(spawn))
             {
                 m_invalidSpawners.RemoveAt(i);
                 m_spawnObjects.Add(spawn);
             }
         }
         if (m_spawnObjects.Count > 0)
         {
             m_spawnedInteractiveObjects.Clear();
             for (Int32 j = m_spawnObjects.Count - 1; j >= 0; j--)
             {
                 Spawn      spawn2     = m_spawnObjects[j];
                 BaseObject baseObject = LegacyLogic.Instance.WorldManager.FindObjectBySpawnerId(spawn2.ID);
                 if (baseObject == null && spawn2.ObjectType == EObjectType.MONSTER && !spawn2.InSpawnRange(position))
                 {
                     m_spawnObjects.RemoveAt(j);
                     m_invalidSpawners.Add(spawn2);
                     spawn2.SetCanRespawn();
                 }
                 else if (baseObject == null)
                 {
                     BaseObject baseObject2 = spawn2.SpawnObject();
                     if (baseObject2 != null)
                     {
                         spawn2.EndTurn();
                         LegacyLogic.Instance.UpdateManager.SpawnTurnActor.RemoveSpawner(spawn2);
                         LegacyLogic.Instance.WorldManager.InvalidSpawner.Add(spawn2.ID);
                         Boolean flag = false;
                         if (baseObject2 is MovingEntity)
                         {
                             MovingEntity movingEntity = (MovingEntity)baseObject2;
                             if (!grid.AddMovingEntity(movingEntity.Position, movingEntity))
                             {
                                 LegacyLogger.LogError(String.Concat(new Object[]
                                 {
                                     "Cannot add object to GRID! SpawnerID: ",
                                     movingEntity.SpawnerID,
                                     ", staticID: ",
                                     movingEntity.StaticID
                                 }));
                             }
                             else
                             {
                                 flag = true;
                             }
                         }
                         else if (baseObject2 is InteractiveObject)
                         {
                             InteractiveObject interactiveObject = (InteractiveObject)baseObject2;
                             grid.AddInteractiveObject(interactiveObject);
                             interactiveObject.OnAfterCreate(grid);
                             interactiveObject.OnAfterSpawn(grid);
                             m_spawnedInteractiveObjects.Add(interactiveObject);
                             flag = true;
                         }
                         if (flag)
                         {
                             LegacyLogic.Instance.WorldManager.SpawnObject(baseObject2, spawn2.Position);
                         }
                     }
                 }
             }
             foreach (InteractiveObject interactiveObject2 in m_spawnedInteractiveObjects)
             {
                 interactiveObject2.OnPrewarm(grid);
             }
             m_stateMachine.ChangeState(EState.RUNNING);
         }
         else
         {
             m_stateMachine.ChangeState(EState.FINISHED);
         }
     }
     else if (State == EState.RUNNING)
     {
         Boolean flag2 = true;
         foreach (Spawn spawn3 in m_spawnObjects)
         {
             if (spawn3.State != Spawn.EState.ACTION_FINISHED && spawn3.State != Spawn.EState.IDLE)
             {
                 flag2 = false;
                 break;
             }
         }
         if (flag2)
         {
             if (m_isFirstUpdate)
             {
                 LegacyLogic.Instance.MapLoader.OnLevelLoaded();
                 m_isFirstUpdate = false;
             }
             m_stateMachine.ChangeState(EState.FINISHED);
             foreach (Spawn spawn4 in m_spawnObjects)
             {
                 spawn4.TurnIdle.Trigger();
             }
         }
     }
     foreach (Spawn spawn5 in m_spawnObjects)
     {
         spawn5.Update();
     }
 }