Flatten ChangeMapHandler

This commit is contained in:
P0nk
2023-02-16 23:46:13 +01:00
parent eb10f02ac3
commit 82157c7bd1

View File

@@ -58,30 +58,23 @@ public final class ChangeMapHandler extends AbstractPacketHandler {
if (chr.getTrade() != null) { if (chr.getTrade() != null) {
Trade.cancelTrade(chr, Trade.TradeResult.UNSUCCESSFUL_ANOTHER_MAP); Trade.cancelTrade(chr, Trade.TradeResult.UNSUCCESSFUL_ANOTHER_MAP);
} }
if (p.available() == 0) { //Cash Shop :)
if (!chr.getCashShop().isOpened()) { boolean enteringMapFromCashShop = p.available() == 0;
c.disconnect(false, false); if (enteringMapFromCashShop) {
enterFromCashShop(c);
return; return;
} }
String[] socket = c.getChannelServer().getIP().split(":");
chr.getCashShop().open(false);
chr.setSessionTransitionState();
try {
c.sendPacket(PacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1])));
} catch (UnknownHostException ex) {
ex.printStackTrace();
}
} else {
if (chr.getCashShop().isOpened()) { if (chr.getCashShop().isOpened()) {
c.disconnect(false, false); c.disconnect(false, false);
return; return;
} }
try { try {
p.readByte(); // 1 = from dying 0 = regular portals p.readByte(); // 1 = from dying 0 = regular portals
int targetid = p.readInt(); int targetMapId = p.readInt();
String startwp = p.readString(); String portalName = p.readString();
Portal portal = chr.getMap().getPortal(startwp); Portal portal = chr.getMap().getPortal(portalName);
p.readByte(); p.readByte();
boolean wheel = p.readByte() > 0; boolean wheel = p.readByte() > 0;
@@ -91,7 +84,7 @@ public final class ChangeMapHandler extends AbstractPacketHandler {
chr.setPosition(new Point(p.readInt(), p.readInt())); chr.setPosition(new Point(p.readInt(), p.readInt()));
} }
if (targetid != -1) { if (targetMapId != -1) {
if (!chr.isAlive()) { if (!chr.isAlive()) {
MapleMap map = chr.getMap(); MapleMap map = chr.getMap();
if (wheel && chr.haveItemWithId(ItemId.WHEEL_OF_FORTUNE, false)) { if (wheel && chr.haveItemWithId(ItemId.WHEEL_OF_FORTUNE, false)) {
@@ -113,40 +106,40 @@ public final class ChangeMapHandler extends AbstractPacketHandler {
} }
} else { } else {
if (chr.isGM()) { if (chr.isGM()) {
MapleMap to = chr.getWarpMap(targetid); MapleMap to = chr.getWarpMap(targetMapId);
chr.changeMap(to, to.getPortal(0)); chr.changeMap(to, to.getPortal(0));
} else { } else {
final int divi = chr.getMapId() / 100; final int divi = chr.getMapId() / 100;
boolean warp = false; boolean warp = false;
if (divi == 0) { if (divi == 0) {
if (targetid == 10000) { if (targetMapId == 10000) {
warp = true; warp = true;
} }
} else if (divi == 20100) { } else if (divi == 20100) {
if (targetid == MapId.LITH_HARBOUR) { if (targetMapId == MapId.LITH_HARBOUR) {
c.sendPacket(PacketCreator.lockUI(false)); c.sendPacket(PacketCreator.lockUI(false));
c.sendPacket(PacketCreator.disableUI(false)); c.sendPacket(PacketCreator.disableUI(false));
warp = true; warp = true;
} }
} else if (divi == 9130401) { // Only allow warp if player is already in Intro map, or else = hack } else if (divi == 9130401) { // Only allow warp if player is already in Intro map, or else = hack
if (targetid == MapId.EREVE || targetid / 100 == 9130401) { // Cygnus introduction if (targetMapId == MapId.EREVE || targetMapId / 100 == 9130401) { // Cygnus introduction
warp = true; warp = true;
} }
} else if (divi == 9140900) { // Aran Introduction } else if (divi == 9140900) { // Aran Introduction
if (targetid == MapId.ARAN_TUTO_2 || targetid == MapId.ARAN_TUTO_3 || targetid == MapId.ARAN_TUTO_4 || targetid == MapId.ARAN_INTRO) { if (targetMapId == MapId.ARAN_TUTO_2 || targetMapId == MapId.ARAN_TUTO_3 || targetMapId == MapId.ARAN_TUTO_4 || targetMapId == MapId.ARAN_INTRO) {
warp = true; warp = true;
} }
} else if (divi / 10 == 1020) { // Adventurer movie clip Intro } else if (divi / 10 == 1020) { // Adventurer movie clip Intro
if (targetid == 1020000) { if (targetMapId == 1020000) {
warp = true; warp = true;
} }
} else if (divi / 10 >= 980040 && divi / 10 <= 980045) { } else if (divi / 10 >= 980040 && divi / 10 <= 980045) {
if (targetid == MapId.WITCH_TOWER_ENTRANCE) { if (targetMapId == MapId.WITCH_TOWER_ENTRANCE) {
warp = true; warp = true;
} }
} }
if (warp) { if (warp) {
final MapleMap to = chr.getWarpMap(targetid); final MapleMap to = chr.getWarpMap(targetMapId);
chr.changeMap(to, to.getPortal(0)); chr.changeMap(to, to.getPortal(0));
} }
} }
@@ -178,6 +171,24 @@ public final class ChangeMapHandler extends AbstractPacketHandler {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}
private void enterFromCashShop(Client c) {
final Character chr = c.getPlayer();
if (!chr.getCashShop().isOpened()) {
c.disconnect(false, false);
return;
}
String[] socket = c.getChannelServer().getIP().split(":");
chr.getCashShop().open(false);
chr.setSessionTransitionState();
try {
c.sendPacket(PacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1])));
} catch (UnknownHostException ex) {
ex.printStackTrace();
} }
} }
} }