Skip to main content

TrialLogic

A class in Root.Township, the global namespace.

Server: runs a trial (a challenge area) as a list of phases, tracking the players inside and resetting everything after they leave. Active trials are listed by chunk identifier through Get and List.

Constructors​

MemberWhat it is
TrialLogic()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

15 private and internal fields
MemberWhat it is
private float completeGraceTimerSeconds to wait before resetting an empty, completed trial.
private int currentPhaseIndex of the current phase, or -1 when inactive.
private string detailsFree text notes for designers.
private float incompleteGraceTimerSeconds to wait before resetting an empty trial that was not finished (default 300).
private static Logger loggerNLog logger for trial events.
private Phase[] phasesThe trial's phases, run in order.
private PlayerDetect playerDetectorArea detector that adds and removes participants.
private Transform playerResetPositionWhere disconnecting players are teleported to.
private Timeline.IEntry resetPending grace timer entry, or null.
private LogicBoolSender resetSenderLogic bool sender pulsed true then false to reset the trial's logic.
private float resetSenderResetDelaySeconds the reset sender stays true.
private ITrialReset[] toResetITrialReset components found under this object when the trial began.
private string trialKeyThis trial's key in the active list (its chunk identifier), or null.
private HashSet<IPlayer> trialParticipantsBacking set for Participants.
private static Dictionary<string, TrialLogic> trialsStatic lookup of active trials by key.

Properties​

MemberWhat it is
bool IsActive { get; }True once a phase has started and until the trial is reset.
bool IsComplete { get; }Meant to be true after the last phase, but it checks currentPhase greater than the phase count, which Progress never reaches.
IEnumerable<IPlayer> Participants { get; }Players currently registered in the trial.

Methods​

MemberWhat it is
void Begin()Starts the trial: force-loads the chunk, registers players in the area, records it under the chunk identifier, fires TrialStarted and enters the first phase.
void ForceProgress()Skips to the next phase if the trial is active.
static TrialLogic Get(string key)Returns the active trial with the given key (chunk identifier), or null.
override void InitializeAsServer(SpawnData spawnData)Server: pulses the reset sender so the trial starts from a clean state.
static IEnumerable<string> List()Keys (chunk identifiers) of all active trials.
void ResetState()Resets every phase and every ITrialReset child, drops all participants and pulses the reset sender. Only acts while active.
11 private and internal methods
MemberWhat it is
private void CheckReset()Runs after the grace timer and resets the trial if nobody has come back.
private void ClearResetSender()Sets the reset sender back to false and stops force-loading the chunk.
private void DeregisterPlayer(IPlayer player)Removes a participant and unhooks their events; starts the reset grace timer if the trial is active and now empty.
private void OnDestroy()Removes the trial from the active list if destroyed while active, logging an error.
private void PlayerDisconnect(Connection connection)Removes a disconnecting player and teleports them to playerResetPosition.
private void Progress()Completes the current phase and begins the next; fires TrialFinished after the last. Resets instead if there are no participants.
private void RegisterPlayer(IPlayer player)Adds a participant, cancels any pending reset and watches for their death and disconnect.
private void RunResetLogic()Sets the reset sender to true, then clears it after resetSenderResetDelay seconds.
private void StartReset()Starts the grace timer (completeGraceTimer or incompleteGraceTimer) before CheckReset runs.
private void StateChange(IPlayerState playerState)Removes a participant when they die.
private void TeleportPlayerOutside(IPlayer player)Moves a player to playerResetPosition, logging an error if it is not set.