Search in sources :

Example 1 with Property

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

the class StringComparison method check.

// if 2 units share race... or classification... if a unit has a
// classification
@Override
public boolean check(Ref ref) {
    if (arg1 == null) {
        this.arg1 = new Property(str1);
    }
    if (arg2 == null) {
        this.arg2 = new Property(str2);
    }
    val1 = arg1.getStr(ref);
    val2 = arg2.getStr(ref);
    boolean result;
    if (val2.contains(StringMaster.AND_SEPARATOR)) {
        for (String s : StringMaster.open(val2, StringMaster.AND_SEPARATOR)) {
            if (compare(val1, s, strict)) {
                return true;
            }
        }
    }
    if (// shouldn't happen
    val1.contains(StringMaster.AND_SEPARATOR)) {
        for (String s : StringMaster.open(val1, StringMaster.AND_SEPARATOR)) {
            if (compare(s, val2, strict)) {
                return true;
            }
        }
    }
    result = compare(val1, val2, strict);
    return result;
}
Also used : Property(main.system.math.Property)

Example 2 with Property

use of main.system.math.Property 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)

Example 3 with Property

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

the class ListItem method getCompIcon.

protected ImageIcon getCompIcon(Entity entity, boolean isSelected) {
    if (entity == null) {
        return null;
    }
    Image img = null;
    if (!noImage) {
        try {
            img = (entity.getCustomIcon() != null ? entity.getCustomIcon().getImage() : ImageManager.getImage(entity.getProperty(G_PROPS.IMAGE, false)));
        } catch (Exception e) {
            main.system.ExceptionMaster.printStackTrace(e);
        }
    }
    if (img == null) {
        noImage = true;
        if (entity.getRef() != null) {
            img = ImageManager.getImage(new Property(entity.getProperty(G_PROPS.IMAGE, false)).getStr(entity.getRef()));
        }
    }
    if (img == null) {
        img = (getEmptyIcon() != null) ? ImageManager.getImage(getEmptyIcon()) : ImageManager.getEmptyIcon(getObjSize()).getImage();
    }
    if (getObjSize() != 0) {
        if (img.getHeight(null) != getObjSize() || img.getWidth(null) != getObjSize()) {
            img = ImageManager.getSizedVersion(img, new Dimension(getObjSize(), getObjSize()));
        } else if (img.getWidth(null) > ImageManager.getMaxTypeIconSize() || img.getHeight(null) > ImageManager.getMaxTypeIconSize()) {
            img = ImageManager.getSizedVersion(img, new Dimension(ImageManager.getMaxTypeIconSize(), ImageManager.getMaxTypeIconSize()));
        }
    }
    ImageIcon icon = new ImageIcon(img);
    return icon;
}
Also used : Property(main.system.math.Property)

Example 4 with Property

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

the class Entity method toBase.

