Client LuaCsForBarotrauma
TutorialPrefab.cs
1 using System.Collections.Immutable;
2 using System.Linq;
3 
4 namespace Barotrauma
5 {
7  {
8 
9  public static readonly PrefabCollection<TutorialPrefab> Prefabs =
10 #if CLIENT
12 #else
14 #endif
15 
16  public readonly int Order;
17  public readonly bool DisableBotConversations;
18  public readonly bool AllowCharacterSwitch;
19 
20  public readonly ContentPath SubmarinePath = ContentPath.FromRaw("Content/Tutorials/Dugong_Tutorial.sub");
21  public readonly ContentPath OutpostPath = ContentPath.FromRaw("Content/Tutorials/TutorialOutpost.sub");
22  public readonly string LevelSeed;
23  public readonly string LevelParams;
24 
25  private readonly ContentXElement tutorialCharacterElement;
26  public readonly ImmutableArray<Identifier> StartingItemTags;
27 
28  public readonly Identifier EventIdentifier;
29 
30  public readonly Sprite Banner;
31 
32  public readonly EndMessageInfo EndMessage;
33 
34  public enum EndType { None, Continue, Restart }
35 
36  public readonly record struct EndMessageInfo(
38  Identifier NextTutorialIdentifier);
39 
40  public TutorialPrefab(ContentFile file, ContentXElement element) : base(file, element.GetAttributeIdentifier("identifier", ""))
41  {
42  Order = element.GetAttributeInt("order", int.MaxValue);
43  DisableBotConversations = element.GetAttributeBool("disablebotconversations", true);
44  AllowCharacterSwitch = element.GetAttributeBool("allowcharacterswitch", false);
45 
46  SubmarinePath = element.GetAttributeContentPath("submarinepath") ?? SubmarinePath;
47  OutpostPath = element.GetAttributeContentPath("outpostpath") ?? OutpostPath;
48  LevelSeed = element.GetAttributeString("levelseed", "nLoZLLtza");
49  LevelParams = element.GetAttributeString("levelparams", "ColdCavernsTutorial");
50 
51  tutorialCharacterElement = element.GetChildElement("characterinfo");
52  if (tutorialCharacterElement != null)
53  {
54  StartingItemTags = tutorialCharacterElement
55  .GetAttributeIdentifierArray("startingitemtags", new Identifier[0])
56  .ToImmutableArray();
57  }
58  else
59  {
60  StartingItemTags = ImmutableArray<Identifier>.Empty;
61  }
62 
63  var bannerElement = element.GetChildElement("banner");
64  if (bannerElement != null)
65  {
66  Banner = new Sprite(bannerElement, lazyLoad: true);
67  }
68 
69  EventIdentifier = element.GetChildElement("scriptedevent")?.GetAttributeIdentifier("identifier", "") ?? Identifier.Empty;
70 
71  if (element.GetChildElement("endmessage") is ContentXElement endMessageElement)
72  {
74  EndType: endMessageElement.GetAttributeEnum("type", EndType.None),
75  NextTutorialIdentifier: endMessageElement.GetAttributeIdentifier("nexttutorial", Identifier.Empty));
76  }
77  }
78 
80  {
81  if (tutorialCharacterElement == null)
82  {
83  return null;
84  }
85  Identifier speciesName = tutorialCharacterElement.GetAttributeIdentifier("speciesname", CharacterPrefab.HumanSpeciesName);
86  Identifier jobPrefabIdentifier = tutorialCharacterElement.GetAttributeIdentifier("jobidentifier", "assistant");
87  if (!JobPrefab.Prefabs.TryGet(jobPrefabIdentifier, out var jobPrefab))
88  {
89  jobPrefab = JobPrefab.Prefabs.First();
90  }
91  int jobVariant = tutorialCharacterElement.GetAttributeInt("variant", 0);
92  var characterInfo = new CharacterInfo(speciesName, jobOrJobPrefab: jobPrefab, variant: jobVariant);
93  foreach (var skillElement in tutorialCharacterElement.GetChildElements("skill"))
94  {
95  Identifier skillIdentifier = skillElement.GetAttributeIdentifier("identifier", "");
96  if (skillIdentifier.IsEmpty) { continue; }
97  float level = skillElement.GetAttributeFloat("level", 0.0f);
98  characterInfo.SetSkillLevel(skillIdentifier, level);
99  }
100  return characterInfo;
101  }
102 
103  public override void Dispose() { }
104  }
105 }
Stores information about the Character that is needed between rounds in the menu etc....
static readonly Identifier HumanSpeciesName
Base class for content file types, which are loaded from filelist.xml via reflection....
Definition: ContentFile.cs:23
static ContentPath FromRaw(string? rawValue)
string? GetAttributeString(string key, string? def)
ContentPath? GetAttributeContentPath(string key)
ContentXElement? GetChildElement(string name)
bool GetAttributeBool(string key, bool def)
int GetAttributeInt(string key, int def)
Identifier GetAttributeIdentifier(string key, string def)
static readonly PrefabCollection< JobPrefab > Prefabs
static void UpdateInstanceTutorialButtons()
readonly Identifier Identifier
Definition: Prefab.cs:34
readonly record struct EndMessageInfo(EndType EndType, Identifier NextTutorialIdentifier)
static readonly PrefabCollection< TutorialPrefab > Prefabs
readonly bool AllowCharacterSwitch
readonly ImmutableArray< Identifier > StartingItemTags
readonly ContentPath SubmarinePath
TutorialPrefab(ContentFile file, ContentXElement element)
readonly Identifier EventIdentifier
readonly ContentPath OutpostPath
readonly EndMessageInfo EndMessage
readonly string LevelSeed
CharacterInfo GetTutorialCharacterInfo()
readonly bool DisableBotConversations
readonly string LevelParams