Ejemplo n.º 1
0
    /// <summary>
    /// 根据Npc现在的剧情状态转换下一个剧情状态
    /// </summary>
    /// <param name="npcName"></param>
    /// <param name="step"></param>
    /// <returns></returns>
    public static string LoadNpcChangeStep(string npcName, StoryStep step)
    {
        int    index    = (int)step;
        string strIndex = "Step" + index;

        XmlDocument xml = new XmlDocument();

        xml.Load(XmlReader.Create(Consts.XmlOfNpc + npcName + ".xml"));

        XmlNodeList nodeList = xml.SelectSingleNode(npcName).ChildNodes;

        foreach (XmlElement x1 in nodeList)
        {
            if (x1.Name == "ChangeStep")
            {
                foreach (XmlElement x2 in x1)
                {
                    if (x2.Name == strIndex)
                    {
                        return(x2.InnerText);
                    }
                }
            }
        }

        return(null);
    }
        private static void AssertUserStepMessage(StoryStep <IMessageActivity> storyStep, PerformanceStep <IMessageActivity> performanceStep, IReadOnlyList <string> options = null)
        {
            var frame = storyStep.StoryFrame;

            switch (frame.ComparisonType)
            {
            case ComparisonType.None:
                break;

            case ComparisonType.TextExact:
                ProcessFrameTextExact(frame, performanceStep.MessageActivity.Type, performanceStep.Message);
                break;

            case ComparisonType.Option:
                AssertUserFrameOption(frame, performanceStep.MessageActivity, options);
                break;

            default:
                var reasonMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    "Comparison type {0} is not supported for user frame.",
                    frame.ComparisonType);

                throw new ArgumentOutOfRangeException(nameof(frame.ComparisonType), reasonMessage);
            }
        }
Ejemplo n.º 3
0
    /// <summary>
    /// 根据npc现在的状态加载npc的剧情
    /// </summary>
    public static List <string> LoadNpcStory(string npcName, StoryStep step)
    {
        int           index       = (int)step;
        string        strIndex    = "Step" + index;
        List <string> commandList = new List <string>();

        XmlDocument xml = new XmlDocument();

        Debug.Log("打开了" + Consts.XmlOfNpc + npcName + ".xml文件");

        xml.Load(XmlReader.Create(Consts.XmlOfNpc + npcName + ".xml"));
        //寻找根节点
        XmlNodeList nodeList = xml.SelectSingleNode(npcName).ChildNodes;

        foreach (XmlElement x1 in nodeList)
        {
            if (x1.Name == "Story")
            {
                foreach (XmlElement x2 in x1)
                {
                    if (strIndex == x2.Name)
                    {
                        foreach (XmlElement x3 in x2)
                        {//命令类型与具体命令用 ; 分割
                            commandList.Add(x3.GetAttribute("CommandType") + ";" + x3.GetAttribute("AC") + ";" + x3.InnerText);
                        }
                    }
                }
            }
        }

        return(commandList);
    }
