package engine.devcmd.cmds;

import engine.devcmd.AbstractDevCmd;
import engine.gameManager.PowersManager;
import engine.gameManager.ZoneManager;
import engine.objects.*;

public class SetCampLevelCmd extends AbstractDevCmd {
    public SetCampLevelCmd() { super("setcamplevel"); }

    @Override
    protected void _doCmd(PlayerCharacter pcSender, String[] args, AbstractGameObject target) {

        if (args.length > 1)
        {
             this.sendUsage(pcSender);
        }

        int targetLevel = 0;
        if (args.length == 1) {
            try {
                targetLevel = Integer.parseInt(args[0]);
            } catch (NumberFormatException nfe) {
                throwbackError(pcSender, "Argument MUST be integer.  Received: " + args[0]);
            } catch (Exception e) {
                throwbackError(pcSender, "Unknown command parsing provided camp level: " + args[0]);
            }
        }

        if ((target instanceof Mob))
        {
            // Get the camp that owns the targeted Mob
            Zone campZone = ((Mob) target).parentZone;

            // Make sure that the zone we're targeting is valid for action
            if (campZone == null ||
                    campZone.zoneMobSet.isEmpty() ||
                    campZone.isPlayerCity()) {
                throwbackError(pcSender, "Current zone must own mobs, and NOT be a city.");
                return;
            }

            campZone.setCampLvl(targetLevel);
        }
        else if (target instanceof PlayerCharacter)
        {
            PlayerCharacter pc = (PlayerCharacter)target;
            PowersManager.applyPower(pc, pc, pc.getLoc(), "CMP-001", targetLevel, false);
        }
    }

    @Override
    protected String _getUsageString() {
        return "Sets the level of the currently occupied camp to the desired level";
    }

    @Override
    protected String _getHelpString() {
        return "'./setcamplevel levelNum'";
    }
}
