private string GetMissionText() { string msg; if (rng.Next(1) == 0) { msg = familyOccurances[rng.Next(familyOccurances.Length)]; string family = DirectionToFamily(currentMission); msg = msg.Replace("@", family); } else { msg = directionOccurances[rng.Next(directionOccurances.Length)]; msg = msg.Replace("@", currentMission.ToString().ToLower()); } return(msg); }
internal static WWW LoadMission(MissionType mt, bool toRepeat) { WWWForm form = new WWWForm(); form.AddField("MissionType", mt.ToString()); form.AddField("ToRepeat", toRepeat ? 1 : 0); return(CreateWWW("/load", form)); }
internal static WWW SendMissionAccomplished(MissionType MissionType, string MissionName, int Round, MissionStatus ms, Dictionary <ScoreType, Result> actualResults, bool getScores) { int interventions = (int)actualResults[ScoreType.Interventions].Value; float time = actualResults[ScoreType.Time].Value; WWWForm form = new WWWForm(); form.AddField("MissionType", MissionType.ToString()); form.AddField("MissionName", MissionName); form.AddField("MissionStatus", ms.ToString()); form.AddField("Interventions", interventions); form.AddField("Time", "" + (int)(time * 1000)); form.AddField("Round", Round); form.AddField("GetScores", getScores ? 1 : 0); WWW www = CreateWWW("/save", form); return(www); }
public string GetLocalizedName(MissionType type) { return(Get(nameof(MissionType), type.ToString())); }
public void SetLocalizedName(MissionType type, string value) { Set(nameof(MissionType), type.ToString(), value); }
// Tries to execute this mission and returns true if it was successfull: public bool TryExecute() { switch (missionType) { case MissionType.DEPLOY: // Ship-Creation is only possible while not in flight with the current implementation: if (HighLogic.LoadedScene != GameScenes.FLIGHT) { CreateShip(); return(true); } return(false); case MissionType.CONSTRUCT: if (HighLogic.LoadedScene != GameScenes.FLIGHT) { Vessel targetVessel = null; if (targetVesselId == null || (targetVessel = TargetVessel.GetVesselById((Guid)targetVesselId)) == null || !TargetVessel.IsValidTarget(targetVessel, MissionController.missionProfiles[profileName])) { // Abort mission (maybe the vessel was removed or got moved out of range): Debug.Log("[KSTS] aborting transport-construction: target-vessel missing or out of range"); ScreenMessages.PostScreenMessage("Aborting construction-mission: Target-vessel not found at expected rendezvous-coordinates!"); } else { CreateShip(); return(true); } } return(false); case MissionType.TRANSPORT: // Our functions for manipulating ships don't work on active vessels, beeing in flight however should be fine: if (FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.id != targetVesselId) { Vessel targetVessel = null; if (!MissionController.missionProfiles.ContainsKey(profileName)) { throw new Exception("unable to execute transport-mission, profile '" + profileName + "' missing"); } if (targetVesselId == null || (targetVessel = TargetVessel.GetVesselById((Guid)targetVesselId)) == null || !TargetVessel.IsValidTarget(targetVessel, MissionController.missionProfiles[profileName])) { // Abort mission (maybe the vessel was removed or got moved out of range): Debug.Log("[KSTS] aborting transport-mission: target-vessel missing or out of range"); ScreenMessages.PostScreenMessage("Aborting transport-mission: Target-vessel not found at expected rendezvous-coordinates!"); } else { // Do the actual transport-mission: if (resourcesToDeliver != null) { foreach (var item in resourcesToDeliver) { TargetVessel.AddResources(targetVessel, item.Key, item.Value); } } if (crewToCollect != null) { foreach (var kerbonautName in crewToCollect) { TargetVessel.RecoverCrewMember(targetVessel, kerbonautName); } } if (crewToDeliver != null) { foreach (var kerbonautName in crewToDeliver) { TargetVessel.AddCrewMember(targetVessel, kerbonautName); } } } return(true); } return(false); default: throw new Exception("unexpected mission-type '" + missionType.ToString() + "'"); } }
public MissionPrefab(XElement element) { ConfigElement = element; Identifier = element.GetAttributeString("identifier", ""); TextIdentifier = element.GetAttributeString("textidentifier", null) ?? Identifier; tags = element.GetAttributeStringArray("tags", new string[0], convertToLowerInvariant: true); Name = TextManager.Get("MissionName." + TextIdentifier, true) ?? element.GetAttributeString("name", ""); Description = TextManager.Get("MissionDescription." + TextIdentifier, true) ?? element.GetAttributeString("description", ""); Reward = element.GetAttributeInt("reward", 1); Commonness = element.GetAttributeInt("commonness", 1); SuccessMessage = TextManager.Get("MissionSuccess." + TextIdentifier, true) ?? element.GetAttributeString("successmessage", "Mission completed successfully"); FailureMessage = TextManager.Get("MissionFailure." + TextIdentifier, true) ?? ""; if (string.IsNullOrEmpty(FailureMessage) && TextManager.ContainsTag("missionfailed")) { FailureMessage = TextManager.Get("missionfailed", returnNull: true) ?? ""; } if (string.IsNullOrEmpty(FailureMessage) && GameMain.Config.Language == "English") { FailureMessage = element.GetAttributeString("failuremessage", ""); } SonarLabel = TextManager.Get("MissionSonarLabel." + TextIdentifier, true) ?? element.GetAttributeString("sonarlabel", ""); SonarIconIdentifier = element.GetAttributeString("sonaricon", ""); MultiplayerOnly = element.GetAttributeBool("multiplayeronly", false); SingleplayerOnly = element.GetAttributeBool("singleplayeronly", false); AchievementIdentifier = element.GetAttributeString("achievementidentifier", ""); Headers = new List <string>(); Messages = new List <string>(); AllowedLocationTypes = new List <Pair <string, string> >(); for (int i = 0; i < 100; i++) { string header = TextManager.Get("MissionHeader" + i + "." + TextIdentifier, true); string message = TextManager.Get("MissionMessage" + i + "." + TextIdentifier, true); if (!string.IsNullOrEmpty(message)) { Headers.Add(header); Messages.Add(message); } } int messageIndex = 0; foreach (XElement subElement in element.Elements()) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "message": if (messageIndex > Headers.Count - 1) { Headers.Add(string.Empty); Messages.Add(string.Empty); } Headers[messageIndex] = TextManager.Get("MissionHeader" + messageIndex + "." + TextIdentifier, true) ?? subElement.GetAttributeString("header", ""); Messages[messageIndex] = TextManager.Get("MissionMessage" + messageIndex + "." + TextIdentifier, true) ?? subElement.GetAttributeString("text", ""); messageIndex++; break; case "locationtype": AllowedLocationTypes.Add(new Pair <string, string>( subElement.GetAttributeString("from", ""), subElement.GetAttributeString("to", ""))); break; case "reputation": case "reputationreward": string factionIdentifier = subElement.GetAttributeString("identifier", ""); float amount = subElement.GetAttributeFloat("amount", 0.0f); if (ReputationRewards.ContainsKey(factionIdentifier)) { DebugConsole.ThrowError($"Error in mission prefab \"{Identifier}\". Multiple reputation changes defined for the identifier \"{factionIdentifier}\"."); continue; } ReputationRewards.Add(factionIdentifier, amount); if (!factionIdentifier.Equals("location", StringComparison.OrdinalIgnoreCase)) { if (FactionPrefab.Prefabs != null && !FactionPrefab.Prefabs.Any(p => p.Identifier.Equals(factionIdentifier, StringComparison.OrdinalIgnoreCase))) { DebugConsole.ThrowError($"Error in mission prefab \"{Identifier}\". Could not find a faction with the identifier \"{factionIdentifier}\"."); } } break; case "metadata": string identifier = subElement.GetAttributeString("identifier", string.Empty); string stringValue = subElement.GetAttributeString("value", string.Empty); if (!string.IsNullOrWhiteSpace(stringValue) && !string.IsNullOrWhiteSpace(identifier)) { object value = SetDataAction.ConvertXMLValue(stringValue); SetDataAction.OperationType operation = SetDataAction.OperationType.Set; string operatingString = subElement.GetAttributeString("operation", string.Empty); if (!string.IsNullOrWhiteSpace(operatingString)) { operation = (SetDataAction.OperationType)Enum.Parse(typeof(SetDataAction.OperationType), operatingString); } DataRewards.Add(Tuple.Create(identifier, value, operation)); } break; } } string missionTypeName = element.GetAttributeString("type", ""); if (!Enum.TryParse(missionTypeName, out Type)) { DebugConsole.ThrowError("Error in mission prefab \"" + Name + "\" - \"" + missionTypeName + "\" is not a valid mission type."); return; } if (Type == MissionType.None) { DebugConsole.ThrowError("Error in mission prefab \"" + Name + "\" - mission type cannot be none."); return; } if (CoOpMissionClasses.ContainsKey(Type)) { constructor = CoOpMissionClasses[Type].GetConstructor(new[] { typeof(MissionPrefab), typeof(Location[]) }); } else if (PvPMissionClasses.ContainsKey(Type)) { constructor = PvPMissionClasses[Type].GetConstructor(new[] { typeof(MissionPrefab), typeof(Location[]) }); } else { DebugConsole.ThrowError("Error in mission prefab \"" + Name + "\" - unsupported mission type \"" + Type.ToString() + "\""); } InitProjSpecific(element); }
public static string From(MissionType missionType) { return(names.ContainsKey(missionType) ? names[missionType] : missionType.ToString()); }
/// <summary> /// 条件などから自動でKeyを作成する /// </summary> public string GetKey() { return(string.Format("{0}{1}", type.ToString(), targetValue.ToString())); }