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


package engine.devcmd.cmds;

import engine.devcmd.AbstractDevCmd;
import engine.gameManager.PowersManager;
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
import engine.mobileAI.MobAI;
import engine.objects.AbstractGameObject;
import engine.objects.Mob;
import engine.objects.PlayerCharacter;
import engine.powers.RunePowerEntry;

import java.util.ArrayList;
import java.util.Map;


/**
 * @author
 */
public class aiInfoCmd extends AbstractDevCmd {

    public aiInfoCmd() {
        super("aiinfo");
    }

    @Override
    protected void _doCmd(PlayerCharacter playerCharacter, String[] words,
                          AbstractGameObject target) {

        // Arg Count Check

        if (words.length != 1) {
            this.sendUsage(playerCharacter);
            return;
        }

        if (playerCharacter == null)
            return;

        String newline = "\r\n ";


        GameObjectType objType = target.getObjectType();
        String output;

        if (objType != GameObjectType.Mob) {
            output = "Please Select A Mob For AI Info" + newline;
            throwbackInfo(playerCharacter, output);
            return;
        }

        Mob mob = (Mob) target;
        output = "Mob AI Information:" + newline;
        output += mob.getName() + newline;
        output += mob.agentType.toString() + newline;

        int contractID = 0;

        if (mob.isPlayerGuard() == true) {

            if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION))
                contractID = mob.guardCaptain.contract.getContractID();
            else
                contractID = mob.contract.getContractID();
        }

        if (contractID != 0) {

            if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION)) {
                output += "Captain Contract: " + contractID + newline;
                output += "Captain UUID: " + mob.guardCaptain.getObjectUUID() + newline;
            } else
                output += "Contract: " + contractID + newline;
        }

        if (mob.behaviourType != null) {
            output += "BehaviourType: " + mob.behaviourType.toString() + newline;
            if (mob.behaviourType.BehaviourHelperType != null) {
                output += "Behaviour Helper Type: " + mob.behaviourType.BehaviourHelperType.toString() + newline;
            } else {
                output += "Behaviour Helper Type: NULL" + newline;
            }
            output += "Wimpy: " + mob.behaviourType.isWimpy + newline;
            output += "Agressive: " + mob.behaviourType.isAgressive + newline;
            output += "Can Roam: " + mob.behaviourType.canRoam + newline;
            output += "Calls For Help: " + mob.behaviourType.callsForHelp + newline;
            output += "Responds To Call For Help: " + mob.behaviourType.respondsToCallForHelp + newline;
        } else {
            output += "BehaviourType: NULL" + newline;
        }
        output += "Aggro Range: " + mob.getAggroRange() + newline;
        output += "Player Aggro Map Size: " + mob.playerAgroMap.size() + newline;
        if (mob.playerAgroMap.size() > 0) {
            output += "Players Loaded:" + newline;
        }
        for (Map.Entry<Integer, Float> entry : mob.playerAgroMap.entrySet()) {
            output += "Player ID: " + entry.getKey() + " Hate Value: " + entry.getValue() + newline;
        }
        if (mob.getCombatTarget() != null)
            output += "Current Target: " + mob.getCombatTarget().getName() + newline;
        else
            output += "Current Target: NULL" + newline;

        if (mob.guardedCity != null)
            output += "Patrolling: " + mob.guardedCity.getCityName() + newline;
        output += "See Invis Level: " + mob.mobBase.getSeeInvis() + newline;
        output += "Can Cast: " + MobAI.canCast(mob) + newline;
        output += "Powers:" + newline;

        ArrayList<RunePowerEntry> powerEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.getMobBaseID()));

        // Additional powers may come from the contract ID.  This is to support
        // powers for player guards irrespective of the mobbase used.

        if (mob.isPlayerGuard()) {

            ArrayList<RunePowerEntry> contractEntries = new ArrayList<>();

            if (mob.contract != null)
                contractEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.contractUUID));

            if (mob.agentType.equals(mbEnums.AIAgentType.GUARDMINION))
                contractEntries = new ArrayList<>(PowersManager.getPowersForRune(mob.guardCaptain.contractUUID));

            powerEntries.addAll(contractEntries);

        }

        for (RunePowerEntry runePowerEntry : powerEntries)
            output += PowersManager.getPowerByToken(runePowerEntry.token).getName() + newline;

        // List outlaws defined for this player guard's city

        if (mob.isPlayerGuard()) {

            ArrayList<Integer> outlaws = new ArrayList(mob.guardedCity.cityOutlaws);

            if (outlaws.isEmpty() == false)
                output += "Outlaws: " + newline;

            for (Integer outlawUUID : outlaws)
                output += outlawUUID + newline;
        }

        throwbackInfo(playerCharacter, output);
    }

    @Override
    protected String _getHelpString() {
        return "Gets AI information on a Mob.";
    }

    @Override
    protected String _getUsageString() {
        return "' /aiinfo targetID'";
    }

}