Example #1
0
        public void RefreshStories()
        {
            Node[]         startNodesArray = nodes.Where(x => x.GetType() == typeof(StartElement)).ToArray();
            StartElement[] startNodes      = new StartElement[startNodesArray.Length];

            for (int i = 0; i < startNodes.Length; i++)
            {
                startNodes[i] = startNodesArray[i] as StartElement;
            }

            StoryNames = startNodes.Select(x => x.StoryName).ToArray();

            _shortStories = new List <StoryElement> [startNodes.Length];
            for (int i = 0; i < _shortStories.Length; i++)
            {
                _shortStories[i] = new List <StoryElement>();
                _shortStories[i].Add(startNodes[i]);

                StartElement currentStartNode = startNodes[i];
                StoryElement currentNode      = startNodes[i].GetOutputPort("NextNode").GetOutputValue() as StoryElement;
                while (currentNode != null && currentNode.GetOutputPort("NextNode").IsConnected&& currentNode.GetOutputPort("NextNode").GetOutputValue().GetType() != typeof(StartElement))
                {
                    _shortStories[i].Add(currentNode);
                    currentNode = currentNode.GetOutputPort("NextNode").GetOutputValue() as StoryElement;
                }
                if (currentNode != null && currentNode.GetType() != typeof(StartElement))
                {
                    _shortStories[i].Add(currentNode);
                }
            }
        }
Example #2
0
        public static Level fromXML(XmlElement node, Game gameref, String campaignPath)
        {
            Level newLvl = new Level();

            newLvl.number = int.Parse(node.GetElementsByTagName("number")[0].FirstChild.Value);
            if (node.HasAttribute("autoProgress"))
            {
                newLvl.autoProgress = bool.Parse(node.GetAttribute("autoProgress"));
            }
            newLvl.name = node.GetAttribute("name");

            foreach (string singleAdj in node.GetElementsByTagName("adj")[0].FirstChild.Value.Split(','))
            {
                newLvl.adjacent.Add(Int32.Parse(singleAdj));
            }
            XmlNodeList list = node.GetElementsByTagName("prereq");

            if (list.Count > 0 && list[0].FirstChild != null)
            {
                foreach (string singlePrereq in node.GetElementsByTagName("prereq")[0].FirstChild.Value.Split(','))
                {
                    newLvl.prereq.Add(Int32.Parse(singlePrereq));
                }
            }
            newLvl.loc = XMLUtil.fromXMLVector2(node.GetElementsByTagName("location")[0]);
            if (node.GetElementsByTagName("horizonPath").Count > 0)
            {
                newLvl.horizon = gameref.Content.Load <Texture2D>(campaignPath + node.GetElementsByTagName("horizonPath")[0].FirstChild.Value);
            }
            if (node.GetElementsByTagName("items").Count > 0)
            {
                foreach (XmlElement item in node.GetElementsByTagName("items")[0].ChildNodes)
                {
                    newLvl.items.Add(GameItem.fromXML(item));
                }
            }
            if (node.GetElementsByTagName("spawns").Count > 0)
            {
                foreach (XmlElement item in node.GetElementsByTagName("spawns")[0].ChildNodes)
                {
                    newLvl.spawns.Add(SpawnPoint.fromXML(item));
                }
            }
            XmlNodeList storyNodes = node.GetElementsByTagName("story");

            if (storyNodes.Count > 0 && storyNodes[0].ChildNodes.Count > 0)
            {
                foreach (XmlNode item in storyNodes[0].ChildNodes)
                {
                    newLvl.storyElements.Add(StoryElement.fromXML(item, gameref));
                }
            }
            newLvl.levelLength = int.Parse(node.GetAttribute("length"));
            foreach (XmlElement graphic in node.GetElementsByTagName("graphic"))
            {
                newLvl.backgroundItems.Add(BackgroundItemStruct.fromXML(graphic));
            }
            return(newLvl);
        }
    void OnEnable()
    {
        //获取当前编辑自定义Inspector的对象
        element = new SerializedObject(target);
        dolist  = element.FindProperty("DoList");
        StoryElement _target = (StoryElement)target;

        showActionList = new bool[dolist.arraySize];
    }
Example #4
0
            public override void OnCreate()
            {
                if (node == null)
                {
                    node = target as StoryElement;
                }
                EditorUtility.SetDirty(node);

                ReplaceTint(node.DisplayColor);
            }
        public void StartStory()
        {
            _storyGraph.ConnectStoryElements();
            _currentElement = _storyGraph.GetRootStory()[0];

            _currentTask           = TaskManager.CreateTask(_currentElement.Execute(_manager, _canvas));
            _currentTask.Finished += AdvanceStory;

            _currentTask.Start();
        }
