Search in sources :

Example 1 with ReceiveEvent

use of org.terasology.gestalt.entitysystem.event.ReceiveEvent in project Anatomy by Terasology.

the class CirculatoryEffectsSystem method onBloodLevelChanged.

@ReceiveEvent
public void onBloodLevelChanged(BloodLevelChangedEvent event, EntityRef entityRef, InjuredCirculatoryComponent injuredCirculatoryComponent) {
    if (injuredCirculatoryComponent.bloodLevel <= 0) {
        Prefab bloodLossDamage = prefabManager.getPrefab("Anatomy:bloodLoss");
        entityRef.send(new DestroyEvent(EntityRef.NULL, EntityRef.NULL, bloodLossDamage));
    }
}
Also used : DestroyEvent(org.terasology.engine.logic.health.DestroyEvent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Example 2 with ReceiveEvent

use of org.terasology.gestalt.entitysystem.event.ReceiveEvent 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 3 with ReceiveEvent

use of org.terasology.gestalt.entitysystem.event.ReceiveEvent in project Anatomy by Terasology.

the class CirculatoryHealthSystem method onPartHealthRegen.

@ReceiveEvent
public void onPartHealthRegen(DelayedActionTriggeredEvent event, EntityRef entityRef, InjuredCirculatoryComponent injuredCirculatoryComponent) {
    if (event.getActionId().startsWith(CIRCULATORY_REGEN_PREFIX)) {
        String partID = event.getActionId().substring(CIRCULATORY_REGEN_PREFIX.length());
        PartHealthDetails partDetails = injuredCirculatoryComponent.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(injuredCirculatoryComponent);
            entityRef.send(new PartCirculatoryHealthChangedEvent(partID));
        }
        delayManager.addDelayedAction(entityRef, CIRCULATORY_REGEN_PREFIX + partID, (long) (1000 / partDetails.regenRate));
    }
}
Also used : PartHealthDetails(org.terasology.anatomy.component.PartHealthDetails) PartCirculatoryHealthChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryHealthChangedEvent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Example 4 with ReceiveEvent

use of org.terasology.gestalt.entitysystem.event.ReceiveEvent in project Anatomy by Terasology.

the class CirculatoryHealthSystem method onBloodLevelRegen.

@ReceiveEvent
public void onBloodLevelRegen(DelayedActionTriggeredEvent event, EntityRef entityRef, InjuredCirculatoryComponent injuredCirculatoryComponent) {
    if (event.getActionId().startsWith(CIRCULATORY_BLOOD_REGEN_PREFIX)) {
        if (injuredCirculatoryComponent.bloodLevel >= 0 && injuredCirculatoryComponent.bloodLevel <= injuredCirculatoryComponent.maxBloodLevel && injuredCirculatoryComponent.bloodRegenRate != 0) {
            int healAmount = 0;
            healAmount += injuredCirculatoryComponent.bloodRegenRate / TeraMath.fastAbs(injuredCirculatoryComponent.bloodRegenRate);
            injuredCirculatoryComponent.nextRegenTick = time.getGameTimeInMs() + (long) (1000 / TeraMath.fastAbs(injuredCirculatoryComponent.bloodRegenRate));
            injuredCirculatoryComponent.bloodLevel += healAmount;
            injuredCirculatoryComponent.bloodLevel = TeraMath.clamp(injuredCirculatoryComponent.bloodLevel, 0, injuredCirculatoryComponent.maxBloodLevel);
            entityRef.saveComponent(injuredCirculatoryComponent);
            entityRef.send(new BloodLevelChangedEvent());
        }
        delayManager.addDelayedAction(entityRef, CIRCULATORY_BLOOD_REGEN_PREFIX, (long) (1000 / TeraMath.fastAbs(injuredCirculatoryComponent.bloodRegenRate)));
    }
}
Also used : BloodLevelChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.BloodLevelChangedEvent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Example 5 with ReceiveEvent

use of org.terasology.gestalt.entitysystem.event.ReceiveEvent 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

ReceiveEvent (org.terasology.gestalt.entitysystem.event.ReceiveEvent)7 PartHealthDetails (org.terasology.anatomy.component.PartHealthDetails)4 PartCirculatoryHealthChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryHealthChangedEvent)2 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 ArrayList (java.util.ArrayList)1 InjuredCirculatoryComponent (org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent)1 BloodLevelChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.BloodLevelChangedEvent)1 InjuredBoneComponent (org.terasology.anatomy.AnatomySkeleton.component.InjuredBoneComponent)1 AnatomyPartTag (org.terasology.anatomy.component.AnatomyPartTag)1 AnatomyPartImpactedEvent (org.terasology.anatomy.event.AnatomyPartImpactedEvent)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 DestroyEvent (org.terasology.engine.logic.health.DestroyEvent)1