/// <summary> /// Hand a new action for the old man to complete /// </summary> void AssignNextAction() { //If the old man doesn't have an action if (oldMan.currentAction == null) { oldMan.currentAction = OM_ActionQueue.Dequeue(); return; } //Stop the current action oldMan.currentAction.StopAction(oldMan); //If the old man hasn't completed this action, add it back if (!oldMan.currentAction.Completed && !OM_ActionQueue.Contains(oldMan.currentAction)) { Debug.Log("<color=#FDF212>The action \"" + oldMan.currentAction.Name + "\" has been put back into the queue.</color>"); OM_ActionQueue.Enqueue(oldMan.currentAction, oldMan.currentAction.Priority); } //Keep the default action inside the queue if (OM_ActionQueue.Count == 1) { oldMan.currentAction = OM_ActionQueue.First; return; } //Get the new action oldMan.currentAction = OM_ActionQueue.Dequeue(); Debug.Log("<color=#FDF212>The action \"" + oldMan.currentAction.Name + "\" has become the old man's current action.</color>"); }
/// <summary> /// Create an action where the Old Man stands in place /// </summary> /// <param name="priority">How important the action is</param> /// <param name="name">The name of this action</param> /// <param name="standLength">How long the stand lasts for, x lessthan/= 0 for infinite</param> /// <param name="standPoint">The Vector3 to stand at. If null is passed in then there is no movement</param> /// <param name="discardTime">The amount of time this action can spend in the queue without being discarded. 0 for infinite.</param> public void AddStandStillAction(float priority, string name, float standLength = 0, Vector3?standPoint = null, Sprite thoughtItem = null, float discardTime = 0) { OM_Action_StandStill action = new OM_Action_StandStill(priority, name, standLength, standPoint, thoughtItem, discardTime); OM_ActionQueue.Enqueue(action, action.Priority); }
/// <summary> /// Create a path action to the queue /// </summary> /// <param name="priority">How important the action is</param> /// <param name="name">The name of this action</param> /// <param name="points">Array of all points</param> /// <param name="startPoint">Start index for this point</param> /// <param name="discardTime">The amount of time this action can spend in the queue without being discarded. 0 for infinite.</param> public void AddPathAction(float priority, string name, OM_MoveData[] points, int startPoint = 0, Sprite thoughtItem = null, float discardTime = 0) { OM_Action_Path action = new OM_Action_Path(priority, name, points, startPoint, thoughtItem, discardTime); OM_ActionQueue.Enqueue(action, action.Priority); }
/// <summary> /// Add a MoveTo action to the queue /// </summary> /// <param name="priority">How important the action is</param> /// <param name="goalPoint">The point the OM is walking to</param> /// <param name="waitBeforeMoving">How long the OM should wait before moving to the goalPoint</param> /// <param name="thoughtItem">The sprite to put in the thought bubble. Can be left null for no item to be shown</param> /// <param name="discardTime">The amount of time this action can spend in the queue without being discarded. 0 for infinite.</param> public void AddMoveToAction(float priority, string name, OM_MoveData goalPoint, float waitBeforeMoving, Sprite thoughtItem = null, float discardTime = 0) { OM_Action_MoveTo action = new OM_Action_MoveTo(priority, name, goalPoint, waitBeforeMoving, thoughtItem, discardTime); OM_ActionQueue.Enqueue(action, action.Priority); }
// Update is called once per frame void Update() { //Early return if Old Man is dead if (GameManager.Instance.OldManDead) { return; } //Error if queue is empty if (OM_ActionQueue.Count <= 0) { Debug.LogError("Action queue is empty. This should never happen! Always have an infinite StandStill action at the bottom of the queue."); return; } if (GameManager.Instance.player.IsNearOldMan && !OM_inDanger) { OM_inDanger = true; OM_ActionQueue.EnqueueWithoutDuplicates( new OM_Action_NearPlayer(PuzzleManager.Instance.exclamationPoint), 0); } //Assign a new action to the old man if necessary if (oldMan.currentAction == null || oldMan.currentAction.Completed || oldMan.currentAction > OM_ActionQueue.First) { AssignNextAction(); } //Tick the discard time and remove the action if necessary foreach (OM_Action action in OM_ActionQueue) { action.TickDiscardTime(); if (action.ToDiscard) { actionsToRemove.Add(action); } } for (int i = actionsToRemove.Count - 1; i >= 0; i--) { Debug.Log("<color=#FDF212>The action \"" + actionsToRemove[i].Name + "\" has been removed from the queue.</color>"); OM_ActionQueue.Remove(actionsToRemove[i]); actionsToRemove.RemoveAt(i); } }
/// <summary> /// Remove an action from the queue by name. Pretty inefficient so only use if necessary /// </summary> /// <param name="name">The name of the action</param> public void RemoveActionByName(string name) { OM_Action toRemove = null; foreach (OM_Action action in OM_ActionQueue) { if (action.Name == name) { toRemove = action; break; } } if (toRemove != null) { OM_ActionQueue.Remove(toRemove); } }
/// <summary> /// Create an action where an animation plays for the old man /// </summary> /// <param name="priority">How important the action is</param> /// <param name="name">The name of this action</param> /// <param name="animName">The name of the animation</param> /// <param name="animLength">How long the animation lasts for. 0 for infinite</param> /// <param name="discardTime">The amount of time this action can spend in the queue without being discarded. 0 for infinite.</param> public void AddAnimationAction(float priority, string name, string animName, float animLength, float discardTime = 0) { OM_Action_Animation action = new OM_Action_Animation(priority, name, animName, animLength, discardTime); OM_ActionQueue.Enqueue(action, action.Priority); }