public override void End() { if (EnoughHaveBeenCollected()) { if (Prefab.LocationTypeChangeOnCompleted != null) { ChangeLocationType(Prefab.LocationTypeChangeOnCompleted); } GiveReward(); completed = true; } foreach (var kvp in SpawnedResources) { foreach (var i in kvp.Value) { if (i != null && !i.Removed && !HasBeenCollected(i)) { i.Remove(); } } } SpawnedResources.Clear(); RelevantLevelResources.Clear(); MissionClusterPositions.Clear(); failed = !completed && state > 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(); }
public override void ClientReadInitial(IReadMessage msg) { byte caveCount = msg.ReadByte(); for (int i = 0; i < caveCount; i++) { byte selectedCave = msg.ReadByte(); if (selectedCave < 255 && Level.Loaded != null) { if (selectedCave < Level.Loaded.Caves.Count) { Level.Loaded.Caves[selectedCave].DisplayOnSonar = true; } else { DebugConsole.ThrowError($"Cave index out of bounds when reading nest mission data. Index: {selectedCave}, number of caves: {Level.Loaded.Caves.Count}"); } } } for (int i = 0; i < ResourceClusters.Count; i++) { var amount = msg.ReadByte(); var rotation = msg.ReadSingle(); for (int j = 0; j < amount; j++) { var item = Item.ReadSpawnData(msg); if (item.GetComponent <Holdable>() is Holdable h) { h.AttachToWall(); item.Rotation = rotation; } if (SpawnedResources.TryGetValue(item.Prefab.Identifier, out var resources)) { resources.Add(item); } else { SpawnedResources.Add(item.Prefab.Identifier, new List <Item>() { item }); } } } CalculateMissionClusterPositions(); for (int i = 0; i < ResourceClusters.Count; i++) { var identifier = msg.ReadString(); var count = msg.ReadByte(); var resources = new Item[count]; for (int j = 0; j < count; j++) { var id = msg.ReadUInt16(); var entity = Entity.FindEntityByID(id); if (!(entity is Item item)) { continue; } resources[j] = item; } RelevantLevelResources.Add(identifier, resources); } }