Пример #1
0
        public static string LuckyOneOfDay(DMEnv env, Scenario sce)
        {
            Investigator luckOne = null;
            int          luckMax = 0;

            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"))
                {
                    continue;
                }
                int luck = CalcLuck(inv, p, tlsn);
                if (luckOne == null || luck > luckMax)
                {
                    luckOne = inv;
                    luckMax = luck;
                }
            }
            if (luckOne == null)
            {
                env.Append("今天没有幸运儿");
                return(null);
            }
            else
            {
                env.Append(string.Format(Templete, luckMax, luckOne.Name, luckOne.Desc));
                return(luckOne.Name);
            }
        }
Пример #2
0
        public static bool UseSpell(DMEnv env, Investigator inv, string name)
        {
            Scenario sce = env.Sce;

            if (!inv.Spells.Contains(name))
            {
                env.Append(inv.Name + "还没学会" + name);
                return(false);
            }
            else if (!sce.Spells.TryGetValue(name, out Spell spell))
            {
                env.Append("不存在法术:" + name);
                return(false);
            }
            else if (!spell.Use(inv, out string reply))
            {
                env.Append("施法失败\n" + reply);
                return(false);
            }
            else
            {
                env.Save();
                env.Append(inv.Name + "使用了" + name + (inv.Is("HIDE_VALUE") ? "" : reply));
                return(true);
            }
        }
Пример #3
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();
        }
Пример #4
0
        private static bool Attack(DMEnv env, Investigator source, Investigator target, string weaponName)
        {
            Item w = source.GetItem(weaponName);

            if (!source.Check(w.SkillName, out CheckResult result, out string str))
            {
                return(false);
            }
            env.AppendLine(str);
            if (!result.succeed)
            {
                env.Append("攻击失败");
                return(false);
            }

            int mulfunctionCheckResult = Dice.Roll(100);

            if (mulfunctionCheckResult > w.Mulfunction)
            {
                env.Append($"{source.Name}的{w.Name}{(w.Type == "射击" ? "炸膛" : "坏掉")}了!({mulfunctionCheckResult} > {w.Mulfunction})");
            }

            switch (w.Type)
            {
            case "肉搏": CommitFight(env, source, target, weaponName, result.points, result.type); return(true);

            case "投掷": CommitFight(env, source, target, weaponName, result.points, result.type); return(true);

            case "射击": CalculateDamage(env, source, target, weaponName); return(true);

            default: env.Append($"未知的武器类型:{w.Type},只能是:肉搏、投掷、射击"); break;
            }

            return(false);
        }
Пример #5
0
        public static bool PickItem(DMEnv env, string name, string newName)
        {
            if (newName == null)
            {
                newName = name;
            }
            Scenario     sce = env.Sce;
            Investigator inv = env.Inv;

            if (!sce.Desk.TryGetValue(name, out Item item))
            {
                env.Append($"桌子上没有物品:{name}");
                return(false);
            }
            if (inv.Inventory.ContainsKey(newName))
            {
                env.Append($"{inv.Name}的物品栏中已经存在{newName},请重命名");
                return(false);
            }
            item.Name = newName;
            inv.Inventory[item.Name] = item;
            sce.Desk.Remove(name);
            env.Save();
            env.Append($"{inv.Name}拾取了:{name}");
            return(true);
        }
Пример #6
0
        public static bool EditItem(DMEnv env, string name, string newName, Args dict)
        {
            if (newName == null)
            {
                newName = name;
            }
            Investigator inv = env.Inv;

            if (!inv.Inventory.TryGetValue(name, out Item item))
            {
                env.Append($"{inv.Name}的物品栏中不存在{name}");
                return(false);
            }
            string wiChanges = FillWeaponInfo(item, dict);

            if (!string.Equals(name, newName))
            {
                inv.Inventory.Remove(name);
                item.Name = newName;
                inv.Inventory[item.Name] = (item);
                env.Save();
                env.Append($"{inv.Name}重命名了物品:{name} => {newName}");
                return(true);
            }
            else
            {
                env.Save();
                env.Append($"{inv.Name}编辑了物品:{name}" + wiChanges);
                return(true);
            }
        }
