Search in sources :

Example 1 with InjuredCirculatoryComponent

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

the class CirculatorySystem method removeEffect.

private void removeEffect(EntityRef entityRef, String partId) {
    InjuredCirculatoryComponent injuredCirculatoryComponent = entityRef.getComponent(InjuredCirculatoryComponent.class);
    if (injuredCirculatoryComponent != null) {
        for (Map.Entry<String, List<String>> partsOfSeverity : injuredCirculatoryComponent.parts.entrySet()) {
            partsOfSeverity.getValue().remove(partId);
        }
        entityRef.saveComponent(injuredCirculatoryComponent);
        entityRef.send(new PartCirculatoryEffectChangedEvent());
    }
}
Also used : PartCirculatoryEffectChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent) InjuredCirculatoryComponent(org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with InjuredCirculatoryComponent

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

the class CirculatorySystem method applyEffect.

private void applyEffect(EntityRef entityRef, String partId, int severity) {
    if (entityRef.getComponent(InjuredCirculatoryComponent.class) == null) {
        entityRef.addComponent(new InjuredCirculatoryComponent());
    }
    InjuredCirculatoryComponent injuredCirculatoryComponent = entityRef.getComponent(InjuredCirculatoryComponent.class);
    for (Map.Entry<String, List<String>> partsOfSeverity : injuredCirculatoryComponent.parts.entrySet()) {
        if (partsOfSeverity.getValue().contains(partId)) {
            if (Integer.parseInt(partsOfSeverity.getKey()) == severity) {
                return;
            } else {
                partsOfSeverity.getValue().remove(partId);
            }
        }
    }
    if (injuredCirculatoryComponent.parts.containsKey(String.valueOf(severity))) {
        injuredCirculatoryComponent.parts.get(String.valueOf(severity)).add(partId);
    } else {
        injuredCirculatoryComponent.parts.put(String.valueOf(severity), Lists.newArrayList(partId));
    }
    entityRef.saveComponent(injuredCirculatoryComponent);
    entityRef.send(new PartCirculatoryEffectChangedEvent());
}
Also used : PartCirculatoryEffectChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent) InjuredCirculatoryComponent(org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with InjuredCirculatoryComponent

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

the class CirculatorySystem method showCirculatoryHealths.

@Command(shortDescription = "Show circulatory healths of all injured parts")
public String showCirculatoryHealths(@Sender EntityRef client) {
    EntityRef character = client.getComponent(ClientComponent.class).character;
    InjuredCirculatoryComponent injuredCirculatoryComponent = character.getComponent(InjuredCirculatoryComponent.class);
    String result = "";
    if (injuredCirculatoryComponent != null) {
        result += "Blood level : ";
        result += injuredCirculatoryComponent.bloodLevel + "/" + injuredCirculatoryComponent.maxBloodLevel + " Blood regen rate: " + injuredCirculatoryComponent.bloodRegenRate + "\n";
        result += "Circulatory system healths :\n";
        for (Map.Entry<String, PartHealthDetails> partHealthDetailsEntry : injuredCirculatoryComponent.partHealths.entrySet()) {
            result += partHealthDetailsEntry.getKey() + " :" + partHealthDetailsEntry.getValue().health + "/" + partHealthDetailsEntry.getValue().maxHealth + "\n";
        }
    } else {
        result += "Circulatory system healthy.\n";
    }
    return result;
}
Also used : PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) InjuredCirculatoryComponent(org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent) 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 InjuredCirculatoryComponent

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

the class CirculatoryHealthSystem method onCirculatoryDamage.

@ReceiveEvent
public void onCirculatoryDamage(AnatomyPartImpactedEvent event, EntityRef entityRef, AnatomyComponent anatomyComponent) {
    if (anatomyComponent.parts.get(event.getTargetPart().id).characteristics.contains(CIRCULATORY_CHARACTERISTIC)) {
        InjuredCirculatoryComponent injuredCirculatoryComponent = entityRef.getComponent(InjuredCirculatoryComponent.class);
        if (injuredCirculatoryComponent == null) {
            injuredCirculatoryComponent = new InjuredCirculatoryComponent();
            entityRef.addComponent(injuredCirculatoryComponent);
        }
        PartHealthDetails partHealthDetails = injuredCirculatoryComponent.partHealths.get(event.getTargetPart().id);
        if (partHealthDetails == null) {
            partHealthDetails = new PartHealthDetails();
            injuredCirculatoryComponent.partHealths.put(event.getTargetPart().id, partHealthDetails);
            // Part has been injured for the first time, so add delayed part health regen event and blood level regen event.
            delayManager.addDelayedAction(entityRef, CIRCULATORY_REGEN_PREFIX + event.getTargetPart().id, (long) (1000 / partHealthDetails.regenRate));
            delayManager.addDelayedAction(entityRef, CIRCULATORY_BLOOD_REGEN_PREFIX, 1000);
        }
        int damageAmount = event.getAmount();
        if (event.getDamageType().getName().equals("Equipment:pierceDamage")) {
            damageAmount *= pierceDamageMultiplier;
        }
        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(injuredCirculatoryComponent);
        entityRef.send(new PartCirculatoryHealthChangedEvent(event.getTargetPart().id));
    }
}
Also used : PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) InjuredCirculatoryComponent(org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent) PartCirculatoryHealthChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryHealthChangedEvent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Example 5 with InjuredCirculatoryComponent

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

the class CirculatorySystem method healAllCirculation.

@Command(shortDescription = "Heal all circulatory system parts to full health")
public String healAllCirculation(@Sender EntityRef client) {
    EntityRef character = client.getComponent(ClientComponent.class).character;
    InjuredCirculatoryComponent injuredCirculatoryComponent = character.getComponent(InjuredCirculatoryComponent.class);
    if (injuredCirculatoryComponent != null) {
        for (Map.Entry<String, PartHealthDetails> partHealthDetailsEntry : injuredCirculatoryComponent.partHealths.entrySet()) {
            partHealthDetailsEntry.getValue().health = partHealthDetailsEntry.getValue().maxHealth;
            character.send(new PartCirculatoryHealthChangedEvent(partHealthDetailsEntry.getKey()));
        }
    }
    return "Circulatory healths fully restored.";
}
Also used : PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) InjuredCirculatoryComponent(org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent) PartCirculatoryHealthChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryHealthChangedEvent) 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)

Aggregations

InjuredCirculatoryComponent (org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 PartHealthDetails (org.terasology.anatomy.component.PartHealthDetails)3 List (java.util.List)2 PartCirculatoryEffectChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent)2 PartCirculatoryHealthChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryHealthChangedEvent)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 ReceiveEvent (org.terasology.gestalt.entitysystem.event.ReceiveEvent)1