Beispiel #1
0
        /// <summary>
        /// Creates a task datastructure from a story event.
        /// </summary>
        /// <param name="ev">The event containing the relevant data.</param>
        public Task(StoryEvent ev)
        {
            //Save us some typing.
            WorldScript ws = Globals.Instance.WorldScript;

            this.ID = ev.ID;
            this.Type = ev.Name;
            this.Actor = ws.GetCharacterByName(ev.GetValue("character1"));
            this.Actee = ws.GetCharacterByName(ev.GetValue("character2"));
            this.Item = ws.GetItemByName(ev.GetValue("item"));
            this.Description = ev.Description;
            this.IsEnding = ev.IsEnding;
            this.Mood = ev.Mood.Trim();
            this.NodeType = ev.NodeType.Trim();
            //Because these aren't consistent.
            if (this.Type == "goto") {
                this.Locale = ws.GetLocaleByName(ev.GetValue("locationTo"));
            } else {
                this.Locale = ws.GetLocaleByName(ev.GetValue("location"));
            }

            this.Description = this.ParseDescription(ev.Description);
            this.PreDialogue = this.ParseDialogue(ev.GetValue("dialogPre"), ev);
            this.PostDialogue = this.ParseDialogue(ev.GetValue("dialogPost"), ev);

            this.StoryEvent = ev;
        }
Beispiel #2
0
        private Dialogue ParseDialogue(string rawDialogue, StoryEvent ev)
        {
            //<Variable>
            //    <Name>dialogPre</Name>
            //    <Value>"{character1}I think I'll should give this {item} to {character2}."</Value>
            //</Variable>
            //<Variable>
            //    <Name>dialogPost</Name>
            //    <Value>"{character1}It's dangerous to go alone! Take this {item}, {character2}!"</Value>
            //</Variable>

            //parse out who is doing the speaking, save to theActor field, and rip the template out of the string
            CharacterScript theActor = this.Actor;
            if( rawDialogue.StartsWith( "{character1}", StringComparison.OrdinalIgnoreCase ) )
            {
                theActor = this.Actor;
                rawDialogue = rawDialogue.Substring( "{character1}".Length );
            }
            else if( rawDialogue.StartsWith( "{character2}", StringComparison.OrdinalIgnoreCase ) )
            {
                theActor = this.Actee;
                rawDialogue = rawDialogue.Substring( "{character2}".Length );
            }

            rawDialogue = rawDialogue.Replace( "{character1}", this.Actor.Name );
            if (this.Actee != null) rawDialogue = rawDialogue.Replace( "{character2}", this.Actee.Name );
            if (this.Item != null) rawDialogue = rawDialogue.Replace("{item}", this.Item.Name);
            rawDialogue = rawDialogue.Replace( "{locationTo}", this.Locale.name );
            //workingStr = workingStr.Replace( "{locationFrom}", this.Actor.name );
            rawDialogue = rawDialogue.Replace( "{location}", this.Locale.name );

            WorldScript ws = Globals.Instance.WorldScript;

            if (ws.GetLocaleByName(ev.GetValue("locationFrom")) != null) rawDialogue = rawDialogue.Replace( "{locationFrom}", ws.GetLocaleByName(ev.GetValue("locationFrom")).name );
            if (ws.GetCharacterByName(ev.GetValue("character3")) != null) rawDialogue = rawDialogue.Replace( "{character3}", ws.GetCharacterByName(ev.GetValue("character3")).Name );
            if (ws.GetCharacterByName(ev.GetValue("character4")) != null) rawDialogue = rawDialogue.Replace( "{character4}", ws.GetCharacterByName(ev.GetValue("character4")).Name );
            if (ws.GetCharacterByName(ev.GetValue("character5")) != null) rawDialogue = rawDialogue.Replace( "{character5}", ws.GetCharacterByName(ev.GetValue("character5")).Name );
            if (ws.GetItemByName(ev.GetValue("item1")) != null) rawDialogue = rawDialogue.Replace( "{item1}", ws.GetItemByName(ev.GetValue("item1")).Name );
            if (ws.GetItemByName(ev.GetValue("item2")) != null) rawDialogue = rawDialogue.Replace( "{item2}", ws.GetItemByName(ev.GetValue("item2")).Name );

            return new Dialogue(theActor, rawDialogue);
        }