use of org.terasology.anatomy.component.PartHealthDetails 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.";
}
use of org.terasology.anatomy.component.PartHealthDetails 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));
}
}
use of org.terasology.anatomy.component.PartHealthDetails 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));
}
}
Aggregations