示例#1
0
        /// <summary>
        /// Finds a branch with a specific id.
        /// </summary>
        /// <param name="id">the branch's id</param>
        /// <returns><see cref="QuestBranch"/> or <see cref="null"/> if none was found</returns>
        public QuestBranch GetBranch(string id)
        {
            // loop through all branches until id is found.
            QuestBranch found = null;

            if (string.Equals(root.RefId, id, StringComparison.OrdinalIgnoreCase))
            {
                found = root;
            }
            else
            {
                found = root.FindChild(id);
            }
            return(found);
        }
示例#2
0
        /// <summary>
        /// Finds a child branch with a specific id.
        /// </summary>
        /// <param name="id">the branch's id</param>
        /// <returns><see cref="QuestBranch"/> or <see cref="null"/> if none was found</returns>
        public QuestBranch FindChild(string id)
        {
            QuestBranch child = null;

            for (int i = branches.Length - 1; i >= 0; i--)
            {
                if (string.Equals(branches[i].RefId, id, StringComparison.OrdinalIgnoreCase))
                {
                    child = branches[i];
                    break;
                }
                child = branches[i].FindChild(id);
                if (child != null)
                {
                    break;
                }
            }
            return(child);
        }
示例#3
0
        public override string ToString()
        {
            PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();

            try
            {
                QuestBranch branch = root;
                sb.Append(branch.Localized);
                sb.Append('\n');
                while (branch.Branches.Length > 0)
                {
                    int i = branch.Branches.Length - 1;
                    for (; i >= 0; i--)
                    {
                        // go through all branches
                        if (branch.Branches[i].Taken)
                        {
                            // follow branch that was taken
                            branch = branch.Branches[i];
                            sb.Append('\n');
                            sb.Append(branch.Localized);
                            sb.Append('\n');
                            break;
                        }
                    }
                    if (i == -1)
                    {
                        // made it through all branches
                        break;
                    }
                }
            }
            catch (PooledException e)
            {
                // e.printStackTrace();
            }
            string s = sb.ToString();

            sb.ReturnToPool();
            return(s);
        }
示例#4
0
 /// <summary>
 /// Adds a branch this <see cref="QuestBranch"/> leads to.
 /// </summary>
 /// <param name="branch">the new <see cref="QuestBranch"/></param>
 public void AddBranch(QuestBranch branch)
 {
     branches    = ArrayUtilities.Instance.ExtendArray(branch, branches);
     branch.Root = this;
 }