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


package engine.devcmd.cmds;

import engine.devcmd.AbstractDevCmd;
import engine.gameManager.ChatManager;
import engine.gameManager.ZoneManager;
import engine.mbEnums;
import engine.objects.AbstractGameObject;
import engine.objects.Mob;
import engine.objects.PlayerCharacter;
import engine.objects.Zone;
import org.pmw.tinylog.Logger;

public class AddMobCmd extends AbstractDevCmd {

    public AddMobCmd() {
        super("mob");
    }

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

        Zone zone = ZoneManager.findSmallestZone(pc.getLoc());

        int loadID;

        try {
            loadID = Integer.parseInt(words[0]);
        } catch (NumberFormatException e) {
            throwbackError(pc, "Supplied type " + words[0]
                    + " failed to parse to an Integer");
            return;
        } catch (Exception e) {
            throwbackError(pc,
                    "An unknown exception occurred when trying to use mob command for type "
                            + words[0]);
            return; // NaN
        }

        if (zone == null) {
            throwbackError(pc, "Failed to find zone to place mob in.");
            return;
        }

        if (zone.guild_zone) {
            throwbackError(pc, "Cannot use ./mob on Player cities. Try ./servermob instead.");
            return;
        }

        Mob mob = Mob.createMob(loadID, pc.getLoc(),
                null, zone, null, null, "", 1, mbEnums.AIAgentType.MOBILE);

        if (mob != null) {
            mob.updateDatabase();
            ChatManager.chatSayInfo(pc,
                    "Mob with ID " + mob.getDBID() + " added");
            this.setResult(String.valueOf(mob.getDBID()));
        } else {
            throwbackError(pc, "Failed to create mob of type " + loadID);
            Logger.error("Failed to create mob of type "
                    + loadID);
        }
    }

    @Override
    protected String _getHelpString() {
        return "Creates a Mob of type 'mobID' at the location your character is standing";
    }

    @Override
    protected String _getUsageString() {
        return "' /mob mobID'";
    }

}
