Example #1
0
        public static void St(DMEnv env, Investigator inv, string str)
        {
            ValueSet values = inv.Values;

            env.Append(inv.Name).Append("的数值:");
            Regex reg = new Regex(@"(\D+)(\d+)");
            Match m   = reg.Match(str);
            int   i   = 0;

            while (m.Success)
            {
                int    val  = int.TryParse(m.Groups[2].Value, out int v) ? v : 1;
                string name = m.Groups[1].Value;
                if (values.TryWidelyGet(name, out Value value))
                {
                    value.Set(val);
                }
                else
                {
                    value = new Value(val);
                    values.Put(name, value);
                }
                if (i++ % 3 == 0)
                {
                    env.Line();
                }
                env.Append(name).Append(':').Append(value).Append(' ');
                m = m.NextMatch();
            }
            env.Save();
        }
Example #2
0
        /// <summary>
        /// 回复内容
        /// </summary>
        /// <param name="msg">接受的信息</param>
        /// <param name="env">环境</param>
        /// <returns>是否有信息输出</returns>
        public static bool Reply(string msg, DMEnv env)
        {
            string raw = msg.Substring(Prefix.Length);

            string[] cmds = Regex.Split(raw, @"[ \t\n\r;;]+" + Prefix);
            bool     flag = false;

            foreach (string c in cmds)
            {
                try {
                    if (Sleep && !Regex.IsMatch(c, @"^全局\s+"))
                    {
                        break;
                    }
                    Dispatcher.Dispatch(c, env, out ICmdResult result);
                    if (!result.IsError)
                    {
                        env.Line();
                        result.Execute();
                        flag = true;
                    }
                    else if (Debug)
                    {
                        env.LineAppend(result.ToString());
                        flag = true;
                    }
                } catch (DiceException ex) {
                    env.LineAppend(ex.Message);
                    flag = true;
                }
            }
            return(flag);
        }
Example #3
0
 public static void Repeat(DMEnv env, CommandResult <DMEnv> cmd, int times)
 {
     for (int i = 0; i < times; i++)
     {
         if (i != 0)
         {
             env.Line();
         }
         cmd.Execute();
     }
 }
 public static void DisplaySpells(DMEnv env, Investigator inv)
 {
     if (inv.Spells.Count == 0)
     {
         env.Next = inv.Name + "不会任何法术";
     }
     env.Append($"{inv.Name}的法术:");
     foreach (string sn in inv.Spells)
     {
         env.Line().Append(sn);
     }
 }
 public static void DisplayFightEvents(DMEnv env, Investigator inv)
 {
     if (inv.Fights.Count == 0)
     {
         env.Next = $"{inv.Name}没有战斗事件";
         return;
     }
     env.Append($"{inv.Name}的战斗事件:");
     foreach (FightEvent fight in inv.Fights)
     {
         env.Line().Append($"来自{fight.SourceName}使用{fight.WeaponName ?? "身体"}的攻击");
     }
 }
 public static void DisplaySpell(DMEnv env, Scenario sce, Investigator inv, string spellName)
 {
     if (!sce.Spells.TryGetValue(spellName, out Spell spell))
     {
         env.Next = "不存在法术:" + spellName;
     }
     else if (!inv.Spells.Contains(spellName))
     {
         env.Next = inv.Name + "还未学会" + spellName;
     }
     env.Append($"{spellName}消耗:");
     foreach (var e in spell.Cost)
     {
         env.Line().Append(e.Key).Append(':').Append(e.Value);
     }
 }
        public static string ListLuck(DMEnv env, Scenario sce)
        {
            Dictionary <string, int> lucks = new Dictionary <string, int>();

            long   seed = DateTime.Today.Ticks;
            int    p    = (int)seed;
            string tlsn = GetTodayLuckySkillName(seed);

            foreach (Investigator inv in sce.Investigators.Values)
            {
                if (!inv.Is("HIDE_VALUE"))
                {
                    lucks[inv.Name] = CalcLuck(inv, p, tlsn);
                }
            }
            List <string> list = new List <string>(lucks.Keys);

            list.Sort((a, b) => lucks[b] - lucks[a]);
            for (int i = 0; i < list.Count; i++)
            {
                if (i > 0)
                {
                    env.Line();
                }
                string indexStr = Convert.ToString(i + 1) + ". ";
                switch (i + 1)
                {
                case 1: indexStr = "🥇"; break;

                case 2: indexStr = "🥈"; break;

                case 3: indexStr = "🥉"; break;
                }
                env.Append(indexStr).Append(list[i]).Append('(').Append(lucks[list[i]]).Append(')');
            }
            return(list.FirstOrDefault());
        }
