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