Ejemplo n.º 1
0
        protected override void StartMissionSpecific(Level level)
        {
            if (SpawnedResources.Any())
            {
#if DEBUG
                throw new Exception($"SpawnedResources.Count > 0 ({SpawnedResources.Count})");
#else
                DebugConsole.AddWarning("Spawned resources list was not empty at the start of a mineral mission. The mission instance may not have been ended correctly on previous rounds.");
                SpawnedResources.Clear();
#endif
            }

            if (RelevantLevelResources.Any())
            {
#if DEBUG
                throw new Exception($"RelevantLevelResources.Count > 0 ({RelevantLevelResources.Count})");
#else
                DebugConsole.AddWarning("Relevant level resources list was not empty at the start of a mineral mission. The mission instance may not have been ended correctly on previous rounds.");
                RelevantLevelResources.Clear();
#endif
            }

            if (MissionClusterPositions.Any())
            {
#if DEBUG
                throw new Exception($"MissionClusterPositions.Count > 0 ({MissionClusterPositions.Count})");
#else
                DebugConsole.AddWarning("Mission cluster positions list was not empty at the start of a mineral mission. The mission instance may not have been ended correctly on previous rounds.");
                MissionClusterPositions.Clear();
#endif
            }

            caves.Clear();

            if (IsClient)
            {
                return;
            }
            foreach (var kvp in ResourceClusters)
            {
                var prefab = ItemPrefab.Find(null, kvp.Key);
                if (prefab == null)
                {
                    DebugConsole.ThrowError("Error in MineralMission - " +
                                            "couldn't find an item prefab with the identifier " + kvp.Key);
                    continue;
                }
                var spawnedResources = level.GenerateMissionResources(prefab, kvp.Value.First, out float rotation);
                if (spawnedResources.Count < kvp.Value.First)
                {
                    DebugConsole.ThrowError("Error in MineralMission - " +
                                            "spawned " + spawnedResources.Count + "/" + kvp.Value.First + " of " + prefab.Name);
                }
                if (spawnedResources.None())
                {
                    continue;
                }
                SpawnedResources.Add(kvp.Key, spawnedResources);
                kvp.Value.Second = rotation;

                foreach (Level.Cave cave in Level.Loaded.Caves)
                {
                    foreach (Item spawnedResource in spawnedResources)
                    {
                        if (cave.Area.Contains(spawnedResource.WorldPosition))
                        {
                            cave.DisplayOnSonar = true;
                            caves.Add(cave);
                            break;
                        }
                    }
                }
            }
            CalculateMissionClusterPositions();
            FindRelevantLevelResources();
        }