void SetResponses(CutsceneAction cutsceneAction)
    {
        CutsceneAction tempAction;

        responseActions = new List <CutsceneAction>();
        string newResponseText = "";

        for (int i = 0; i < cutsceneAction.indexesOfNextActions.Count; i++)
        {
            tempAction = currentCutscene.cutsceneActions[cutsceneAction.indexesOfNextActions[i]];

            if (CheckAllConditions(tempAction))
            {
                // Only add each action to the list, if its conditions have been met
                responseActions.Add(tempAction);
                newResponseText += tempAction.textContent + "\n";
            }
        }

        if (responseActions.Count > 0)
        {
            dialogWindow.SetResponses(newResponseText);
            selectionIndex = 1;
            waitingOnInput = true;
        }
        else
        {
            // All responses have conditions, which have not been met
            EndCutscene();
        }
    }
 void ExecuteResponse()
 {
     currentAction   = responseActions[selectionIndex - 1];
     responseActions = null;
     selectionIndex  = 1;
     GoToNextAction();
 }
    public void StartCutscene(int cutsceneID)
    {
        if (cutsceneInProgress)
        {
            Debug.LogWarning("Cannot start new cutscene while another cutscene is in progress");
        }
        else
        {
            int cutsceneIndex = GetCutsceneIndex(cutsceneID);

            if (cutsceneIndex >= 0)
            {
                playerManager.CloseAllMenus();
                playerManager.SetHotbarVisibility(false);
                playerController.SetCutsceneState(true);
                cutsceneInProgress = true;
                waitingOnInput     = false;
                responseActions    = null;
                selectionIndex     = 1;
                dialogWindow.SetHighlightRow(selectionIndex);
                dialogWindow.ResetText();
                currentCutscene = cutsceneData.listItems[cutsceneIndex].cutscene;
                currentAction   = currentCutscene.cutsceneActions[0];
                InterpretCurrentAction();
            }
            else
            {
                Debug.LogError("Cutscene ID " + cutsceneID + " not found in list of indexes");
            }
        }
    }
Beispiel #4
0
    void OnEnable()
    {
        actions = new List <CutsceneAction>();

        for (int i = 0; i < transform.childCount; i++)
        {
            Transform t = transform.GetChild(i);

            CutsceneAction act = t.GetComponent <CutsceneAction>();
            if (act != null)
            {
                actions.Add(act);
            }
        }

        if (actions.Count == 0)
        {
            return;
        }

        if (LockPlayer)
        {
            playerControl         = GameObject.Find("PlayerCharacter").GetComponent <Platformer2DUserControl>();
            playerControl.enabled = false;
        }

        foreach (var action in actions)
        {
            action.parentCutscene = this;
            action.gameObject.SetActive(false);
        }

        actions[0].gameObject.SetActive(true);
        actions[0].OnActionInit();
    }
    void InterpretDialogue(CutsceneAction cutsceneAction)
    {
        string newDialogueLines = playerManager.RewriteString(cutsceneAction.textContent);
        string newSpeakerName   = playerManager.RewriteString(cutsceneAction.titleText);

        readyToContinue    = false;
        monitorScrollState = true;
        timeOfLastChange   = Time.time;
        dialogWindow.SetMessage(newSpeakerName, newDialogueLines, cutsceneAction.rightActor);
    }
    void InterpretVariable(CutsceneAction cutsceneAction)
    {
        string variableName      = cutsceneAction.titleText;
        string variableValue     = cutsceneAction.textContent;
        object parentObject      = this;
        bool   affectionVariable = false;

        // Special rules using . to indicate that the variable being changed is on something other than the cutscene manager
        if (variableName.Contains("."))
        {
            int    indexOfDot     = variableName.IndexOf(".");
            string variablePrefix = variableName.Substring(0, indexOfDot).ToLower();
            variableName = variableName.Substring(indexOfDot + 1, variableName.Length - indexOfDot - 1);

            if (variablePrefix == "aff" || variablePrefix == "affection")
            {
                affectionVariable = true;
            }
        }

        if (affectionVariable)
        {
            // Affection variables have their own special processing
            AffectionTracker affectionTracker = this.gameObject.GetComponent <AffectionTracker>();
            if (affectionTracker)
            {
                int  affectionChange;
                bool validIntValue = int.TryParse(variableValue, out affectionChange);

                if (validIntValue)
                {
                    affectionTracker.AddAffection(variableName, affectionChange);
                }
                else
                {
                    Debug.LogWarning("Invalid affection change value provided");
                }
            }
        }
        else
        {
            int variableCacheIndex = playerManager.GetVariableIndex(variableName);

            if (variableCacheIndex >= 0)
            {
                playerManager.SetVariable(variableCacheIndex, variableValue);
            }
            else
            {
                Debug.LogWarning("Variable " + variableName + " not found while attempting to change");
            }
        }

        GoToNextAction();
    }
 void EndCutscene()
 {
     dialogWindow.SetVisibility(false);
     dialogWindow.ClearPortrait(true);
     dialogWindow.ClearPortrait(false);
     playerManager.SetHotbarVisibility(true);
     currentCutscene    = null;
     currentAction      = null;
     cutsceneInProgress = false;
     waitingOnInput     = false;
     selectionIndex     = 0;
     playerController.SetCutsceneState(false);
     cameraController.ResetView();
     //cameraScreen.ResetValues();
 }
