public override decimal evalPercent(EvaluationContext context) { decimal operandValue = operand.evalPercent(context); switch (operator_.text) { case "-": return -operandValue; } throw null; }
public override decimal evalPercent(EvaluationContext context) { return value.value; }
public override int evalInt(EvaluationContext context) { int operandValue = operand.evalInt(context); switch (operator_.text) { case "-": return -operandValue; } throw null; }
public override int evalInt(EvaluationContext context) { return context.evalInt(token.text); }
public override int evalInt(EvaluationContext context) { return value.value; }
public override decimal evalPercent(EvaluationContext context) { if (condition.evalBoolean(context)) return thenPart.evalPercent(context); else return operand.evalPercent(context); }
public override bool evalBoolean(EvaluationContext context) { return context.evalBoolean(token.text); }
public override decimal evalPercent(EvaluationContext context) { if (left.ToString().Contains("level")) return left.evalInt(context) * right.evalPercent(context); else return left.evalPercent(context) * right.evalInt(context); }
public override bool evalBoolean(EvaluationContext context) { return value.value; }
public override bool evalBoolean(EvaluationContext context) { switch (operator_.text) { case "<=": return left.evalInt(context) <= right.evalInt(context); case "<": return left.evalInt(context) < right.evalInt(context); case ">=": return left.evalInt(context) >= right.evalInt(context); case ">": return left.evalInt(context) > right.evalInt(context); case "AND": return left.evalBoolean(context) && right.evalBoolean(context); case "OR": return left.evalBoolean(context) || right.evalBoolean(context); } throw null; }
public override int evalInt(EvaluationContext context) { int leftValue = left.evalInt(context); int rightValue = right.evalInt(context); switch (operator_.text) { case "*": return leftValue * rightValue; case "/": return leftValue / rightValue; case "+": return leftValue + rightValue; case "-": return leftValue - rightValue; } throw null; }
public virtual decimal evalPercent(EvaluationContext context) { throw new NotImplementedException(); }
public virtual int evalInt(EvaluationContext context) { throw new NotImplementedException(); }
public virtual bool evalBoolean(EvaluationContext context) { throw new NotImplementedException(); }
private int getUnmodifiedCost() { EvaluationContext context = new EvaluationContext(character, this, purchasedLevels); if (property is Advantage) return ((Advantage)property).costFormula.evalInt(context); if (property is AbstractSkill) { // purchased: 0, 1, 2, 3, 4, ... +1 // cost: 0, 1, 2, 4, 8, ... +4 return purchasedLevels < 3 ? purchasedLevels : 4 * (purchasedLevels - 2); } if (property is AttributeFunction) return 0; throw null; }
public int getCost() { int cost = getUnmodifiedCost(); decimal discountPercent = 0; decimal extraCostPercent = 0; foreach (CostModifier effect in from x in property.effectedBy where x is CostModifier select x) { PurchasedProperty otherPurchasedProperty = character.getPurchasedProperty(effect.owner.name); if (!otherPurchasedProperty.nonDefault) continue; EvaluationContext context = new EvaluationContext(character, otherPurchasedProperty, otherPurchasedProperty.getLevel()); if (effect.parsedThing.declarationOperator == "-=") discountPercent += effect.formula.evalPercent(context); else if (effect.parsedThing.declarationOperator == "+=") extraCostPercent += effect.formula.evalPercent(context); else throw null; } // TODO enhancement/limitation cost modifiers go here // cap discount at -80% discountPercent = Math.Min(discountPercent, 0.80m); int costEffect = (int)Math.Floor(cost * (extraCostPercent - discountPercent)); cost += costEffect; return cost; }