Пример #1
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);
        }
Пример #2
0
        public static void OrderByValue(DMEnv env, Scenario scenario, string[] invNames, string valueName)
        {
            IList <string> notFoundNames        = new List <string>();
            IList <string> notFoundValues       = new List <string>();
            IDictionary <Investigator, int> map = new Dictionary <Investigator, int>();

            foreach (string name in invNames)
            {
                Match  m       = Regex.Match(name, @"[+-]\d+$");
                int    fix     = 0;
                string invName = name;
                if (m.Success)
                {
                    invName = name.Substring(0, name.Length - m.Value.Length);
                    fix     = int.Parse(m.Value);
                }
                if (scenario.TryGetInvestigator(invName, out Investigator inv))
                {
                    if (inv.Values.TryGet(valueName, out Value value))
                    {
                        map[inv] = value.Val + fix;
                    }
                    else
                    {
                        notFoundValues.Add(invName);
                    }
                }
                else
                {
                    notFoundNames.Add(invName);
                }
            }

            if (map.Count > 0)
            {
                List <Investigator> list = new List <Investigator>(map.Keys);
                list.Sort((a, b) => map[b] - map[a]);
                for (int i = 0; i < list.Count; i++)
                {
                    if (i > 0)
                    {
                        env.Append(" > ");
                    }
                    Investigator inv = list[i];
                    env.Append(inv.Name).Append('(').Append(inv.Is("HIDE_VALUE") ? "???" : Convert.ToString(map[inv])).Append(')');
                }
            }
            if (notFoundNames.Count > 0)
            {
                env.LineAppend("未找到调查员:").Append(string.Join("、", notFoundNames));
            }
            if (notFoundValues.Count > 0)
            {
                env.LineAppend($"未找到带{valueName}调查员:").Append(string.Join("、", notFoundValues));
            }
        }
 public static void DisplayInventory(DMEnv env, Investigator inv, string itemName)
 {
     if (inv.Inventory.Count == 0)
     {
         env.Next = $"{inv.Name}没有物品";
     }
     if (!string.IsNullOrEmpty(itemName))
     {
         if (inv.Inventory.TryGetValue(itemName, out Item it))
         {
             env.AppendLine($"{inv.Name}的 {itemName}:")
             .Append("技能名:").AppendLine(it.SkillName)
             .Append("类型:").AppendLine(it.Type)
             .Append("伤害:").AppendLine(it.Damage)
             .Append("贯穿:").AppendLine(it.Impale ? "是" : "否")
             .Append("连发数:").AppendLine(it.MaxCount.ToString())
             .Append("弹匣:").AppendLine(it.Capacity.ToString())
             .Append("故障值:").AppendLine(it.Mulfunction.ToString())
             .Append("弹药:").AppendLine(it.CurrentLoad.ToString())
             .Append("消耗:").Append(it.Cost.ToString());
         }
         else
         {
             env.Next = $"{inv.Name}没有{itemName}";
         }
         return;
     }
     foreach (Item item in inv.Inventory.Values)
     {
         env.LineAppend(item.Name);
     }
 }
Пример #4
0
 public static void Grow(DMEnv env, Investigator inv, string[] skillNames, Dice dice)
 {
     env.Append(inv.Name + "的成长:");
     foreach (string skillName in skillNames)
     {
         env.LineAppend(Grow(inv, skillName, dice));
     }
     env.Save();
 }
Пример #5
0
        public static void Step(DMEnv env)
        {
            var horses   = env.Sce.Horses;
            var scenario = env.Sce;

            if (horses.Count == 0)
            {
                env.Next = "🏇还未开始!";
                return;
            }
            HashSet <int> winners = new HashSet <int>();

            for (int i = 0; i < horses.Count; i++)
            {
                if (horses[i].Step())
                {
                    winners.Add(i);
                }
            }
            env.Append(DisplayHorses(horses));
            if (winners.Count > 0)
            {
                env.LineAppend("赢家:");
                Dictionary <string, int> profits = new Dictionary <string, int>();
                foreach (int index in winners)
                {
                    env.Append(Indices.ElementAt(index));
                    double bonus = BonusMin + Horse.Rand.NextDouble() * (BonusMax - BonusMin);
                    foreach (var e in horses[index].Bets)
                    {
                        profits[e.Key] = (int)(e.Value * bonus) + (profits.ContainsKey(e.Key) ? profits[e.Key] : 0);
                    }
                }
                env.AppendLine("号🐎。");
                foreach (var e in profits)
                {
                    if (scenario.TryGetInvestigator(e.Key, out Investigator inv))
                    {
                        if (!inv.Values.TryWidelyGet("账户", out Value account))
                        {
                            account = new Value(0);
                            inv.Values.Put("账户", account);
                        }
                        env.AppendLine(inv.Change("账户", e.Value));
                    }
                    else
                    {
                        env.AppendLine($"未找到【{e.Key}】,很遗憾,他的奖金全没了");
                    }
                }
                horses.Clear();
                env.Append("🏇已结束!");
            }
            env.Save();
        }
Пример #6
0
 public static void DrawProperties(DMEnv env, int size, int age)
 {
     for (int i = 0; i < size; i++)
     {
         if (i > 0)
         {
             env.LineAppend("----------------").Line();
         }
         DrawProperty(env, age);
     }
 }
Пример #7
0
        public static void Kill(DMEnv env, Investigator source, int index, string weaponName)
        {
            List <Horse> horses = env.Sce.Horses;

            if (horses.Count == 0)
            {
                env.Next = "🏇已经结束!";
                return;
            }
            if (index <= 0 || index > horses.Count)
            {
                env.Next = $"找不到{index}号🐎";
                return;
            }

            Horse  horse     = horses[index - 1];
            string horseName = Indices[index - 1] + "号🐎";

            if (horse.Sources.Contains(source.Name))
            {
                env.Next = $"{source.Name}本轮已经杀过此🐎了!";
                return;
            }

            Item w = source.GetItem(weaponName);

            horse.Sources.Add(source.Name);

            if (!source.Check(w.SkillName, out CheckResult sr, out string str))
            {
                env.Save();
                env.Append(str);
                return;
            }
            env.AppendLine(str);
            if (!sr.succeed)
            {
                env.Save();
                env.Append("杀🐎失败,该回合不能再杀此🐎");
                return;
            }
            // 检定🐎的闪避
            CheckResult hr = new Value(horse.Ponential).Check();

            env.AppendLine($"{horseName} => {hr.points},逃离{hr.TypeString}");
            if (hr.succeed && hr.type <= sr.type)
            {
                env.Save();
                env.Next = $"{source.Name}没有打中飞速移动中的{horseName}";
                return;
            }
            // 计算伤害
            int r = Dice.RollWith(w.Damage, source.DamageBonus);

            env.Append($"造成伤害:{r}");
            if (r > 0)
            {
                int prev = horse.Health;
                horse.Health = Math.Min(Math.Max(0, prev - r), Horse.MaxHealth);
                env.LineAppend($"{horseName}的体力:{prev} - {r} => {horse.Health}");
                if (horse.Health <= 0)
                {
                    int totalBets = 0;
                    foreach (int bet in horse.Bets.Values)
                    {
                        totalBets += bet;
                    }
                    horse.Bets.Clear();
                    env.AppendLine($"{source.Name}获得{horseName}身上的所有筹码({totalBets})");
                    env.Append(source.Change("账户", totalBets));
                }
            }
            env.Save();
        }