Search in sources :

Example 71 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class HealthCommands method heal.

@Command(shortDescription = "Restores your health by an amount", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String heal(@Sender EntityRef client, @CommandParam("amount") int amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    clientComp.character.send(new DoHealEvent(amount, clientComp.character));
    return "Health restored for " + amount;
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 72 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class HealthCommands method killCommand.

@Command(value = "kill", shortDescription = "Reduce the player's health to zero", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public void killCommand(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
    if (health != null) {
        clientComp.character.send(new DestroyEvent(clientComp.character, EntityRef.NULL, EngineDamageTypes.DIRECT.get()));
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 73 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class HealthCommands method setMaxHealth.

@Command(shortDescription = "Set max health", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setMaxHealth(@Sender EntityRef client, @CommandParam("max") int max) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
    float oldMaxHealth = health.maxHealth;
    if (health != null) {
        health.maxHealth = max;
        clientComp.character.saveComponent(health);
    }
    return "Max health changed from " + oldMaxHealth + " to " + max;
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 74 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class HealthCommands method setRegenRate.

@Command(shortDescription = "Set health regen rate", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setRegenRate(@Sender EntityRef client, @CommandParam("rate") float rate) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
    float oldRegenRate = health.regenRate;
    if (health != null) {
        health.regenRate = rate;
        clientComp.character.saveComponent(health);
    }
    return "Health regeneration changed from " + oldRegenRate + " to " + rate;
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 75 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class ItemCommands method give.

@Command(shortDescription = "Adds an item or block to your inventory", helpText = "Puts the desired number of the given item or block with the given shape into your inventory", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String give(@Sender EntityRef client, @CommandParam("prefabId or blockName") String itemPrefabName, @CommandParam(value = "amount", required = false) Integer amount, @CommandParam(value = "blockShapeName", required = false) String shapeUriParam) {
    int itemAmount = amount != null ? amount : 1;
    if (itemAmount < 1) {
        return "Requested zero (0) items / blocks!";
    }
    Set<ResourceUrn> matches = assetManager.resolve(itemPrefabName, Prefab.class);
    if (matches.size() == 1) {
        Prefab prefab = assetManager.getAsset(matches.iterator().next(), Prefab.class).orElse(null);
        if (prefab != null && prefab.getComponent(ItemComponent.class) != null) {
            EntityRef playerEntity = client.getComponent(ClientComponent.class).character;
            for (int quantityLeft = itemAmount; quantityLeft > 0; quantityLeft--) {
                EntityRef item = entityManager.create(prefab);
                if (!inventoryManager.giveItem(playerEntity, playerEntity, item)) {
                    item.destroy();
                    itemAmount -= quantityLeft;
                    break;
                }
            }
            return "You received " + (itemAmount > 1 ? itemAmount + " items of " : "an item of ") + // TODO Use item display name
            prefab.getName() + (shapeUriParam != null ? " (Item can not have a shape)" : "");
        }
    } else if (matches.size() > 1) {
        StringBuilder builder = new StringBuilder();
        builder.append("Requested item \"");
        builder.append(itemPrefabName);
        builder.append("\": matches ");
        Joiner.on(" and ").appendTo(builder, matches);
        builder.append(". Please fully specify one.");
        return builder.toString();
    }
    // If no no matches are found for items, try blocks
    String message = blockCommands.giveBlock(client, itemPrefabName, amount, shapeUriParam);
    if (message != null) {
        return message;
    }
    return "Could not find an item or block matching \"" + itemPrefabName + "\"";
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

Command (org.terasology.logic.console.commandSystem.annotations.Command)76 ClientComponent (org.terasology.network.ClientComponent)48 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)16 Vector3f (org.terasology.math.geom.Vector3f)14 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 LocationComponent (org.terasology.logic.location.LocationComponent)10 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)9 ResourceUrn (org.terasology.assets.ResourceUrn)8 Prefab (org.terasology.entitySystem.prefab.Prefab)6 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 SimpleUri (org.terasology.engine.SimpleUri)5 BlockFamily (org.terasology.world.block.family.BlockFamily)4 Map (java.util.Map)3 AnatomyComponent (org.terasology.anatomy.component.AnatomyComponent)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2