Search in sources :

Example 6 with ReceiveEvent

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));
    }
}
Also used : BoneHealthChangedEvent(org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent) PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Example 7 with ReceiveEvent

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()));
    }
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) ArrayList(java.util.ArrayList) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.gestalt.entitysystem.event.ReceiveEvent)7 PartHealthDetails (org.terasology.anatomy.component.PartHealthDetails)4 PartCirculatoryHealthChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryHealthChangedEvent)2 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 ArrayList (java.util.ArrayList)1 InjuredCirculatoryComponent (org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent)1 BloodLevelChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.BloodLevelChangedEvent)1 InjuredBoneComponent (org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent)1 AnatomyPartTag (org.terasology.anatomy.component.AnatomyPartTag)1 AnatomyPartImpactedEvent (org.terasology.anatomy.event.AnatomyPartImpactedEvent)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 DestroyEvent (org.terasology.engine.logic.health.DestroyEvent)1