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 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 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 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); }
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 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); } }
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 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 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 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); }
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 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 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 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); }
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); }
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); }
public static bool CreateItem(DMEnv env, string name, Args dict) { Investigator inv = env.Inv; if (inv.Inventory.ContainsKey(name)) { env.Next = $"{inv.Name}的物品栏中已经存在{name},请重命名"; return(false); } Item item = new Item(name); env.Append($"{inv.Name}创造了物品:{name}" + FillWeaponInfo(item, dict)); inv.Inventory[name] = item; env.Save(); return(true); }
public static void Bet(DMEnv env, Investigator inv, int index, int amount) { var horses = env.Sce.Horses; if (horses.Count == 0) { env.Next = "🏇还未开始!"; return; } if (amount < 0) { env.Next = "必须输入账户且必须大于零!"; return; } else if (index <= 0 || index > horses.Count) { env.Next = $"找不到{index}号🐎"; return; } if (!inv.Values.TryGet("账户", out Value account)) { env.Next = $"{inv.Name}没有账户"; return; } else if (account.Val < amount) { env.Next = $"{inv.Name}的账户只有{account.Val}不足{amount}"; return; } account.Add(-amount); Horse horse = horses[index - 1]; if (horse.Bets.ContainsKey(inv.Name)) { horse.Bets[inv.Name] += amount; } else { horse.Bets[inv.Name] = amount; } env.Save(); env.Next = $"{inv.Name}下注成功,对象:{index}号🐎,金额:{amount},总金额:{horse.Bets[inv.Name]}"; }
public static bool Rename(DMEnv env, string name) { Investigator inv = env.Inv; string oldName = inv.Name; if (oldName == name) { env.Next = "新旧名字相同,无需更改"; return(false); } inv.Name = name; env.Sce.Investigators.Remove(oldName); env.Sce.PutInvestigator(inv); env.Sce.Control(env.SelfId, inv.Name); env.Save(); env.Next = $"{oldName}被重命名为:{name}" + (CheckNameInputHardness(name, out string hint) ? "\n" + hint : ""); return(true); }
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); }
public static object ControlAndAct(DMEnv env, Investigator inv, CommandResult <DMEnv> action) { Scenario sce = env.Sce; if (!sce.PlayerNames.TryGetValue(env.SelfId, out string selfName)) { selfName = null; } sce.Control(env.SelfId, inv.Name); env.ClearCache(); action.Env = env; object res = action.Execute(); if (selfName != null) { sce.Control(env.SelfId, selfName); } env.Save(); return(res); }
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); }
public static bool DestoryInv(DMEnv env, string name) { Scenario sce = env.Sce; if (!env.IsAdmin) { env.Next = "你不是管理员!"; return(false); } else if (!sce.ExistInvestigator(name)) { env.Next = "不存在调查员:" + name; return(false); } sce.PlayerNames.Remove(env.SelfId); sce.Investigators.Remove(name); env.Save(); env.Next = "成功销毁:" + name + ",TA永远地消失了……"; return(true); }
public static bool PassItem(DMEnv env, string name, Investigator targetInv, string newName) { if (newName == null) { newName = name; } if (!env.Inv.Inventory.TryGetValue(name, out Item item)) { env.Append($"{env.Inv.Name}的物品栏中不存在{name}"); return(false); } if (targetInv.Inventory.ContainsKey(newName)) { env.Append($"{targetInv.Name}的物品栏中已经存在{newName}"); return(false); } env.Inv.Inventory.Remove(name); item.Name = newName; targetInv.Inventory[item.Name] = item; env.Save(); env.Append($"{env.Inv.Name}把{item.Name}给了:{targetInv.Name}"); return(true); }
public static void Start(DMEnv env, int amount) { var horses = env.Sce.Horses; if (horses.Count > 0) { env.Next = "🏇已经开始!"; return; } if (amount < 2 || amount > 10) { env.Next = "🐎匹不得少于2只且不得大于10只!"; return; } for (int i = 0; i < amount; i++) { Horse horse = new Horse(); horses.Add(horse); } env.Save(); env.Next = DisplayHorses(horses); }
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); }
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(); }
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(); }