Example #6
0
    void UpdateToNewStoryElement()
    {
        // TODO Day view is shifted by 1
        // This is stupid but no time to fix it
        daysText.text          = dayNumber.ToString();
        dayNumber             += 1;
        daysTextInOverlay.text = string.Format(DAYS_TEXT, dayNumber.ToString());


        // TODO
        int caughtScore = Random.Range(40, 100);

        if (riskAmount > caughtScore)
        {
            currentStoryElement = null;
            int numberOfPitfalls = story.pitfalls.Length;
            int pitfallIndex     = Random.Range(0, numberOfPitfalls);
            currentPitfall = story.pitfalls[pitfallIndex];
        }
        else
        {
            currentPitfall = null;
            int numberOfStoryElements = story.storyElements.Length;

            List <StoryElement> accessibleStoryElements = new List <StoryElement>();

            // This is HORRIBLE >:(
            for (int i = 0; i < numberOfStoryElements; i++)
            {
                StoryElement current = story.storyElements[i];
                bool         isLevelAchievedHighEnough = current.prerequisites.level <= currentLevel;
                bool         isStoryAlreadyDone        = alreadyDoneStories.Contains(current.id) && current.prerequisites.doableOnce;
                if (isLevelAchievedHighEnough && !isStoryAlreadyDone)
                {
                    if (!current.prerequisites.needsUnlock)
                    {
                        // If it does not need any unlock, it's okay!
                        accessibleStoryElements.Add(current);
                    }
                    else
                    {
                        // Otherwise, element has to be present in list
                        if (unlockedStories.Contains(current.id))
                        {
                            accessibleStoryElements.Add(current);
                        }
                    }
                }
            }

            int numberOfAccessibleStoryElements = accessibleStoryElements.Count;
            int level = Random.Range(0, numberOfAccessibleStoryElements);
            currentStoryElement = accessibleStoryElements[level];
        }
    }
    public StoryElement Convert(int index)
    {
        StoryElement SR = new StoryElement();

        SR.NPCName  = ST.DSE [index].NPCName;
        SR.Portrait = Resources.Load <Sprite>(ST.DSE [index].Portrait);
        for (int x = 0; x < ST.DSE [index].DialogueBoxes.Count; x++)
        {
            SR.DialogueBoxes[x] = new StoryDialogue(ST.DSE [index].DialogueBoxes[x]);
        }
        return(SR);
    }
Example #8
0
 //添加故事管理器
 public void AddStoryElement(StoryElement element)
 {
     if (!StoryElements.Contains(element))
     {
         StoryElements.Add(element);
         Debug.Log("已添加故事管理器。 " + element.transform);
     }
     else
     {
         Debug.Log("已经包含了这个故事管理器! " + element.transform);
     }
 }
        public void CreateSubStory(StoryGraph graph, UVNFManager manager, UVNFCanvas canvas)
        {
            if (_subgraphHandler == null)
            {
                _afterSubgraphElement = _currentElement.Next;

                _subgraphHandler  = new UVNFStoryManager(graph, manager, canvas, HandleSubgraphFinish);
                _handlingSubgraph = true;
            }
            else
            {
                _subgraphHandler.CreateSubStory(graph, manager, canvas);
            }
        }
    void PlayNextElement(StoryElement justFinished)
    {
        if (justFinished)
            justFinished.OnDone -= PlayNextElement;

        storyElements[currentElement].Play();

        if (currentElement < storyElements.Count)
            storyElements[currentElement].OnDone += PlayNextElement;
        else
        { } // story ended!

        Debug.Log("playing " + storyElements[currentElement]);

        currentElement++;
    }
    public void ReadStoryFormFile()
    {
        Command     command = new Command();
        XmlDocument xmlDoc  = new XmlDocument();

        xmlDoc.LoadXml(story.text);
        XmlNodeList storyElementList = xmlDoc.SelectSingleNode("/Story").ChildNodes;

        foreach (XmlNode _storyElement in storyElementList)
        {
            StoryElement storyElement      = new StoryElement();
            XmlNode      conditionListNode = _storyElement.SelectSingleNode("ConditionList");
            XmlNode      TaskNode          = _storyElement.SelectSingleNode("Task");
            XmlNode      dialogListNode    = _storyElement.SelectSingleNode("DialogList");
            XmlNode      npcActionListNode = _storyElement.SelectSingleNode("NpcActionList");

            if (conditionListNode != null)
            {
                List <Condition> ConditionList;
                ConditionList = ReadConditionList(conditionListNode);
                ConditionCommand conditionCommand = new ConditionCommand(ConditionList);
                storyElement.commandList.Add(conditionCommand);
            }
            if (dialogListNode != null)
            {
                List <Dialog> DialogList;
                DialogList = ReadDialogList(dialogListNode);
                DialogCommand dialogCommand = new DialogCommand(DialogList);
                storyElement.commandList.Add(dialogCommand);
            }
            if (npcActionListNode != null)
            {
                List <NpcAction> NpcActionList;
                NpcActionList = ReadNpcActionList(npcActionListNode);
                NpcActionCommand npcActionCommand = new NpcActionCommand(NpcActionList);
                storyElement.commandList.Add(npcActionCommand);
            }
            if (TaskNode != null)
            {
                Task task;
                task = ReadTask(TaskNode);
                TaskCommand taskCommand = new TaskCommand(task);
                storyElement.commandList.Add(taskCommand);
            }
            storyList.Add(storyElement);
        }
    }
