static void AddEvent(EventDebugStats stats, EventPrefab eventPrefab) { if (eventPrefab.EventType == typeof(MonsterEvent)) { float spawnProbability = eventPrefab.ConfigElement.GetAttributeFloat("spawnprobability", 1.0f); if (Rand.Value(Rand.RandSync.Server) > spawnProbability) { return; } string character = eventPrefab.ConfigElement.GetAttributeString("characterfile", ""); System.Diagnostics.Debug.Assert(!string.IsNullOrEmpty(character)); int amount = eventPrefab.ConfigElement.GetAttributeInt("amount", 0); int minAmount = eventPrefab.ConfigElement.GetAttributeInt("minamount", amount); int maxAmount = eventPrefab.ConfigElement.GetAttributeInt("maxamount", amount); int count = Rand.Range(minAmount, maxAmount + 1); if (count <= 0) { return; } if (!stats.MonsterCounts.ContainsKey(character)) { stats.MonsterCounts[character] = 0; } stats.MonsterCounts[character] += count; } }
private bool TestEvent(OutpostGenerationParams?param, LocationType?type) { SubmarineInfo subInfo = SubmarineInfo.SavedSubmarines.FirstOrDefault(info => info.HasTag(SubmarineTag.Shuttle)); XElement? eventXml = ExportXML(); EventPrefab?prefab; if (eventXml != null) { prefab = new EventPrefab(eventXml); } else { GUI.AddMessage("Unable to open test enviroment because the event contains errors.", GUI.Style.Red); return(false); } GameSession gameSession = new GameSession(subInfo, "", GameModePreset.TestMode, CampaignSettings.Empty, null); TestGameMode gameMode = (TestGameMode)gameSession.GameMode; gameMode.SpawnOutpost = true; gameMode.OutpostParams = param; gameMode.OutpostType = type; gameMode.TriggeredEvent = prefab; gameMode.OnRoundEnd = () => { Submarine.Unload(); GameMain.EventEditorScreen.Select(); }; GameMain.GameScreen.Select(); gameSession.StartRound(null, false); return(true); }
public MonsterEvent(EventPrefab prefab) : base(prefab) { speciesName = prefab.ConfigElement.GetAttributeString("characterfile", ""); CharacterPrefab characterPrefab = CharacterPrefab.FindByFilePath(speciesName); if (characterPrefab != null) { speciesName = characterPrefab.Identifier; } if (string.IsNullOrEmpty(speciesName)) { throw new Exception("speciesname is null!"); } int defaultAmount = prefab.ConfigElement.GetAttributeInt("amount", 1); minAmount = prefab.ConfigElement.GetAttributeInt("minamount", defaultAmount); maxAmount = Math.Max(prefab.ConfigElement.GetAttributeInt("maxamount", 1), minAmount); maxAmountPerLevel = prefab.ConfigElement.GetAttributeInt("maxamountperlevel", int.MaxValue); var spawnPosTypeStr = prefab.ConfigElement.GetAttributeString("spawntype", ""); if (string.IsNullOrWhiteSpace(spawnPosTypeStr) || !Enum.TryParse(spawnPosTypeStr, true, out spawnPosType)) { spawnPosType = Level.PositionType.MainPath; } //backwards compatibility if (prefab.ConfigElement.GetAttributeBool("spawndeep", false)) { spawnPosType = Level.PositionType.Abyss; } spawnPointTag = prefab.ConfigElement.GetAttributeString("spawnpointtag", string.Empty); offset = prefab.ConfigElement.GetAttributeFloat("offset", 0); scatter = Math.Clamp(prefab.ConfigElement.GetAttributeFloat("scatter", 500), 0, 3000); if (GameMain.NetworkMember != null) { List <string> monsterNames = GameMain.NetworkMember.ServerSettings.MonsterEnabled.Keys.ToList(); string tryKey = monsterNames.Find(s => speciesName.ToLower() == s.ToLower()); if (!string.IsNullOrWhiteSpace(tryKey)) { if (!GameMain.NetworkMember.ServerSettings.MonsterEnabled[tryKey]) { disallowed = true; //spawn was disallowed by host } } } }
public MalfunctionEvent(EventPrefab prefab) : base(prefab) { targetItems = new List <Item>(); minItemAmount = prefab.ConfigElement.GetAttributeInt("minitemamount", 1); maxItemAmount = prefab.ConfigElement.GetAttributeInt("maxitemamount", minItemAmount); decreaseConditionAmount = prefab.ConfigElement.GetAttributeFloat("decreaseconditionamount", 0.0f); duration = prefab.ConfigElement.GetAttributeFloat("duration", 0.0f); targetItemIdentifiers = prefab.ConfigElement.GetAttributeStringArray("itemidentifiers", new string[0]); }
private float CalculateCommonness(EventPrefab eventPrefab, float baseCommonness) { if (level.LevelData.NonRepeatableEvents.Contains(eventPrefab)) { return(0.0f); } float retVal = baseCommonness; if (level.LevelData.EventHistory.Contains(eventPrefab)) { retVal *= 0.1f; } return(retVal); }
public ScriptedEvent(EventPrefab prefab) : base(prefab) { foreach (XElement element in prefab.ConfigElement.Elements()) { if (element.Name.ToString().Equals("statuseffect", StringComparison.OrdinalIgnoreCase)) { DebugConsole.ThrowError($"Error in event prefab \"{prefab.Identifier}\". Status effect configured as an action. Please configure status effects as child elements of a StatusEffectAction."); continue; } var action = EventAction.Instantiate(this, element); if (action != null) { Actions.Add(action); } } if (!Actions.Any()) { DebugConsole.ThrowError($"Scripted event \"{prefab.Identifier}\" has no actions. The event will do nothing."); } }
public ArtifactEvent(EventPrefab prefab) : base(prefab) { if (prefab.ConfigElement.Attribute("itemname") != null) { DebugConsole.ThrowError("Error in ArtifactEvent - use item identifier instead of the name of the item."); string itemName = prefab.ConfigElement.GetAttributeString("itemname", ""); itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name " + itemName); } } else { string itemIdentifier = prefab.ConfigElement.GetAttributeString("itemidentifier", ""); itemPrefab = MapEntityPrefab.Find(null, itemIdentifier) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Error in ArtifactEvent - couldn't find an item prefab with the identifier " + itemIdentifier); } } }
public Event(EventPrefab prefab) { this.prefab = prefab; }
private EventSet(XElement element, string debugIdentifier, EventSet parentSet = null) { DebugIdentifier = element.GetAttributeString("identifier", null) ?? debugIdentifier; Commonness = new Dictionary <string, float>(); EventPrefabs = new List <Pair <EventPrefab, float> >(); ChildSets = new List <EventSet>(); MinLevelDifficulty = element.GetAttributeFloat("minleveldifficulty", 0); MaxLevelDifficulty = Math.Max(element.GetAttributeFloat("maxleveldifficulty", 100), MinLevelDifficulty); string levelTypeStr = element.GetAttributeString("leveltype", "LocationConnection"); if (!Enum.TryParse(levelTypeStr, true, out LevelType)) { DebugConsole.ThrowError($"Error in event set \"{debugIdentifier}\". \"{levelTypeStr}\" is not a valid level type."); } string[] locationTypeStr = element.GetAttributeStringArray("locationtype", null); if (locationTypeStr != null) { LocationTypeIdentifiers = locationTypeStr; if (LocationType.List.Any()) { CheckLocationTypeErrors(); } } MinIntensity = element.GetAttributeFloat("minintensity", 0.0f); MaxIntensity = Math.Max(element.GetAttributeFloat("maxintensity", 100.0f), MinIntensity); ChooseRandom = element.GetAttributeBool("chooserandom", false); EventCount = element.GetAttributeInt("eventcount", 1); MinDistanceTraveled = element.GetAttributeFloat("mindistancetraveled", 0.0f); MinMissionTime = element.GetAttributeFloat("minmissiontime", 0.0f); AllowAtStart = element.GetAttributeBool("allowatstart", false); PerRuin = element.GetAttributeBool("perruin", false); PerCave = element.GetAttributeBool("percave", false); PerWreck = element.GetAttributeBool("perwreck", false); IgnoreCoolDown = element.GetAttributeBool("ignorecooldown", parentSet?.IgnoreCoolDown ?? (PerRuin || PerCave || PerWreck)); DelayWhenCrewAway = element.GetAttributeBool("delaywhencrewaway", !PerRuin && !PerCave && !PerWreck); OncePerOutpost = element.GetAttributeBool("perwreck", false); TriggerEventCooldown = element.GetAttributeBool("triggereventcooldown", true); Commonness[""] = 1.0f; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "commonness": Commonness[""] = subElement.GetAttributeFloat("commonness", 0.0f); foreach (XElement overrideElement in subElement.Elements()) { if (overrideElement.Name.ToString().Equals("override", StringComparison.OrdinalIgnoreCase)) { string levelType = overrideElement.GetAttributeString("leveltype", ""); if (!Commonness.ContainsKey(levelType)) { Commonness.Add(levelType, overrideElement.GetAttributeFloat("commonness", 0.0f)); } } } break; case "eventset": ChildSets.Add(new EventSet(subElement, this.DebugIdentifier + "-" + ChildSets.Count, this)); break; default: //an element with just an identifier = reference to an event prefab if (!subElement.HasElements && subElement.Attributes().First().Name.ToString().Equals("identifier", StringComparison.OrdinalIgnoreCase)) { string identifier = subElement.GetAttributeString("identifier", ""); var prefab = PrefabList.Find(p => p.Identifier.Equals(identifier, StringComparison.OrdinalIgnoreCase)); if (prefab == null) { DebugConsole.ThrowError($"Error in event set \"{debugIdentifier}\" - could not find the event prefab \"{identifier}\"."); } else { float commonness = subElement.GetAttributeFloat("commonness", prefab.Commonness); EventPrefabs.Add(new Pair <EventPrefab, float>(prefab, commonness)); } } else { var prefab = new EventPrefab(subElement); EventPrefabs.Add(new Pair <EventPrefab, float>(prefab, prefab.Commonness)); } break; } } }
public SubEventPrefab(EventPrefab prefab, float commonness, float probability) { Prefabs = prefab.ToEnumerable().ToImmutableArray(); Commonness = commonness; Probability = probability; }