Esempio n. 1
0
        public static string Build(SystemMessageData template, params string[] parameters)
        {
            var pieces = new List <string>();
            var sb     = new StringBuilder();

            var prm        = ChatUtils.SplitDirectives(parameters);
            var txt        = template.Template.UnescapeHtml().Replace("<BR>", "\r\n");
            var html       = new HtmlDocument(); html.LoadHtml(txt);
            var htmlPieces = html.DocumentNode.ChildNodes;

            if (prm == null)
            {
                //only one parameter (opcode) so just add text

                foreach (var htmlPiece in htmlPieces)
                {
                    var content = htmlPiece.InnerText;
                    pieces.Add(content);
                }
            }
            else
            {
                //more parameters
                foreach (var piece in htmlPieces)
                {
                    if (piece.Name == "img")
                    {
                        continue;
                    }
                    var content       = ChatUtils.ReplaceParameters(piece.InnerText, prm, true);
                    var innerPieces   = content.Split(new[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries);
                    var plural        = false;
                    var selectionStep = 0;

                    foreach (var inPiece in innerPieces)
                    {
                        switch (selectionStep)
                        {
                        case 1:
                            if (int.Parse(inPiece) != 1)
                            {
                                plural = true;
                            }
                            selectionStep++;
                            continue;

                        case 2:
                            if (inPiece == "/s//s" && plural)
                            {
                                pieces[^ 1] = pieces.Last() + "s";
Esempio n. 2
0
        public ChatMessage CreateEnchantSystemMessage(string systemMessage)
        {
            return(_dispatcher.InvokeAsync(() =>
            {
                var msg = CreateMessage(ChatChannel.Enchant);
                var e = "";

                if (systemMessage.Contains("enchantCount:"))
                {
                    var s = systemMessage.IndexOf("enchantCount:", StringComparison.InvariantCultureIgnoreCase);
                    var ench = systemMessage.Substring(s + "enchantCount:".Length, 1);
                    e = $"+{ench} ";
                }

                var prm = ChatUtils.SplitDirectives(systemMessage);
                if (prm == null)
                {
                    return msg;
                }


                msg.Author = prm["UserName"];
                var txt = "{ItemName}";
                txt = ChatUtils.ReplaceParameters(txt, prm, true);
                txt = txt.Replace("{", "");
                txt = txt.Replace("}", "");
                var mp = MessagePieceBuilder.BuildSysMsgItem(txt);
                var sb = new StringBuilder();
                sb.Append("<");
                sb.Append(e);
                sb.Append(mp.Text.Substring(1));
                mp.Text = sb.ToString();
                msg.AddPiece(new SimpleMessagePiece("Successfully enchanted ", App.Settings.FontSize, false, "cccccc"));
                msg.AddPiece(mp);

                return msg;
            }).Result);
        }