Search in sources :

Example 1 with BoneHealthChangedEvent

use of org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent 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)

Example 2 with BoneHealthChangedEvent

use of org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent in project Anatomy by Terasology.

the class SkeletalSystem method healAllBones.

/**
 * Console command - Heals all parts' skeletal healths to max.
 */
@Command(shortDescription = "Heal all bone parts to full health")
public String healAllBones(@Sender EntityRef client) {
    EntityRef character = client.getComponent(ClientComponent.class).character;
    InjuredBoneComponent injuredBoneComponent = character.getComponent(InjuredBoneComponent.class);
    if (injuredBoneComponent != null) {
        for (Map.Entry<String, PartHealthDetails> partHealthDetailsEntry : injuredBoneComponent.partHealths.entrySet()) {
            partHealthDetailsEntry.getValue().health = partHealthDetailsEntry.getValue().maxHealth;
            character.send(new BoneHealthChangedEvent(partHealthDetailsEntry.getKey()));
        }
    }
    return "Skeletal healths fully restored.";
}
Also used : BoneHealthChangedEvent(org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent) PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) InjuredBoneComponent(org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) HashMap(java.util.HashMap) Map(java.util.Map) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 3 with BoneHealthChangedEvent

use of org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent in project Anatomy by Terasology.

the class SkeletalAuthoritySystem method onBoneDamage.

@ReceiveEvent
public void onBoneDamage(AnatomyPartImpactedEvent event, EntityRef entityRef, AnatomyComponent anatomyComponent, BoneComponent boneComponent) {
    PartSkeletalDetails partDetails = boneComponent.parts.get(event.getTargetPart().id);
    // Check if the part contains bone.
    int damageAmount = event.getAmount();
    if (partDetails != null) {
        if (event.getDamageType().getName().equals("Equipment:bluntDamage")) {
            damageAmount *= bluntDamageMultiplier;
        }
        partDetails.health -= damageAmount;
        if (partDetails.health < 0) {
            partDetails.health = 0;
        }
        partDetails.nextRegenTick = time.getGameTimeInMs() + TeraMath.floorToInt(partDetails.waitBeforeRegen * 1000);
        entityRef.saveComponent(boneComponent);
        entityRef.send(new BoneHealthChangedEvent(event.getTargetPart().id));
    }
}
Also used : BoneHealthChangedEvent(org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent) PartSkeletalDetails(org.terasology.anatomy.component.PartSkeletalDetails) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 4 with BoneHealthChangedEvent

use of org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent in project Anatomy by Terasology.

the class SkeletalHealthSystem method onBoneDamage.

@ReceiveEvent
public void onBoneDamage(AnatomyPartImpactedEvent event, EntityRef entityRef, AnatomyComponent anatomyComponent) {
    if (anatomyComponent.parts.get(event.getTargetPart().id).characteristics.contains(BONE_CHARACTERISTIC)) {
        InjuredBoneComponent injuredBoneComponent = entityRef.getComponent(InjuredBoneComponent.class);
        if (injuredBoneComponent == null) {
            injuredBoneComponent = new InjuredBoneComponent();
            entityRef.addComponent(injuredBoneComponent);
        }
        PartHealthDetails partHealthDetails = injuredBoneComponent.partHealths.get(event.getTargetPart().id);
        if (partHealthDetails == null) {
            partHealthDetails = new PartHealthDetails();
            injuredBoneComponent.partHealths.put(event.getTargetPart().id, partHealthDetails);
            // Part has been injured for the first time, so add delayed regen event.
            delayManager.addDelayedAction(entityRef, SKELETAL_REGEN_PREFIX + event.getTargetPart().id, (long) (1000 / partHealthDetails.regenRate));
        }
        int damageAmount = event.getAmount();
        if (event.getDamageType().getName().equals("Equipment:bluntDamage")) {
            damageAmount *= bluntDamageMultiplier;
        }
        partHealthDetails.health -= damageAmount;
        partHealthDetails.health = TeraMath.clamp(partHealthDetails.health, 0, partHealthDetails.maxHealth);
        partHealthDetails.nextRegenTick = time.getGameTimeInMs() + TeraMath.floorToInt(partHealthDetails.waitBeforeRegen * 1000);
        entityRef.saveComponent(injuredBoneComponent);
        entityRef.send(new BoneHealthChangedEvent(event.getTargetPart().id));
    }
}
Also used : BoneHealthChangedEvent(org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent) PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) InjuredBoneComponent(org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Example 5 with BoneHealthChangedEvent

use of org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent 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)

Aggregations

BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)5 PartHealthDetails (org.terasology.anatomy.component.PartHealthDetails)3 InjuredBoneComponent (org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 ReceiveEvent (org.terasology.gestalt.entitysystem.event.ReceiveEvent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BoneComponent (org.terasology.anatomy.AnatomySkeleton.component.BoneComponent)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)1 ClientComponent (org.terasology.engine.network.ClientComponent)1