Search in sources :

Example 1 with BloodLevelChangedEvent

use of org.terasology.anatomy.AnatomyCirculation.event.BloodLevelChangedEvent in project Anatomy by Terasology.

the class CirculatoryHealthSystem method onBloodLevelRegen.

@ReceiveEvent
public void onBloodLevelRegen(DelayedActionTriggeredEvent event, EntityRef entityRef, InjuredCirculatoryComponent injuredCirculatoryComponent) {
    if (event.getActionId().startsWith(CIRCULATORY_BLOOD_REGEN_PREFIX)) {
        if (injuredCirculatoryComponent.bloodLevel >= 0 && injuredCirculatoryComponent.bloodLevel <= injuredCirculatoryComponent.maxBloodLevel && injuredCirculatoryComponent.bloodRegenRate != 0) {
            int healAmount = 0;
            healAmount += injuredCirculatoryComponent.bloodRegenRate / TeraMath.fastAbs(injuredCirculatoryComponent.bloodRegenRate);
            injuredCirculatoryComponent.nextRegenTick = time.getGameTimeInMs() + (long) (1000 / TeraMath.fastAbs(injuredCirculatoryComponent.bloodRegenRate));
            injuredCirculatoryComponent.bloodLevel += healAmount;
            injuredCirculatoryComponent.bloodLevel = TeraMath.clamp(injuredCirculatoryComponent.bloodLevel, 0, injuredCirculatoryComponent.maxBloodLevel);
            entityRef.saveComponent(injuredCirculatoryComponent);
            entityRef.send(new BloodLevelChangedEvent());
        }
        delayManager.addDelayedAction(entityRef, CIRCULATORY_BLOOD_REGEN_PREFIX, (long) (1000 / TeraMath.fastAbs(injuredCirculatoryComponent.bloodRegenRate)));
    }
}
Also used : BloodLevelChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.BloodLevelChangedEvent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Aggregations

BloodLevelChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.BloodLevelChangedEvent)1 ReceiveEvent (org.terasology.gestalt.entitysystem.event.ReceiveEvent)1