Пример #7
0
        public static bool CreateSpell(DMEnv env, string name, Args cost)
        {
            Scenario sce = env.Sce;

            if (sce.Spells.ContainsKey(name))
            {
                env.Append("已经存在法术:" + name);
                return(false);
            }

            Dictionary <string, string> costStr = new Dictionary <string, string>();

            foreach (string valueName in cost.Keys)
            {
                if (cost.TryGet(valueName, out Dice dice))
                {
                    costStr[valueName] = dice.ToString();
                }
            }
            Spell spell = new Spell(name, costStr);

            sce.Spells[name] = spell;
            env.Save();
            env.Append("成功创造法术:" + name);
            return(false);
        }
Пример #8
0
        public static bool ThrowItem(DMEnv env, string name, string newName)
        {
            if (newName == null)
            {
                newName = name;
            }
            Scenario     sce = env.Sce;
            Investigator inv = env.Inv;

            if (sce.Desk.ContainsKey(newName))
            {
                env.Append($"桌子上已有物品:{newName},请重命名");
                return(false);
            }
            if (!inv.Inventory.TryGetValue(name, out Item item))
            {
                env.Append($"{inv.Name}的物品栏中不存在{name}");
                return(false);
            }
            inv.Inventory.Remove(name);
            item.Name           = newName;
            sce.Desk[item.Name] = item;
            env.Save();
            env.Append($"{inv.Name}丢弃了{name}" + (name == newName ? "" : ",并重命名为:" + newName));
            return(true);
        }
Пример #9
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));
            }
        }
Пример #10
0
 public static void FillWithDefaultValues(DMEnv env, Scenario scenario, Investigator inv, bool force)
 {
     if (!force)
     {
         env.Append("覆盖操作有极大可能会对你已经设定的数值进行更改!若确定你在做什么,请在指令后面加上“强制”");
     }
     inv.Values.FillWith(Global.DefaultValues);
     SaveUtil.Save(scenario);
     env.Append($"{inv.Name}的数值与别名已被默认值覆盖!已有的数值可能被覆盖!");
 }
Пример #11
0
 public static bool SimpleCheckTo(DMEnv env, Investigator inv, string valueName, string target)
 {
     if (!inv.Check(valueName, out CheckResult result, out string str))
     {
         env.Append(str);
         return(false);
     }
     env.Append(str + (result.succeed ? $",{inv.Name}把{target}给{valueName}了!" : ""));
     return(result.succeed);
 }
Пример #12
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();
        }
 public static bool SaveScenario(DMEnv env, string sceName)
 {
     if (Global.Scenarios.TryGetValue(sceName, out Scenario scenario))
     {
         SaveUtil.Save(scenario);
         env.Append("保存完毕:" + sceName);
         return(true);
     }
     env.Append($"未找到团:{sceName}");
     return(false);
 }
Пример #14
0
 public static bool RemoveVal(DMEnv env, Scenario scenario, Investigator inv, string valueName)
 {
     if (inv.Values.Remove(valueName, out bool isAlias))
     {
         SaveUtil.Save(scenario);
         env.Append($"移除了{inv.Name}的{(isAlias ? "别名" : "数值")}:{valueName}");
         return(true);
     }
     env.Append($"未找到{inv.Name}的{valueName}");
     return(false);
 }
Пример #15
0
        public static bool DestoryItem(DMEnv env, string name)
        {
            Investigator inv = env.Inv;

            if (!inv.Inventory.ContainsKey(name))
            {
                env.Append($"未找到{inv.Name}的{name}");
                return(false);
            }
            inv.Inventory.Remove(name);
            env.Save();
            env.Append($"{inv.Name}销毁了了物品:{name}");
            return(true);
        }
Пример #16
0
        public static bool ForgetSpell(DMEnv env, Investigator inv, string name)
        {
            Scenario sce = env.Sce;

            if (!inv.Spells.Contains(name))
            {
                env.Append(inv.Name + "还没学会" + name);
                return(false);
            }
            inv.Spells.Remove(name);
            env.Save();
            env.Append(inv.Name + "忘记了法术:" + name);
            return(true);
        }
