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); }
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); }
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); }
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); } }
/// <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); }
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); } }
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 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); } }
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); } }
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); } }
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); }
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 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(); }
public static bool ExistSce(DMEnv env, Args args, object ori, out object arg, out string err) { arg = env.Sce; arg = null; err = null; return(true); }
public static string SendClaps(DMEnv env, Dice times) { if (times == null) { times = Dice.Of("1d5"); } return(env.Next = Repeat(Clap, times.Roll())); }
private static void CommitFight(DMEnv env, Investigator source, Investigator target, string weaponName, int points, int resultType) { FightEvent fight = new FightEvent(source.Name, target.Name, weaponName, points, resultType); target.Fights.Enqueue(fight); env.Save(); env.Next = target.Name + "即将受到" + fight; }
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); }
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)); }
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())); } }
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(); }
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 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 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); }
private static void Skip(DMEnv env, Investigator inv) { if (inv.Fights.Count > 0) { FightEvent fight = inv.Fights.Dequeue(); env.Save(); env.Next = $"已经跳过了来自{fight.SourceName}的打斗"; } env.Next = "没有需要跳过打斗"; }
public static void RemoveTags(DMEnv env, Investigator inv, string[] tags) { foreach (string tag in tags) { inv.Tags.Remove(tag.ToUpper()); } env.Save(); env.Next = inv.Name + "移除了标签:" + string.Join("、", tags); }
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}的数值与别名已被默认值覆盖!已有的数值可能被覆盖!"); }
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); }
public static void PrintHelp(DMEnv env, string head) { CommandNode <DMEnv> node = null; if ((node = Global.Dispatcher[head]) != null) { env.Next = string.Join("\n", node.GetHelp()); } env.Next = $"未找到指令:{head}"; }
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(); }