/*
 * Copyright 2014 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.entitySystem.event;

import gnu.trove.iterator.TFloatIterator;
import gnu.trove.list.TFloatList;
import gnu.trove.list.array.TFloatArrayList;

/**
 */
public abstract class AbstractValueModifiableEvent implements Event {
    private float baseValue;

    private TFloatList modifiers = new TFloatArrayList();
    private TFloatList multipliers = new TFloatArrayList();
    private TFloatList postModifiers = new TFloatArrayList();

    protected AbstractValueModifiableEvent(float baseValue) {
        this.baseValue = baseValue;
    }

    public float getBaseValue() {
        return baseValue;
    }

    public void multiply(float amount) {
        this.multipliers.add(amount);
    }

    public void add(float amount) {
        modifiers.add(amount);
    }

    public void addPostMultiply(float amount) {
        postModifiers.add(amount);
    }

    public float getResultValue() {
        // For now, add all modifiers and multiply by all multipliers. Negative modifiers cap to zero, but negative
        // multipliers remain.

        float result = baseValue;
        TFloatIterator modifierIter = modifiers.iterator();
        while (modifierIter.hasNext()) {
            result += modifierIter.next();
        }
        result = Math.max(0, result);

        TFloatIterator multiplierIter = multipliers.iterator();
        while (multiplierIter.hasNext()) {
            result *= multiplierIter.next();
        }

        final TFloatIterator postModifierIter = postModifiers.iterator();
        while (postModifierIter.hasNext()) {
            result += postModifierIter.next();
        }
        return result;
    }

    public TFloatList getModifiers() {
        return modifiers;
    }

    public void setModifiers(TFloatList modifiers) {
        this.modifiers = modifiers;
    }

    public TFloatList getMultipliers() {
        return multipliers;
    }

    public void setMultipliers(TFloatList multipliers) {
        this.multipliers = multipliers;
    }

    public TFloatList getPostModifiers() {
        return postModifiers;
    }

    public void setPostModifiers(TFloatList postModifiers) {
        this.postModifiers = postModifiers;
    }
}

@@ -760,16 +760,111 @@
 t;%0A%0A/**%0A
+ * A generic event for getting a value for a property.%0A *%0A * @see AbstractValueModifiableEvent%0A
  */%0Apubl
@@ -1570,67 +1570,76 @@
     
-public float getR
+/**%0A     * Calculates the r
 esult
-V
+ v
 alue
-() %7B%0A        // For now, add all
+ from the base value and given
  mod
@@ -1660,106 +1660,323 @@
 tipl
-y by all multipliers. Negative modifiers cap to zero, but negative%0A        // multipliers remain.%0A
+iers.%0A     * %0A     * The value is calculated base on the following formula:%0A     * %3Cpre%3E%0A     * result = max(0, %3CbaseValue%3E + %CE%A3 %3Cmodifier%3E) * %CE%A0 %3Cmultiplier%3E + %CE%A3 %3CpostModifier%3E%0A     * %3C/pre%3E%0A     *%0A     * %3Cemph%3ENote that the value range of result is not restricted!%3C/emph%3E%0A     */%0A    public float getResultValue() %7B
 %0A   

Add docs and contracts