Example #8
0
        private static void CalculateDamage(DMEnv env, Investigator source, Investigator target, string weaponName)
        {
            Item w = null;

            if (weaponName != null)
            {
                if (!source.Inventory.TryGetValue(weaponName, out w))
                {
                    env.Next = $"未找到{source.Name}武器:{weaponName}";
                }
            }
            else
            {
                w = new Item("身体");
            }

            if (w.CurrentLoad <= 0)
            {
                env.Next = "弹药不足,请装弹";
            }

            // 计算伤害值
            int r    = Dice.RollWith(w.Damage, source.DamageBonus);
            int cost = Math.Min(w.Cost, w.CurrentLoad);

            w.CurrentLoad -= cost;
            env.Append($"{source.Name}对{target.Name}造成伤害{r}");
            if (w.Cost == 0)
            {
                env.Append($",弹药消耗{cost},弹药剩余{w.CurrentLoad}/{w.Capacity}");
            }
            env.Line();
            // 计算护甲格挡
            if (target.Values.TryGet("护甲", out Value protect) && protect.Val > 0)
            {
                r = Math.Max(0, r - protect.Val);
                env.AppendLine("护甲阻挡部分伤害,最终实际伤害:" + r);
            }
            // 施加伤害
            if (r > 0)
            {
                if (!target.Values.TryGet("体力", out Value th))
                {
                    env.Append("而对方没有体力").ToString();
                    return;
                }
                // 真正减少体力
                int prev = th.Val;
                env.Append(target.Change("体力", -r));
                if (prev < r)   // 检定是否可急救
                {
                    env.Line().Append("受伤过重,无法治疗");
                }
                else if (r >= (int)(th.Max / 2.0) && th.Val > 0)     // 检定昏迷
                {
                    env.Line().Append("一次失血过半,");
                    if (!target.Values.TryWidelyGet("意志", out Value san))
                    {
                        san = new Value(50);
                    }
                    if (!target.Check("意志", out CheckResult cr, out string str))
                    {
                        env.Append(str);
                        return;
                    }
                    env.Append(str).Append(",");
                    if (cr.succeed)
                    {
                        env.Append($"{target.Name}成功挺住");
                    }
                    else
                    {
                        env.Append($"{target.Name}昏厥");
                    }
                }
            }
            env.Save();
        }
