Client LuaCsForBarotrauma
AbilityConditionMission.cs
1 using System;
2 using System.Collections.Immutable;
3 using System.Linq;
4 
5 namespace Barotrauma.Abilities
6 {
8  {
9  private readonly ImmutableHashSet<Identifier> missionType;
10  private readonly bool isAffiliated;
11 
12  public AbilityConditionMission(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
13  {
14  missionType = conditionElement.GetAttributeIdentifierImmutableHashSet("missiontype", ImmutableHashSet<Identifier>.Empty)!;
15  isAffiliated = conditionElement.GetAttributeBool("isaffiliated", false);
16  }
17 
18  protected override bool MatchesConditionSpecific(AbilityObject abilityObject)
19  {
20  if (abilityObject is IAbilityMission { Mission: { } mission })
21  {
22  if (!isAffiliated) { return CheckMissionType(); }
23 
24  if (GameMain.GameSession?.Campaign?.Factions is not { } factions) { return false; }
25 
26  foreach (var reputationReward in mission.ReputationRewards)
27  {
28  if (reputationReward.Amount <= 0) { continue; }
29  if (GetMatchingFaction(reputationReward.FactionIdentifier) is { } faction &&
31  {
32  return CheckMissionType();
33  }
34  }
35 
36  return false;
37 
38  Faction GetMatchingFaction(Identifier factionIdentifier) =>
39  factionIdentifier == "location"
40  ? mission.OriginLocation?.Faction
41  : factions.FirstOrDefault(f => factionIdentifier == f.Prefab.Identifier);
42 
43  bool CheckMissionType() => missionType.IsEmpty || missionType.Contains(mission.Prefab.Type);
44  }
45 
46  LogAbilityConditionError(abilityObject, typeof(IAbilityMission));
47  return false;
48  }
49  }
50 }
void LogAbilityConditionError(AbilityObject abilityObject, Type expectedData)
override bool MatchesConditionSpecific(AbilityObject abilityObject)
AbilityConditionMission(CharacterTalent characterTalent, ContentXElement conditionElement)
bool GetAttributeBool(string key, bool def)
ImmutableHashSet< Identifier > GetAttributeIdentifierImmutableHashSet(string key, ImmutableHashSet< Identifier >? def, bool trim=true)
Faction(CampaignMetadata? metadata, FactionPrefab prefab)
Definition: Factions.cs:20
static FactionAffiliation GetPlayerAffiliationStatus(Faction faction)
Get what kind of affiliation this faction has towards the player depending on who they chose to side ...
Definition: Factions.cs:30
static GameSession?? GameSession
Definition: GameMain.cs:88
FactionAffiliation
Definition: Factions.cs:9