Пример #17
0
 public static bool NewName(DMEnv env, Scenario scenario, Investigator inv, string valueName, string newName)
 {
     if (inv.Values.SetAlias(newName, valueName))
     {
         SaveUtil.Save(scenario);
         env.Append($"{inv.Name}的{valueName}的新别名:{newName}");
         return(true);
     }
     else
     {
         env.Append($"{inv.Name}不存在原本名为{valueName}的数值");
         return(false);
     }
 }
Пример #18
0
        public static bool DestorySpell(DMEnv env, string name)
        {
            Scenario sce = env.Sce;

            if (!sce.Spells.ContainsKey(name))
            {
                env.Append("不存在法术:" + name);
                return(false);
            }
            sce.Spells.Remove(name);
            env.Save();
            env.Append("成功销毁法术:" + name);
            return(true);
        }
Пример #19
0
        private static bool Dodge(DMEnv env, Investigator inv)
        {
            FightEvent fight = inv.PeekNextFight(env.Sce, out Investigator source, out Item oppositeWeapon);

            if (oppositeWeapon.Type == "射击")
            {
                env.Next = oppositeWeapon + "是射击武器,仅肉搏或投掷武器可闪避!";
                return(false);
            }

            if (!inv.Check("闪避", out CheckResult result, out string str))
            {
                env.Next = str;
                return(false);
            }
            inv.Fights.Dequeue();

            env.AppendLine(str);
            env.Save();
            if (result.succeed && result.type <= fight.ResultType)
            {
                env.Append($"躲开了{fight}!");
                return(true);
            }
            else
            {
                env.AppendLine($"受到了{fight}");
                CalculateDamage(env, source, inv, fight.WeaponName);
                return(false);
            }
        }
 public static void DisplayValue(DMEnv env, Investigator inv, string valueName)
 {
     if (!string.IsNullOrEmpty(valueName))
     {
         if (inv.Values.TryWidelyGet(valueName, out Value value))
         {
             StringBuilder b = new StringBuilder()
                               .Append($"{inv.Name}的{valueName}:")
                               .Append(value.Val).Append('/')
                               .Append(value.HardVal).Append('/')
                               .Append(value.ExtremeVal);
             if (value.Max > 0)
             {
                 b.Append('(').Append(value.Max).Append(')');
             }
         }
         else
         {
             env.Next = $"未找到{inv.Name}的{valueName}";
         }
         return;
     }
     else
     {
         env.AppendLine($"{inv.Name}的数值:");
         foreach (string name in inv.Values.Names)
         {
             env.Append(name).Append(':').Append(inv.Values[name]).Append(' ');
         }
     }
 }
 public static bool LoadScenario(DMEnv env, long groupId, string sceName)
 {
     try {
         if (SaveUtil.TryLoad(sceName, out Scenario scenario))
         {
             Global.Scenarios[sceName] = scenario;
             Global.Groups[groupId]    = scenario.Name;
             env.Append($"读团完毕:{sceName}");
             return(true);
         }
     } catch (Exception e) {
         env.Append("读团失败,原因:" + e.Message);
         return(false);
     }
     env.Append($"读团失败:{sceName}");
     return(false);
 }
Пример #22
0
        public static bool ChangeVal(DMEnv env, Scenario scenario, Investigator inv, string valueName, Dice increment, bool posotive)
        {
            int inc = increment.Roll() * (posotive ? 1 : -1);

            env.Append(inv.Change(valueName, inc));
            SaveUtil.Save(scenario);
            return(true);
        }
Пример #23
0
        public static void SetDB(DMEnv env, Dice db)
        {
            env.Inv.DamageBonus = db.ToString();
            env.Save();

            env.Append(env.Inv.Name).AppendLine("的数据:")
            .Append("体格:").Append(env.Inv.Build).Append(',')
            .Append("伤害加值:").Append(env.Inv.DamageBonus);
        }
 public static bool LoadScenario(DMEnv env, long groupId)
 {
     if (!Global.Groups.TryGetValue(groupId, out string sceName))
     {
         env.Append("该群还未有存档存在");
         return(false);
     }
     return(LoadScenario(env, groupId, sceName));
 }
