Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: Java | Size: 5.91 KB | Hits: 99 | Expires: Never
Copy text to clipboard
  1. /*
  2.         This file is part of the OdinMS Maple Story Server
  3.     Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
  4.                        Matthias Butz <matze@odinms.de>
  5.                        Jan Christian Meyer <vimes@odinms.de>
  6.  
  7.     This program is free software: you can redistribute it and/or modify
  8.     it under the terms of the GNU Affero General Public License as
  9.     published by the Free Software Foundation version 3 as published by
  10.     the Free Software Foundation. You may not use, modify or distribute
  11.     this program under any other version of the GNU Affero General Public
  12.     License.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU Affero General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU Affero General Public License
  20.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. package server.maps;
  23.  
  24. import client.MapleCharacter;
  25. import java.awt.Point;
  26. import client.MapleClient;
  27. import net.world.MaplePartyCharacter;
  28. import scripting.portal.PortalScriptManager;
  29. import server.MaplePortal;
  30. import tools.MaplePacketCreator;
  31.  
  32. public class MapleGenericPortal implements MaplePortal {
  33.     private String name;
  34.     private String target;
  35.     private Point position;
  36.     private int targetmap;
  37.     private int type;
  38.     private boolean status = true;
  39.     private int id;
  40.     private String scriptName;
  41.     private boolean portalState;
  42.  
  43.     public MapleGenericPortal(int type) {
  44.         this.type = type;
  45.     }
  46.  
  47.     @Override
  48.     public int getId() {
  49.         return id;
  50.     }
  51.  
  52.     public void setId(int id) {
  53.         this.id = id;
  54.     }
  55.  
  56.     @Override
  57.     public String getName() {
  58.         return name;
  59.     }
  60.  
  61.     @Override
  62.     public Point getPosition() {
  63.         return position;
  64.     }
  65.  
  66.     @Override
  67.     public String getTarget() {
  68.         return target;
  69.     }
  70.  
  71.     @Override
  72.     public void setPortalStatus(boolean newStatus) {
  73.         this.status = newStatus;
  74.     }
  75.  
  76.     @Override
  77.     public boolean getPortalStatus() {
  78.         return status;
  79.     }
  80.  
  81.     @Override
  82.     public int getTargetMapId() {
  83.         return targetmap;
  84.     }
  85.  
  86.     @Override
  87.     public int getType() {
  88.         return type;
  89.     }
  90.  
  91.     @Override
  92.     public String getScriptName() {
  93.         return scriptName;
  94.     }
  95.  
  96.     public void setName(String name) {
  97.         this.name = name;
  98.     }
  99.  
  100.     public void setPosition(Point position) {
  101.         this.position = position;
  102.     }
  103.  
  104.     public void setTarget(String target) {
  105.         this.target = target;
  106.     }
  107.  
  108.     public void setTargetMapId(int targetmapid) {
  109.         this.targetmap = targetmapid;
  110.     }
  111.  
  112.     @Override
  113.     public void setScriptName(String scriptName) {
  114.         this.scriptName = scriptName;
  115.     }
  116.  
  117.     @Override
  118.     public void enterPortal(MapleClient c) {
  119.         boolean changed = false;
  120.         if (getScriptName() != null) {
  121.             if (!handlePortal(getScriptName(), c.getPlayer())) {
  122.                 changed = PortalScriptManager.getInstance().executePortalScript(this, c);
  123.             }
  124.         } else if (getTargetMapId() != 999999999) {
  125.             MapleMap to = c.getPlayer().getEventInstance() == null ? c.getChannelServer().getMapFactory().getMap(getTargetMapId()) : c.getPlayer().getEventInstance().getMapInstance(getTargetMapId());
  126.             MaplePortal pto = to.getPortal(getTarget());
  127.             if (pto == null) {// fallback for missing portals - no real life case anymore - intresting for not implemented areas
  128.                 pto = to.getPortal(0);
  129.             }
  130.             c.getPlayer().changeMap(to, pto); //late resolving makes this harder but prevents us from loading the whole world at once
  131.             changed = true;
  132.         }
  133.         if (!changed) {
  134.             c.getSession().write(MaplePacketCreator.enableActions());
  135.         }
  136.     }
  137.  
  138.     public void setPortalState(boolean state) {
  139.         this.portalState = state;
  140.     }
  141.  
  142.     public boolean getPortalState() {
  143.         return portalState;
  144.     }
  145.  
  146.     public static boolean handlePortal(String name, MapleCharacter c) {
  147.         boolean partyCheck = true;
  148.         if (c.getParty() != null) {
  149.             for (MaplePartyCharacter mpc : c.getParty().getMembers()) {
  150.                 if (mpc.getJobId() % 100 != 2 || mpc.getJobId() / 100 != 1) {
  151.                     partyCheck = false;
  152.                     break;
  153.                 }
  154.             }
  155.         } else {
  156.             return false;
  157.         }
  158.         if (name.equals("s4rush")) {
  159.             if (c.getParty().getLeader().getId() != c.getId()) {
  160.                 if (!partyCheck) {
  161.                     c.dropMessage("You step into the portal, but it swiftly kicks you out.");
  162.                 } else {
  163.                     c.dropMessage("You're not the party leader.");
  164.                 }
  165.                 c.getClient().getSession().write(MaplePacketCreator.enableActions());
  166.                 return true;
  167.             }
  168.             if (!partyCheck) {
  169.                 c.dropMessage("Someone in your party is not a 4th Job warrior.");
  170.                 c.getClient().getSession().write(MaplePacketCreator.enableActions());
  171.                 return true;
  172.             }
  173.             c.getClient().getChannelServer().getEventSM().getEventManager("4jrush").startInstance(c.getParty(), c.getMap());
  174.             return true;
  175.         } else if (name.equals("s4berserk")) {
  176.             if (!c.haveItem(4031475)) {
  177.                 c.dropMessage("The portal to the Forgotten Shrine is locked");
  178.                 c.getClient().getSession().write(MaplePacketCreator.enableActions());
  179.                 return true;
  180.             }
  181.             c.getClient().getChannelServer().getEventSM().getEventManager("4jberserk").startInstance(c.getParty(), c.getMap());
  182.             return true;
  183.         }
  184.         return false;
  185.     }
  186. }