public static ConditionalMissionUnlock FromString(string str) { // Syntax: // UnlockMissionName|Variable1Name:Variable1State,Variable2Name:Variable2State,... string[] parts = str.Split('|'); if (parts.Length != 2) { Logger.Log("Parsing MissionUnlockCondition failed: " + str); return(null); } var missionUnlockCondition = new ConditionalMissionUnlock(parts[0]); string[] conditions = parts[1].Split(','); foreach (string condition in conditions) { string[] conditionParts = condition.Split(':'); if (conditionParts.Length != 2) { Logger.Log("Parsing MissionUnlockCondition failed: " + str); return(null); } var globalVariableCondition = new GlobalVariableCondition(conditionParts[0], Conversions.BooleanFromString(conditionParts[1], false)); missionUnlockCondition.PrerequisiteGlobalVariableStates.Add(globalVariableCondition); } return(missionUnlockCondition); }
public Mission(IniSection iniSection, bool isCampaignMission) { InternalName = iniSection.SectionName; Side = iniSection.GetIntValue(nameof(Side), 0); Scenario = iniSection.GetStringValue(nameof(Scenario), string.Empty); GUIName = iniSection.GetStringValue("Description", "Undefined mission"); if (iniSection.KeyExists("UIName")) { GUIName = iniSection.GetStringValue("UIName", GUIName); } IconPath = iniSection.GetStringValue(nameof(IconPath), string.Empty); GUIDescription = iniSection.GetStringValue("LongDescription", string.Empty); PreviewImagePath = iniSection.GetStringValue(nameof(PreviewImagePath), string.Empty); RequiredAddon = iniSection.GetBooleanValue(nameof(RequiredAddon), false); Enabled = iniSection.GetBooleanValue(nameof(Enabled), true); BuildOffAlly = iniSection.GetBooleanValue(nameof(BuildOffAlly), false); WarnOnHardWithoutMediumPlayed = iniSection.GetBooleanValue(nameof(WarnOnHardWithoutMediumPlayed), WarnOnHardWithoutMediumPlayed); PlayerAlwaysOnNormalDifficulty = iniSection.GetBooleanValue(nameof(PlayerAlwaysOnNormalDifficulty), false); if (iniSection.KeyExists("DifficultyLabels")) { DifficultyLabels = iniSection.GetListValue("DifficultyLabels", ',', s => s).ToArray(); if (DifficultyLabels.Length != DifficultyLabelCount) { throw new NotSupportedException($"Invalid number of DifficultyLabels= specified for mission { InternalName }: " + $"{DifficultyLabels.Length}, expected {DifficultyLabelCount}"); } } CampaignInternalName = iniSection.GetStringValue(nameof(CampaignInternalName), null); RequiresUnlocking = iniSection.GetBooleanValue(nameof(RequiresUnlocking), isCampaignMission); UnlockMissions = iniSection.GetStringValue(nameof(UnlockMissions), string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); UsedGlobalVariables = iniSection.GetStringValue(nameof(UsedGlobalVariables), string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); UnlockGlobalVariables = iniSection.GetStringValue(nameof(UnlockGlobalVariables), string.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); // Parse conditional mission unlocks int i = 0; while (true) { string conditionalMissionUnlockData = iniSection.GetStringValue("ConditionalMissionUnlock" + i, null); if (string.IsNullOrWhiteSpace(conditionalMissionUnlockData)) { break; } var conditionalMissionUnlock = ConditionalMissionUnlock.FromString(conditionalMissionUnlockData); if (conditionalMissionUnlock != null) { ConditionalMissionUnlocks.Add(conditionalMissionUnlock); } i++; } GUIDescription = GUIDescription.Replace("@", Environment.NewLine); }