public void Deactivate() { if (state == State.Inactive) { this.LogError($"{this} is already inactive"); } // Send the deactivation event DeactivateEvent e = new DeactivateEvent(this); StratusScene.Dispatch <DeactivateEvent>(e); // If the deactivation was succesful if (e.valid) { OnDeactivate(); this.Log("Deactivated"); state = State.Inactive; onDeactivate?.Invoke(); } else { this.LogError($"Failed to deactivate {this}"); } }
public static IEnumerator TestStratusEvent() { // Create the object, add the component GameObject go = new GameObject("Test"); EventsSample eventSample = go.AddComponent <EventsSample>(); Assert.AreEqual(0, eventSample.sampleEventsReceived); yield return(null); // Construct the event EventsSample.SampleEvent e = new EventsSample.SampleEvent() { number = 5 }; // Dispatch to game object eventSample.gameObject.Dispatch <EventsSample.SampleEvent>(e); Assert.AreEqual(1, eventSample.sampleEventsReceived); Assert.AreEqual(5, eventSample.latestEvent.number); // Dispatch to scene e.number = 14; StratusScene.Dispatch <EventsSample.SampleEvent>(e); Assert.AreEqual(2, eventSample.sampleEventsReceived); Assert.AreEqual(14, eventSample.latestEvent.number); yield return(null); }
/// <summary> /// Ends the dialog. /// </summary> private void EndStory() { if (debug) { this.Log($"The story {story.name} has ended at the knot '{story.latestKnot}'"); } // Dispatch the ended event var storyEnded = new StratusStory.EndedEvent() { reader = this, story = this.story }; this.gameObject.Dispatch <StratusStory.EndedEvent>(storyEnded); StratusScene.Dispatch <StratusStory.EndedEvent>(storyEnded); onStoryEnded?.Invoke(story); // Save the story if (saveOnEnd) { Save(); } // We are no longer reading a story currentlyReading = false; // If we are queuing stories and there's one queueud up, let's start it if (queueStories && storyQueue.Count > 0) { QueueNextStory(); } }
/// <summary> /// Jumps the player character onto the segment's checkpoint /// </summary> /// <param name="segment"></param> /// <param name="checkpointIndex"></param> public void Jump(StratusSegmentBehaviour segment, int checkpointIndex = 0) { Vector3 position = segment.checkpoints[checkpointIndex].transform.position; switch (mechanism) { case JumpMechanism.Translate: var navigation = targetTransform.GetComponent <NavMeshAgent>(); if (navigation != null) { navigation.Warp(position); } else { targetTransform.position = position; } break; case JumpMechanism.Callback: onJump?.Invoke(segment, checkpointIndex); break; case JumpMechanism.Event: StratusScene.Dispatch <JumpToSegmentEvent>(new JumpToSegmentEvent(segment, checkpointIndex, position) { episode = this }); break; default: break; } }
public void Activate() { if (!initialized) { this.LogError("Cannot activate before being initialized"); } // If already active if (state == State.Active) { this.LogError($"{this} is already active"); } // Send the activation event ActivateEvent activation = new ActivateEvent(this); StratusScene.Dispatch <ActivateEvent>(activation); // If the activation was successful if (activation.valid) { OnActivate(); this.Log("Activated"); state = State.Active; onActivate?.Invoke(); } else { this.LogError($"Failed to activate {this}"); } }
//------------------------------------------------------------------------------------------/ // Methods: Parsing //------------------------------------------------------------------------------------------/ /// <summary> /// Starts the current dialog. /// </summary> void StartStory(bool resume = false) { // If a knot has been selected... if (story.startingKnot.Length > 0) { this.JumpToKnot(story.startingKnot); } // Inform the space that dialog has started var startedEvent = new StratusStory.StartedEvent() { reader = this, story = story }; // Dispatch to this gameobject and the scene this.gameObject.Dispatch <StratusStory.StartedEvent>(startedEvent); StratusScene.Dispatch <StratusStory.StartedEvent>(startedEvent); onStoryStarted?.Invoke(story); currentlyReading = true; // Update the first line of dialog this.ContinueStory(!resume); story.started = true; if (debug) { StratusDebug.Log($"The story {story.name} has started at the knot '{latestKnot}'"); } }
public void Initialize() { OnInitialize(); initialized = true; this.Log($"Initialized {this}"); StratusScene.Dispatch <SpawnEvent>(new SpawnEvent(this)); }
/// <summary> /// Ends this episode /// </summary> public void End() { current = null; StratusScene.Dispatch <EndEvent>(new EndEvent() { episode = this }); }
/// <summary> /// Starts this trigger. /// </summary> /// <param name="space"></param> public void Start(StratusCombatController caster, Type type, float duration) { var startedEvent = new StartedEvent(); // Make a copy of this trigger ?? startedEvent.Instance = new StratusCombatTrigger.Instance(Copy(this), caster, type, duration); StratusScene.Dispatch <StartedEvent>(startedEvent); }
public bool Instantiate() { if (instanced) { return(false); } StratusScene.Dispatch <InstantiateEvent>(new InstantiateEvent(this)); return(true); }
public static void FadeAction(float speed, Action action, bool endOnAction = true) { StratusScene.Dispatch <FadeEvent>(new FadeEvent() { speed = speed, onStarted = action, endOnAction = endOnAction }); }
//------------------------------------------------------------------------/ // Messages //------------------------------------------------------------------------/ private void Awake() { this.Subscribe(); this.OnCombatSystemSubscribe(); this.OnCombatSystemInitialize(); // Announce that the combat system has finished initializing StratusScene.Dispatch <InitializedEvent>(new InitializedEvent()); }
/// <summary> /// Called upon to continue the story /// </summary> public void ContinueStory() { var continueEvent = new StratusStory.ContinueEvent() { reader = this.reader, story = this.story }; reader.gameObject.Dispatch <StratusStory.ContinueEvent>(continueEvent); StratusScene.Dispatch <StratusStory.ContinueEvent>(continueEvent); }
//------------------------------------------------------------------------/ // Methods: Static //------------------------------------------------------------------------/ public static void FadeOut(float speed, float duration = 0f, Action onStarted = null, Action onEnded = null) { StratusScene.Dispatch <FadeEvent>(new FadeEvent() { speed = speed, duration = duration, onStarted = onStarted, onEnded = onEnded }); }
private void SampleEventToScene() { // Construct the event object SampleEvent eventObj = new SampleEvent { number = 15 }; // Dispatch the event StratusScene.Dispatch <SampleEvent>(eventObj); }
/// <summary> /// Presents choices at the current story node /// </summary> void PresentChoices() { if (debug) { this.Log("Presenting dialog choices!"); } var choicesEvent = new StratusStory.PresentChoicesEvent(); choicesEvent.choices = story.runtime.currentChoices.ToArray(x => new StratusStoryChoice(x)); StratusScene.Dispatch <StratusStory.PresentChoicesEvent>(choicesEvent); }
protected override void OnTrigger() { switch (eventScope) { case StratusEvent.Scope.GameObject: target.gameObject.Dispatch <StratusStatefulObject.StateEvent>(new StratusStatefulObject.StateEvent(eventType, state)); break; case StratusEvent.Scope.Scene: StratusScene.Dispatch <StratusStatefulObject.StateEvent>(new StratusStatefulObject.StateEvent(eventType, state)); break; } }
//------------------------------------------------------------------------/ // Methods: Public //------------------------------------------------------------------------/ /// <summary> /// Begins this episode /// </summary> public void Begin() { current = this; if (debugDisplay) { StratusDebug.Log($"Beginning this episode at {initialSegment.label}", this); } Enter(currentSegment, true); StratusScene.Dispatch <BeginEvent>(new BeginEvent() { episode = this }); }
/// <summary> /// Exits this segment /// </summary> public void Exit() { StratusScene.Dispatch <ExitedEvent>(new ExitedEvent(this)); if (onExited != null) { onExited?.Invoke(); } Toggle(false); state = State.Exited; if (debug) { StratusDebug.Log($"Exiting", this); } }
protected override void OnTrigger() { switch (scope) { case Scope.Target: reader.gameObject.Dispatch <StratusStory.LoadEvent>(storyEvent); break; case Scope.Scene: StratusScene.Dispatch <StratusStory.LoadEvent>(storyEvent); break; default: break; } }
protected override void OnTrigger() { switch (eventScope) { case StratusEvent.Scope.GameObject: foreach (var target in targets) { if (target) { target.Dispatch(eventInstance, type.Type); } } break; case StratusEvent.Scope.Scene: StratusScene.Dispatch(eventInstance, type.Type); break; } }
/// <summary> /// Called upon when a particular choice has been selected /// </summary> /// <param name="choice"></param> public void SelectChoice(StratusStoryChoice choice) { if (logging) { StratusDebug.Log(choice.text + " was selected", this); } // Inform the current conversation of the choice var choiceEvent = new StratusStory.SelectChoiceEvent() { story = this.story, reader = this.reader }; choiceEvent.choice = choice; reader.gameObject.Dispatch <StratusStory.SelectChoiceEvent>(choiceEvent); StratusScene.Dispatch <StratusStory.SelectChoiceEvent>(choiceEvent); // Now do any extra stuff OnChoiceSelected(); }
/// <summary> /// Enters this segment /// </summary> public virtual void Enter(bool suspend = false) { // We will announce that this segment has been entered in a moment... EnteredEvent e = new EnteredEvent(this); // Inform the previous segment its been exited if (current != null && current != this) { current.Exit(); } // If the segment is currently active, let's do a restart instead // This will set everything back to the initial state at this segment if (state != State.Inactive && restart) { Restart(); e.restarted = true; } if (debug) { StratusDebug.Log($"Entering", this); } // Invoke the optional callbacks if (onEntered != null) { onEntered.Invoke(); } // If not suspended, toggle this segment Toggle(!suspend); // This is now the current segment StratusScene.Dispatch <EnteredEvent>(e); state = State.Entered; current = this; }
public override void Submit() { StratusScene.Dispatch <StratusDialogConfirmationRequest>(this); }
public static void Transition(TransitionEvent e) { StratusScene.Dispatch <StratusScreenShaderTransition.TransitionEvent>(e); }
protected override void OnTrigger() { StratusScene.Dispatch <StratusScreenShaderTransition.TransitionEvent>(this.transition); }
protected virtual void NotifyCombatSystemTurnEnded() { StratusScene.Dispatch <StratusCombatControllerTurnTakenEvent>(new StratusCombatControllerTurnTakenEvent(this)); }
/// <summary> /// Loads a story from file /// </summary> /// <param name="storyFile"></param> private void LoadStory(TextAsset storyFile, bool restart = false, string knot = null) { StratusStory newStory = null; // If this story has already been loaded, use the previous state bool previouslyLoaded = stories.ContainsKey(storyFile.name); if (previouslyLoaded) { if (debug) { StratusDebug.Log($"{storyFile.name} has already been loaded! Using the previous state."); } newStory = stories[storyFile.name]; LoadState(newStory); } // If the story hasn't been loaded yet else { if (debug) { StratusDebug.Log($"{storyFile.name} has not been loaded yet. Constructing a new state."); } newStory = ConstructStory(storyFile); } // Assign the story story = newStory; // If a knot was provided if (knot != null && knot.Length > 0) { if (!story.runtime.canContinue) { if (automaticRestart) { Restart(clearStateOnRestart); } else { StratusDebug.LogError($"The story {story.name} has already been ended, thus we can't jump to the knot!", this); } } JumpToKnot(knot); } else if (restart || automaticRestart) { Restart(clearStateOnRestart); } // Announce that we are loding the story var loadedEvent = new StratusStory.LoadedEvent() { reader = this, story = this.story }; this.gameObject.Dispatch <StratusStory.LoadedEvent>(loadedEvent); StratusScene.Dispatch <StratusStory.LoadedEvent>(loadedEvent); // Invoke any subclass callbacks OnStoryLoaded(story); // Now start the story // If the story was previously loaded, we need not start from a new line this.StartStory(previouslyLoaded && story.started); }
protected void StartCombat() { //Gamestate.Change(Gamestate.State.Combat); StratusScene.Dispatch <StratusCombat.StartedEvent>(new StratusCombat.StartedEvent()); }
protected void EndCombat() { //Gamestate.Revert(); StratusScene.Dispatch <StratusCombat.EndedEvent>(new StratusCombat.EndedEvent()); }