Search in sources :

Example 1 with PartCirculatoryEffectChangedEvent

use of org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent in project Anatomy by Terasology.

the class CirculatorySystem method removeEffect.

private void removeEffect(EntityRef entityRef, String partId) {
    InjuredCirculatoryComponent injuredCirculatoryComponent = entityRef.getComponent(InjuredCirculatoryComponent.class);
    if (injuredCirculatoryComponent != null) {
        for (Map.Entry<String, List<String>> partsOfSeverity : injuredCirculatoryComponent.parts.entrySet()) {
            partsOfSeverity.getValue().remove(partId);
        }
        entityRef.saveComponent(injuredCirculatoryComponent);
        entityRef.send(new PartCirculatoryEffectChangedEvent());
    }
}
Also used : PartCirculatoryEffectChangedEvent(org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent) InjuredCirculatoryComponent(org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PartCirculatoryEffectChangedEvent

use of org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent in project Anatomy by Terasology.

the class CirculatorySystem method applyEffect.

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

Aggregations

HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 InjuredCirculatoryComponent (org.terasology.anatomy.AnatomyCirculation.component.InjuredCirculatoryComponent)2 PartCirculatoryEffectChangedEvent (org.terasology.anatomy.AnatomyCirculation.event.PartCirculatoryEffectChangedEvent)2