// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
//      Magicbane Emulator Project © 2013 - 2022
//                www.magicbane.com


package engine.devcmd.cmds;

import engine.devcmd.AbstractDevCmd;
import engine.objects.*;
import engine.powers.EffectsBase;

public class EnchantCmd extends AbstractDevCmd {

    public EnchantCmd() {
        super("enchant");
    }

    @Override
    protected void _doCmd(PlayerCharacter pc, String[] words,
                          AbstractGameObject target) {
        int rank = 0;
        if (words.length < 1) {
            this.sendUsage(pc);
            return;
        }


        try {
            rank = Integer.parseInt(words[0]);
        } catch (Exception e) {

        }


        Item item;
        if (target == null || target instanceof Item)
            item = (Item) target;
        else {
            throwbackError(pc, "Must have an item targeted");
            return;
        }

        CharacterItemManager cim = pc.getCharItemManager();
        if (cim == null) {
            throwbackError(pc, "Unable to find the character item manager for player " + pc.getFirstName() + '.');
            return;
        }

        if (words[0].equals("clear")) {
            item.clearEnchantments();
            cim.updateInventory();
            this.setResult(String.valueOf(item.getObjectUUID()));
        } else {
            int cnt = words.length;
            String enchant = words[1];
            enchant = EffectsBase.getItemEffectsByName(enchant.toLowerCase());
            item.addPermanentEnchantmentForDev(enchant, 0);
            cim.updateInventory();
        }
    }

    @Override
    protected String _getHelpString() {
        return "Enchants an item with a prefix and suffix";
    }

    @Override
    protected String _getUsageString() {
        return "' /enchant clear/Enchant1 Enchant2 Enchant3 ...'";
    }

}