Beispiel #8
0
 public CutsceneScriptLine(
     CutsceneAction action,
     CutsceneBackground background  = CutsceneBackground.None,
     CutsceneSide side              = CutsceneSide.Left,
     CutsceneCharacter character    = null,
     CharacterExpression expression = CharacterExpression.Default,
     string dialogue = "")
 {
     this.action     = action;
     this.background = background;
     this.side       = side;
     this.character  = character;
     this.expression = expression;
     this.dialogue   = dialogue;
 }
    void InterpretPauseAction(CutsceneAction cutsceneAction)
    {
        string pauseLength_string = cutsceneAction.titleText;
        float  newPauseLength;

        if (float.TryParse(pauseLength_string, out newPauseLength))
        {
            timeOfPause = Time.time;
            pauseLength = newPauseLength;
            dialogWindow.SetVisibility(false);
        }
        else
        {
            Debug.LogWarning("Invalid pause time provided");
        }
    }
    bool CheckAllConditions(CutsceneAction cutsceneAction)
    {
        int  numberOfConditionsMet = 0;
        bool conditionsMet         = false;

        if (cutsceneAction.conditionValues == null)
        {
            conditionsMet = true;
        }
        else
        {
            if (cutsceneAction.conditionValues.Count == 0)
            {
                // It shouldn't be possible for this to happen - condition values found, but count is 0
                conditionsMet = true;
            }
            else
            {
                for (int j = 0; j < cutsceneAction.conditionValues.Count; j++)
                {
                    if (playerManager.CheckDynamicCondition(cutsceneAction.conditionVariables[j], cutsceneAction.conditionValues[j]))
                    {
                        numberOfConditionsMet++;
                    }
                }

                if (cutsceneAction.titleText == "AND" && numberOfConditionsMet == cutsceneAction.conditionValues.Count)
                {
                    conditionsMet = true;
                }
                else if (cutsceneAction.titleText == "OR" && numberOfConditionsMet > 0)
                {
                    conditionsMet = true;
                }
                else if (cutsceneAction.titleText == "NAND" && numberOfConditionsMet == 0)
                {
                    conditionsMet = true;
                }
                else if (cutsceneAction.titleText == "XOR" && numberOfConditionsMet == 1)
                {
                    conditionsMet = true;
                }
            }
        }

        return(conditionsMet);
    }
    void InterpretAnimation(CutsceneAction cutsceneAction)
    {
        GameObject actorObject;
        Animator   actorAnimator;

        actorObject = GameObject.Find(cutsceneAction.titleText);
        if (actorObject)
        {
            actorAnimator = actorObject.GetComponent <Animator>();
            if (actorAnimator)
            {
                actorAnimator.SetTrigger(cutsceneAction.textContent);
            }
        }

        GoToNextAction();
    }
    protected override void ActionStart()
    {
        subActions = new List <CutsceneAction>();

        for (int i = 0; i < transform.childCount; i++)
        {
            Transform t = transform.GetChild(i);
            t.gameObject.SetActive(true);

            CutsceneAction act = t.GetComponent <CutsceneAction>();
            if (act != null)
            {
                act.OnActionInit();
                subActions.Add(act);
            }
        }
    }
 void InterpretMultiCondition(CutsceneAction cutsceneAction)
 {
     if (CheckAllConditions(cutsceneAction))
     {
         currentAction = currentCutscene.cutsceneActions[cutsceneAction.indexesOfNextActions[1]];
         InterpretCurrentAction();
     }
     else
     {
         if (cutsceneAction.indexesOfNextActions[0] > 0)
         {
             currentAction = currentCutscene.cutsceneActions[cutsceneAction.indexesOfNextActions[0]];
             InterpretCurrentAction();
         }
         else
         {
             // No else path available
             EndCutscene();
         }
     }
 }
    void GoToNextAction()
    {
        waitingOnInput = false;

        if (currentAction.indexesOfNextActions.Count > 0)
        {
            if (currentCutscene.cutsceneActions[currentAction.indexesOfNextActions[0]].myActionType == CutsceneAction.actionType.Response)
            {
                SetResponses(currentAction);
            }
            else
            {
                currentAction = currentCutscene.cutsceneActions[currentAction.indexesOfNextActions[0]];
                InterpretCurrentAction();
            }
        }
        else
        {
            EndCutscene();
        }
    }
    private void Add(System.Type type, int index, int size)
    {
        serializedTarget.Update();

        // create and append
        var subAsset = CutsceneAction.CreateInstance(type);

        AppendSubAsset(subAsset);

        // insert
        var k = size > 0 ? index + 1 : 0;

        actionProp.InsertArrayElementAtIndex(k);
        actionProp.GetArrayElementAtIndex(k).objectReferenceValue = subAsset;

        // save
        SaveTarget(k);

        GUIUtility.keyboardControl = 0;
        Repaint();
    }
    void InterpretCondition(CutsceneAction cutsceneAction)
    {
        string variableName   = cutsceneAction.titleText;
        int    conditionIndex = 0;

        for (int i = 0; i < cutsceneAction.conditionValues.Count; i++)
        {
            if (playerManager.CheckDynamicCondition(variableName, cutsceneAction.conditionValues[i]))
            {
                conditionIndex = i + 1;
                break;
            }
        }

        if (conditionIndex < currentCutscene.cutsceneActions.Count && currentAction.indexesOfNextActions[conditionIndex] >= 0)
        {
            currentAction = currentCutscene.cutsceneActions[currentAction.indexesOfNextActions[conditionIndex]];
            InterpretCurrentAction();
        }
        else
        {
            EndCutscene();
        }
    }
    void InterpretPortrait(CutsceneAction cutsceneAction)
    {
        string characterName  = cutsceneAction.titleText;
        string expressionName = cutsceneAction.textContent;

        if (characterName.Length > 0)
        {
            if (characterName.ToLower() == "clear")
            {
                dialogWindow.ClearPortrait(cutsceneAction.rightActor);
            }
            else
            {
                dialogWindow.SetPortrait(characterName, cutsceneAction.rightActor);
            }
        }

        if (expressionName.Length > 0)
        {
            dialogWindow.SetExpression(expressionName, cutsceneAction.rightActor);
        }

        GoToNextAction();
    }
