public static bool TwiceCheck(DMEnv env, Investigator inv, string valueName, bool isBonus, int hardness)
        {
            Value       value   = inv.Values[valueName];
            CheckResult bigger  = value.Check(hardness);
            CheckResult smaller = value.Check(hardness);

            if (bigger.points < smaller.points)
            {
                CheckResult tmp = bigger;
                bigger  = smaller;
                smaller = tmp;
            }
            if (isBonus)
            {
                env.AppendLine($"{inv.Name}的奖励{valueName}:")
                .Append(GenResultStr(inv, smaller, false) + $"({bigger.points})," + smaller.ActualTypeString);
                return(smaller.succeed);
            }
            else
            {
                env.AppendLine($"{inv.Name}的惩罚{valueName}:")
                .Append(GenResultStr(inv, bigger, false) + $"({smaller.points})," + bigger.ActualTypeString);
                return(bigger.succeed);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
 public static void PrintAllHelp(DMEnv env)
 {
     env.AppendLine("可用的命令集:");
     foreach (CommandNode <DMEnv> node in Global.Dispatcher.Commands)
     {
         env.AppendLine("----------------");
         env.AppendLine(string.Join("\n", node.GetHelp()));
     }
 }
예제 #4
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 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 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);
     }
 }
예제 #7
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);
        }
        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);
        }
        public static bool SimpleCheck(DMEnv env, Investigator inv, string valueName, int hardness)
        {
            CheckResult result = inv.Values[valueName].Check(hardness);
            string      hardnessStr;

            switch (hardness)
            {
            case CheckResult.ExtremeSuccess: hardnessStr = "极难"; break;

            case CheckResult.HardSuccess: hardnessStr = "困难"; break;

            case CheckResult.NormalSuccess: hardnessStr = "普通"; break;

            default: hardnessStr = "普通"; break;
            }

            env.AppendLine($"{inv.Name}的{hardnessStr}{valueName}:")
            .Append(GenResultStr(inv, result, true));
            return(result.succeed);
        }
예제 #10
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);
        }
예제 #11
0
        private static bool FightBack(DMEnv env, Investigator target, string weaponName)
        {
            Item       selfWeapon = target.GetItem(weaponName);
            FightEvent fight      = target.PeekNextFight(env.Sce, out Investigator source, out Item oppositeWeapon);

            if (oppositeWeapon.Type != "肉搏")
            {
                env.Next = oppositeWeapon + "不是肉搏武器,仅肉搏可反击!";
                return(false);
            }

            if (!target.Check(oppositeWeapon.SkillName, out CheckResult result, out string str))
            {
                env.Next = str;
                return(false);
            }

            target.Fights.Dequeue();

            env.AppendLine(str);
            if (result.succeed && result.type < fight.ResultType)
            {
                int mulfunctionCheckResult = Dice.Roll(100);
                if (mulfunctionCheckResult > selfWeapon.Mulfunction)
                {
                    env.Append($"{target.Name}的{selfWeapon.Name}{(selfWeapon.Type == "射击" ? "炸膛" : "坏掉")}了!({mulfunctionCheckResult} > {selfWeapon.Mulfunction})");
                    return(false);
                }
                env.Append($"反击了{fight}!");
                CalculateDamage(env, target, source, weaponName);
            }
            else
            {
                env.Append($"受到了{fight}!");
                CalculateDamage(env, source, target, fight.WeaponName);
            }
            return(true);
        }
예제 #12
0
        public static bool LoadBullets(DMEnv env, string name, Dice amount)
        {
            Investigator inv = env.Inv;

            if (!inv.Inventory.TryGetValue(name, out Item item))
            {
                env.Append($"{inv.Name}的物品栏中不存在{name}");
                return(false);
            }
            int left = item.Capacity - item.CurrentLoad;

            if (left <= 0)
            {
                env.Append("弹匣已经装满,无需装弹");
                return(false);
            }
            int loaded = Math.Min(left, amount.Roll());

            item.CurrentLoad += loaded;
            env.Save();
            env.AppendLine($"{inv.Name}为{name}装弹{loaded}")
            .Append($"弹药:{item.CurrentLoad}/{item.Capacity}");
            return(false);
        }
예제 #13
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();
        }
예제 #14
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();
        }