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.
- Listed in Global namespace: T to X
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
TrialLogic() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
15 private and internal fields
| Member | What it is |
|---|---|
private float completeGraceTimer | Seconds to wait before resetting an empty, completed trial. |
private int currentPhase | Index of the current phase, or -1 when inactive. |
private string details | Free text notes for designers. |
private float incompleteGraceTimer | Seconds to wait before resetting an empty trial that was not finished (default 300). |
private static Logger logger | NLog logger for trial events. |
private Phase[] phases | The trial's phases, run in order. |
private PlayerDetect playerDetector | Area detector that adds and removes participants. |
private Transform playerResetPosition | Where disconnecting players are teleported to. |
private Timeline.IEntry reset | Pending grace timer entry, or null. |
private LogicBoolSender resetSender | Logic bool sender pulsed true then false to reset the trial's logic. |
private float resetSenderResetDelay | Seconds the reset sender stays true. |
private ITrialReset[] toReset | ITrialReset components found under this object when the trial began. |
private string trialKey | This trial's key in the active list (its chunk identifier), or null. |
private HashSet<IPlayer> trialParticipants | Backing set for Participants. |
private static Dictionary<string, TrialLogic> trials | Static lookup of active trials by key. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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. |