Search in sources :

Example 1 with InjuredBoneComponent

use of org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent 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 2 with InjuredBoneComponent

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

the class SkeletalSystem method applyEffect.

/**
 * Applies effect of particular severity to an anatomy part.
 */
private void applyEffect(EntityRef entityRef, String partId, int severity) {
    if (entityRef.getComponent(InjuredBoneComponent.class) == null) {
        entityRef.addComponent(new InjuredBoneComponent());
    }
    InjuredBoneComponent injuredBoneComponent = entityRef.getComponent(InjuredBoneComponent.class);
    for (Map.Entry<String, List<String>> partsOfSeverity : injuredBoneComponent.parts.entrySet()) {
        // If the part already has a skeletal effect.
        if (partsOfSeverity.getValue().contains(partId)) {
            // If the severity matches, return.
            if (Integer.parseInt(partsOfSeverity.getKey()) == severity) {
                return;
            } else {
                // Else, remove the incorrect severity effect.
                partsOfSeverity.getValue().remove(partId);
            }
        }
    }
    // Add the skeletal effect with correct severity.
    if (injuredBoneComponent.parts.containsKey(String.valueOf(severity))) {
        injuredBoneComponent.parts.get(String.valueOf(severity)).add(partId);
    } else {
        injuredBoneComponent.parts.put(String.valueOf(severity), Lists.newArrayList(partId));
    }
    entityRef.saveComponent(injuredBoneComponent);
}
Also used : InjuredBoneComponent(org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with InjuredBoneComponent

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

the class SkeletalSystem method showBoneHealths.

/**
 * Console command - Shows the skeletal healths of injured parts.
 */
@Command(shortDescription = "Show bone healths of all injured parts")
public String showBoneHealths(@Sender EntityRef client) {
    EntityRef character = client.getComponent(ClientComponent.class).character;
    InjuredBoneComponent injuredBoneComponent = character.getComponent(InjuredBoneComponent.class);
    String result = "";
    if (injuredBoneComponent != null) {
        result += "Bone healths :\n";
        for (Map.Entry<String, PartHealthDetails> partHealthDetailsEntry : injuredBoneComponent.partHealths.entrySet()) {
            result += partHealthDetailsEntry.getKey() + " :" + partHealthDetailsEntry.getValue().health + "/" + partHealthDetailsEntry.getValue().maxHealth + "\n";
        }
    } else {
        result += "Skeletal system healthy.\n";
    }
    return result;
}
Also used : 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 4 with InjuredBoneComponent

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

Aggregations

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