Ejemplo n.º 4
0
    private string GetLineOfConversation(string npcName)
    {
        StoryStep currentStoryStep = stroy.stroySteps [storyStepIndex];

        string returnString = null;

        switch (npcName)
        {
        case "Letter":
            if (currentStoryStep.Letter == null || currentStoryStep.Letter.Length - 1 < conversationLineIndex)
            {
                return(null);
            }
            returnString = currentStoryStep.Letter [conversationLineIndex];
            break;

        case "Mary":
            if (currentStoryStep.Mary == null || currentStoryStep.Mary.Length - 1 < conversationLineIndex)
            {
                return(null);
            }
            returnString = currentStoryStep.Mary [conversationLineIndex];
            break;

        case "Sheriff":
            if (currentStoryStep.Sheriff == null || currentStoryStep.Sheriff.Length - 1 < conversationLineIndex)
            {
                return(null);
            }
            returnString = currentStoryStep.Sheriff [conversationLineIndex];
            break;

        case "GunSmith":
            if (currentStoryStep.GunSmith == null || currentStoryStep.GunSmith.Length - 1 < conversationLineIndex)
            {
                return(null);
            }
            returnString = currentStoryStep.GunSmith [conversationLineIndex];
            break;

        case "Daisy":
            if (currentStoryStep.Daisy == null || currentStoryStep.Daisy.Length - 1 < conversationLineIndex)
            {
                return(null);
            }
            returnString = currentStoryStep.Daisy [conversationLineIndex];
            break;

        case "Joe":
            if (currentStoryStep.Joe == null || currentStoryStep.Joe.Length - 1 < conversationLineIndex)
            {
                return(null);
            }
            returnString = currentStoryStep.Joe [conversationLineIndex];
            break;
        }

        return(returnString);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 进入场景前检验是否有剧情
    /// </summary>
    public static void CheckStoryBeforeScene()
    {
        StoryStep step = PlayerPropertyManager.playerData.DoingStep;

        if (step == StoryStep.Step0)
        {//触发第一阶段剧情
            AnalyXml.AnalyNpcBehavior("Player", step);
        }
    }
Ejemplo n.º 6
0
    public static bool IsNPCInScene(NPC npc)
    {
        if (storyStepIndex == 0)
        {
            return(true);
        }

        StoryStep currentStoryStep = stroy.stroySteps [storyStepIndex];

        switch (npc.NPCName)
        {
        case "Letter":
            if (currentStoryStep.Letter == null)
            {
                return(false);
            }
            break;

        case "Mary":
            if (currentStoryStep.Mary == null)
            {
                return(false);
            }
            break;

        case "Sheriff":
            if (currentStoryStep.Sheriff == null)
            {
                return(false);
            }
            break;

        case "GunSmith":
            if (currentStoryStep.GunSmith == null)
            {
                return(false);
            }
            break;

        case "Daisy":
            if (currentStoryStep.Daisy == null)
            {
                return(false);
            }
            break;

        case "Joe":
            if (currentStoryStep.Joe == null)
            {
                return(false);
            }
            break;
        }

        return(true);
    }
Ejemplo n.º 7
0
    /// <summary>
    /// 解析Npc的下一个状态
    /// </summary>
    /// <param name="npcName"></param>
    /// <param name="step">当前状态</param>
    public static StoryStep AnalyNpcNextStep(string npcName, StoryStep step)
    {
        string str = XmlIO.LoadNpcChangeStep(npcName, step);

        str = str.Replace("Step", "");

        int index = int.Parse(str);

        return((StoryStep)index);
    }
        private async Task WriteUserMessageActivity(StoryStep <IMessageActivity> step)
        {
            if (step.Actor == Actor.User)
            {
                var messageActivity = this.dialogWriter.GetStepMessageActivity(step.StoryFrame);
                this.performanceStory.AddStep(messageActivity, Actor.User);

                await this.dialogWriter.SendActivity(messageActivity);
            }
        }
        public static void AssertStep(StoryStep <IMessageActivity> storyStep, PerformanceStep <IMessageActivity> performanceStep, string[] options = null)
        {
            switch (storyStep.Actor)
            {
            case Actor.Bot:
                AssertBotStepMessage(storyStep, performanceStep);
                break;

            case Actor.User:
                AssertUserStepMessage(storyStep, performanceStep, options);
                break;
            }
        }
Ejemplo n.º 10
0
    /// <summary>
    /// 根据当前npc的剧情改变到下一个剧情状态
    /// </summary>
    /// <param name="npcName"></param>
    /// <param name="step"></param>
    /// <param name="immediateTrigger">需要立即触发这个状态的行为</param>
    public static void ChangeStep(string npcName, StoryStep step, bool immediateTrigger = false)
    {
        NpcData npcData = ObjectManager.GetAIData(npcName) as NpcData;

        npcData.DoingStep = step;

        if (immediateTrigger)
        {
            TalkAction.Instance.TryWithNpcDialogue();
        }

        Debug.Log(npcName + " changes " + step);
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 解析npc一系列行为
    /// </summary>
    /// <param name="npcName"></param>
    /// <param name="step"></param>
    public static void AnalyNpcBehavior(string npcName, StoryStep step)
    {
        List <string> commandList = XmlIO.LoadNpcStory(npcName, step);
        //异步指令
        bool needAC;

        if (commandList == null)
        {
            Debug.Log("没有读取到Xml信息");
            return;
        }

        //把命令添加到命令队列中
        foreach (string item in commandList)
        {
            string[] strArray = item.Split(';');
            needAC = false;

            if (strArray[1] == "T")
            {
                needAC = true;
            }

            switch (strArray[0])
            {
            case "Dialogue":
                AnalyDialogueCommand(strArray[2], needAC);
                break;

            case "Move":
                AnalyMoveCommand(strArray[2], needAC);
                break;

            case "Turn":
                AnalyTurnCommand(strArray[2], needAC);
                break;

            case "Toggle":
                AnalyToggleCommand(strArray[2], npcName, needAC);
                break;

            case "Property":
                AnalyPropertyCommand(strArray[2], needAC);
                break;
            }
        }
        //开始执行命令
        CommandManager.Instance.ExcuteCommand();
    }
Ejemplo n.º 12
0
    /// <summary>
    /// 检测玩家是否能与npc聊天,返回true表示可以聊天
    /// </summary>
    public bool TryWithNpcDialogue()
    {
        if (GetNpcGoByRay())
        {//如果射线接触到NPC,开始获取这个npc的Xml指令
            //指定npc朝向
            npcGo.GetComponent <AIAttribute>().PlayerTouchYou(dir);

            StoryStep step = npcGo.GetComponent <AIAttribute>().GetAIData().DoingStep;
            AnalyXml.AnalyNpcBehavior(npcGo.name, step);

            return(true);
        }

        return(false);
    }
Ejemplo n.º 13
0
    IEnumerator StartTransition(float fadeDelay, Choice choice)
    {
        fadeOut = true;
        //cleaning after ourselves
        for (int i = 0; i < btnHolder.childCount; i++)
        {
            Button btn = btnHolder.GetChild(i).GetComponent <Button>();
            btn.onClick.RemoveAllListeners();
        }
        img.GetComponent <AudioSource>().Stop();
        yield return(new WaitForSeconds(fadeDelay));

        //game state changes
        switch (choice.name)
        {
        case "Walk it":
            didWalkDog = true;
            break;
        }
        if (name == "Pub1" && choice.name != "Left One")
        {
            currDrunkLvl++;
        }
        if (name == "Pub2" && choice.name != "Light")
        {
            currDrunkLvl++;
        }
        if (name == "Pub3" && choice.name != "Left")
        {
            currDrunkLvl++;
        }
        BlurOptimized.Inst.blurSize       = blurSizeMin + (blurSizeMax - blurSizeMin) * (currDrunkLvl / 3f);
        BlurOptimized.Inst.blurIterations = Mathf.RoundToInt(blurItersMin + (blurItersMax - blurItersMin) * (currDrunkLvl / 3f));

        //cleanup
        gameObject.SetActive(false);
        //init
        StoryStep nextStep = choice.nextStep.GetComponent <StoryStep>();

        nextStep.img       = img;
        nextStep.btnHolder = btnHolder;
        nextStep.btnGroup  = btnGroup;
        nextStep.imgGroup  = imgGroup;
        //reveal
        choice.nextStep.SetActive(true);
    }
        private static void AssertBotStepMessage(StoryStep <IMessageActivity> storyStep, PerformanceStep <IMessageActivity> performanceStep)
        {
            var message = performanceStep.MessageActivity;
            var frame   = storyStep.StoryFrame;

            switch (frame.ComparisonType)
            {
            case ComparisonType.None:
                break;

            case ComparisonType.TextExact:
                ProcessFrameTextExact(frame, performanceStep.MessageActivity.Type, performanceStep.Message);
                break;

            case ComparisonType.TextMatchRegex:
                ProcessBotFrameTextMatchRegex(frame, message);
                break;

            case ComparisonType.AttachmentListPresent:
                ProcessBotFrameListPresent(frame, message);
                break;

            case ComparisonType.TextExactWithSuggestions:
                ProcessBotFrameTextWithSuggestions(frame, message);
                break;

            case ComparisonType.TextMatchRegexWithSuggestions:
                ProcessBotFrameTextMatchRegexWithSuggestions(frame, message);
                break;

            case ComparisonType.Predicate:
                ProcessBotFramePredicate(frame, message);
                break;

            default:
                var reasonMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    "Comparison type {0} is not supported for bot frame.",
                    frame.ComparisonType);

                throw new ArgumentOutOfRangeException(nameof(frame.ComparisonType), reasonMessage);
            }
        }
Ejemplo n.º 15
0
        public void AssertDialogFinishStep(StoryStep storyStep)
        {
            if (!(storyStep.StoryFrame is DialogStoryFrame dialogStoryFrame))
            {
                return;
            }

            this.VerifyStatusesEqual(dialogStoryFrame);
            this.VerifyResultNotEmpty(dialogStoryFrame);

            if (dialogStoryFrame.ResultPredicate != null)
            {
                this.VerifyResultPredicate(dialogStoryFrame);
            }

            if (dialogStoryFrame.ExceptionType != null)
            {
                this.VerifyExceptionType(dialogStoryFrame);
            }
        }
Ejemplo n.º 16
0
        public void AssertDialogFinishStep(StoryStep <IMessageActivity> storyStep)
        {
            var dialogStoryFrame = storyStep.StoryFrame as DialogStoryFrame <IMessageActivity>;

            if (dialogStoryFrame == null)
            {
                return;
            }

            this.VerifyStatusesEqual(dialogStoryFrame);
            this.VerifyResultNotEmpty(dialogStoryFrame);

            if (dialogStoryFrame.ResultPredicate != null)
            {
                this.VerifyResultPredicate(dialogStoryFrame);
            }

            if (dialogStoryFrame.ExceptionType != null)
            {
                this.VerifyExceptionType(dialogStoryFrame);
            }
        }