use of main.system.math.Formula in project Eidolons by IDemiurge.
the class DC_RequirementsManager method generateSkillRequirements.
public Requirements generateSkillRequirements(Entity type, int mode) {
if (mode == RANK_MODE) {
return generateSkillRankRequirements(type);
}
String cost = HeroManager.getCost(type, getHero());
Condition xpReq = ConditionMaster.getParamCondition(1, PARAMS.XP, PARAMS.XP_COST);
String mastery = type.getProperty(G_PROPS.MASTERY);
MASTERY_RANK rank = getRank(type.getIntParam("SKILL_DIFFICULTY"));
Condition rankReq = ConditionMaster.getParamCondition(mastery, rank.getMasteryReq() + "");
((NumericCondition) xpReq).setComparingValue(new Formula("" + cost));
return new Requirements(new Conditions(new SkillPointCondition(), ConditionMaster.getPropCondition(PROPS.SKILLS, PROPS.SKILL_REQUIREMENTS, KEYS.SOURCE.toString(), KEYS.MATCH.toString()), rankReq, xpReq, // TODO OR CONDITION!
ConditionMaster.getPropCondition(PROPS.SKILLS, PROPS.SKILL_OR_REQUIREMENTS, KEYS.SOURCE.toString(), KEYS.MATCH.toString())), InfoMaster.NOT_ENOUGH_MASTERY, InfoMaster.getPropReasonString(type, PROPS.SKILL_REQUIREMENTS), InfoMaster.getSkillRankReqString(mastery, type, rank), InfoMaster.getParamReasonString(type, PARAMS.XP, cost), InfoMaster.getOrReasonStringFromContainer(PROPS.SKILL_OR_REQUIREMENTS, type.getProperty(PROPS.SKILL_OR_REQUIREMENTS)));
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class DC_RequirementsManager method generateClassRequirements.
public Requirements generateClassRequirements(Entity type, int mode) {
// multi :
if (mode == RANK_MODE) {
return generateClassRankRequirements(type);
}
Requirements requirements = new Requirements();
for (PARAMS mastery : DC_ContentManager.getMasteryParams()) {
PARAMETER req = ContentManager.getReqParam(mastery);
int param = type.getIntParam(req);
if (param <= 0) {
continue;
}
Condition c = ConditionMaster.getParamCondition(0, mastery, req);
String t = InfoMaster.getParamReasonString(type, mastery, req);
Requirement r = new Requirement(c, t);
requirements.add(r);
}
String cost = HeroManager.getCost(type, getHero());
Requirement xpReq = new Requirement(ConditionMaster.getParamCondition(0, PARAMS.XP, PARAMS.XP_COST), InfoMaster.getParamReasonString(type, PARAMS.XP, cost));
((NumericCondition) xpReq.getCondition()).setComparingValue(new Formula("" + cost));
requirements.add(xpReq);
if (ClassView.isMulticlass(type)) {
// TODO changing to simpler form with baseType?
requirements.add(getBaseTypeRequirement(type, type.getOBJ_TYPE_ENUM()));
requirements.add(new Requirement(new PropCondition(PROPS.CLASSES, type.getProperty(PROPS.BASE_CLASSES_TWO), false), InfoMaster.MULTICLASS_SECOND_CLASS + StringMaster.cropLast(type.getProperty(PROPS.BASE_CLASSES_TWO), 2, ";").replace(";", " or ")));
requirements.add(new Requirement(new MultiClassCondition(type.getName()), InfoMaster.MULTICLASS));
} else {
requirements.add(new Requirement(new ClassTreeCondition(type.getName()), InfoMaster.CLASS_TREE));
Conditions conditions = new OrConditions();
conditions.add(new EmptyStringCondition(StringMaster.getValueRef(KEYS.SOURCE, PROPS.FIRST_CLASS)));
conditions.add(new EmptyStringCondition(StringMaster.getValueRef(KEYS.SOURCE, PROPS.SECOND_CLASS)));
conditions.add(new StringComparison(type.getProperty(G_PROPS.CLASS_GROUP), StringMaster.getValueRef(KEYS.SOURCE, PROPS.FIRST_CLASS), true));
conditions.add(new StringComparison(type.getProperty(G_PROPS.CLASS_GROUP), StringMaster.getValueRef(KEYS.SOURCE, PROPS.SECOND_CLASS), true));
requirements.add(new Requirement(conditions, InfoMaster.MAX_CLASSES));
}
return requirements;
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class RollMaster method roll.
/**
* @return true if {failure} formula rolls more, false otherwise
*/
public static boolean roll(ROLL_TYPES roll_type, String success, String fail, Ref ref, String logAppendix, String rollSource, Boolean logged) {
Obj source = ref.getSourceObj();
Obj target = ref.getTargetObj();
// if (roll == null)
roll = new Roll(roll_type, success, fail, 0);
if (StringMaster.isEmpty(fail)) {
fail = initStdFail(roll_type);
}
Formula failFormula = new Formula(fail);
if (source != null) {
failFormula.applyFactor(getFailFactor(roll_type));
}
Boolean result;
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);
if (min1 >= max2) {
return true;
}
if (min2 >= max1) {
return false;
}
// per die?
rolledValue = RandomWizard.getRandomIntBetween(min1, max1);
rolledValue2 = RandomWizard.getRandomIntBetween(min2, max2);
roll.setRolledValue(rolledValue);
roll.setRolledValue2(rolledValue2);
result = rolledValue > rolledValue2;
if (target == null) {
target = ref.getEvent().getRef().getTargetObj();
}
// TODO display roll formulas if FULL_INFO is on!
if (rollSource == null) {
rollSource = rolledValue + " out of " + max1;
} else {
rollSource += StringMaster.wrapInParenthesis(rolledValue + " out of " + max1);
}
String rollTarget = rolledValue2 + " out of " + max2;
logString = target.getName() + ((result) ? " fails" : " wins") + " a " + roll_type.getName() + " roll with " + rollTarget + " vs " + source.getName() + "'s " + rollSource;
if (logAppendix != null) {
if (isAppendixAdded(logAppendix, result)) {
logString = logString + logAppendix.replace(getSuccessAppendixIdentifier(), "");
}
}
if (logged == null) {
logged = checkRollLogged(roll_type, result);
}
if (logged) {
ref.getGame().getLogManager().log(logString);
}
ref.getGame().getLogManager();
ref.getGame().getLogManager();
if (!ref.isAnimationDisabled()) {
PhaseAnimation anim = null;
if (ref.getActive() != null) {
// else ?
anim = ((DC_ActiveObj) ref.getActive()).getAnimation();
}
if (anim != null) {
anim.addPhaseArgs(PHASE_TYPE.ROLL, roll);
}
}
roll.setResult(result);
roll.setLogAppendix(logAppendix);
roll.setRollSource(rollSource);
roll.setRollTarget(rollTarget);
return result;
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class HC_Tree method updateText.
private void updateText() {
textMap.clear();
textBgPoint1 = null;
textBgPoint2 = null;
if (isViewMode()) {
return;
}
if (Launcher.DEV_MODE) {
if (CoreEngine.isArcaneVault()) {
return;
}
}
// TODO draw black background for this!
if (isDisplayRequirements()) {
boolean rank = false;
if (reqTextType == null) {
reqTextType = getSelectedType();
} else {
rank = true;
}
if (types.contains(reqTextType)) {
Integer x = null;
Integer y = map.getPointForType(reqTextType).y + 58;
boolean above = false;
boolean centered = false;
Integer originX = null;
if (y >= HT_MapBuilder.defTreeHeight - 130) {
y = map.getPointForType(reqTextType).y - 20;
above = true;
}
int mode = 0;
// display SD ?
if (rank) {
mode = RequirementsManager.RANK_MODE;
}
Requirements reqs = reqTextType.getGame().getRequirementsManager().getRequirements((rank ? hero.getFeat(isSkill(), reqTextType) : reqTextType), mode);
Point point;
Color color = ColorManager.CRIMSON;
Font font = getDefaultFont();
List<String> list;
if (reasons != null) {
list = reasons;
} else {
Ref ref = new Ref(hero);
ref.setMatch((reqTextType).getId());
reqs.preCheck(ref);
list = reqs.getReasons();
reasons = new ArrayList<>();
}
for (String text : list) {
if (text.equals(InfoMaster.NOT_ENOUGH_MASTERY)) {
text = InfoMaster.NOT_ENOUGH_MASTERY_SLOTS + ((SkillPointCondition) reqs.getReqMap().get(text)).getPointsRequired();
}
text = TextParser.parse(text, new Ref(getHero()));
text = text.replace(StringMaster.MASTERY + " ", "");
text = text.replace(" needed", "");
text = text.replace(" required", "");
if (!text.contains(" or ")) {
if (text.contains(": ")) {
String varPart = text.split(": ")[1];
if (varPart.startsWith("(") || StringMaster.isInteger("" + varPart.charAt(0))) {
String parsedVarPart = "";
try {
parsedVarPart = "" + new Formula(varPart).getInt(new Ref(getHero()));
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
if (!parsedVarPart.isEmpty()) // TextParser.parse(varPart, new
// Ref(getHero()));
{
text = text.replace(varPart, parsedVarPart);
}
}
}
}
reasons.add(text);
}
Collections.sort(reasons, new Comparator<String>() {
public int compare(String o1, String o2) {
if (o1.length() < o2.length()) {
return 1;
}
if (o1.length() > o2.length()) {
return -1;
}
return 0;
}
});
int stringWidth;
for (String text : reasons) {
SmartText smartText = new SmartText(text, color);
smartText.setFont(font);
stringWidth = FontMaster.getStringWidth(font, text);
if (x == null) {
x = map.getPointForType(reqTextType).x;
if (x + stringWidth >= getPanel().getWidth() - 10) {
x = getPanel().getWidth() - stringWidth - 10;
originX = x;
centered = true;
}
} else if (centered) {
x = originX;
// x = stringWidth - originX / 2 + getPanel().getWidth()
// - stringWidth / 2;
}
if (x == map.getPointForType(reqTextType).x) {
x = map.getPointForType(reqTextType).x - stringWidth / 4;
}
if (x < 0) {
x = 0;
}
if (above) {
y -= 20;
} else {
y += 20;
}
if (x == null) {
x = map.getPointForType(reqTextType).x;
}
point = new Point(x, y);
textMap.put(point, smartText);
// TODO if above... vice versa
if (textBgPoint1 == null) {
textBgPoint1 = new Point(x + stringWidth, y - FontMaster.getFontHeight(font));
}
}
textBgPoint2 = new Point(x, y);
if (above) {
Point buffer = textBgPoint1;
textBgPoint1 = new Point(textBgPoint2.x, textBgPoint2.y - FontMaster.getFontHeight(font));
textBgPoint2 = new Point(buffer.x, buffer.y + FontMaster.getFontHeight(font));
}
// mouse map on reqs -> goto req-skill or so
}
}
reasons = null;
reqTextType = null;
}
use of main.system.math.Formula in project Eidolons by IDemiurge.
the class DataModel method modifyParameter.
public boolean modifyParameter(PARAMETER param, String amountString, Integer minMax, boolean quietly, String modifierKey) {
if (amountString == null) {
return true;
}
if (amountString.isEmpty()) {
return true;
}
Number amount = null;
if (!StringMaster.isNumber(amountString, false))
amount = new Formula(amountString).evaluate(ref);
else if (StringMaster.isInteger(amountString)) {
amount = StringMaster.getInteger(amountString);
if (amount.equals(0)) {
return false;
}
} else {
amount = StringMaster.getDouble(amountString);
if (amount.equals(0.0))
return false;
}
if (LogMaster.VALUE_DEBUG_ON)
LogMaster.log(LogMaster.VALUE_DEBUG, "modifying " + getName() + "'s " + param.getName() + " by " + amount);
if (!quietly || GuiEventManager.isParamEventAlwaysFired(param.getName()))
if (!fireParamEvent(param, String.valueOf(amount), CONSTRUCTED_EVENT_TYPE.PARAM_BEING_MODIFIED)) {
// false?
return true;
}
boolean result = true;
Double newValue;
Double prevValue = getParamDouble(param, false);
if (prevValue > 0) {
newValue = amount.doubleValue() + prevValue;
} else {
newValue = amount.doubleValue();
}
// intAmount = prevValue
if (minMax != null) {
if (amount.doubleValue() < 0) {
if ((prevValue) < minMax) {
return false;
}
if (newValue.doubleValue() < minMax) {
newValue = (double) minMax;
}
} else {
if ((prevValue) > minMax) {
return false;
}
if (newValue.intValue() > minMax) {
newValue = (double) minMax;
}
}
}
setParam(param, newValue.toString(), quietly);
Map<String, Double> map = getModifierMaps().get(param);
if (map == null) {
map = new XLinkedMap<>();
getModifierMaps().put(param, map);
}
if (modifierKey == null) {
modifierKey = this.modifierKey;
}
Double amountByModifier = map.get(modifierKey);
this.modifierKey = null;
if (amountByModifier == null) {
map.put(modifierKey, amount.doubleValue());
} else {
map.put(modifierKey, amountByModifier + amount.doubleValue());
}
if (newValue.intValue() <= 0) {
result = false;
}
return result;
}
Aggregations