Client LuaCsForBarotrauma
ModifyLocationAction.cs
1 namespace Barotrauma
2 {
7  {
8  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the faction to set as the location's primary faction (optional).")]
9  public Identifier Faction { get; set; }
10 
11  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the faction to set as the location's secondary faction (optional).")]
12  public Identifier SecondaryFaction { get; set; }
13 
14  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the location type to set as the location's new type (optional)")]
15  public Identifier Type { get; set; }
16 
17  [Serialize("", IsPropertySaveable.Yes, description: "New name to give to the location (optional). Can either be the name as-is, or a tag referring to a line in a text file.")]
18  public Identifier Name { get; set; }
19 
20  private bool isFinished;
21 
22  public ModifyLocationAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
23  {
24  }
25 
26  public override bool IsFinished(ref string goTo)
27  {
28  return isFinished;
29  }
30  public override void Reset()
31  {
32  isFinished = false;
33  }
34 
35  public override void Update(float deltaTime)
36  {
37  if (isFinished) { return; }
38 
39  if (GameMain.GameSession.GameMode is CampaignMode campaign)
40  {
41  var location = campaign.Map.CurrentLocation;
42  if (location != null)
43  {
44  if (!Faction.IsEmpty)
45  {
46  var faction = campaign.Factions.Find(f => f.Prefab.Identifier == Faction);
47  if (faction == null)
48  {
49  DebugConsole.ThrowError($"Error in ModifyLocationAction ({ParentEvent.Prefab.Identifier}): could not find a faction with the identifier \"{Faction}\".",
50  contentPackage: ParentEvent?.Prefab?.ContentPackage);
51  }
52  else
53  {
54  location.Faction = faction;
55  }
56  }
57  if (!SecondaryFaction.IsEmpty)
58  {
59  var secondaryFaction = campaign.Factions.Find(f => f.Prefab.Identifier == SecondaryFaction);
60  if (secondaryFaction == null)
61  {
62  DebugConsole.ThrowError($"Error in ModifyLocationAction ({ParentEvent.Prefab.Identifier}): could not find a faction with the identifier \"{SecondaryFaction}\".",
63  contentPackage: ParentEvent.Prefab.ContentPackage);
64  }
65  else
66  {
67  location.SecondaryFaction = secondaryFaction;
68  }
69  }
70  if (!Type.IsEmpty)
71  {
72  var locationType = LocationType.Prefabs.Find(lt => lt.Identifier == Type);
73  if (locationType == null)
74  {
75  DebugConsole.ThrowError($"Error in ModifyLocationAction ({ParentEvent.Prefab.Identifier}): could not find a location type with the identifier \"{Type}\".",
76  contentPackage: ParentEvent.Prefab.ContentPackage);
77  }
78  else if (!location.LocationTypeChangesBlocked)
79  {
80  location.ChangeType(campaign, locationType);
81  }
82  }
83  if (!Name.IsEmpty)
84  {
85  location.ForceName(Name);
86  }
87  }
88  }
89  isFinished = true;
90  }
91 
92  public override string ToDebugString()
93  {
94  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(ModifyLocationAction)}";
95  }
96  }
97 }
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:102
EventPrefab Prefab
Definition: Event.cs:16
static GameSession?? GameSession
Definition: GameMain.cs:88
static readonly PrefabCollection< LocationType > Prefabs
Definition: LocationType.cs:15
Modifies the current location in some way (e.g. adjusting the faction, type of name).
ModifyLocationAction(ScriptedEvent parentEvent, ContentXElement element)
override bool IsFinished(ref string goTo)
Has the action finished.
override string ToDebugString()
Rich test to display in debugdraw
override void Update(float deltaTime)
ContentPackage? ContentPackage
Definition: Prefab.cs:37