Пример #1
0
        public static async Task Create(SocketUserMessage msg)
        {
            StorePrmInfos();

            string send_msg = msg.Author.Mention + "\nType : CoC\n";

            foreach (var v in _prmInfo)
            {
                for (int i = 0; i < v.Value.Item1; i++)
                {
                    RandomManager.Rand(6);
                }

                _prmResult[v.Key] = RandomManager.DiceResultHistory.Sum() + v.Value.Item2;
                send_msg         += v.Key + " : " + _prmResult[v.Key] + " ([";

                for (int i = 0; i < v.Value.Item1; i++)
                {
                    send_msg += RandomManager.DiceResultHistory[i];
                    if (i != v.Value.Item1 - 1)
                    {
                        send_msg += ", ";
                    }
                    else
                    {
                        send_msg += "]";
                    }
                }

                if (v.Value.Item2 != 0)
                {
                    send_msg += " + " + v.Value.Item2;
                }

                send_msg += ")\n";

                RandomManager.ClearHistory();
            }

            send_msg += "\n";

            send_msg += "HP : " + (_prmResult["CON"] + _prmResult["SIZ"]) / 2 + " ((CON + SIZ) / 2)\n";
            send_msg += "MP : " + _prmResult["POW"] + " (POW)\n";
            send_msg += "SAN : " + _prmResult["POW"] * 5 + " (POW * 5)\n";
            send_msg += "ダメボ : " + CalcDamageBonus(_prmResult["STR"] + _prmResult["SIZ"]) + "\n";
            send_msg += "アイデア : " + _prmResult["INT"] * 5 + " (INT * 5)\n";
            send_msg += "知識 : " + _prmResult["EDU"] * 5 + " (EDU * 5)\n";
            send_msg += "幸運 : " + _prmResult["POW"] * 5 + " (POW * 5)";

            await msg.Channel.SendMessageAsync(send_msg);
        }
