Search in sources :

Example 1 with BrokenBoneComponent

use of org.terasology.anatomy.AnatomySkeleton.component.BrokenBoneComponent in project Anatomy by Terasology.

the class SkeletalSystem method applyEffect.

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

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BrokenBoneComponent (org.terasology.anatomy.AnatomySkeleton.component.BrokenBoneComponent)1