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


package engine.devcmd.cmds;


import engine.devcmd.AbstractDevCmd;
import engine.gameManager.DispatchManager;
import engine.mbEnums.GameObjectType;
import engine.net.client.msg.ApplyBuildingEffectMsg;
import engine.net.client.msg.UpdateCharOrMobMessage;
import engine.objects.*;

public class SetSubRaceCmd extends AbstractDevCmd {

    public SetSubRaceCmd() {
        super("setSubRace");
        this.addCmdString("subrace");
    }

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

        if (target instanceof AbstractCharacter) {

            if (words[0].equals("race")) {
                if (target.getObjectType() != GameObjectType.PlayerCharacter)
                    return;
                PlayerCharacter player = (PlayerCharacter) target;
                int raceID = Integer.parseInt(words[1]);
                player.setSubRaceID(raceID);
                if (raceID == 0)
                    raceID = player.getRaceID();
                UpdateCharOrMobMessage ucm = new UpdateCharOrMobMessage(player, 1, raceID);
                DispatchManager.sendToAllInRange(player, ucm);
                return;
            }
            if (words[0].equals("all")) {
                for (int i = 15999; i < 16337; i++) {
                    ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(4, 0, target.getObjectType().ordinal(), target.getObjectUUID(), i);
                    DispatchManager.sendToAllInRange((AbstractWorldObject) target, applyBuildingEffectMsg);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

            } else {
                ApplyBuildingEffectMsg applyBuildingEffectMsg = new ApplyBuildingEffectMsg(4, 0, target.getObjectType().ordinal(), target.getObjectUUID(), Integer.parseInt(words[0]));
                DispatchManager.sendToAllInRange((AbstractWorldObject) target, applyBuildingEffectMsg);
            }

            return;
        }

        Building building = (Building) target;

        building.removeAllVisualEffects();
        building.addEffectBit(1 << Integer.parseInt(words[0]));
        building.updateEffects();

    }

    @Override
    protected String _getHelpString() {
        return "Temporarily Changes SubRace";
    }

    @Override
    protected String _getUsageString() {
        return "' /subrace mobBaseID";
    }

}