Beispiel #18
0
 public bool RemoveAction(CutsceneAction cutsceneAction)
 {
     return(cutsceneActions.Remove(cutsceneAction));
 }
    //Processes actual action - moves NPC, triggers animation, etc
    private void ProcessAction(CutsceneAction action)
    {
        switch (action.Action)
        {
        //Move camera
        //Args: float x_dir, float y_dir, float moveSpeed, float time
        case CutsceneAction.CAction.CAMERA_MOVE:
        {
            var camera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraFollow>();
            camera.Locked = false;
            camera.Pan((float)action.Arg1, (float)action.Arg2, (float)action.Arg3, (float)action.Arg4);
            break;
        }

        //Start combat once the scene is over
        //Args: GameObject combatDetails
        case CutsceneAction.CAction.COMBAT_START:
        {
            CombatDetails = (GameObject)action.Arg1;
            break;
        }

        //Activate game object
        //Args: GameObject object
        case CutsceneAction.CAction.GAMEOBJECT_ACTIVATE:
        {
            ((GameObject)action.Arg1).SetActive(true);
            break;
        }

        //Deactivate game object
        //Args: GameObject object
        case CutsceneAction.CAction.GAMEOBJECT_DEACTIVATE:
        {
            ((GameObject)action.Arg1).SetActive(false);
            break;
        }

        //Animate NPC
        //Args: GameObject npc, string animName
        case CutsceneAction.CAction.NPC_ANIMATE:
        {
            var anim = ((GameObject)action.Arg1).GetComponent <Animator>();
            anim.Play((string)action.Arg2);
            break;
        }

        //Make NPC face certain direction
        //Args: GameObject npc, int direction
        case CutsceneAction.CAction.NPC_FACE:
        {
            var npc = ((GameObject)action.Arg1).GetComponent <NPC_Controller>();
            npc.Face((int)action.Arg2);
            break;
        }

        //Move NPC
        //Args: GameObject npc, float x_dir, float y_dir, float moveSpeed, float time
        case CutsceneAction.CAction.NPC_MOVE:
        {
            var npc = ((GameObject)action.Arg1).GetComponent <NPC_Controller>();
            npc.Move((float)action.Arg2, (float)action.Arg3, (float)action.Arg5);
            npc.MoveSpeed = (float)action.Arg4;
            break;
        }

        //Make NPC speak
        //Args: GameObject npc, string dialog, float time
        case CutsceneAction.CAction.NPC_SPEAK:
        {
            var npc = ((GameObject)action.Arg1).GetComponent <NPC_Controller>();
            if (npc != null)
            {
                npc.Speak((string)action.Arg2, (float)action.Arg3);
            }
            else
            {
                var dialog = ((GameObject)action.Arg1).GetComponent <DialogController>();
                dialog.Speak((string)action.Arg2, (float)action.Arg3);
            }
            break;
        }

        //Animate player
        //Args: string animName
        case CutsceneAction.CAction.PLAYER_ANIMATE:
        {
            var anim = player.GetComponent <Animator>();
            anim.Play((string)action.Arg1);
            break;
        }

        //Make player face certain direction
        //Args: int direction
        case CutsceneAction.CAction.PLAYER_FACE:
        {
            var playerController = player.GetComponent <PlayerController>();
            playerController.Face((int)action.Arg1);
            break;
        }

        //Move player
        //Args: float x_dir, float y_dir, float moveSpeed, float time
        case CutsceneAction.CAction.PLAYER_MOVE:
        {
            var playerController = player.GetComponent <PlayerController>();

            playerController.MovementVector        = new Vector3((float)action.Arg1, (float)action.Arg2, 0);
            playerController.ScriptedMovementSpeed = (float)action.Arg3;
            playerController.ScriptedTimeRemaining = (float)action.Arg4;
            break;
        }

        //Make player speak
        //Args: string dialog, float time
        case CutsceneAction.CAction.PLAYER_SPEAK:
        {
            var dialogController = player.GetComponent <DialogController>();
            dialogController.Speak((string)action.Arg1, (float)action.Arg2);
            break;
        }

        //Complete a quest objective
        case CutsceneAction.CAction.QUEST_COMPLETEOBJECTIVE:
        {
            NotifyQuestManagerUponCompletion = true;
            break;
        }

        //Start a new quest
        case CutsceneAction.CAction.QUEST_STARTQUEST:
        {
            var eventManager = player.GetComponent <EventManager>();
            eventManager.StartQuest((double)action.Arg1);
            break;
        }

        //Add an item
        case CutsceneAction.CAction.INVENTORY_ADDITEM:
        {
            var inventory = player.GetComponent <Inventory>();
            inventory.AddItemToInventory(((GameObject)action.Arg1).GetComponent <Item>().ID, (int)action.Arg2);
            break;
        }

        //Remove an item
        case CutsceneAction.CAction.INVENTORY_REMOVEITEM:
        {
            var inventory = player.GetComponent <Inventory>();
            inventory.RemoveItemFromInventory(((GameObject)action.Arg1).GetComponent <Item>().ID, (int)action.Arg2);
            break;
        }

        //Load level when cutscene ends
        case CutsceneAction.CAction.LOADLEVEL:
        {
            if (((GameObject)action.Arg1) != null)
            {
                LevelSceneManager = ((GameObject)action.Arg1).GetComponent <SceneManager>();
            }
            LevelToLoadOnEnd  = (string)action.Arg2;
            LevelSpawnPointID = (int)action.Arg3;
            break;
        }

        //Changes sprite on objects with "QuestSprite" script attached
        case CutsceneAction.CAction.SPRITE_CHANGE:
        {
            var sprite = ((GameObject)action.Arg1).GetComponent <QuestSprite>();
            sprite.ChangeSprite();
            break;
        }

        //Teleports NPC to specific coordinates
        case CutsceneAction.CAction.NPC_TELEPORT:
        {
            var transform = ((GameObject)action.Arg1).gameObject.transform;
            transform.position = new Vector3((float)action.Arg2, (float)action.Arg3, transform.position.z);
            break;
        }
        }
    }
