Skip to main content

MicroTutorial

A class in Root.Township, ATT.MicroTutorial.

Server: one run of a micro tutorial for one player. It moves the player into a private domain, runs the steps in order, and returns them to the overworld when despawned.

Constructors​

MemberWhat it is
MicroTutorial(IMicroTutorialSettings settings, IPlayer player, IMicroTutorialSystem tutorialSystem, IDomainController domainController)Creates a MicroTutorial from settings, player, tutorialSystem and domainController.

Fields​

8 private and internal fields
MemberWhat it is
private LoadingStatus clientLoadStatusWhether the client has acknowledged spawning the tutorial content.
private Domain domainThe player's private tutorial domain, created in CreateDomain.
private readonly IDomainController domainControllerDomain controller used to create the tutorial domain.
private static readonly MicroTutorialLogger loggerMicro tutorial logger for this class.
private static readonly object staticLockLock around the instance counter when building SessionId.
private readonly List<IServerStepInstance> stepsThe server step instances, one per settings step.
private static long tutorialInstanceCountCount of tutorials made since start, hashed with the server ID and tutorial name into SessionId.
private readonly IMicroTutorialSystem tutorialSystemThe micro tutorial system, used for settings and the sync controller.

Properties​

MemberWhat it is
LocationChunk Chunk { get; }The chunk of the tutorial's domain.
NetworkEntity Entity { get; }The network entity of the tutorial's domain.
bool IsReplay { get; }True if the player had already completed this tutorial when it was created.
IPlayer Player { get; }The player taking the tutorial.
string SessionId { get; }A hash of the server ID, tutorial name and an instance counter, unique per tutorial run.
IMicroTutorialSettings Settings { get; }The tutorial's settings, including its list of steps.
TutorialState State { get; private set; }Inactive, Started or Completed.
int StepIndex { get; private set; }Index of the current step.
IReadOnlyList<IServerStepInstance> Steps { get; }The server step instances, one per step in the settings.
Transform Transform { get; }The transform of the tutorial's domain.
3 private and internal properties
MemberWhat it is
private IServerStepInstance CurrentStep { get; }The step instance at StepIndex.
private bool IsFinalStep { get; }True when StepIndex is the last step.
private int StepCount { get; }Number of steps in the settings.

Events​

MemberWhat it is
event Action<IPlayer, IMicroTutorial> DespawnedRaised after the tutorial has been cleaned up.
event Action<IPlayer, IMicroTutorial> SpawnedRaised once the domain is up and the client has finished loading.
event Action<IPlayer, IMicroTutorial> StepCompletedRaised every time a step finishes, including the last.
event Action<IPlayer, IMicroTutorial> TutorialCompletedRaised when the final step finishes. Despawning is left to the caller.

Methods​

MemberWhat it is
async Task Despawn()Respawns the player at the domain's entry point in the overworld, then despawns step content and destroys the domain. Also runs if the player disconnects.
async Task Spawn()Docks or drops held items, creates the domain, starts step one and waits for the client to load. Damage to the player is then ignored.
override string ToString()Tutorial name and step progress, for logs.
13 private and internal methods
MemberWhat it is
private async Task CleanUpTutorialContent()Despawns and stops every step in reverse order, clears the list and destroys the domain. Called from Despawn.
private async Task CreateDomain()Asks the domain controller for a private domain for the player and spawns them into it.
private void CreateStepInstances()Makes a ServerStepInstance for each step in the settings and hooks its StepCompleted. Called from the constructor.
private string GetStepInfo()Short state text used by ToString, such as how many steps are done.
private void NextStep()Increments StepIndex and starts that step.
private void OnClientLoadCompleted(IPlayer player)Marks the client load as done when the tutorial's own player reports it; ignores other players.
private void OnPlayerDisconnected(Connection connection)Despawns the tutorial when its player disconnects.
private void OnStepCompleted(IServerStepInstance stepInstance)Raises TutorialCompleted on the last step, then StepCompleted, then starts the next step if there is one.
private void OnTutorialPlayerDamaged(DamageState damageState)Marks all damage to the player as handled, so they can't be hurt during the tutorial.
private void PreparePlayerForTutorialStart()Docks held items to the player's back and drops held items matching the system's drop tags.
private async Task ReturnPlayerToGame()Destroys the tutorial controller, removes the save blocker and respawns the player at their entry point in the overworld.
private void Start()Sets the state to started and starts the first step.
private async Task WaitForClientLoad()Polls every 100 ms until the client says it has spawned the first step's content.