Search in sources :

Example 1 with PartSkeletalDetails

use of org.terasology.anatomy.component.PartSkeletalDetails 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 PartSkeletalDetails

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

the class SkeletalSystem method healAllBones.

@Command(shortDescription = "Heal all bone parts to full health")
public String healAllBones(@Sender EntityRef client) {
    EntityRef character = client.getComponent(ClientComponent.class).character;
    BoneComponent boneComponent = character.getComponent(BoneComponent.class);
    if (boneComponent != null) {
        for (Map.Entry<String, PartSkeletalDetails> partSkeletalDetails : boneComponent.parts.entrySet()) {
            partSkeletalDetails.getValue().health = partSkeletalDetails.getValue().maxHealth;
        }
    }
    return "Healths fully restored.";
}
Also used : BrokenBoneComponent(org.terasology.anatomy.AnatomySkeleton.component.BrokenBoneComponent) BoneComponent(org.terasology.anatomy.AnatomySkeleton.component.BoneComponent) PartSkeletalDetails(org.terasology.anatomy.component.PartSkeletalDetails) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) HashMap(java.util.HashMap) Map(java.util.Map) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 3 with PartSkeletalDetails

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

the class SkeletalSystem method showBoneHealths.

@Command(shortDescription = "Show bone healths of all parts")
public String showBoneHealths(@Sender EntityRef client) {
    EntityRef character = client.getComponent(ClientComponent.class).character;
    BoneComponent boneComponent = character.getComponent(BoneComponent.class);
    String result = "Bone healths :\n";
    if (boneComponent != null) {
        for (Map.Entry<String, PartSkeletalDetails> partSkeletalDetails : boneComponent.parts.entrySet()) {
            result += partSkeletalDetails.getKey() + " :" + partSkeletalDetails.getValue().health + "/" + partSkeletalDetails.getValue().maxHealth + "\n";
        }
    }
    return result;
}
Also used : BrokenBoneComponent(org.terasology.anatomy.AnatomySkeleton.component.BrokenBoneComponent) BoneComponent(org.terasology.anatomy.AnatomySkeleton.component.BoneComponent) PartSkeletalDetails(org.terasology.anatomy.component.PartSkeletalDetails) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) HashMap(java.util.HashMap) Map(java.util.Map) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 4 with PartSkeletalDetails

use of org.terasology.anatomy.component.PartSkeletalDetails 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)

Aggregations

PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)4 BoneComponent (org.terasology.anatomy.AnatomySkeleton.component.BoneComponent)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BrokenBoneComponent (org.terasology.anatomy.AnatomySkeleton.component.BrokenBoneComponent)2 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 Command (org.terasology.logic.console.commandSystem.annotations.Command)2 ClientComponent (org.terasology.network.ClientComponent)2