package core.game.interaction.item.withnpc;

import org.rs09.consts.Items;
import core.game.interaction.NodeUsageEvent;
import core.game.interaction.UseWithHandler;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.plugin.Initializable;
import core.plugin.Plugin;

/**
 * Represents the plugin used to "poison" King Arthur.
 * @author afaroutdude
 */
@Initializable
public final class KingArthurPoisonChalicePlugin extends UseWithHandler {
    private static final Item POISON_CHALICE = new Item(Items.POISON_CHALICE_197);

    /**
     * Constructs a new {@code LadyKeliRopePlugin} {@code Object}.
     */
    public KingArthurPoisonChalicePlugin() {
        super(POISON_CHALICE.getId());
    }

    @Override
    public Plugin<Object> newInstance(Object arg) throws Throwable {
        addHandler(251, NPC_TYPE, this);
        return new KingArthurPoisonChalicePlugin();
    }

    @Override
    public boolean handle(NodeUsageEvent event) {
        final Player player = event.getPlayer();
        final NPC npc = event.getUsedWith() instanceof NPC ? event.getUsedWith().asNpc() : null;
        if (npc != null) {
            player.getDialogueInterpreter().open(npc.getId(), npc, POISON_CHALICE);
        }
        return true;
    }

}