Пример #25
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();
 }
Пример #26
0
        public static void ReCalc(DMEnv env, Investigator inv)
        {
            inv.Calc(out string err);
            env.Save();

            env
            .Append(inv.Name).AppendLine("的数据:")
            .Append("体格:").Append(inv.Build).Append(',')
            .Append("伤害加值:").Append(inv.DamageBonus);
        }
        public static bool StartScenario(DMEnv env, long groupId, long selfId, string sceName)
        {
            Scenario s = new Scenario(sceName);

            Global.Scenarios[sceName] = s;
            Global.Groups[groupId]    = s.Name;
            SaveUtil.Save(s);
            env.Append($"【{sceName}】开团啦!");
            return(true);
        }
Пример #28
0
        public static bool LearnSpell(DMEnv env, Investigator inv, string name)
        {
            Scenario sce = env.Sce;

            if (!sce.Spells.ContainsKey(name))
            {
                env.Append("不存在法术:" + name);
                return(false);
            }
            else if (inv.Spells.Contains(name))
            {
                env.Append(inv.Name + "已经学会了" + name);
                return(false);
            }
            inv.Spells.Add(name);
            env.Save();
            env.Append(inv.Name + "学习了法术:" + name);
            return(true);
        }
Пример #29
0
        public static bool CheckAgainst(DMEnv env, Investigator inv, string valueName, Investigator target, string againstValueName, bool byLevel)
        {
            CheckResult selfResult = inv.Values[valueName].Check();

            if (!target.Values.TryWidelyGet(againstValueName, out Value againstValue))
            {
                env.Append($"{target.Name}没有{againstValueName}");
                return(false);
            }
            CheckResult targetResult = againstValue.Check();
            string      resultStr    = null;
            bool        r            = false;

            if (byLevel)
            {
                if (!selfResult.succeed)
                {
                    resultStr = "完败";
                    r         = false;
                }
                else if (selfResult.type == targetResult.type)
                {
                    resultStr = "平分秋色";
                    r         = true;
                }
                else
                {
                    resultStr = (r = selfResult.type < targetResult.type) ? "完胜" : "完败";
                }
            }
            else
            {
                if (!selfResult.succeed)
                {
                    resultStr = "失败";
                    r         = false;
                }
                else if (selfResult.points == targetResult.points)
                {
                    resultStr = "平局";
                    r         = true;
                }
                else
                {
                    resultStr = (r = selfResult.points < targetResult.points) ? "胜利" : "失败";
                }
            }

            env
            .AppendLine($"{inv.Name}的{valueName}:" + GenResultStr(inv, selfResult, false))
            .AppendLine($"{target.Name}的{againstValueName}:" + GenResultStr(target, targetResult, false))
            .Append(inv.Name).Append(":").Append(resultStr);
            return(r);
        }
Пример #30
0
        public static bool CreateInv(DMEnv env, string name, string desc, Args dict)
        {
            Scenario     sce = env.Sce;
            Investigator inv = new Investigator(name, desc);

            inv.Values.FillWith(Global.DefaultValues);

            foreach (string key in dict.Keys)
            {
                if (dict.TryGet(key, out Value value))
                {
                    inv.Values.Put(key, value);
                }
            }
            inv.Calc(out string err);

            env.Append("名字:", name).Line();
            if (!string.IsNullOrEmpty(desc))
            {
                env.Append("描述:", desc).Line();
            }
            if (CheckNameInputHardness(name, out string hint))
            {
                env.AppendLine(hint).Line();
            }
            env
            .Append("体格:").Append(inv.Build)
            .Append("伤害加值:").AppendLine(inv.DamageBonus);

            foreach (string key in inv.Values.Names)
            {
                if (inv.Values.TryWidelyGet(key, out Value value))
                {
                    env.Append($"{key}:{value} ");
                }
            }
            sce.PutInvestigator(inv);
            sce.Control(env.SelfId, inv.Name);
            env.Save();
            return(true);
        }