@Handler(op = InHeader.USER_TRANSFER_FIELD_REQUEST)
    public static void handleUserTransferFieldRequest(Client c, InPacket inPacket) {
        Char chr = c.getChr();
        if (inPacket.getUnreadAmount() == 0) {
            // Coming back from the cash shop
//            chr.warp(chr.getOrCreateFieldByCurrentInstanceType(chr.getFieldID()));
            c.getChannelInstance().addClientInTransfer(c.getChannel(), chr.getId(), c);
            c.write(ClientSocket.migrateCommand(true, (short) c.getChannelInstance().getPort()));
            return;
    }
        byte fieldKey = inPacket.decodeByte();
        int targetField = inPacket.decodeInt();
        if (targetField == 106020100 || targetField == 106020400) {
            // same issue as below, its in mushroom kingdom so maybe the maps are just outdated or w/e
            targetField = 106020403;
        } else if (targetField == 106020402) {
            // warping from portal in 106020403 is unable to find defined portal (not a scripted portal)
            targetField = 106020000;
        }
        int x = inPacket.decodeShort();
        int y = inPacket.decodeShort();
        String portalName = inPacket.decodeString();
        if (portalName != null && !"".equals(portalName)) {
            Field field = chr.getField();
            Portal portal = field.getPortalByName(portalName);
            if (portal.getScript() != null && !portal.getScript().equals("")) {
                chr.getScriptManager().startScript(portal.getId(), portal.getScript(), ScriptType.Portal);
            } else {
                Field toField = chr.getOrCreateFieldByCurrentInstanceType(portal.getTargetMapId());
                if (toField == null) {
                    return;
                }
                Portal toPortal = toField.getPortalByName(portal.getTargetPortalName());
                if (toPortal == null) {
                    toPortal = toField.getPortalByName("sp");
                }
                chr.warp(toField, toPortal);
            }
        } else if (chr.getHP() <= 0) {
            if (InGameEventManager.getInstance().charInEventMap(chr.getId())) {
                InGameEventManager.getInstance().getActiveEvent().onMigrateDeath(chr);
                chr.heal(chr.getMaxHP());
                chr.healMP(chr.getMaxMP());
                return;
            }
            // Character is dead, respawn request
            inPacket.decodeByte(); // always 0
            byte tarfield = inPacket.decodeByte(); // ?
            byte reviveType = inPacket.decodeByte();
            int returnMap = chr.getField().getReturnMap() == 999999999
                    ? chr.getPreviousFieldID()
                    : chr.getField().getReturnMap();
            switch (reviveType) {
                // so far only got 0?
            }
            if (!chr.hasBuffProtector()) {
                chr.getTemporaryStatManager().removeAllStats();
            }
            int deathcount = chr.getDeathCount();
            if (deathcount != 0) {
                if (deathcount > 0) {
                    deathcount--;
                    chr.setDeathCount(deathcount);
                    chr.write(UserLocal.deathCountInfo(deathcount));
                }
                chr.setNearestReturnPortal(); // attempt to respawn them where they died.. maybe portal 0 is better tho?
                chr.warp(chr.getFieldID(), chr.getPreviousPortalID(), false);
                chr.healHPMP();
                return;
            } else if (chr.getInstance() != null) {
                chr.getInstance().removeChar(chr);
            } else if (chr.getTransferField() == targetField && chr.getTransferFieldReq() == chr.getField().getId()) {
                Field toField = chr.getOrCreateFieldByCurrentInstanceType(chr.getTransferField());
                if (toField != null && chr.getTransferField() > 0) {
                    chr.warp(toField);
                }
                chr.setTransferField(0);
                return;
            } else {
                chr.warp(chr.getOrCreateFieldByCurrentInstanceType(chr.getField().getForcedReturn()));
            }
            chr.healHPMP();
            chr.setBuffProtector(false);
        } else if (chr.getTransferField() == targetField && chr.getTransferFieldReq() == chr.getField().getId()) {
            Field toField = chr.getOrCreateFieldByCurrentInstanceType(chr.getTransferField());
            if (toField != null && chr.getTransferField() > 0) {
                chr.warp(toField);
            }
            chr.setTransferField(0);
        }
    }
