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.";
}
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);
}
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;
}
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));
}
}
Aggregations