Skip to content

Commit

Permalink
implement more commands
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtomi committed Dec 12, 2022
1 parent 2330449 commit 468949b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/vamk/tbg/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.vamk.tbg.command.impl.HealCommand;
import com.vamk.tbg.command.impl.KillCommand;
import com.vamk.tbg.command.impl.ListCommand;
import com.vamk.tbg.command.impl.ListEffectsCommand;
import com.vamk.tbg.command.impl.ListMovesCommand;
import com.vamk.tbg.command.impl.RemoveEffectCommand;
import com.vamk.tbg.command.impl.SetEffectCommand;
import com.vamk.tbg.command.mapper.ArgumentMapper;
Expand Down Expand Up @@ -65,6 +67,8 @@ public CommandManager(Game game) {
new HealCommand(),
new KillCommand(),
new ListCommand(game),
new ListEffectsCommand(),
new ListMovesCommand(),
new RemoveEffectCommand(),
new SetEffectCommand()
);
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/vamk/tbg/command/impl/ListEffectsCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.vamk.tbg.command.impl;

import com.vamk.tbg.command.Argument;
import com.vamk.tbg.command.Command;
import com.vamk.tbg.command.CommandContext;
import com.vamk.tbg.command.CommandException;
import com.vamk.tbg.effect.StatusEffect;
import com.vamk.tbg.game.Entity;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;

public class ListEffectsCommand extends Command {

public ListEffectsCommand() {
super(
"ls-eff",
"List status effects of an entity or all of them",
new Argument("target", "The entity whose active status effects should be displayed", true)
);
}

@Override
public void run(CommandContext context) throws CommandException {
if (context.remaining() > 0) {
Entity target = context.nextArg(Entity.class);
Set<StatusEffect> effects = target.getEffects().keySet();
if (effects.isEmpty()) {
context.respond("Entity %d doesn't have active effects at the moment.".formatted(target.getId()));
} else {
String active = target.getEffects()
.keySet()
.stream()
.map(StatusEffect::name)
.collect(Collectors.joining(", "));
context.respond("Entity %d's acitve effects: %s".formatted(target.getId(), active));
}
} else {
String all = Arrays.stream(StatusEffect.values())
.map(StatusEffect::name)
.collect(Collectors.joining(", "));

context.respond("Listing all available effects: %s".formatted(all));
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/vamk/tbg/command/impl/ListMovesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.vamk.tbg.command.impl;

import com.vamk.tbg.combat.Move;
import com.vamk.tbg.command.Argument;
import com.vamk.tbg.command.Command;
import com.vamk.tbg.command.CommandContext;
import com.vamk.tbg.command.CommandException;
import com.vamk.tbg.game.Entity;

import java.util.stream.Collectors;

public class ListMovesCommand extends Command {

public ListMovesCommand() {
super(
"ls-mov",
"List moves of the specified entity",
new Argument("target", "The entity whose moves should be listed")
);
}

@Override
public void run(CommandContext context) throws CommandException {
Entity target = context.nextArg(Entity.class);
String moves = target.getMoves().stream()
.map(Move::getId)
.collect(Collectors.joining(", "));
context.respond("Entity %d's moves: %s".formatted(target.getId(), moves));
}
}

0 comments on commit 468949b

Please sign in to comment.