Example #1
0
        private Answer CreateAnswer(Passage p)
        {
            Answer answer = Ocean.Instance.Get(answerPfb);

            // Answer answer = Instantiate(answerPfb, answerRoot);

            answer.SetPassage(p);
            answer.text.fontSize = LayoutManager.Instance.esw;
            answer.text.margin   = LayoutManager.Instance.defaultMargins;
            currentAnswers.Add(answer);

            var ftueState = Inventory.Instance.ftueState.Value;

            if (!ftueState.GetFTUE(FTUEType.CHAT_SCREEN_CHOOSE_ANSWER) &&
                ftueState.needShowChatScreenChooseAnswerFtue)
            {
                UIManager.Instance.FTUEWidget.Show(() =>
                {
                    UIManager.Instance.FTUEWidget.PresentFTUE(answer.gameObject, FTUEType.CHAT_SCREEN_CHOOSE_ANSWER);
                    answer.text.SetAllDirty();
                });
            }

            return(answer);
        }
Example #2
0
 public void OnReturnToPool()
 {
     // first disable then move
     gameObject.SetActive(false);
     gameObject.transform.SetParent(Ocean.Instance.transform);
     passage = null;
 }
        public void ParseSetCompanionName(string t, Passage p)
        {
            try
            {
                int    colon       = t.IndexOf(':');
                string compCodeStr = t.Substring(colon + 1);

                var companionState = Inventory.Instance.worldState.Value.GetCompanion(compCodeStr);
                if (companionState != null)
                {
                    var s = new SetCompanionNameSfStatement()
                    {
                        companionId = companionState.Data.id
                    };
                    p.effects.Add(s);
                }
                else
                {
                    Debug.LogError($"DialogueManager: failed to find companion for companion code {compCodeStr}");
                    return;
                }
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseUnlockDialog(string t, Passage p)
        {
            // unlockDialog:1
            try
            {
                int    colon1      = t.IndexOf(':');
                string companionId = t.Substring(colon1 + 1);
                CompanionData.ItemID eCompanionId;
                if (!CompanionData.ItemID.TryParse(companionId, out eCompanionId))
                {
                    Debug.LogError($"DialogueManager: failed to parse companionId in unlockDialog tag: {t}");
                    return;
                }

                var s = new UnlockDialogSfStatement()
                {
                    companionId = eCompanionId
                };
                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseUnlockCompanion(string t, Passage p)
        {
            // unlockPerson:1
            try
            {
                int    colon1      = t.IndexOf(':');
                string companionId = t.Substring(colon1 + 1);
                CompanionData.ItemID eCompanionId;
                if (!CompanionData.ItemID.TryParse(companionId, out eCompanionId))
                {
                    Debug.LogError($"DialogueManager: failed to parse companionId in unlockPerson tag: {t}");
                    return;
                }

                var unlockStatement = (UnlockCompanionSfStatement)p.GetStatement(SFStatement.Type.UNLOCK_COMPANION);
                if (unlockStatement == null)
                {
                    unlockStatement = new UnlockCompanionSfStatement();
                    p.effects.Add(unlockStatement);
                }
                unlockStatement.companionIds.Add(eCompanionId);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
Example #6
0
        public void PrepareNewPassagePresent()
        {
            state = State.WAITING_TO_PRESENT_PASSAGE;
            if (Inventory.Instance.disableWait.Value)
            {
                timeToWait = 0.2f;
            }
            else
            {
                timeToWait = currentPassage.WaitTimeAfterExec;
            }
            time           = 0;
            currentPassage = tempNextAvailablePassages[0];
            typingText.gameObject.SetActive(true);
            string continues = "";

            if (currentCompanion.Data.id == CompanionData.ItemID.PARENTS)
            {
                continues = "продолжают";
            }
            else
            {
                continues = "продолжает";
            }
            typingText.text = $"{currentCompanion.Data.shortName} {continues}.";
        }
        public void ParseShowIfItem(string t, Passage p)
        {
            // showIfItem:item-code:0
            try
            {
                int    colon1    = t.IndexOf(':');
                int    colon2    = t.IndexOf(':', colon1 + 1);
                string itemCode  = t.Substring(colon1 + 1, colon2 - colon1 - 1);
                string itemState = t.Substring(colon2 + 1);

                SFItemStateCondition.ItemState eItemState;
                if (!SFItemStateCondition.ItemState.TryParse(itemState, out eItemState))
                {
                    Debug.LogError($"DialogueManager: failed to parse operand as SFItemStateCondition.ItemState: {eItemState}");
                }

                if (Inventory.Instance.worldState.Value.GetPlayerItem(itemCode) == null)
                {
                    Debug.LogError($"DialogueManager: failed to find item with code {itemCode} specified in tag: {t}");
                }

                var c = new SFItemStateCondition()
                {
                    itemCode  = itemCode,
                    itemState = eItemState,
                };
                p.conditions.Add(c);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseSetReaction(string t, Passage p)
        {
            // setReaction:sad
            try
            {
                int    colon           = t.IndexOf(':');
                string fullEmotionName = t.Substring(colon + 1);

                int lastHyphen = fullEmotionName.LastIndexOf('-');
                if (lastHyphen == -1)
                {
                    Debug.LogError($"DialogueManager: failed parse, hence find emotion of a companion with fullEmotionName: {fullEmotionName}");
                    return;
                }

                string companionCode  = fullEmotionName.Substring(0, lastHyphen);
                var    companionState = Inventory.Instance.worldState.Value.GetCompanion(companionCode);
                if (companionState != null)
                {
                    string emotion = fullEmotionName.Substring(lastHyphen + 1);
                    if (emotion == "unexistent")
                    {
                        var s = new ChangeImageSfStatement()
                        {
                            emotionName = emotion,
                            companionId = companionState.Data.id
                        };
                        p.effects.Add(s);
                    }
                    else
                    {
                        var e = companionState.Data.GetEmotion(emotion);
                        if (e == null)
                        {
                            Debug.LogError($"DialogueManager: failed to find companion for fullEmotionName: {fullEmotionName}");
                        }
                        else
                        {
                            var s = new ChangeImageSfStatement()
                            {
                                emotionName = emotion,
                                companionId = companionState.Data.id
                            };
                            p.effects.Add(s);
                        }
                    }
                }
                else
                {
                    Debug.LogError($"DialogueManager: failed to find companion for fullEmotionName: {fullEmotionName}");
                    return;
                }
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        protected void ConvertToSnowflake(TwineRoot root)
        {
            toParse.Clear();
            Passage curP = root.FindPassageWithTag("t:sp");

            if (curP == null)
            {
                curP = root.FindPassageWithTag("t:sh");
            }

            if (curP == null)
            {
                Debug.LogError("DialogueManager: failed to find starting tag.");
                return;
            }
            else
            {
                root.startPassage = curP;
            }

            toParse.Add(curP);
            int i = 0;
            int q = 0;

            while (i < toParse.Count)
            {
                while (q < toParse.Count)
                {
                    ParsePassage(toParse[q], root);
                    q++;
                }

                q = i;
                i = toParse.Count;

                while (q < i)
                {
                    var pLinks = toParse[q].passageLinks;
                    for (int j = 0; j < pLinks.Count; j++)
                    {
                        if (toParse.IndexOf(pLinks[j]) == -1)
                        {
                            toParse.Add(pLinks[j]);
                        }
                    }
                    q++;
                }
            }
        }
Example #10
0
        public void BuildPastConversation()
        {
            savePath          = false;
            soundEnabled      = false;
            executeStatements = false;
            var dialogue = currentCompanion.dialogues[currentDialog];

            for (int i = 0; i < dialogue.path.Count - 1; i++)
            {
                currentPassage = dialogue.root.Find(dialogue.path[i]);

                PresentPassage();
            }
            savePath          = true;
            soundEnabled      = true;
            executeStatements = true;

            dialogueIsBuilt = true;
        }
        public void ParseStartVideo(string t, Passage p)
        {
            // startVideo:video-code-string
            try
            {
                int    colon1    = t.IndexOf(':');
                string videoName = t.Substring(colon1 + 1);

                var s = new StartVideoSfStatement()
                {
                    videoKey = videoName
                };
                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseRemoveGameItem(string t, Passage p)
        {
            // removeItem:item-code-string
            try
            {
                int            colon        = t.IndexOf(':');
                string         gameItemCode = t.Substring(colon + 1);
                PlayerItemData itemData     = DB.Instance.gameItems.GetPlayerItem(gameItemCode);

                var s = new RemoveGameItemSfStatement()
                {
                    itemId = itemData.id
                };
                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseChangeVariable(string t, Passage p)
        {
            // change:someVar:4
            try
            {
                VariableOperation oper = VariableOperation.UNKNOWN;
                int    colon1          = t.IndexOf(':');
                int    colon2          = t.IndexOf(':', colon1 + 1);
                string varName         = t.Substring(colon1 + 1, colon2 - colon1 - 1);
                string varValue        = t.Substring(colon2 + 1);
                // int colon3 = t.IndexOf(':', colon2 + 1);
                // string operation = t.Substring(colon2, colon3);
                // if (operation == "+")
                // {
                oper = VariableOperation.SUM;
                // }
                // else if (operation == "-")
                // {
                //     oper = VariableOperation.SUBTRACT;
                // }
                // else
                // {
                //     Debug.LogError($"DialogueManager: cant parse operation {operation}");
                // }
                // int colon4 = t.IndexOf(':', colon2 + 1);

                var s = new ChangeVariableSfStatement()
                {
                    variableName = varName,
                    operation    = oper,
                    operand      = varValue
                };
                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseGameOver(string t, Passage p)
        {
            // game_over:win / game_over:lose
            try
            {
                int    colon1         = t.IndexOf(':');
                string gameOverResult = t.Substring(colon1 + 1);

                GameOverSfStatement.GameOverResult result = GameOverSfStatement.GameOverResult.NONE;

                switch (gameOverResult)
                {
                case "win":
                    result = GameOverSfStatement.GameOverResult.WIN;
                    break;

                case "lose":
                    result = GameOverSfStatement.GameOverResult.LOSE;
                    break;

                default:
                    Debug.LogError($"DialogueManager: unknown game over result {gameOverResult}");
                    return;
                }

                var s = new GameOverSfStatement()
                {
                    result = result,
                };

                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseDelay(string t, Passage p)
        {
            try
            {
                int    colon    = t.IndexOf(':');
                string delayStr = t.Substring(colon + 1);
                float  fDelay   = 0;

                if (!float.TryParse(delayStr, out fDelay))
                {
                    Debug.LogError($"DialogueManager: failed to parse delay tag: {t}");
                    return;
                }

                p.waitTimeAfterExec = fDelay / 1000f;
                p.customWaitTime    = true;
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
        public void ParseSetVariable(string tag, Passage p)
        {
            // set:someVar:4
            try
            {
                int    colon1   = tag.IndexOf(':');
                int    colon2   = tag.IndexOf(':', colon1 + 1);
                string varName  = tag.Substring(colon1 + 1, colon2 - colon1 - 1);
                string varValue = tag.Substring(colon2 + 1);

                var s = new SetVariableSfStatement()
                {
                    variableName = varName,
                    operand      = varValue
                };

                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {tag}");
                throw;
            }
        }
        public void ParseHide(string t, Passage p)
        {
            // hide:someVar:=:4
            try
            {
                int    colon1    = t.IndexOf(':');
                int    colon2    = t.IndexOf(':', colon1 + 1);
                string varName   = t.Substring(colon1 + 1, colon2 - colon1 - 1);
                int    colon3    = t.IndexOf(':', colon2 + 1);
                string operation = t.Substring(colon2 + 1, colon3 - colon2 - 1);
                string operand   = t.Substring(colon3 + 1);
                SFHideIfCondition.BoolOperation eOperation = SFHideIfCondition.BoolOperation.NONE;

                if (operation == "=")
                {
                    eOperation = SFHideIfCondition.BoolOperation.EQUALS;
                }
                else if (operation == "!=")
                {
                    eOperation = SFHideIfCondition.BoolOperation.NOT_EQUALS;
                }
                else if (operation == "<")
                {
                    eOperation = SFHideIfCondition.BoolOperation.LESS;
                }
                else if (operation == ">")
                {
                    eOperation = SFHideIfCondition.BoolOperation.GREATER;
                }
                else if (operation == ">=")
                {
                    eOperation = SFHideIfCondition.BoolOperation.GREATER_EQUALS;
                }
                else if (operation == "<=")
                {
                    eOperation = SFHideIfCondition.BoolOperation.LESS_EQUALS;
                }
                else
                {
                    Debug.LogError($"DialogueManager: failed to parse operation: {operation}");
                }

                int value;
                if (!int.TryParse(operand, out value))
                {
                    Debug.LogError($"DialogueManager: failed to parse operand as int: {operand}");
                }

                var c = new SFHideIfCondition()
                {
                    variableName = varName,
                    operation    = eOperation,
                    value        = value
                };
                p.conditions.Add(c);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse tag {t}");
                throw;
            }
        }
Example #18
0
 public void SetPassage(Passage p)
 {
     text.text = p.ParsedText;
     passage   = p;
 }
 public void ParsePassage(Passage p, TwineRoot root)
 {
     p.RegenerateLinks(root);
     ParseTags(p);
     p.parsed = true;
 }
 public void ParseTags(Passage p)
 {
     foreach (var t in p.tags)
     {
         if (t.StartsWith("set:"))
         {
             ParseSetVariable(t, p);
         }
         else if (t.StartsWith("change:"))
         {
             ParseChangeVariable(t, p);
         }
         else if (t.StartsWith("setReaction:"))
         {
             ParseSetReaction(t, p);
         }
         else if (t == "t:f")
         {
             ParseShowAdvice(p);
             p.type = Passage.PassageType.ADVICE;
         }
         else if (t.StartsWith("showThing:"))
         {
             ParseAddGameItem(t, p);
         }
         else if (t.StartsWith("removeItem:"))
         {
             ParseRemoveGameItem(t, p);
         }
         else if (t.StartsWith("unlockDialog:"))
         {
             ParseUnlockDialog(t, p);
         }
         else if (t.StartsWith("unlockPerson:"))
         {
             ParseUnlockCompanion(t, p);
         }
         else if (t.StartsWith("startVideo:"))
         {
             ParseStartVideo(t, p);
         }
         else if (t.StartsWith("hide:"))
         {
             ParseHide(t, p);
         }
         else if (t.StartsWith("showIfItem:"))
         {
             ParseShowIfItem(t, p);
         }
         else if (t.StartsWith("game_over:"))
         {
             ParseGameOver(t, p);
         }
         else if (t == "t:p" || t == "t:sp")
         {
             p.type = Passage.PassageType.COMPANION_MESSAGE;
         }
         else if (t == "t:h" || t == "t:sh")
         {
             p.type = Passage.PassageType.HERO_MESSAGE;
         }
         else if (t == "t:imgp")
         {
             p.type     = Passage.PassageType.COMPANION_IMAGE;
             p.imageKey = p.parsedText;
         }
         else if (t.StartsWith("delay:"))
         {
             ParseDelay(t, p);
         }
         else if (t.StartsWith("setCompanionName:"))
         {
             ParseSetCompanionName(t, p);
         }
         else if (t == "finishBlock")
         {
         }
         else
         {
             Debug.LogError($"DialogueManager: failed to parse tag: {t}");
         }
     }
 }
        public void ParseShowAdvice(Passage p)
        {
            try
            {
                bool showOnAdviceScreen = true;
                int  adviceId           = 0;

                int bracket2 = p.parsedText.IndexOf('}');
                if (bracket2 == -1)
                {
                    Debug.LogError($"DialogueManager: Failed to find advice id of passage with pid {p.pid}");
                    return;
                }

                int adviceIdPart = p.parsedText.IndexOf("{adviceId=", 0, bracket2 + 1);
                if (adviceIdPart == -1)
                {
                    Debug.LogError($"DialogueManager: Failed to find advice id of passage with pid {p.pid}");
                    return;
                }

                int    comma = p.parsedText.IndexOf(',', 0, bracket2 + 1);
                string adviceIdStr;
                if (comma != -1)
                {
                    int showPart = p.parsedText.IndexOf("show=", comma, bracket2 - comma + 1);
                    if (showPart == -1)
                    {
                        Debug.LogError($"DialogueManager: failed to parse show part in adviceId of passage with pid {p.pid}");
                        return;
                    }
                    string showStr = p.parsedText.Substring(showPart + 5, bracket2 - showPart - 5);
                    int    showInt;
                    if (!int.TryParse(showStr, out showInt))
                    {
                        Debug.LogError($"DialogueManager: failed to parse show part in adviceId of passage with pid {p.pid}");
                        return;
                    }
                    showOnAdviceScreen = showInt != 0;

                    adviceIdStr = p.parsedText.Substring(adviceIdPart + 10, comma - adviceIdPart - 10);
                }
                else
                {
                    adviceIdStr = p.parsedText.Substring(adviceIdPart + 10, bracket2 - adviceIdPart - 10);
                }

                if (!int.TryParse(adviceIdStr, out adviceId))
                {
                    Debug.LogError($"DialogueManager: failed to parse adviceId of passage with pid {p.pid} as int");
                    return;
                }

                string adviceText = p.parsedText.Substring(bracket2 + 1).Trim();
                p.parsedText = adviceText;
                p.adviceId   = adviceId;

                if (!Inventory.Instance.worldState.Value.advicesLoaded)
                {
                    var anotherAdvice = Inventory.Instance.worldState.Value.unicornAdvicesState.GetAdviceById(adviceId);
                    if (anotherAdvice == null)
                    {
                        AdviceState adviceState = new AdviceState()
                        {
                            id    = adviceId,
                            found = false,
                            data  = new AdviceData()
                            {
                                id                 = adviceId,
                                caption            = p.name,
                                text               = adviceText,
                                showOnAdviceScreen = showOnAdviceScreen,
                                companionId        = currentCompanion.id,
                            }
                        };

                        Inventory.Instance.worldState.Value.unicornAdvicesState.unicornAdviceStates.Add(adviceState);
                    }
                    else
                    {
                        Debug.LogWarning($"DialogueManager: there are 2 advices with the same id the first one's text:\n{adviceText}\n\nthe second one's text:\n{anotherAdvice.data.text}");
                    }
                }

                var s = new ShowAdviceSfStatement()
                {
                    adviceId = adviceId
                };
                p.effects.Add(s);
            }
            catch
            {
                Debug.LogError($"DialogueManager: Failed to parse advice, passage {p.pid}");
                throw;
            }
        }
Example #22
0
        public override void Show(Action onComplete = null)
        {
            base.Show(onComplete);

            if (firstTimeShown)
            {
                StartCoroutine(GradualInit());

                firstTimeShown = false;
            }

            savePath              = true;
            executeStatements     = true;
            soundEnabled          = true;
            currentStatement      = null;
            currentStatementIndex = -1;

            var newCompanion = Inventory.Instance.worldState.Value.GetCompanion(Inventory.Instance.currentCompanion.Value);

            if (currentCompanion == null || newCompanion.Data.id != currentCompanion.Data.id || currentCompanion.lastDialogueTaken != currentCompanion.activeDialogue)
            {
                dialogueIsBuilt = false;
                ResetScreen();
            }

            var lm = LayoutManager.Instance;

            currentCompanion = newCompanion;

            companionNameText.fontSize = 1.25f * lm.esw;

            currentCompanion.lastDialogueTaken = currentCompanion.activeDialogue;
            currentDialog = currentCompanion.activeDialogue;

            // screenWidth = UIManager.Instance.canvasRectTransform.rect.size.x;
            // em = screenWidth / 25f;
            // margins = new Vector4(em, 0.5f * em, em, 0.5f * em);
            typingText.fontSize = 0.75f * lm.esw;

            SFDialogue dialogue = currentCompanion.dialogues[currentCompanion.activeDialogue];
            var        path     = dialogue.path;

            // we either talked to some companion, went back and entered another companion screen
            // or this is the first time we enter companion screen
            if (!dialogueIsBuilt)
            {
                time       = 0;
                timeToWait = 0;

                SetEmotionAndName(currentCompanion, "main");

                BuildPastConversation();

                // dialogue was undergoing before
                if (path.Count != 0)
                {
                    currentPassage = dialogue.root.Find(path[path.Count - 1]);

                    tempNextAvailablePassages.Clear();
                    currentPassage.GetNextAvailablePassages(ref tempNextAvailablePassages);

                    // if it is the end of the dialogue present last passage and do nothing
                    if (tempNextAvailablePassages.Count == 0)
                    {
                        savePath          = false;
                        executeStatements = false;
                        soundEnabled      = false;
                        PresentPassage();
                        savePath          = true;
                        executeStatements = true;
                        soundEnabled      = true;

                        state = State.DIALOGUE_FINISHED;
                    }
                    // if dialogue is continuing then show last line with sound effect
                    else
                    {
                        savePath          = false;
                        executeStatements = false;
                        PresentPassage();
                        savePath          = true;
                        executeStatements = true;

                        ContinueDialogue();
                    }
                }
                // dialogue is undergoing first time
                else
                {
                    currentPassage = dialogue.root.startPassage;
                    SFStatement e = currentPassage.GetStatement(SFStatement.Type.CHANGE_IMAGE);
                    if (e != null)
                    {
                        e.Execute();
                    }

                    e = currentPassage.GetStatement(SFStatement.Type.SET_COMPANION_NAME);
                    if (e != null)
                    {
                        e.Execute();
                    }

                    StartDialogue(); //blocking
                }
            }
            // else
            // {
            //     if (path.Count != 0)
            //     {
            //         StartDialogue();
            //     }
            // }
        }