Search in sources :

Example 1 with BoneComponent

use of org.terasology.anatomy.AnatomySkeleton.component.BoneComponent in project Anatomy by Terasology.

the class SkeletalAuthoritySystem method onRegen.

@ReceiveEvent
public void onRegen(DelayedActionTriggeredEvent event, EntityRef entityRef) {
    BoneComponent boneComponent = entityRef.getComponent(BoneComponent.class);
    String partID = event.getActionId().substring(SKELETAL_REGEN_PREFIX.length());
    PartSkeletalDetails partDetails = boneComponent.parts.get(partID);
    if (partDetails.health >= 0 && partDetails.health != partDetails.maxHealth && partDetails.regenRate != 0) {
        int healAmount = 0;
        healAmount = regenerateHealth(partDetails, healAmount);
        partDetails.health += healAmount;
        entityRef.saveComponent(boneComponent);
        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) BoneComponent(org.terasology.anatomy.AnatomySkeleton.component.BoneComponent) PartSkeletalDetails(org.terasology.anatomy.component.PartSkeletalDetails) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

BoneComponent (org.terasology.anatomy.AnatomySkeleton.component.BoneComponent)1 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)1 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1