public void GiveReward() { if (!(GameMain.GameSession.GameMode is CampaignMode campaign)) { return; } campaign.Money += GetReward(Submarine.MainSub); foreach (KeyValuePair <string, float> reputationReward in ReputationRewards) { if (reputationReward.Key.Equals("location", StringComparison.OrdinalIgnoreCase)) { Locations[0].Reputation.Value += reputationReward.Value; Locations[1].Reputation.Value += reputationReward.Value; } else { Faction faction = campaign.Factions.Find(faction1 => faction1.Prefab.Identifier.Equals(reputationReward.Key, StringComparison.OrdinalIgnoreCase)); if (faction != null) { faction.Reputation.Value += reputationReward.Value; } } } if (Prefab.DataRewards != null) { foreach (var(identifier, value, operation) in Prefab.DataRewards) { SetDataAction.PerformOperation(campaign.CampaignMetadata, identifier, value, operation); } } }
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 void GiveReward() { if (!(GameMain.GameSession.GameMode is CampaignMode campaign)) { return; } int reward = GetReward(Submarine.MainSub); float baseExperienceGain = reward * 0.09f; float difficultyMultiplier = 1 + level.Difficulty / 100f; baseExperienceGain *= difficultyMultiplier; IEnumerable <Character> crewCharacters = GameSession.GetSessionCrewCharacters(); // use multipliers here so that we can easily add them together without introducing multiplicative XP stacking var experienceGainMultiplier = new AbilityValue(1f); crewCharacters.ForEach(c => c.CheckTalents(AbilityEffectType.OnAllyGainMissionExperience, experienceGainMultiplier)); crewCharacters.ForEach(c => experienceGainMultiplier.Value += c.GetStatValue(StatTypes.MissionExperienceGainMultiplier)); int experienceGain = (int)(baseExperienceGain * experienceGainMultiplier.Value); #if CLIENT foreach (Character character in crewCharacters) { character.Info?.GiveExperience(experienceGain, isMissionExperience: true); } #else foreach (Barotrauma.Networking.Client c in GameMain.Server.ConnectedClients) { //give the experience to the stored characterinfo if the client isn't currently controlling a character (c.Character?.Info ?? c.CharacterInfo)?.GiveExperience(experienceGain, isMissionExperience: true); } #endif // apply money gains afterwards to prevent them from affecting XP gains var moneyGainMission = new AbilityValueMission(1f, this); crewCharacters.ForEach(c => c.CheckTalents(AbilityEffectType.OnGainMissionMoney, moneyGainMission)); crewCharacters.ForEach(c => moneyGainMission.Value += c.GetStatValue(StatTypes.MissionMoneyGainMultiplier)); campaign.Money += (int)(reward * moneyGainMission.Value); foreach (Character character in crewCharacters) { character.Info.MissionsCompletedSinceDeath++; } foreach (KeyValuePair <string, float> reputationReward in ReputationRewards) { if (reputationReward.Key.Equals("location", StringComparison.OrdinalIgnoreCase)) { Locations[0].Reputation.AddReputation(reputationReward.Value); Locations[1].Reputation.AddReputation(reputationReward.Value); } else { Faction faction = campaign.Factions.Find(faction1 => faction1.Prefab.Identifier.Equals(reputationReward.Key, StringComparison.OrdinalIgnoreCase)); if (faction != null) { faction.Reputation.AddReputation(reputationReward.Value); } } } if (Prefab.DataRewards != null) { foreach (var(identifier, value, operation) in Prefab.DataRewards) { SetDataAction.PerformOperation(campaign.CampaignMetadata, identifier, value, operation); } } }