/*
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.Item;
import server.Player;
import server.SyntaxException;
import server.token.TokenString;

public class EatCommand extends Command {

    private static final TokenString TS_EAT = new TokenString("%MN1 %v1/eats/eat/ %Mc21/%x2/%n2/.");

    public EatCommand() {
        super(CommandCategory.INTERACTION, "Eats an item.");
    }

    @Override
    public void run(Player player) throws SyntaxException {
        String name = CommandProcessor.nextToken();
        if (name == null || CommandProcessor.nextToken() != null) {
            throw new SyntaxException();
        }
        Item item = player.matchInventoryItem(name);
        if (item == null) {
            item = player.matchLocalItem(name);
            if (item == null) {
                player.sendText(true, "There's nothing here by that name.");
                return;
            }
        }
        item.destroy();
        player.getRoom().sendText(null, null, TS_EAT, null, null, null, player, item);
    }

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

}