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)));
}
}
Aggregations