Search in sources :

Example 6 with EquationTransform

use of de.slikey.effectlib.math.EquationTransform in project EffectLib by Slikey.

the class ModifiedEffect method onRun.

@Override
public void onRun() {
    if (!initialized) {
        initialized = true;
        if (effect == null) {
            effectManager.onError("ModifiedEffect missing inner effect configuration");
            cancel();
            return;
        }
        if (effectClass == null) {
            effectClass = effect.getString("class");
        }
        if (effectClass == null) {
            effectManager.onError("ModifiedEffect missing inner effect class property");
            cancel();
            return;
        }
        innerEffect = effectManager.getEffect(effectClass, effect, origin, target, null, targetPlayer);
        if (innerEffect == null) {
            cancel();
            return;
        }
        innerEffect.materialData = materialData;
        innerEffect.material = material;
        for (Map.Entry<String, String> entry : parameters.entrySet()) {
            String equation = entry.getValue();
            String fieldName = entry.getKey();
            // Allow underscore_style and dash_style parameters
            if (fieldName.contains("-")) {
                fieldName = fieldName.replace("-", "_");
            }
            if (fieldName.contains("_")) {
                fieldName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, fieldName);
            }
            EquationTransform transform = EquationStore.getInstance().getTransform(equation, variables);
            Exception ex = transform.getException();
            if (ex != null) {
                effectManager.onError("Error parsing equation: " + equation, ex);
                continue;
            }
            try {
                Field field = innerEffect.getClass().getField(fieldName);
                parameterTransforms.put(field, transform);
            } catch (Exception ex2) {
                effectManager.onError("Error binding to field: " + fieldName + " of effect class " + effectClass, ex2);
                continue;
            }
        }
        innerEffect.prepare();
        if (xEquation != null)
            xTransform = EquationStore.getInstance().getTransform(xEquation, _variables);
        if (yEquation != null)
            yTransform = EquationStore.getInstance().getTransform(yEquation, _variables);
        if (zEquation != null)
            zTransform = EquationStore.getInstance().getTransform(zEquation, _variables);
    }
    if (innerEffect == null) {
        cancel();
        return;
    }
    if (origin != null && xTransform != null || yTransform != null || zTransform != null) {
        Vector offset = new Vector(xTransform == null ? 0 : xTransform.get(step, maxIterations), yTransform == null ? 0 : yTransform.get(step, maxIterations), zTransform == null ? 0 : zTransform.get(step, maxIterations));
        if (previousOffset != null) {
            offset.subtract(previousOffset);
        } else {
            previousOffset = new Vector();
        }
        Location location = getLocation();
        if (orient && orientPitch) {
            offset = VectorUtils.rotateVector(offset, location);
        } else if (orient) {
            offset = VectorUtils.rotateVector(offset, location.getYaw(), 0);
        }
        origin.addOffset(offset);
        previousOffset.add(offset);
    }
    for (Map.Entry<Field, EquationTransform> entry : parameterTransforms.entrySet()) {
        double value = entry.getValue().get(step, maxIterations);
        try {
            Field field = entry.getKey();
            if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) {
                entry.getKey().set(innerEffect, value);
            } else if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) {
                entry.getKey().set(innerEffect, (int) value);
            } else if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) {
                entry.getKey().set(innerEffect, (float) value);
            } else if (field.getType().equals(Short.class) || field.getType().equals(Short.TYPE)) {
                entry.getKey().set(innerEffect, (short) value);
            } else if (field.getType().equals(Byte.class) || field.getType().equals(Byte.TYPE)) {
                entry.getKey().set(innerEffect, (byte) value);
            } else {
                effectManager.onError("Can't assign property " + entry.getKey().getName() + " of effect class " + effectClass + " of type " + field.getType().getName());
                cancel();
                return;
            }
        } catch (Exception ex) {
            effectManager.onError("Error assigning to : " + entry.getKey().getName() + " of effect class " + effectClass, ex);
            cancel();
            return;
        }
    }
    try {
        innerEffect.onRun();
    } catch (Exception ex) {
        innerEffect.onDone();
        effectManager.onError(ex);
    }
    step++;
}
Also used : EquationTransform(de.slikey.effectlib.math.EquationTransform) Field(java.lang.reflect.Field) HashMap(java.util.HashMap) Map(java.util.Map) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 7 with EquationTransform

use of de.slikey.effectlib.math.EquationTransform in project EffectLib by Slikey.

the class PlotEffect method onRun.

@Override
public void onRun() {
    int base = persistent ? 0 : step;
    for (int i = base; i <= step; i++) {
        Location location = getLocation().clone();
        double xOffset = step;
        double yOffset = step;
        double zOffset = 0;
        if (xEquation != null && !xEquation.isEmpty()) {
            EquationTransform xTransform = EquationStore.getInstance().getTransform(xEquation, variables);
            xOffset = xTransform.get(i, maxIterations);
        }
        if (yEquation != null && !yEquation.isEmpty()) {
            EquationTransform yTransform = EquationStore.getInstance().getTransform(yEquation, variables);
            yOffset = yTransform.get(i, maxIterations);
        }
        if (zEquation != null && !zEquation.isEmpty()) {
            EquationTransform zTransform = EquationStore.getInstance().getTransform(zEquation, variables);
            zOffset = zTransform.get(i, maxIterations);
        }
        location.add(xOffset * xScale, yOffset * yScale, zOffset * zScale);
        display(particle, location);
    }
    step++;
}
Also used : EquationTransform(de.slikey.effectlib.math.EquationTransform) Location(org.bukkit.Location)

Aggregations

EquationTransform (de.slikey.effectlib.math.EquationTransform)7 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 Location (org.bukkit.Location)3 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)3 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 CastContext (com.elmakers.mine.bukkit.action.CastContext)1 Batch (com.elmakers.mine.bukkit.api.batch.Batch)1 SpellBatch (com.elmakers.mine.bukkit.api.batch.SpellBatch)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)1 CastingCost (com.elmakers.mine.bukkit.api.spell.CastingCost)1 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)1 PrerequisiteSpell (com.elmakers.mine.bukkit.api.spell.PrerequisiteSpell)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 SpellParameters (com.elmakers.mine.bukkit.magic.SpellParameters)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1