public void toBase() {
    setBeingReset(true);
    // TODO DRY!
    if (getMaster() != null) {
        if (getResetter() != null) {
            getResetter().toBase();
            setBeingReset(false);
            return;
        }
    }
    getPropCache().clear();
    // TODO [OPTIMIZED] no need to clear
    getIntegerMap(false).clear();
    // type's map?
    if (modifierMaps != null) {
        // remember? For interesting spells or log
        modifierMaps.clear();
    }
    // info...
    if (!type.checkProperty(G_PROPS.DISPLAYED_NAME)) {
        setProperty(G_PROPS.DISPLAYED_NAME, getName(), true);
    }
    if (this.owner != getOriginalOwner()) {
        LogMaster.log(LogMaster.CORE_DEBUG, getName() + ": original owner restored!");
    }
    this.owner = getOriginalOwner();
    HashSet<PARAMETER> params = new HashSet<>(getParamMap().keySet());
    params.addAll(type.getParamMap().keySet());
    for (PARAMETER p : params) {
        if (p == null) {
            continue;
        }
        if (p.isDynamic()) {
            if (p.isWriteToType()) {
                getType().setParam(p, getParam(p), true);
            }
            continue;
        }
        String baseValue = getType().getParam(p);
        String value = getParam(p);
        getValueCache().put(p, value);
        if (!value.equals(baseValue)) {
            String amount = getType().getParam(p);
            putParameter(p, amount);
            if (game.isStarted() && !game.isSimulation()) {
                if (p.isDynamic()) {
                    fireParamEvent(p, amount, CONSTRUCTED_EVENT_TYPE.PARAM_MODIFIED);
                }
            }
        }
    }
    HashSet<PROPERTY> props = new HashSet<>(getPropMap().keySet());
    props.addAll(type.getPropMap().keySet());
    for (PROPERTY p : props) {
        if (p.isDynamic()) {
            if (p.isWriteToType()) {
                getType().setProperty(p, getProperty(p));
            }
            continue;
        }
        String baseValue = getType().getProperty(p);
        if (TextParser.isRef(baseValue)) {
            baseValue = new Property(baseValue).getStr(ref);
            if ((baseValue) == null) {
                baseValue = getType().getProperty(p);
            }
        }
        String value = getProperty(p);
        getValueCache().put(p, value);
        if (!value.equals(baseValue)) {
            putProperty(p, baseValue);
        } else {
            putProperty(p, baseValue);
        }
    }
    // resetStatus();
    setDirty(false);
    setBeingReset(false);
}
Also used : PROPERTY(main.content.values.properties.PROPERTY) Property(main.system.math.Property) PARAMETER(main.content.values.parameters.PARAMETER)

Example 5 with Property

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

the class SummonEffect method applyThis.

@Override
public boolean applyThis() {
    // TODO XP -> LEVEL!
    Ref REF = Ref.getCopy(ref);
    REF.setValue(KEYS.STRING, typeName);
    ObjType type = DataManager.getType(typeName, getTYPE());
    game.fireEvent(new Event(getEventType(), REF));
    Coordinates c = ref.getTargetObj().getCoordinates();
    if (type == null) {
        String str = new Property(typeName, true).getStr(ref);
        type = DataManager.getType(str);
    }
    if (type.getOBJ_TYPE_ENUM() != DC_TYPE.CHARS) {
        type = addXp(type);
    }
    if (owner == null) {
        owner = ref.getSourceObj().getOwner();
    }
    setUnit((BattleFieldObject) game.createUnit(type, c.x, c.y, owner, ref.getCopy()));
    if (unit instanceof Unit) {
        if (!((Unit) unit).isHero()) {
            UnitTrainingMaster.train((Unit) unit);
        }
    }
    getUnit().getRef().setID(KEYS.SUMMONER, ref.getSource());
    REF.setID(KEYS.SUMMONED, getUnit().getId());
    ref.setID(KEYS.SUMMONED, getUnit().getId());
    game.fireEvent(new Event(getEventTypeDone(), REF));
    unit.getRef().setID(KEYS.ACTIVE, ref.getId(KEYS.ACTIVE));
    UpkeepRule.addUpkeep(unit);
    if (unit instanceof Unit) {
        SummoningSicknessRule.apply((Unit) unit);
    }
    if (effects != null) {
        REF.setTarget(getUnit().getId());
        return effects.apply(REF);
    }
    DC_SoundMaster.playEffectSound(SOUNDS.READY, unit);
    return true;
}
Also used : Ref(main.entity.Ref) ObjType(main.entity.type.ObjType) Coordinates(main.game.bf.Coordinates) Event(main.game.logic.event.Event) Unit(eidolons.entity.obj.unit.Unit) Property(main.system.math.Property)

Aggregations

Property (main.system.math.Property)6 PARAMETER (main.content.values.parameters.PARAMETER)3 PROPERTY (main.content.values.properties.PROPERTY)2 Unit (eidolons.entity.obj.unit.Unit)1 HashSet (java.util.HashSet)1 AbilityObj (main.ability.AbilityObj)1 VALUE (main.content.VALUE)1 Entity (main.entity.Entity)1 Ref (main.entity.Ref)1 ObjType (main.entity.type.ObjType)1 Coordinates (main.game.bf.Coordinates)1 Game (main.game.core.game.Game)1 Event (main.game.logic.event.Event)1 Formula (main.system.math.Formula)1 Parameter (main.system.math.Parameter)1