// warping from portal in 106020403 is unable to find defined portal (not a scripted portal)
@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);
        }
    }
targetField = 106020403;
} else if (targetField == 106020402) {
// warping from portal in 106020403 is unable to find defined portal (not a scripted portal)
targetField = 106020000;
}
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);
@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);