Search in sources :

Example 6 with Property

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

the class EntityResetter method toBase.

public void toBase() {
    getPropCache().clear();
    // TODO [OPTIMIZED] no need to clear
    getEntity().getIntegerMap(false).clear();
    // type's map?
    if (getEntity().getModifierMaps() != null) {
        // remember? For interesting spells or log
        getEntity().getModifierMaps().clear();
    }
    // info...
    if (!getType().checkProperty(G_PROPS.DISPLAYED_NAME)) {
        getEntity().setProperty(G_PROPS.DISPLAYED_NAME, getName(), true);
    }
    if (this.getEntity().getOwner() != getEntity().getOriginalOwner()) {
        LogMaster.log(LogMaster.CORE_DEBUG, getName() + ": original owner restored!");
    }
    getEntity().setOwner(getEntity().getOriginalOwner());
    HashSet<PARAMETER> params = new HashSet<>(getEntity().getParamMap().keySet());
    params.addAll(getType().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);
        getEntity().getValueCache().put(p, value);
        if (!value.equals(baseValue)) {
            String amount = getType().getParam(p);
            if (getEntity().isTypeLinked()) {
                getType().getParamMap().put(p, value);
            }
            getEntity().getParamMap().put(p, amount);
            if (game.isStarted() && !game.isSimulation()) {
                if (p.isDynamic()) {
                    getEntity().fireParamEvent(p, amount, CONSTRUCTED_EVENT_TYPE.PARAM_MODIFIED);
                }
            }
        }
    }
    HashSet<PROPERTY> props = new HashSet<>(getEntity().getPropMap().keySet());
    props.addAll(getType().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(getRef());
            if ((baseValue) == null) {
                baseValue = getType().getProperty(p);
            }
        }
        String value = getProperty(p);
        getEntity().getValueCache().put(p, value);
        if (!value.equals(baseValue)) {
            if (getEntity().isTypeLinked()) {
                getType().getPropMap().put(p, value);
            }
            getEntity().getPropMap().put(p, baseValue);
        } else {
            // TODO ???
            if (getEntity().isTypeLinked()) {
                getType().getPropMap().put(p, value);
            }
            getEntity().getPropMap().put(p, baseValue);
        }
    }
    resetStatus();
    getEntity().setDirty(false);
}
Also used : PROPERTY(main.content.values.properties.PROPERTY) Property(main.system.math.Property) PARAMETER(main.content.values.parameters.PARAMETER) HashSet(java.util.HashSet)

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