Search in sources :

Example 1 with Parameter

use of main.system.math.Parameter in project Eidolons by IDemiurge.

the class TextParser method parseRef.

// perhaps I should refactor into method per parse_type!
private static String parseRef(String ref_substring, Ref ref) {
    if (ref == null) {
        return parseVarRef(ref_substring);
    }
    String value = StringMaster.cropRef(ref_substring);
    if (!StringMaster.isInteger(value)) {
        if (isAbilityParsing()) {
            return ref_substring;
        }
    }
    int id = 0;
    if (isActiveParsing()) {
        id = ref.getId(KEYS.ACTIVE);
    } else {
        try {
            id = ref.getId(KEYS.INFO);
        } catch (Exception e) {
        }
    }
    Game game = ref.getGame();
    // if (id == 0) {
    // if (game.isRunning()) {
    // id = game.getManager().getInfoObj().getId();
    // }
    // }
    // else if (CharacterCreator.isRunning())
    String replacement = ref_substring;
    Entity entity = ref.getInfoEntity();
    if (entity == null) {
        if (game.isSimulation() && !isBuffParsing() && !isAbilityParsing()) {
            entity = game.getTypeById(id);
        } else {
            entity = game.getObjectById(id);
        }
    }
    if (entity == null) {
        return ref_substring;
    }
    if (entity instanceof AbilityObj) {
        entity = entity.getType();
    }
    if (StringMaster.isInteger(value)) {
        int index = StringMaster.getInteger(value) - 1;
        String varProp = entity.getProperty(G_PROPS.VARIABLES);
        if (StringMaster.isEmpty(varProp)) {
            varProp = DEFAULT_VARS;
        }
        boolean containerFormula = false;
        if (!entity.getParam("FORMULA").isEmpty()) {
            // StringMaster.compare(varProp.replace(";", ""), "FORMULA",
            // true)) {
            varProp = entity.getParam("FORMULA");
            containerFormula = true;
        }
        List<String> openContainer = StringMaster.openContainer(varProp);
        if (openContainer.size() > index) {
            VALUE val = null;
            if (!containerFormula && !isBuffParsing()) {
                val = ContentManager.getValue(openContainer.get(index));
                replacement = entity.getValue(val);
            } else {
                replacement = openContainer.get(index);
            }
            if (containerFormula || val instanceof PARAMETER) {
                if (StringMaster.isInteger(replacement)) {
                    return replacement;
                }
                try {
                    if (isAbilityParsing()) // if (replacement.contains(",")) {
                    // // TODO all function names!
                    // if (replacement.toLowerCase().contains("min")
                    // || replacement.toLowerCase().contains(
                    // "max")) {
                    // // get the insides of the formula?
                    // // parts = replacement.split(regex);
                    // // parts[1] = parts[1].
                    // //
                    // // replacement = parts[0] + parts[1];
                    // return replacement.replace(",",
                    // StringMaster.COMMA_CODE);
                    // }
                    // } else
                    {
                        return replacement.replace(",", StringMaster.COMMA_CODE);
                    }
                    if (game.isSimulation()) {
                        replacement = new Formula(replacement).getInt(ref) + " (" + formatFormula(replacement) + ")";
                    } else {
                        replacement = new Formula(replacement).getInt(ref) + "";
                    }
                } catch (Exception e) {
                    main.system.ExceptionMaster.printStackTrace(e);
                }
            } else {
                String result = new Property(true, replacement).getStr(ref);
                if (StringMaster.isEmpty(result)) {
                    replacement = new Parameter(replacement).getInt(ref) + "";
                } else {
                    replacement = result;
                }
            }
        }
    } else {
        if (!isAbilityParsing()) {
            if (StringMaster.isInteger(replacement)) {
                return replacement;
            }
            if (game.isSimulation() && !tooltipParsing) {
                Integer VAL = new Formula(replacement).getInt(ref);
                replacement = VAL + " (" + replacement + ")";
            } else {
                // TODO
                replacement = new Formula(replacement).getInt(ref) + "";
            }
        // props!
        }
    }
    return replacement;
}
Also used : Entity(main.entity.Entity) VALUE(main.content.VALUE) AbilityObj(main.ability.AbilityObj) Formula(main.system.math.Formula) Game(main.game.core.game.Game) Parameter(main.system.math.Parameter) Property(main.system.math.Property) PARAMETER(main.content.values.parameters.PARAMETER)

Aggregations

AbilityObj (main.ability.AbilityObj)1 VALUE (main.content.VALUE)1 PARAMETER (main.content.values.parameters.PARAMETER)1 Entity (main.entity.Entity)1 Game (main.game.core.game.Game)1 Formula (main.system.math.Formula)1 Parameter (main.system.math.Parameter)1 Property (main.system.math.Property)1