Search in sources :

Example 1 with AnatomyPartImpactedEvent

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

the class AnatomySystem method dmgAnatomyPart.

@Command(shortDescription = "Damage Anatomy part for amount")
public void dmgAnatomyPart(@CommandParam("name") String partName, @CommandParam("amount") int amount) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(AnatomyComponent.class)) {
        AnatomyComponent anatomyComponent = clientEntity.getComponent(AnatomyComponent.class);
        AnatomyPartTag partTag = anatomyComponent.parts.get(partName);
        if (partTag != null) {
            clientEntity.send(new AnatomyPartImpactedEvent(amount, partTag));
        }
    }
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) AnatomyComponent(org.terasology.anatomy.component.AnatomyComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 2 with AnatomyPartImpactedEvent

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

the class AnatomySystem method dmgAnatomyPart.

/**
 * Console command - Damages a particular anatomy part for a given amount.
 */
@Command(shortDescription = "Damage Anatomy part for amount")
public String dmgAnatomyPart(@Sender EntityRef entityRef, @CommandParam("name") String partName, @CommandParam("amount") int amount) {
    EntityRef clientEntity = entityRef.getComponent(ClientComponent.class).character;
    AnatomyComponent anatomyComponent = clientEntity.getComponent(AnatomyComponent.class);
    AnatomyPartTag partTag = anatomyComponent.parts.get(partName);
    if (partTag != null) {
        clientEntity.send(new AnatomyPartImpactedEvent(amount, partTag));
        return "Inflicted " + amount + " damage to " + getAnatomyNameFromID(partTag.id, anatomyComponent);
    } else {
        return "No such part found.";
    }
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) AnatomyComponent(org.terasology.anatomy.component.AnatomyComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 3 with AnatomyPartImpactedEvent

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

the class AnatomySystem method dmgAnatomyPartAll.

@Command(shortDescription = "Damage ALL Anatomy parts for amount")
public void dmgAnatomyPartAll(@CommandParam("amount") int amount) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(AnatomyComponent.class)) {
        AnatomyComponent anatomyComponent = clientEntity.getComponent(AnatomyComponent.class);
        List<String> keys = new ArrayList<>(anatomyComponent.parts.keySet());
        for (String key : keys) {
            AnatomyPartTag partTag = anatomyComponent.parts.get(key);
            clientEntity.send(new AnatomyPartImpactedEvent(amount, partTag));
        }
    }
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) AnatomyComponent(org.terasology.anatomy.component.AnatomyComponent) ArrayList(java.util.ArrayList) EntityRef(org.terasology.entitySystem.entity.EntityRef) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 4 with AnatomyPartImpactedEvent

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

the class AnatomySystem method dmgAnatomyPartAll.

/**
 * Console command - Damages all anatomy parts for a given amount.
 */
@Command(shortDescription = "Damage ALL Anatomy parts for amount")
public String dmgAnatomyPartAll(@Sender EntityRef entityRef, @CommandParam("amount") int amount) {
    EntityRef clientEntity = entityRef.getComponent(ClientComponent.class).character;
    AnatomyComponent anatomyComponent = clientEntity.getComponent(AnatomyComponent.class);
    List<String> keys = new ArrayList<>(anatomyComponent.parts.keySet());
    String result = "";
    for (String key : keys) {
        result += "Inflicted " + amount + " damage to " + getAnatomyNameFromID(key, anatomyComponent) + "\n";
        AnatomyPartTag partTag = anatomyComponent.parts.get(key);
        clientEntity.send(new AnatomyPartImpactedEvent(amount, partTag));
    }
    return result;
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) AnatomyComponent(org.terasology.anatomy.component.AnatomyComponent) ArrayList(java.util.ArrayList) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 5 with AnatomyPartImpactedEvent

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

the class AnatomySystem method onDamage.

/**
 * Receives an {@link OnDamagedEvent} and allocates the damage to an anatomy part.
 */
@ReceiveEvent
public void onDamage(OnDamagedEvent event, EntityRef entity, AnatomyComponent comp) {
    if (comp != null) {
        List<String> keys = new ArrayList<>(comp.parts.keySet());
        // Randomly assign damage to a part, until positional damage is introduced.
        AnatomyPartTag partTag = comp.parts.get(keys.get(random.nextInt(0, keys.size() - 1)));
        entity.send(new AnatomyPartImpactedEvent(event.getDamageAmount(), partTag, event.getType(), event.getInstigator()));
    }
}
Also used : AnatomyPartTag(org.terasology.anatomy.component.AnatomyPartTag) ArrayList(java.util.ArrayList) AnatomyPartImpactedEvent(org.terasology.anatomy.event.AnatomyPartImpactedEvent) ReceiveEvent(org.terasology.gestalt.entitysystem.event.ReceiveEvent)

Aggregations

AnatomyPartTag (org.terasology.anatomy.component.AnatomyPartTag)5 AnatomyPartImpactedEvent (org.terasology.anatomy.event.AnatomyPartImpactedEvent)5 AnatomyComponent (org.terasology.anatomy.component.AnatomyComponent)4 ArrayList (java.util.ArrayList)3 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)2 ClientComponent (org.terasology.engine.network.ClientComponent)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)2 Command (org.terasology.logic.console.commandSystem.annotations.Command)2 ReceiveEvent (org.terasology.gestalt.entitysystem.event.ReceiveEvent)1