use of org.terasology.entitySystem.prefab.Prefab in project Terasology by MovingBlocks.
the class HealthAuthoritySystem method damageEntity.
static void damageEntity(AttackEvent event, EntityRef targetEntity) {
int damage = 1;
Prefab damageType = EngineDamageTypes.PHYSICAL.get();
// Calculate damage from item
ItemComponent item = event.getDirectCause().getComponent(ItemComponent.class);
if (item != null) {
damage = item.baseDamage;
if (item.damageType != null) {
damageType = item.damageType;
}
}
targetEntity.send(new DoDamageEvent(damage, damageType, event.getInstigator(), event.getDirectCause()));
// consume the event so that the health system can take priority over default engine behavior
event.consume();
}
use of org.terasology.entitySystem.prefab.Prefab in project Terasology by MovingBlocks.
the class HealthCommands method restoreCollisionDamage.
@Command(shortDescription = "Restore default collision damage values", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String restoreCollisionDamage(@Sender EntityRef client) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
Optional<Prefab> prefab = Assets.get(new ResourceUrn("engine:player"), Prefab.class);
HealthComponent healthDefault = prefab.get().getComponent(HealthComponent.class);
HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
if (health != null && healthDefault != null) {
health.fallingDamageSpeedThreshold = healthDefault.fallingDamageSpeedThreshold;
health.horizontalDamageSpeedThreshold = healthDefault.horizontalDamageSpeedThreshold;
health.excessSpeedDamageMultiplier = healthDefault.excessSpeedDamageMultiplier;
clientComp.character.saveComponent(health);
}
return "Normal collision damage values restored";
}
use of org.terasology.entitySystem.prefab.Prefab 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 + "\"";
}
use of org.terasology.entitySystem.prefab.Prefab in project Terasology by MovingBlocks.
the class ItemCommands method listItems.
@Command(shortDescription = "Lists all available items (prefabs)\nYou can filter by adding the beginning of words " + "after the commands, e.g.: \"listItems engine: core:\" will list all items from the engine and core module", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listItems(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
List<String> stringItems = Lists.newArrayList();
for (Prefab prefab : prefabManager.listPrefabs()) {
if (!BlockCommands.uriStartsWithAnyString(prefab.getName(), startsWith)) {
continue;
}
stringItems.add(prefab.getName());
}
Collections.sort(stringItems);
StringBuilder items = new StringBuilder();
for (String item : stringItems) {
if (!items.toString().isEmpty()) {
items.append(Console.NEW_LINE);
}
items.append(item);
}
return items.toString();
}
Aggregations