Example #9
0
        public static bool Check(DMEnv env, Investigator inv)
        {
            HashSet <string> missingValueNames = new HashSet <string>();
            ValueSet         values            = inv.Values;

            foreach (string name in BasicNine)
            {
                if (!values.Has(name))
                {
                    missingValueNames.Add(name);
                }
            }
            int           maxHealth, maxMagic, calcDodge;
            List <string> warnings = new List <string>();

            // 通过体质与体型检查体力数值
            if (!values.TryGet("体力", out Value health))
            {
                missingValueNames.Add("体力");
            }
            else if (health.Max <= 0)
            {
                warnings.Add("【体力】未设上限");
            }
            else if (
                !values.TryGet("体型", out Value siz) &&
                !values.TryGet("体质", out Value con) &&
                health.Max != (maxHealth = (int)((siz.Val + con.Val) / 10.0)))
            {
                warnings.Add($"【体力】上限不等于[体型]与[体质]之和的十分之一({maxHealth})");
            }
            // 通过意志检查魔法数值
            if (!values.TryGet("魔法", out Value magic))
            {
                missingValueNames.Add("魔法");
            }
            else if (magic.Max <= 0)
            {
                warnings.Add("【魔法】未设上限");
            }
            else if (
                !values.TryGet("意志", out Value pow) &&
                magic.Max != (maxMagic = (int)(pow.Val / 5.0)))
            {
                warnings.Add($"【魔法】上限不等于[意志]的五分之一({maxMagic})");
            }
            // 通过意志检查理智数值
            if (!values.TryGet("理智", out Value sannity))
            {
                missingValueNames.Add("理智");
            }
            else if (
                !values.TryGet("意志", out Value pow) &&
                magic.Max != pow.Val)
            {
                warnings.Add($"【理智】不等于[意志]的值({pow.Val})");
            }
            // 通过敏捷检查闪避数值
            if (!values.TryGet("闪避", out Value dodge))
            {
                missingValueNames.Add("闪避");
            }
            else if (
                !values.TryGet("敏捷", out Value dex) &&
                dodge.Max != (calcDodge = (int)(dex.Val / 2.0)))
            {
                warnings.Add($"【闪避】不等于[敏捷]的一半({calcDodge})");
            }

            if (missingValueNames.Count == 0 && warnings.Count == 0)
            {
                env.Next = "未发现数据错误(不包括体格、伤害加值)";
                return(true);
            }

            if (missingValueNames.Count > 0)
            {
                env.Append("缺失数据:" + string.Join("、", missingValueNames));
                if (warnings.Count > 0)
                {
                    env.Line();
                }
            }
            if (warnings.Count > 0)
            {
                env.Append(string.Join("\n", warnings));
            }

            return(false);
        }
        public static void DrawProperty(DMEnv env, int age)
        {
            Dictionary <string, int> result = new Dictionary <string, int>();
            Dictionary <string, int> addons = new Dictionary <string, int>();
            int rest = 0;

            // 基础值
            foreach (var e in properties)
            {
                result[e.Key] = e.Value.Roll() * 5;
            }
            // 年龄的影响
            if (age > 0)
            {
                if (age < 20)
                {
                    ConCheck(-5, "力量", "体型", addons);
                    addons["教育"] = -5;
                }
                else if (age < 40)
                {
                    AddEdu(1, result, addons);
                }
                else if (age < 50)
                {
                    AddEdu(2, result, addons);
                    ConCheck(-5, "力量", "体质", "敏捷", addons);
                    addons["外貌"] = -5;
                }
                else if (age < 60)
                {
                    AddEdu(3, result, addons);
                    ConCheck(-10, "力量", "体质", "敏捷", addons);
                    addons["外貌"] = -10;
                }
                else if (age < 70)
                {
                    AddEdu(4, result, addons);
                    ConCheck(-20, "力量", "体质", "敏捷", addons);
                    addons["外貌"] = -15;
                }
                else if (age < 80)
                {
                    AddEdu(4, result, addons);
                    ConCheck(-40, "力量", "体质", "敏捷", addons);
                    addons["外貌"] = -20;
                }
                else
                {
                    AddEdu(4, result, addons);
                    ConCheck(-80, "力量", "体质", "敏捷", addons);
                    addons["外貌"] = -25;
                }
            }
            // 统计
            int i = 0;

            foreach (var e in result)
            {
                env.Append(e.Key).Append(':');
                int value = e.Value;
                if (addons.TryGetValue(e.Key, out int addon))
                {
                    value += addon;
                    value  = Math.Max(0, Math.Min(value, 99));
                    env
                    .Append(value)
                    .Append('(')
                    .Append(e.Value).Append(addon >= 0 ? "+" + addon : Convert.ToString(addon))
                    .Append(')');
                }
                else
                {
                    env.Append(e.Value);
                }
                env.Append(';');
                rest += value;
                i++;
                if (i % 2 == 0)
                {
                    env.Line();
                }
            }
            int luck = Dice.Roll("3d6") * 5;

            env.Append("幸运:");
            if (age > 0 && age < 20)
            {
                int addLuck = Dice.Roll("3d6") * 5;
                env.Append(Math.Max(luck, addLuck)).Append('(').Append(Math.Min(luck, addLuck)).Append(')');
            }
            else
            {
                env.Append(luck);
            }
            env.Line();
            env.Append($"带幸运:{rest + luck},不带幸运:{rest}");
        }