use of org.terasology.gestalt.entitysystem.event.ReceiveEvent in project Anatomy by Terasology.
the class SkeletalHealthSystem method onRegen.
@ReceiveEvent
public void onRegen(DelayedActionTriggeredEvent event, EntityRef entityRef, InjuredBoneComponent injuredBoneComponent) {
if (event.getActionId().startsWith(SKELETAL_REGEN_PREFIX)) {
String partID = event.getActionId().substring(SKELETAL_REGEN_PREFIX.length());
PartHealthDetails partDetails = injuredBoneComponent.partHealths.get(partID);
if (partDetails.health >= 0 && partDetails.health != partDetails.maxHealth && partDetails.regenRate != 0) {
int healAmount = 0;
healAmount = regenerateHealth(partDetails, healAmount);
partDetails.health += healAmount;
partDetails.health = TeraMath.clamp(partDetails.health, 0, partDetails.maxHealth);
entityRef.saveComponent(injuredBoneComponent);
entityRef.send(new BoneHealthChangedEvent(partID));
}
delayManager.addDelayedAction(entityRef, SKELETAL_REGEN_PREFIX + partID, (long) (1000 / partDetails.regenRate));
}
}
use of org.terasology.gestalt.entitysystem.event.ReceiveEvent in project Anatomy by Terasology.
the class AnatomySystem method onDamage.
/**
* Receives an {@link OnDamagedEvent} and allocates the damage to an anatomy part.
*/
@ReceiveEvent
public void onDamage(OnDamagedEvent event, EntityRef entity, AnatomyComponent comp) {
if (comp != null) {
List<String> keys = new ArrayList<>(comp.parts.keySet());
// Randomly assign damage to a part, until positional damage is introduced.
AnatomyPartTag partTag = comp.parts.get(keys.get(random.nextInt(0, keys.size() - 1)));
entity.send(new AnatomyPartImpactedEvent(event.getDamageAmount(), partTag, event.getType(), event.getInstigator()));
}
}
Aggregations