Пример #2
0
        public static async Task Execute(SocketUserMessage msg)
        {
            string dice_area = msg.Content.Replace("&", "&");

            if (dice_area[0] != '&')
            {
                return;
            }

            // 全角文字を半角文字に、スペースの除去
            dice_area = ConvertAsciiAndNoSpace.Convert(dice_area);

            if (Regex.IsMatch(msg.ToString(), @"(?i)^&help$"))
            {
                await msg.Channel.SendMessageAsync(
                    "実は本当のプレフィックスは `%` です。\n" +
                    "コマンドは現在、`%help` `%version(ver)` `%git` `%calc` があります。"
                    );

                return;
            }

            ProcessTaarget["+"] = ProcessTaargetAdd;

            ProcessTaarget["-"] = ProcessTaargetSub;

            ProcessTaarget["*"] = ProcessTaargetMul;

            ProcessTaarget["/"] = ProcessTaargetDiv;

            string send_msg = msg.Author.Mention + '\n';

            Match per_check = Regex.Match(dice_area, @"(?i)^&\s*(percent|per|p)");
            Match tar       = Regex.Match(dice_area, @"(?i)(?<=^&\s*(percent|per|p)\s*)(?<minus>\-*)(?<val>\d+)");

            int finaly_tar = 0;


            if (per_check.Length != 0)
            {
                MatchCollection tar_fixs = Regex.Matches(dice_area, @"(?i)(?<=\d+\s*)(?<ope>(\+|\-|\*|/))(?<val>\d+)");
                dice_area = "1d100 tar=";
                if (tar.Length != 0)
                {
                    finaly_tar = int.Parse(tar.Groups["val"].Value);

                    if (tar.Groups["minus"].Value == "-")
                    {
                        finaly_tar = -finaly_tar;
                    }

                    foreach (Match m in tar_fixs)
                    {
                        ProcessTaarget[m.Groups["ope"].Value](ref finaly_tar, int.Parse(m.Groups["val"].Value));
                    }

                    dice_area += finaly_tar.ToString();
                }
            }

            ISocketMessageChannel channel = msg.Channel;

            RandomManager.ClearHistory();

            // キャラクリの位置
            Match create_coc_match = Regex.Match(dice_area, @"(?i)coc");

            if (create_coc_match.Success)
            {
                await CharacterCreateCoC.Create(msg);
            }

            MatchCollection dices = Regex.Matches(dice_area, @"(?i)(?<sign>(\+|\-|))(?<value>\d+)(?<type>(d|r))(?<sides>\d+)((\[|@)(?<critical>\d+)(\]|))?");
            MatchCollection fixes = Regex.Matches(dice_area, @"(?i)(?<fix>(\+|\-)\d+)(?=(\+|\-|$))");
            MatchCollection dxs   = Regex.Matches(dice_area, @"(?i)(?<sign>(\+|\-|))(?<value>\d+)dx((\[|@)(?<critical>\d+)(\]|))?");

            Match target_match = Regex.Match(dice_area, @"(?i)(target|tar|trg|tgt)=(?<minus>\-*)(?<target>\d+)");

            if (target_match.Success)
            {
                int tar_val = int.Parse(target_match.Groups["minus"].Value + target_match.Groups["target"].Value);
                send_msg += "Target -> " + tar_val + "\n";

                if (tar_val <= 0)
                {
                    await CocJudgeImageOutput.AutoFailAsync(msg);

                    return;
                }
                else if (tar_val >= 100)
                {
                    await CocJudgeImageOutput.AutoSuccessAsync(msg);

                    return;
                }
            }

            int d, r;

            d = r = 0;

            // 数値がおかしくないかの確認
            foreach (Match m in dices)
            {
                if (Int64.Parse(m.Groups["value"].Value) > 10_000)
                {
                    await channel.SendMessageAsync(msg.Author.Mention + "\nパソコンを破壊する気...?");

                    return;
                }
                if (Int64.Parse(m.Groups["sides"].Value) > 1_000_000_000)
                {
                    await channel.SendMessageAsync(msg.Author.Mention + "\nんん...流石に面の数が多すぎるかな...");

                    return;
                }
            }

            foreach (Match m in dices)
            {
                string res = "";

                if (m.Groups["type"].Value.ToLower() == "d")
                {
                    res += NDXRoll(channel, int.Parse(m.Groups["value"].Value), int.Parse(m.Groups["sides"].Value), m.Groups["sign"].ToString() == "-");
                    d++;
                }
                else if (m.Groups["type"].Value.ToLower() == "r")
                {
                    if (m.Groups["critical"].Value == "")
                    {
                        res += NRXRoll(channel, int.Parse(m.Groups["value"].Value), int.Parse(m.Groups["sides"].Value));
                    }
                    else
                    {
                        res += NRXRoll(channel, int.Parse(m.Groups["value"].Value), int.Parse(m.Groups["sides"].Value), int.Parse(m.Groups["critical"].Value));
                    }
                    r++;
                }

                if (res.EndsWith("failed"))
                {
                    return;
                }
                else
                {
                    send_msg += res + '\n';
                }
            }

            foreach (Match m in dxs)
            {
                string res = "";

                if (m.Groups["critical"].Value == "")
                {
                    res += NRXRoll(channel, int.Parse(m.Groups["value"].Value), 10);
                }
                else
                {
                    res += NRXRoll(channel, int.Parse(m.Groups["value"].Value), 10, int.Parse(m.Groups["critical"].Value));
                }

                if (res.EndsWith("failed"))
                {
                    return;
                }
                else
                {
                    send_msg += res + '\n';
                }
                r++;
            }

            if (d + r == 0)
            {
                return;
            }

            int fix_sum = 0;

            foreach (Match m in fixes)
            {
                fix_sum += int.Parse(m.Groups["fix"].Value);
            }

            send_msg += "\nResult: " + RandomManager.DiceResultHistory.Sum(val => (Int64)val);

            if (fixes.Count != 0)
            {
                send_msg += ' ' + fix_sum.ToString("+ #;- #") + " -> " + (RandomManager.DiceResultHistory.Sum() + fix_sum);
            }

            if (target_match.Success)
            {
                string target = target_match.Groups["target"].Value;

                //if (5 >= (RandomManager.DiceResultHistory.Sum() + fix_sum) && int.Parse(target) >= (RandomManager.DiceResultHistory.Sum() + fix_sum))
                //{
                //	send_msg += "    _**__Critical!!!__**_";
                //}
                //else if(int.Parse(target) >= (RandomManager.DiceResultHistory.Sum() + fix_sum))
                //{
                //	send_msg += "    **Success**";
                //}
                //else if(95 >= (RandomManager.DiceResultHistory.Sum() + fix_sum))
                //{
                //	send_msg += "    **Fail**";
                //}
                //else
                //{
                //	send_msg += "    _**__Famble...__**_";
                //}

                await CocJudgeImageOutput.PutCocPDiceImageAsync(msg, RandomManager.DiceResultHistory.Sum() + fix_sum, int.Parse(target));

                RandomManager.ClearHistory();

                return;
            }

            if (send_msg.Length > 2000)
            {
                await TooLongStringAsync(msg, send_msg);

                return;
            }

            await msg.Channel.SendMessageAsync(send_msg);
        }