Example #12
0
    private void SerializeElements()
    {
        Transform ElementsContainer = GameObject.FindGameObjectWithTag("Canvas").transform;
        int       count             = ElementsContainer.childCount;

        SerializedElements = new ElementData[count];

        for (int i = 0; i < count; i++)
        {
            StoryElement s = ElementsContainer.GetChild(i).gameObject.GetComponent <StoryElement>();
            if (s == null)
            {
                continue;
            }
            SerializedElements[i] = new ElementData(ElementsContainer.GetChild(i).gameObject);
        }
    }
Example #13
0
    public ElementData(GameObject StoryElement)
    {
        Name   = StoryElement.name;
        Index  = StoryElement.transform.GetSiblingIndex();
        Active = StoryElement.activeSelf;
        Image  = StoryElement.GetComponent <Image>().sprite.name;

        StoryElement EventSystemScript = StoryElement.GetComponent <StoryElement>();

        SubmenuType = EventSystemScript.SubmenuType;
        Id          = EventSystemScript.id;


        TransformData transformData = new TransformData();

        transformData.PullFromTransform(StoryElement.GetComponent <RectTransform>());
        Transform = transformData;
    }
        public void AdvanceStory(bool manual)
        {
            if (!manual && !_handlingSubgraph)
            {
                if (_currentElement.Next != null && _currentTask != null && !_currentTask.Running)
                {
                    _currentElement = _currentElement.Next;

                    _currentTask           = TaskManager.CreateTask(_currentElement.Execute(_manager, _canvas));
                    _currentTask.Finished += AdvanceStory;
                    _currentTask.Start();
                }
                else
                {
                    _afterSubgraphHandler?.Invoke();
                }
            }
        }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        if (waitingOnDialog)
        {
            return;
        }

        if (dialogDataLoaded)
        {
            // Dialog has been loaded
            if (storyQueue.Count != 0)
            {
                // We have more story elements in the queue
                StoryElement se = storyQueue.Dequeue();
                if (se.zoomIn)
                {
                    // Set position here
                    //se.zoomToPosition;
                }

                // Let the Player Move script know we need to
                // disable controls if the Story Element wants to
                disableControls = se.DisableControls();
                if (disableControls)
                {
                    PlayerMove playerMove = gameObject.GetComponent <PlayerMove>();
                    playerMove.DisableMove();
                }

                // Tell the Story Element notify the Dialog Manager
                // to begin loading dialog attached to this element
                se.TriggerDialog();
                waitingOnDialog = true;
            }
            else
            {
                // consume (DESTROY) the dialog after processing
                Destroy(dialogToDestroy);
                storyQueue       = new Queue <StoryElement>();
                dialogDataLoaded = false;
                waitingOnDialog  = false;
            }
        }
    }
Example #16
0
    void PlayNextElement(StoryElement justFinished)
    {
        if (justFinished)
        {
            justFinished.OnDone -= PlayNextElement;
        }

        storyElements[currentElement].Play();

        if (currentElement < storyElements.Count)
        {
            storyElements[currentElement].OnDone += PlayNextElement;
        }
        else
        {
        }           // story ended!

        Debug.Log("playing " + storyElements[currentElement]);

        currentElement++;
    }
 public override string GetNodeMenuName(Type type)
 {
     if (type.BaseType == typeof(Node) || type.IsSubclassOf(typeof(Node)))
     {
         if (type.IsSubclassOf(typeof(StoryElement)))
         {
             StoryElement element      = ScriptableObject.CreateInstance(type) as StoryElement;
             string       returnString = element.Type.ToString() + "/" + type.Name.Replace("Element", "");
             UnityEngine.Object.DestroyImmediate(element);
             return(returnString);
         }
         else
         {
             return(base.GetNodeMenuName(type).Replace("Node", ""));
         }
     }
     else
     {
         return(null);
     }
 }
        public void AdvanceStory(StoryElement newStoryPoint, bool continueToRun = false)
        {
            if (_handlingSubgraph)
            {
                _subgraphHandler.AdvanceStory(false);
            }
            else if (newStoryPoint != null)
            {
                if (!continueToRun)
                {
                    _currentTask.Stop();
                }

                _currentElement = newStoryPoint;

                _currentTask           = TaskManager.CreateTask(_currentElement.Execute(_manager, _canvas));
                _currentTask.Finished += AdvanceStory;
                _currentTask.Start();
            }
            else
            {
                _afterSubgraphHandler?.Invoke();
            }
        }
Example #19
0
 // Use this for initialization
 void Start()
 {
     shDialog = GetComponent <ShowHideDialog>();
     dialog   = GetComponent <StoryElement>();
 }
 public void AdvanceStoryGraph(StoryElement element, bool continueInBackground)
 {
     _currentStoryManager.AdvanceStory(element, continueInBackground);
 }
 public void AdvanceStoryGraph(StoryElement element)
 {
     _currentStoryManager.AdvanceStory(element);
 }
Example #22
0
 private void Display(string file)
 {
     currentStoryElement = loader.GetStoryElement(path + file + ".json");
     mainDisplayBox.Text = currentStoryElement.Display();
 }