/*
Copyright (C) 2005 David Green <green@couchpotato.net>
All Rights Reserved.

This file is part of Aelfengard.

Aelfengard is proprietary software. You may not redistribute it without
prior written permission from the copyright holder.
*/

package server.command;

import server.Living;
import server.Player;
import server.SyntaxException;

public class FinishCommand extends Command {

    public FinishCommand() {
        super(CommandCategory.COMBAT, "Finishes someone off.");
    }

    @Override
    public void run(Player player) throws SyntaxException {
        String name = CommandProcessor.nextToken();
        if (name == null || CommandProcessor.nextToken() != null) {
            throw new SyntaxException();
        }
        Living other = player.matchLocalLiving(name);
        if (other == null) {
            player.sendText(true, "There's noone here by that name.");
            return;
        }
        if (other == player) {
            player.sendText(true, "You can't kill yourself.");
            return;
        }
        if (other.isDead()) {
            player.sendText(true, other.getName(player, false) + " is already dead.");
        } else if (!other.isUnconscious()) {
            player.sendText(true, "You can only finish someone who is already unconscious.");
        }
        else {
            other.killedBy(player);
        }
    }

    @Override
    public String[] getSyntax(Player player) {
        return new String[] { "<who>" };
    }

}