public static (int[] Nums, int Result) Roll(int count, int sides, AdvantageType adv = AdvantageType.None) { int[] results = new int[count]; int sum = 0; for (int i = 0; i < count; i++) { int num = rand.Next(1, sides + 1); if (adv != AdvantageType.None) { int num2 = rand.Next(1, sides + 1); if (adv == AdvantageType.Advantage && num2 > num) { num = num2; } else if (adv == AdvantageType.Disadvantage && num2 < num) { num = num2; } } results[i] = num; sum += results[i]; } return(results, sum); }
public bool CompareTo(Country value, string good, AdvantageType type = AdvantageType.Comparative) { if (type == AdvantageType.Comparative) { return(goods.Single(g => g.name == good).hoursToProduce / goods.Single(g => g.name != good).hoursToProduce); } }
public void SetAdvantage(string type, AdvantageType adv) { if (Skills.ContainsKey(type)) { Skills[type].Advantage = adv; } else if (Abilities.ContainsKey(type)) { Abilities[type].Advantage = adv; } }
private void EnemyDisadvantageRadio_CheckedChanged(object sender, EventArgs e) { if (!(sender is RadioButton radio)) { return; } if (!radio.Checked) { return; } enemyAdvantageType = AdvantageType.Disadvantage; }
private void AlliedNormalRadio_CheckedChanged(object sender, EventArgs e) { if (!(sender is RadioButton radio)) { return; } if (!radio.Checked) { return; } alliedAdvantageType = AdvantageType.Normal; }
public Ability(Ability oldAbility) { Score = oldAbility.Score; Advantage = oldAbility.Advantage; }
public static T SetSavingThrowAdvantageType <T>(this T entity, AdvantageType value) where T : FeatureDefinitionConditionAffinity { entity.SetField("savingThrowAdvantageType", value); return(entity); }
public static ExpressionResult Evaluate(double initialValue, string expr, Character charRef, VariableCollection variables) { expr = expr.ToUpperInvariant(); MatchCollection matches = rx.Matches(expr); Stack <double[]> values = new Stack <double[]>(); // Stack of tuples of the form ([operator],[order of operation]) // where higher orders of operation are evaluated first. Stack <(string, int)> operators = new Stack <(string, int)>(); // String used to keep track of what is being evaluated vs. ignored. // Return this with the result for useful feedback string evaluated_string = ""; variables["ANS"] = new double[] { initialValue }; foreach (Match match in matches) { if (match.Value == "") { continue; } GroupCollection groups = match.Groups; double[] value = new double[] { 0 }; int opOrder = -1; // Insert the operator into the evaluated string if (groups["op"].Value != "") { if (values.Count <= 0) { evaluated_string += $"ANS"; values.Push(variables["ANS"]); } evaluated_string += $" {groups["op"].Value} "; } // Insert preoperator into the evaluated string if (groups["pre_op"].Value != "") { evaluated_string += groups["pre_op"].Value; } // Prepare the parsed value if (groups["dice"].Value != "") { evaluated_string += groups["dice"].Value; int d_count = Int32.Parse(groups["d_count"].Value); int d_sides = Int32.Parse(groups["d_sides"].Value); AdvantageType adv = AdvantageType.None; if (groups["d_adv"].Value != "") { if (groups["d_adv"].Value == "a") { adv = AdvantageType.Advantage; } else if (groups["d_adv"].Value == "d") { adv = AdvantageType.Disadvantage; } } (int[] results, int sum) = Dice.Roll(d_count, d_sides, adv); if (groups["reroll_nums"].Value != "") { evaluated_string += " -"; int[] nums = Array.ConvertAll(groups["reroll_nums"].Value.Split(','), Int32.Parse); for (int i = 0; i < results.Length; i++) { if (Array.IndexOf(nums, results[i]) != -1) { #if (DEBUG) Console.WriteLine("rerolling: {0}", results[i]); #endif evaluated_string += results[i] + "-"; sum -= results[i]; results[i] = Dice.Roll(1, d_sides).Item2; sum += results[i]; } } } value = Array.ConvertAll <int, double>(results, x => x); evaluated_string += String.Format(" ([{0}])", String.Join(",", results)); } else if (groups["const"].Value != "") { if (groups["const_list"].Value != "") { string[] args = SplitBalanced(',', groups["const_list"].Value); List <double> tempValue = new List <double>(args.Length); evaluated_string += "["; for (int i = 0; i < args.Length; i++) { args[i] = args[i].Trim(); ExpressionResult result = Evaluate(args[i], charRef, variables); if (!result.Success) { return(result); } if (i != 0) { evaluated_string += ","; } evaluated_string += result.Message; tempValue.AddRange(result.Values); } value = tempValue.ToArray(); evaluated_string += "]"; } else { value = new double[] { Int32.Parse(groups["const"].Value) }; evaluated_string += groups["const"].Value; } } else if (groups["var"].Value != "") { string id = groups["var"].Value; if (id == "TRUE") { value[0] = 1; } else if (id == "FALSE") { value[0] = 0; } else if (variables.Contains(id)) { value = variables[id]; } else if (charRef == null) { return(new ExpressionResult(false, "No character given to reference", new double[] { 0 })); } else { switch (id) { case "STR": value[0] = charRef.GetAbilityMod("Strength"); break; case "CON": value[0] = charRef.GetAbilityMod("Constitution"); break; case "DEX": value[0] = charRef.GetAbilityMod("Dexterity"); break; case "WIS": value[0] = charRef.GetAbilityMod("Wisdom"); break; case "INT": value[0] = charRef.GetAbilityMod("Intelligence"); break; case "CHA": value[0] = charRef.GetAbilityMod("Charisma"); break; case "PRO": value[0] = charRef.GetProficiencyBonus(); break; case "LVL": value[0] = charRef.Level; break; case "AC": value[0] = charRef.GetAC(); break; default: return(new ExpressionResult(false, $"Invalid variable name \"{id}\"", new double[] { 1 })); } } evaluated_string += String.Format("{0} ({1})", id, String.Join(",", value)); } else if (groups["paren"].Value != "") { #if (DEBUG) Console.WriteLine("{0}({1}){2}", groups["paren_mul_l"], groups["paren"], groups["paren_mul_r"]); Console.WriteLine("================="); #endif ExpressionResult result = Evaluate(groups["paren"].Value, charRef, variables); if (!result.Success) { return(result); } value = result.Values; if (groups["paren_mul_l"].Value != "") { if (groups["paren_mul_l"].Value == "-") { value = calculate("*", value, new double[] { (double)Int32.Parse(groups["paren_mul_l"].Value + "1") }); } else { value = calculate("*", value, new double[] { (double)Int32.Parse(groups["paren_mul_l"].Value) }); } evaluated_string += groups["paren_mul_l"].Value; } evaluated_string += $"({result.Message})"; if (groups["paren_mul_r"].Value != "") { value = calculate("*", new double[] { (double)Int32.Parse(groups["paren_mul_r"].Value) }, value); evaluated_string += groups["paren_mul_r"].Value; } #if (DEBUG) Console.WriteLine("================="); #endif } else if (groups["named_value"].Value != "") { string key = groups["name"].Value; ExpressionResult result = Evaluate(groups["named_inside"].Value, charRef, variables); if (!result.Success) { return(result); } value = result.Values; evaluated_string += $"{key}{{{result.Message}}}"; variables[key] = value; } else if (groups["list_op"].Value != "") { string opName = groups["list_op"].Value; int resultCount = 1; if (groups["list_count"].Value != "") { resultCount = Int32.Parse(groups["list_count"].Value); } if (resultCount <= 0) { resultCount = 1; } // Deal with the operation name Func <double, double, bool> compare; switch (opName) { case "MAX": compare = delegate(double _new, double _old) { return(_new > _old); }; break; case "MIN": compare = delegate(double _new, double _old) { return(_new < _old); }; break; default: return(new ExpressionResult(false, $"{opName} is not a valid list operation", new double[] { 0 })); } // Parse the arguments string[] exprs = SplitBalanced(',', groups["list_inside"].Value); if (exprs.Length <= 0) { return(new ExpressionResult(false, $"{opName} must have at least 1 value", new double[] { 0 })); } evaluated_string += $"{opName}{resultCount}["; // initialize comparison values: double[] compValues = new double[resultCount]; int initIndex = 0; for (int i = 0; i < exprs.Length; i++) { ExpressionResult result = Evaluate(exprs[i], charRef, variables); if (!result.Success) { return(result); } if (i != 0) { evaluated_string += ", "; } evaluated_string += result.Message; // set comparison values to the first item in the first expression's result // finish comparison if needed foreach (double newVal in result.Values) { // if our initial values aren't filled in, fill them first. // no comparison is needed for the initial set. if (initIndex < resultCount) { compValues[initIndex] = newVal; initIndex++; continue; } int k = 0; double oldVal = 0; for (; k < resultCount; k++) { // if we have a match, store the old value, // plug in the new one, and break out of this loop if (compare(newVal, compValues[k])) { oldVal = compValues[k]; compValues[k] = newVal; break; } } // sift the old value down the rest of the results for (; k < resultCount; k++) { if (compare(oldVal, compValues[k])) { compValues[k] = oldVal; } } } } value = compValues; evaluated_string += $"] ({String.Join(",",value)})"; } else if (groups["func"].Value != "") { string funcName = groups["func"].Value; string[] funcArgs = SplitBalanced(',', groups["func_args"].Value); if (funcArgs[0] == "") { funcArgs = new string[0]; } for (int i = 0; i < funcArgs.Length; i++) { funcArgs[i] = funcArgs[i].Trim(); } if (charRef == null) { return(new ExpressionResult(false, "No character given to reference", new double[] { 0 })); } else if (funcName == "EQUIPPED") { if (charRef.HasItemEquipped(funcArgs)) { value[0] = 1; } else { value[0] = 0; } } else { switch (funcName + funcArgs.Length.ToString()) { case "HASPROF1": if (charRef.HasProficiency(funcArgs[0])) { value[0] = 1; } else { value[0] = 0; } break; case "ABILITYSCORE1": value[0] = charRef.GetAbilityScore(funcArgs[0]); break; case "ABILITYMOD1": value[0] = charRef.GetAbilityMod(funcArgs[0]); break; case "SKILLMOD1": value[0] = charRef.GetSkillMod(funcArgs[0]); break; default: return(new ExpressionResult(false, $"{funcName} with {funcArgs.Length} arguments is not a valid function", new double[] { 0 })); } } evaluated_string += $"{funcName}({String.Join(",",funcArgs)}) ({value[0]})"; } else { return(new ExpressionResult(false, $"Invalid Operator\n \"{expr}\"\n" + " " + underlineError(match), new double[] { 0 })); } // Handle preoperator if (groups["pre_op"].Value != "") { value = calculate(groups["pre_op"].Value, value, new double[] { 0 }); evaluated_string += $"({String.Join(",",value)})"; } // Handle Operator switch (groups["op"].Value) { case "&&": case "AND": case "||": case "OR": opOrder = 0; break; case "<": case ">": case "=": case "<=": case ">=": case "!=": opOrder = 1; break; case "+": case "-": opOrder = 2; break; case "*": case "/": opOrder = 3; break; default: if (values.Count > 0) { return(new ExpressionResult(false, $"Invalid Syntax\n \"{expr}\"\n" + " " + underlineError(match), new double[] { 5 })); } else { values.Push(value); } break; } if (opOrder > -1) { #if (DEBUG) debugStack <double[]>(values); debugStack <(string, int)>(operators); #endif while (operators.Count > 0 && operators.Peek().Item2 > opOrder) { values.Push(calculate(operators.Pop().Item1, values.Pop(), values.Pop())); } operators.Push((groups["op"].Value, opOrder)); values.Push(value); } } // Check to make sure stacks are alligned properly. There should always be one more values than operators if (values.Count != operators.Count + 1) { return(new ExpressionResult(false, $"Invalid Expression\n \"{expr}\"", new double[] { 6 })); } // Compute remaining stack elements while (operators.Count > 0) { #if (DEBUG) debugStack <double[]>(values); debugStack <(string, int)>(operators); #endif values.Push(calculate(operators.Pop().Item1, values.Pop(), values.Pop())); } // The last remaining value is the answer double[] total = values.Pop(); #if (DEBUG) Console.WriteLine(total); #endif return(new ExpressionResult(true, evaluated_string, total)); }
public Advantage(String n, int p, AdvantageType t) { Name = n; Points = p; Type = t; }
public static T SetInitiativeAffinity <T>(this T entity, AdvantageType value) where T : FeatureDefinitionCombatAffinity { entity.SetField("initiativeAffinity", value); return(entity); }
public static T SetScribeAdvantageType <T>(this T entity, AdvantageType value) where T : FeatureDefinitionMagicAffinity { entity.SetField("scribeAdvantageType", value); return(entity); }
public static T SetAdvantageType <T>(this T entity, AdvantageType value) where T : HitAffinityByTag { entity.SetField("advantageType", value); return(entity); }
public static T SetMyAttackAdvantage <T>(this T entity, AdvantageType value) where T : FeatureDefinitionCombatAffinity { entity.SetField("myAttackAdvantage", value); return(entity); }
public Skill(string _ability, AdvantageType _adv = AdvantageType.None) { Ability = _ability; Advantage = _adv; }
public static T SetConcentrationAdvantage <T>(this T entity, AdvantageType value) where T : FeatureDefinitionMagicAffinity { entity.SetField("concentrationAdvantage", value); return(entity); }
public Skill(Skill oldSkill) { Ability = oldSkill.Ability; Advantage = oldSkill.Advantage; }
public static T SetForcedSavingThrowAffinity <T>(this T entity, AdvantageType value) where T : FeatureDefinitionMagicAffinity { entity.SetField("forcedSavingThrowAffinity", value); return(entity); }
public Ability(int _score = 10, AdvantageType _adv = AdvantageType.None) { Score = _score; Advantage = _adv; }
public static T SetAttackOfOpportunityOnMeAdvantageType <T>(this T entity, AdvantageType value) where T : FeatureDefinitionCombatAffinity { entity.SetField("attackOfOpportunityOnMeAdvantageType", value); return(entity); }