use of main.system.math.Formula in project Eidolons by IDemiurge.
the class DC_MathManager method getDivinationPool.
public static int getDivinationPool(Unit hero) {
Formula divinationPoolFormula = DC_Formulas.DIVINATION_POOL_FORMULA;
String property = hero.getProperty(PROPS.DIVINATION_PARAMETER);
if (!property.isEmpty()) {
if (!property.contains("{")) {
property = StringMaster.wrapInCurlyBraces(property);
}
divinationPoolFormula = new Formula(DC_Formulas.DIVINATION_POOL_FORMULA.toString().toLowerCase().replace("{charisma}", hero.getProperty(PROPS.DIVINATION_PARAMETER)));
}
return divinationPoolFormula.getInt(hero.getRef());
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class RollMaster method getRollChance.
public static int getRollChance(ROLL_TYPES roll_type, String success, String fail, Ref ref) {
if (StringMaster.isEmpty(fail)) {
fail = initStdFail(roll_type);
}
Formula failFormula = new Formula(fail);
failFormula.applyFactor(getFailFactor(roll_type));
int max1 = failFormula.getInt(ref);
if (StringMaster.isEmpty(success)) {
success = initStdSuccess(roll_type);
}
Formula successFormula = new Formula(success);
successFormula.applyFactor(getSuccessFactor(roll_type));
int max2 = successFormula.getInt(ref);
int min1 = MathMaster.applyMod(max1, DEFAULT_MIN_ROLL_PERC);
int min2 = MathMaster.applyMod(max2, DEFAULT_MIN_ROLL_PERC);
int proportion = Math.round((min1 + max1) / 2 * 100) / ((min2 + max2) / 2);
int perc = 50 + (100 - proportion) / 2;
return perc;
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class PriorityManagerImpl method getDurationMultiplier.
@Override
public int getDurationMultiplier(Action action) {
int multiplier;
int duration = new Formula(action.getActive().getParam(G_PARAMS.DURATION)).getInt(action.getRef());
duration = MathMaster.addFactor(duration, ParamPriorityAnalyzer.getResistanceFactor(action));
multiplier = (int) Math.sqrt(duration * getConstInt(AiConst.GEN_SPELL_DURATION_SQRT_MULTIPLIER)) + getConstInt(AiConst.GEN_SPELL_DURATION_MULTIPLIER);
return multiplier;
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class PriorityManagerImpl method getSpellCustomHostileEffectPriority.
@Override
public int getSpellCustomHostileEffectPriority(DC_Obj target, DC_ActiveObj action, Effect e) {
if (e instanceof AddBuffEffect) {
AddBuffEffect buffEffect = (AddBuffEffect) e;
// duration
int mod = 100;
// getDurationPriorityMod(buffEffect.getDurationFormula().getInt(action.getRef()));
return getSpellCustomHostileEffectPriority(target, action, buffEffect.getEffect()) * mod / 100;
}
if (e instanceof Effects) {
Effects effects = (Effects) e;
int p = 0;
for (Effect eff : effects) {
p += getSpellCustomHostileEffectPriority(target, action, eff);
}
return p;
}
if (e instanceof RollEffect) {
RollEffect rollEffect = (RollEffect) e;
int mod = getRollPriorityMod(rollEffect);
return getSpellCustomHostileEffectPriority(target, action, rollEffect.getEffect()) * mod / 100;
}
if (e instanceof InstantDeathEffect) {
return 2 * getUnitPriority(target, true);
}
if (e instanceof BehaviorModeEffect) {
int duration = new Formula(action.getParam(G_PARAMS.DURATION)).getInt(action.getRef());
BehaviorModeEffect behaviorModeEffect = (BehaviorModeEffect) e;
switch(behaviorModeEffect.getMode()) {
case BERSERK:
return getUnitPriority(target, true) * (Math.min(4, duration / 5 * 3));
case CONFUSED:
return getUnitPriority(target, true) * (Math.min(2, duration / 2));
case PANIC:
return getUnitPriority(target, true) * (Math.min(3, duration / 3 * 2));
default:
break;
}
}
if (e instanceof OwnershipChangeEffect) {
int duration = new Formula(action.getParam(G_PARAMS.DURATION)).getInt(action.getRef());
return getUnitPriority(target, true) * (Math.min(5, duration));
}
return 0;
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class PriorityManagerImpl method getParamModSpellPriority.
@Override
public int getParamModSpellPriority(Action action, Boolean buff) {
DC_ActiveObj spell = action.getActive();
DC_Obj target = action.getTarget();
if (buff == null) {
buff = EffectFinder.check(spell.getAbilities(), AddBuffEffect.class);
}
if (buff) {
if (!spell.checkBool(GenericEnums.STD_BOOLS.STACKING)) {
try {
List<ObjType> buffsFromSpell = BuffMaster.getBuffsFromSpell(spell);
if (buffsFromSpell.isEmpty()) {
priority = 0;
return 0;
}
ObjType objType = buffsFromSpell.get(0);
if (!objType.checkBool(GenericEnums.STD_BOOLS.STACKING)) {
if (target.hasBuff(objType.getName())) {
priority = 0;
return 0;
}
}
} catch (Exception e) {
}
}
}
int priority = (getUnitPriority(target, false));
boolean ally = target.getOwner().equals(getUnit().getOwner());
// boolean mod = EffectMaster.preCheck(spell.getAbilities(),
// ModifyValueEffect.class);
List<Effect> effects = EffectFinder.getEffectsOfClass(spell.getAbilities(), (buff) ? AddBuffEffect.class : ModifyValueEffect.class);
if (buff) {
List<Effect> list = new ArrayList<>();
for (Effect e : effects) {
list.addAll(EffectFinder.getBuffEffects(e, ModifyValueEffect.class));
}
// TODO count the duration from buffEffect
effects = list;
}
initRollMap(spell, effects);
boolean valid = false;
for (Effect e : effects) {
ModifyValueEffect valueEffect = (ModifyValueEffect) e;
for (String sparam : StringMaster.open(valueEffect.getParamString())) {
for (PARAMETER param : DC_ContentManager.getParams(sparam)) {
// TODO apply generic fix!
if (param == PARAMS.C_INITIATIVE_BONUS)
param = PARAMS.C_INITIATIVE;
if (TextParser.checkHasValueRefs(valueEffect.getFormula().toString())) {
String parsed = TextParser.parse(valueEffect.getFormula().toString(), action.getRef(), TextParser.ACTIVE_PARSING_CODE);
parsed = TextParser.replaceCodes(parsed);
valueEffect.setFormula(new Formula(parsed));
}
int amount = valueEffect.getFormula().getInt(action.getRef());
if (valueEffect.getMod_type() == MOD.MODIFY_BY_PERCENT) {
amount = MathMaster.getFractionValueCentimal(target.getIntParam(param, valueEffect.getFormula().toString().contains(StringMaster.BASE_CHAR)), amount);
}
boolean drain = (e instanceof DrainEffect);
int final_value = target.getIntParam(param) + amount;
int min_max = valueEffect.initMinMaxAmount(target, amount);
if (min_max != Integer.MAX_VALUE && min_max != Integer.MIN_VALUE) {
if (amount >= 0) {
if (final_value > min_max) {
amount = min_max - target.getIntParam(param);
}
} else {
if (amount < min_max) {
amount = target.getIntParam(param) - min_max;
}
}
}
if (!ally && !drain) {
amount = -amount;
}
priority = (int) (priority * getParamModFactor(target, e, param, amount));
if (drain) {
// TODO limit the amount!
priority = (int) (priority * getParamModFactor(getUnit(), null, param, amount));
}
}
}
if (!buff) {
if (!ally && valid) {
applyResistPenalty(action);
}
} else {
priority = priority * (getDurationMultiplier(action)) / 100;
}
}
if (!valid) {
return 0;
// applyMultiplier(0, "Empty");
}
return priority;
}
Aggregations