コード例 #1
0
ファイル: DialogueScreen.cs プロジェクト: pquinn/time-sink
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="id">The GUID of the <see cref="NPCPrompt"/>NPCPrompt</see> in the database.</param>
 public DialogueScreen(Guid id)
     : base()
 {
     this.scale = 0.75f;
     this.prompt = FindPrompt(id);
     this.responses = new List<Response>();
     IsPopup = false;
     InitializeActions();
 }
コード例 #2
0
ファイル: DialogueScreen.cs プロジェクト: pquinn/time-sink
        /// <summary>
        /// Retrieves the appropriate <see cref="NPCPrompt"/>NPCPrompt</see> from the database.
        /// </summary>
        /// <param name="id">The GUID of the <see cref="NPCPrompt"/>NPCPrompt</see></param>
        /// <returns>The <see cref="NPCPrompt"/>NPCPrompt</see></returns>
        private NPCPrompt FindPrompt(Guid id)
        {
            List<IDialogueAction> promptActions = new List<IDialogueAction>();
            try
            {
                DataTable entry;
                String query = "select speaker \"speaker\", entry \"entry\", ";
                query += "animation \"animation\", sound \"sound\", quest \"quest\", ";
                query += "response_required \"response\" ";
                query += "from Prompt where id = \"" + id.ToString() + "\";";
                entry = StarterGame.Instance.database.GetDataTable(query);
                // only take the first result (there should only be one anyway)
                DataRow result = entry.Rows[0];
                String speaker = (String)result["speaker"];
                String body = (String)result["entry"];

                if (!DBNull.Value.Equals(result["animation"]))
                {
                    promptActions.Add(new AnimationAction((String)result["animation"]));
                }

                if (!DBNull.Value.Equals(result["sound"]))
                {
                    promptActions.Add(new SoundAction((String)result["sound"]));
                }

                if (!DBNull.Value.Equals(result["quest"]))
                {
                    promptActions.Add(new QuestAction((String)result["quest"]));
                }

                Boolean responseRequired = (Boolean)result["response"];
                NPCPrompt prompt = new NPCPrompt(id, speaker, body, promptActions, responseRequired);
                return prompt;

            }
            catch (Exception e)
            {
                String error = "The following error has occurred:\n";
                error += e.Message.ToString() + "\n";
                Console.WriteLine(error);
                return new NPCPrompt(id, "error", error, promptActions, false);
            }
        }