public void RefreshCache() { if (Global.Groups.TryGetValue(GroupId, out string sceName)) { if (Global.Scenarios.TryGetValue(sceName, out Scenario sce)) { this.SceCache = sce; if (sce != null && sce.PlayerNames.TryGetValue(SelfId, out string invName) && sce.Investigators.TryGetValue(invName, out Investigator inv)) { this.InvCache = inv; } else { this.InvCache = null; } } else { this.SceCache = null; this.InvCache = null; } } }
public bool Use(Investigator user, out string reply) { Dictionary <string, int> actualCost = new Dictionary <string, int>(); foreach (var e in Cost) { int c = Dice.RollWith(e.Value, user.DamageBonus); if (!user.Values.TryWidelyGet(e.Key, out Value value)) { reply = user.Name + "不存在数值:" + e.Key; return(false); } else if (value.Val < c) { reply = $"{user.Name}的{e.Key}少于消耗数值:{value.Val} < {c}"; return(false); } actualCost[e.Key] = c; } StringBuilder builder = new StringBuilder(); foreach (var e in actualCost) { if (!user.Values.TryWidelyGet(e.Key, out Value value)) { reply = user.Name + "不存在数值:" + e.Key; return(false); } int prev = value.Val; value.Sub(e.Value); builder.AppendLine().Append(e.Key).Append(':').Append(prev).Append(" - ").Append(e.Value).Append(" => ").Append(value.Val); } reply = builder.ToString(); return(true); }
/// <summary> /// 通过玩家ID获取调查员 /// </summary> /// <param name="qq">玩家id</param> /// <param name="investigator">调查员</param> /// <returns>是否成功</returns> public bool TryGetInvestigator(long user, out Investigator investigator) { if (!PlayerNames.TryGetValue(user, out string name)) { investigator = null; return(false); } return(Investigators.TryGetValue(name, out investigator)); }
public bool TryGetInv(out Scenario sce, out Investigator inv) { if (!Global.Groups.TryGetValue(GroupId, out string sceName) || !Global.Scenarios.TryGetValue(sceName, out sce) || !sce.PlayerNames.TryGetValue(SelfId, out string invName) || !sce.TryGetInvestigator(invName, out inv)) { sce = null; inv = null; return(false); } return(true); }
/// <summary> /// 获取下一个打斗事件,以下情况均会抛出异常: /// - 打斗事件队列为空 /// - 打斗的对象不存在 /// - 打斗的对象的武器不存在 /// 要注意,这并不会将该事件撤出队列! /// </summary> /// <param name="sce">用来检查的存档</param> /// <param name="oppositeInv">对手实例</param> /// <param name="oppositeWeapon">对手武器</param> /// <returns>合法的下一个打斗事件</returns> public FightEvent PeekNextFight(Scenario sce, out Investigator oppositeInv, out Item oppositeWeapon) { if (Fights.Count == 0) { throw new DiceException("未找到打斗事件"); } FightEvent fight = Fights.Peek(); if (!sce.TryGetInvestigator(fight.SourceName, out oppositeInv)) { throw new DiceException($"未找到打斗来源:{fight.SourceName}"); } if (fight.WeaponName == null) { oppositeWeapon = new Item("身体"); } else if (!oppositeInv.Inventory.TryGetValue(fight.WeaponName, out oppositeWeapon)) { throw new DiceException($"未找到{oppositeInv.Name}的{fight.WeaponName}"); } return(fight); }
/// <summary> /// 通过调查员名字获取调查员 /// </summary> /// <param name="name">调查员名</param> /// <param name="investigator">调查员</param> /// <returns>是否成功</returns> public bool TryGetInvestigator(string name, out Investigator investigator) { return(Investigators.TryGetValue(name, out investigator)); }
/// <summary> /// 加入新的调查员 /// </summary> /// <param name="inv">调查员</param> public void PutInvestigator(Investigator inv) { Investigators[inv.Name] = inv; }
public void SetCache(Scenario sce, Investigator inv) { this.SceCache = sce; this.InvCache = inv; }
public void ClearCache() { this.SceCache = null; this.InvCache = null; }