@Handler(op = InHeader.USER_TRANSFER_FIELD_REQUEST)
    public static void handleUserTransferFieldRequest(Client c, InPacket inPacket) {
        Char chr = c.getChr();
        if (inPacket.getUnreadAmount() == 0) {
           
            c.getChannelInstance().addClientInTransfer(c.getChannel(), chr.getId(), c);
            c.write(ClientSocket.migrateCommand(true, (short) c.getChannelInstance().getPort()));
            return;
    }
        byte fieldKey = inPacket.decodeByte();
        int targetField = inPacket.decodeInt();
        if (targetField == 106020100 || targetField == 106020400) {
           
            targetField = 106020403;
        } else if (targetField == 106020402) {
           
            targetField = 106020000;
        }
        int x = inPacket.decodeShort();
        int y = inPacket.decodeShort();
        String portalName = inPacket.decodeString();
        if (portalName != null && !"".equals(portalName)) {
            Field field = chr.getField();
            Portal portal = field.getPortalByName(portalName);
            if (portal.getScript() != null && !portal.getScript().equals("")) {
                chr.getScriptManager().startScript(portal.getId(), portal.getScript(), ScriptType.Portal);
            } else {
                Field toField = chr.getOrCreateFieldByCurrentInstanceType(portal.getTargetMapId());
                if (toField == null) {
                    return;
                }
                Portal toPortal = toField.getPortalByName(portal.getTargetPortalName());
                if (toPortal == null) {
                    toPortal = toField.getPortalByName("sp");
                }
                chr.warp(toField, toPortal);
            }
        } else if (chr.getHP() <= 0) {
            if (InGameEventManager.getInstance().charInEventMap(chr.getId())) {
                InGameEventManager.getInstance().getActiveEvent().onMigrateDeath(chr);
                chr.heal(chr.getMaxHP());
                chr.healMP(chr.getMaxMP());
                return;
            }
           
            inPacket.decodeByte();
            byte tarfield = inPacket.decodeByte();
            byte reviveType = inPacket.decodeByte();
            int returnMap = chr.getField().getReturnMap() == 999999999
                    ? chr.getPreviousFieldID()
                    : chr.getField().getReturnMap();
            switch (reviveType) {
               
            }
            if (!chr.hasBuffProtector()) {
                chr.getTemporaryStatManager().removeAllStats();
            }
            int deathcount = chr.getDeathCount();
            if (deathcount != 0) {
                if (deathcount > 0) {
                    deathcount--;
                    chr.setDeathCount(deathcount);
                    chr.write(UserLocal.deathCountInfo(deathcount));
                }
                chr.setNearestReturnPortal();
                chr.warp(chr.getFieldID(), chr.getPreviousPortalID(), false);
                chr.healHPMP();
                return;
            } else if (chr.getInstance() != null) {
                chr.getInstance().removeChar(chr);
            } else if (chr.getTransferField() == targetField && chr.getTransferFieldReq() == chr.getField().getId()) {
                Field toField = chr.getOrCreateFieldByCurrentInstanceType(chr.getTransferField());
                if (toField != null && chr.getTransferField() > 0) {
                    chr.warp(toField);
                }
                chr.setTransferField(0);
                return;
            } else {
                chr.warp(chr.getOrCreateFieldByCurrentInstanceType(chr.getField().getForcedReturn()));
            }
            chr.healHPMP();
            chr.setBuffProtector(false);
        } else if (chr.getTransferField() == targetField && chr.getTransferFieldReq() == chr.getField().getId()) {
            Field toField = chr.getOrCreateFieldByCurrentInstanceType(chr.getTransferField());
            if (toField != null && chr.getTransferField() > 0) {
                chr.warp(toField);
            }
            chr.setTransferField(0);
        }
    }
@handler(op = inheader.user_transfer_field_request) public static void handleusertransferfieldrequest(client c, inpacket inpacket) { char chr = c.getchr(); if (inpacket.getunreadamount() == 0) { c.getchannelinstance().addclientintransfer(c.getchannel(), chr.getid(), c); c.write(clientsocket.migratecommand(true, (short) c.getchannelinstance().getport())); return; } byte fieldkey = inpacket.decodebyte(); int targetfield = inpacket.decodeint(); if (targetfield == 106020100 || targetfield == 106020400) { targetfield = 106020403; } else if (targetfield == 106020402) { targetfield = 106020000; } int x = inpacket.decodeshort(); int y = inpacket.decodeshort(); string portalname = inpacket.decodestring(); if (portalname != null && !"".equals(portalname)) { field field = chr.getfield(); portal portal = field.getportalbyname(portalname); if (portal.getscript() != null && !portal.getscript().equals("")) { chr.getscriptmanager().startscript(portal.getid(), portal.getscript(), scripttype.portal); } else { field tofield = chr.getorcreatefieldbycurrentinstancetype(portal.gettargetmapid()); if (tofield == null) { return; } portal toportal = tofield.getportalbyname(portal.gettargetportalname()); if (toportal == null) { toportal = tofield.getportalbyname("sp"); } chr.warp(tofield, toportal); } } else if (chr.gethp() <= 0) { if (ingameeventmanager.getinstance().charineventmap(chr.getid())) { ingameeventmanager.getinstance().getactiveevent().onmigratedeath(chr); chr.heal(chr.getmaxhp()); chr.healmp(chr.getmaxmp()); return; } inpacket.decodebyte(); byte tarfield = inpacket.decodebyte(); byte revivetype = inpacket.decodebyte(); int returnmap = chr.getfield().getreturnmap() == 999999999 ? chr.getpreviousfieldid() : chr.getfield().getreturnmap(); switch (revivetype) { } if (!chr.hasbuffprotector()) { chr.gettemporarystatmanager().removeallstats(); } int deathcount = chr.getdeathcount(); if (deathcount != 0) { if (deathcount > 0) { deathcount--; chr.setdeathcount(deathcount); chr.write(userlocal.deathcountinfo(deathcount)); } chr.setnearestreturnportal(); chr.warp(chr.getfieldid(), chr.getpreviousportalid(), false); chr.healhpmp(); return; } else if (chr.getinstance() != null) { chr.getinstance().removechar(chr); } else if (chr.gettransferfield() == targetfield && chr.gettransferfieldreq() == chr.getfield().getid()) { field tofield = chr.getorcreatefieldbycurrentinstancetype(chr.gettransferfield()); if (tofield != null && chr.gettransferfield() > 0) { chr.warp(tofield); } chr.settransferfield(0); return; } else { chr.warp(chr.getorcreatefieldbycurrentinstancetype(chr.getfield().getforcedreturn())); } chr.healhpmp(); chr.setbuffprotector(false); } else if (chr.gettransferfield() == targetfield && chr.gettransferfieldreq() == chr.getfield().getid()) { field tofield = chr.getorcreatefieldbycurrentinstancetype(chr.gettransferfield()); if (tofield != null && chr.gettransferfield() > 0) { chr.warp(tofield); } chr.settransferfield(0); } }