Beispiel #20
0
    void NextStep()
    {
        if (narrator.isWriting())
        {
            narrator.SpeedUp();
            return;
        }
        if (step >= narration.Length)
        {
            narrator.CloseNarration();
            StopScene();
            return;
        }
        if (narration[step].Remove(5) == ">wait")
        {
            string delayInfo = narration[step].Substring(5);
            float  delay     = int.Parse(delayInfo);

            if (timer < 0f)
            {
                timer = Time.time;
            }
            if (Time.time > timer + delay / 1000f)
            {
                loop  = false;
                timer = -1f;
                step += 1;
                NextStep();
            }
            else
            {
                loop = true;
            }
            return;
        }
        else if (narration[step] == "<close_narration>")
        {
            narrator.CloseNarration();
            step++;
            NextStep();
            return;
        }
        else if (narration[step] != "<action>" && narration[step] != "<stopping_action>")
        {
            if (!narrator.IsOpen())
            {
                narrator.OpenNarration();
            }
            narrator.SetNarration(narration[step]);
        }
        else if (actionStep < action.Length)
        {
            CutsceneAction csa = action[actionStep].GetComponent <CutsceneAction> ();
            csa.TriggerAction();
            actionStep++;
            if (narration[step] != "<stopping_action>")
            {
                step++;
                NextStep();
                return;
            }
        }

        step++;
    }
    void InterpretCameraAction(CutsceneAction cutsceneAction)
    {
        string        eventName         = cutsceneAction.conditionValues[0].ToLower();
        List <string> eventParameters   = new List <string>();
        string        newFollowTarget   = cutsceneAction.conditionValues[1];
        bool          waitForCompletion = cutsceneAction.rightActor;

        string newPositionX_string = cutsceneAction.conditionValues[2];
        string newPositionY_string = cutsceneAction.conditionValues[3];
        string newSpeed_string     = cutsceneAction.conditionValues[4];
        float  newPositionX;
        float  newPositionY;
        float  newSpeed;

        if (eventName.Length > 0)
        {
            // Some events have parameters, separated by dots, extract them if found before processing the event
            if (eventName.Contains("."))
            {
                int    numberOfParameters = eventName.Length - eventName.Replace(".", "").Length + 1;
                string tempString         = eventName;
                string nextValue          = "";

                for (int i = 0; i < numberOfParameters; i++)
                {
                    nextValue = "";

                    if (tempString.Contains("."))
                    {
                        nextValue = tempString.Substring(0, tempString.IndexOf("."));
                    }
                    else
                    {
                        nextValue = tempString;
                    }

                    if (nextValue.Length > 0)
                    {
                        eventParameters.Add(nextValue);
                    }
                    else
                    {
                        Debug.LogWarning("Invalid event parameter given, canceling all camera actions");
                        return;
                    }

                    if (i < numberOfParameters - 1)
                    {
                        tempString = tempString.Substring(nextValue.Length + 1, tempString.Length - nextValue.Length - 1);
                    }
                }
                eventName = eventParameters[0];
                eventParameters.RemoveAt(0);

                if (eventName.Length <= 0)
                {
                    Debug.LogWarning("Invalid event given");
                }
            }


            // -----BEGIN CAMERA EVENTS-----
            if (eventName == "reset")
            {
                cameraController.ResetView();
            }
            else if (eventName == "tint")
            {
                if (eventParameters.Count == 4)
                {
                    float newColorR    = NormalizeColor(StringToFloat(eventParameters[0]));
                    float newColorG    = NormalizeColor(StringToFloat(eventParameters[1]));
                    float newColorB    = NormalizeColor(StringToFloat(eventParameters[2]));
                    float newColorA    = NormalizeColor(StringToFloat(eventParameters[3]));
                    float newTintSpeed = StringToFloat(newSpeed_string);

                    if (newSpeed_string.Length == 0)
                    {
                        //cameraScreen.SetTint(newColorR, newColorG, newColorB, newColorA);
                    }
                    else
                    {
                        //cameraScreen.SetTint(newColorR, newColorG, newColorB, newColorA, newTintSpeed);
                    }
                }
                else
                {
                    Debug.LogWarning("Invalid number of camera tint parameters (" + eventParameters.Count + ") provided, no tint applied");
                }
            }

            // -----END CAMERA EVENTS-----
        }

        // New follow target
        if (newFollowTarget.Length > 0)
        {
            GameObject newFollowTargetObject = GameObject.Find(newFollowTarget);
            if (newFollowTargetObject)
            {
                cameraController.FollowNewTarget(newFollowTargetObject.transform);
            }
            else
            {
                Debug.LogWarning("Unable to find target named: " + newFollowTarget);
            }
        }

        // New position/offset
        if (newPositionX_string.Length > 0 || newPositionY_string.Length > 0)
        {
            newPositionX = StringToFloat(newPositionX_string);
            newPositionY = StringToFloat(newPositionY_string);
            cameraController.SetOffset(newPositionX, newPositionY);
        }

        // New speed - this is also used for some events (tint)
        if (newSpeed_string.Length > 0)
        {
            newSpeed = StringToFloat(newSpeed_string);
            cameraController.SetMoveSpeed(newSpeed);
        }
    }