MapleGenericPortal.java
Upload User: gwt600
Upload Date: 2021-06-03
Package Size: 704k
Code Size: 5k
Category:

Games

Development Platform:

Java

  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. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18. package net.sf.odinms.server.maps;
  19. import java.awt.Point;
  20. import net.sf.odinms.client.MapleCharacter;
  21. import net.sf.odinms.client.MapleClient;
  22. import net.sf.odinms.client.anticheat.CheatingOffense;
  23. import net.sf.odinms.net.channel.ChannelServer;
  24. import net.sf.odinms.scripting.portal.PortalScriptManager;
  25. import net.sf.odinms.server.MaplePortal;
  26. import net.sf.odinms.server.fourthjobquests.FourthJobQuestsPortalHandler;
  27. import net.sf.odinms.tools.MaplePacketCreator;
  28. public class MapleGenericPortal implements MaplePortal {
  29.     private String name;
  30.     private String target;
  31.     private Point position;
  32.     private int targetmap;
  33.     private int type;
  34.     private int id;
  35.     private String scriptName;
  36.     private boolean portalState;
  37.     public MapleGenericPortal(int type) {
  38.         this.type = type;
  39.         portalState = OPEN;
  40.     }
  41.     @Override
  42.     public void setPortalState(boolean state) {
  43.         this.portalState = state;
  44.     }
  45.     @Override
  46.     public boolean getPortalState() {
  47.         return portalState;
  48.     }
  49.     @Override
  50.     public int getId() {
  51.         return id;
  52.     }
  53.     public void setId(int id) {
  54.         this.id = id;
  55.     }
  56.     @Override
  57.     public String getName() {
  58.         return name;
  59.     }
  60.     @Override
  61.     public Point getPosition() {
  62.         return position;
  63.     }
  64.     @Override
  65.     public String getTarget() {
  66.         return target;
  67.     }
  68.     @Override
  69.     public int getTargetMapId() {
  70.         return targetmap;
  71.     }
  72.     @Override
  73.     public int getType() {
  74.         return type;
  75.     }
  76.     @Override
  77.     public String getScriptName() {
  78.         return scriptName;
  79.     }
  80.     public void setName(String name) {
  81.         this.name = name;
  82.     }
  83.     public void setPosition(Point position) {
  84.         this.position = position;
  85.     }
  86.     public void setTarget(String target) {
  87.         this.target = target;
  88.     }
  89.     public void setTargetMapId(int targetmapid) {
  90.         this.targetmap = targetmapid;
  91.     }
  92.     @Override
  93.     public void setScriptName(String scriptName) {
  94.         this.scriptName = scriptName;
  95.     }
  96.     @Override
  97.     public void enterPortal(MapleClient c) {
  98.         MapleCharacter player = c.getPlayer();
  99.         double distanceSq = getPosition().distanceSq(player.getPosition());
  100.         if (distanceSq > 22500) {
  101.             player.getCheatTracker().registerOffense(CheatingOffense.USING_FARAWAY_PORTAL, "D" + Math.sqrt(distanceSq));
  102.         }
  103.         boolean changed = false;
  104.         if (getScriptName() != null) {
  105.             if (!FourthJobQuestsPortalHandler.handlePortal(getScriptName(), c.getPlayer())) {
  106.                 changed = PortalScriptManager.getInstance().executePortalScript(this, c);
  107.             }
  108.         } else if (getTargetMapId() != 999999999) {
  109.             MapleMap to;
  110.             if (player.getEventInstance() == null) {
  111.                 to = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(getTargetMapId());
  112.             } else {
  113.                 to = player.getEventInstance().getMapInstance(getTargetMapId());
  114.             }
  115.             MaplePortal pto = to.getPortal(getTarget());
  116.             if (pto == null) { // fallback for missing portals - no real life case anymore - intresting for not implemented areas
  117.                 pto = to.getPortal(0);
  118.             }
  119.             if (getTargetMapId() >= 910000010 && getTargetMapId() <= 910000021) {
  120.             c.getSession().write(MaplePacketCreator.enableActions());
  121.             player.getClient().getSession().write(MaplePacketCreator.serverNotice(5, "[公告]请通过npc进入pk房间!"));
  122.             } else {
  123.             c.getPlayer().changeMap(to, pto); //late resolving makes this harder but prevents us from loading the whole world at once
  124.             changed = true;
  125.         }
  126.         if (!changed) {
  127.             c.getSession().write(MaplePacketCreator.enableActions());
  128.         }
  129.     }
  130.     }
  131.     public void setPortalStatus(boolean newStatus) {
  132.         throw new UnsupportedOperationException("Not supported yet.");
  133.     }
  134. }