Effects - Sponge-RPG-dev/NT-RPG GitHub Wiki

Effects

Effects are temporal data which can be attached to any object which implements EffectConsumer interface. All effects are handled by the EffectService. You should never ever need to call method EffectConsumer.addEffect. Effects are not persistant between server restarts, unless you serialize them with your own business logic.

Example

`

public class DamageBonus extends EffectBase {
    public static final String name = "BonusDamage";
    float bonusDamage;

public DamageBonus(IEffectConsumer consumer, long duration, float bonusDamage) {
    super(name, consumer);
    setDuration(duration);
    setBonusDamage(bonusDamage);
}

public float getBonusDamage() {
    return bonusDamage;
}

public void setBonusDamage(float bonusDamage) {
    this.bonusDamage = bonusDamage;
}

@Override
public void onApply() {
    super.onApply();
    IActiveCharacter character = (IActiveCharacter) getConsumer();
    character.setCharacterProperty(DefaultProperties.weapon_damage_bonus, character.getCharacterProperty(DefaultProperties.weapon_damage_bonus) + getBonusDamage());
    getGlobalScope().damageService.recalculateCharacterWeaponDamage(character);
}

@Override
public void onRemove() {
    super.onRemove();
    IActiveCharacter character = (IActiveCharacter) getConsumer();
    character.setCharacterProperty(DefaultProperties.weapon_damage_bonus, character.getCharacterProperty(DefaultProperties.weapon_damage_bonus) - getBonusDamage());
    getGlobalScope().damageService.recalculateCharacterWeaponDamage(character);
}
}



IActiveCharacter entity = ...
DamageBonus damagebonu = new DamageBonus(entity,10L,10f);
effectService.addEffect(damagebonu,entity)

Global Effects

If you would like to access this effect from command, or as an item echantment you have to either create a new class which implements from IGlobalEffect, or use @Generate annotation. The effect must contain a constructor (IEffectConsumer, long duration, float level)

If the effect's duration is set to -1 the effect will never expire. If the effect's period is greater than 0 the effect service will call onTick method. By default minimal period between two ticks is 150 ms. The value can be changed in config files but may decrease server performance.

Properties

Each property is a single-value data represented as a float and stored in a primitive float array. Its guaranteed every player has all properties.

Defining a property

@PropertyContainer
public class SomeProperties {

    @Property(name = "max_mana")
    public static int max_mana;
}

That's it. Each field annotated with @Property represents an index of property in the array. Type of the field must be static and either int or short. If "name" attribute is specified the property will be accessible from configuration files (such as class configs) or commands. All properties are printed into a file properties_dump.info

Accessing a property value

IActiveCharacter c = ...
float maxmana = c.getCharacterProperty(SomeProperties.max_mana);

Javascript

todo