/// <summary> /// Sends dialog to player's client. /// </summary> /// <param name="message"></param> /// <param name="elements"></param> public void Msg(Hide hide, string message, params DialogElement[] elements) { var mes = new DialogElement(); mes.Add(new DialogText(message)); mes.Add(elements); this.Msg(hide, mes); }
/// <summary> /// Sends dialog to player's client. /// </summary> /// <param name="hide"></param> /// <param name="elements"></param> public void Msg(Hide hide, params DialogElement[] elements) { var element = new DialogElement(); if (hide == Hide.Face || hide == Hide.Both) element.Add(new DialogPortrait(null)); else if (this.NPC.DialogPortrait != null) element.Add(new DialogPortrait(this.NPC.DialogPortrait)); if (hide == Hide.Name || hide == Hide.Both) element.Add(new DialogTitle(null)); element.Add(elements); var xml = string.Format( "<call convention='thiscall' syncmode='non-sync'>" + "<this type='character'>{0}</this>" + "<function>" + "<prototype>void character::ShowTalkMessage(character, string)</prototype>" + "<arguments>" + "<argument type='character'>{0}</argument>" + "<argument type='string'>{1}</argument>" + "</arguments>" + "</function>" + "</call>", this.Player.EntityId, HtmlEncode(element.ToString())); Send.NpcTalk(this.Player, xml); }
public void ElementComposition() { var sb = new StringBuilder(); var elements = new DialogElement(); elements.Add(new DialogButton("Foobar1")); elements.Render(ref sb); Assert.Equal("<button title='Foobar1' keyword='@foobar1' />", sb.ToString()); sb.Clear(); elements.Add(new DialogButton("Foobar2")); elements.Render(ref sb); Assert.Equal("<button title='Foobar1' keyword='@foobar1' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString()); sb.Clear(); elements.Insert(1, new DialogButton("Foobar3")); elements.Render(ref sb); Assert.Equal("<button title='Foobar1' keyword='@foobar1' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString()); sb.Clear(); elements.Replace(0, new DialogButton("Foobar4")); elements.Render(ref sb); Assert.Equal("<button title='Foobar4' keyword='@foobar4' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString()); sb.Clear(); elements.Insert(0, new DialogButton("Foobar5")); elements.Render(ref sb); Assert.Equal("<button title='Foobar5' keyword='@foobar5' /><button title='Foobar4' keyword='@foobar4' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' />", sb.ToString()); sb.Clear(); elements.Insert(99, new DialogButton("Foobar6")); elements.Render(ref sb); Assert.Equal("<button title='Foobar5' keyword='@foobar5' /><button title='Foobar4' keyword='@foobar4' /><button title='Foobar3' keyword='@foobar3' /><button title='Foobar2' keyword='@foobar2' /><button title='Foobar6' keyword='@foobar6' />", sb.ToString()); sb.Clear(); elements = new DialogElement(); elements.Insert(1, new DialogButton("Foobar7")); elements.Render(ref sb); Assert.Equal("<button title='Foobar7' keyword='@foobar7' />", sb.ToString()); sb.Clear(); elements = new DialogElement(); elements.Replace(0, new DialogButton("Foobar8")); elements.Render(ref sb); Assert.Equal("<button title='Foobar8' keyword='@foobar8' />", sb.ToString()); sb.Clear(); elements = new DialogElement("foobar, <username/>!", new DialogButton("Foobar9"), new DialogButton("Foobar10")); elements.Render(ref sb); Assert.Equal("foobar, <username/>!<button title='Foobar9' keyword='@foobar9' /><button title='Foobar10' keyword='@foobar10' />", sb.ToString()); sb.Clear(); elements.Replace(0, "barfoo?"); elements.Insert(1, new DialogButton("Foobar11")); elements.Render(ref sb); Assert.Equal("barfoo?<button title='Foobar11' keyword='@foobar11' /><button title='Foobar9' keyword='@foobar9' /><button title='Foobar10' keyword='@foobar10' />", sb.ToString()); sb.Clear(); }