MonsterCarnivalHandler.java
Upload User: gwt600
Upload Date: 2021-06-03
Package Size: 704k
Code Size: 4k
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.net.channel.handler;
  19. import java.awt.Point;
  20. import net.sf.odinms.client.MapleClient;
  21. import net.sf.odinms.net.AbstractMaplePacketHandler;
  22. import net.sf.odinms.server.life.MapleLifeFactory;
  23. import net.sf.odinms.server.life.MapleMonster;
  24. import net.sf.odinms.tools.MaplePacketCreator;
  25. import net.sf.odinms.tools.data.input.SeekableLittleEndianAccessor;
  26. public class MonsterCarnivalHandler extends AbstractMaplePacketHandler {
  27.     @Override
  28.     public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
  29.         int tab = slea.readByte();
  30.         int num = slea.readByte();
  31.         c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.playerSummoned(c.getPlayer().getName(), tab, num));
  32.         if (tab == 0) { //only spawning for now..
  33.             MapleMonster mob = MapleLifeFactory.getMonster(getMonsterIdByNum(num));
  34.             //c.getPlayer().getMap().spawnMonsterOnGroundBelow(mob, randomizePosition(c.getPlayer().getMapId()));
  35.             c.getPlayer().getMap().spawnMonsterOnGroundBelow(mob, randomizePosition(c.getPlayer().getMapId(), 1));
  36.         }
  37.     }
  38.     public Point randomizePosition(int mapid, int team) {
  39.         int posx = 0;
  40.         int posy = 0;
  41.         if (mapid == 980000301) { //room 3 iirc
  42.             posy = 162;
  43.             if(team == 0){ //maple red goes left
  44.                 posx = rand(-1554, -151);
  45.             }else{ //maple blue goes right
  46.                 posx = rand(148, 1571);
  47.             }
  48.         }
  49.         return new Point(posx, posy);
  50.     }
  51.     public int getMonsterIdByNum(int num) {
  52.         /*
  53.          *  1 - Brown Teddy - 3000005
  54.         2 - Bloctopus - 3230302
  55.         3 - Ratz - 3110102
  56.         4 - Chronos - 3230306
  57.         5 - Toy Trojan - 3230305
  58.         6 - Tick-Tock - 4230113
  59.         7 - Robo - 4230111
  60.         8 - King Bloctopus - 3230103
  61.         9 - Master Chronos - 4230115
  62.         10 - Rombot - 4130103
  63.          * */
  64.         int mid = 0;
  65.         num++; //whatever, don't wanna change all the cases XD
  66.         switch (num) {
  67.             case 1:
  68.                 mid = 3000005;
  69.                 break;
  70.             case 2:
  71.                 mid = 3230302;
  72.                 break;
  73.             case 3:
  74.                 mid = 3110102;
  75.                 break;
  76.             case 4:
  77.                 mid = 3230306;
  78.                 break;
  79.             case 5:
  80.                 mid = 3230305;
  81.                 break;
  82.             case 6:
  83.                 mid = 4230113;
  84.                 break;
  85.             case 7:
  86.                 mid = 4230111;
  87.                 break;
  88.             case 8:
  89.                 mid = 3230103;
  90.                 break;
  91.             case 9:
  92.                 mid = 4230115;
  93.                 break;
  94.             case 10:
  95.                 mid = 4130103;
  96.                 break;
  97.             default:
  98.                 mid = 210100; //LOL slime.. w/e, shouldn't happen
  99.                 break;
  100.         }
  101.         return mid;
  102.     }
  103.     private static int rand(int lbound, int ubound) {
  104.         return (int) ((Math.random() * (ubound - lbound + 1)) + lbound);
  105.     }
  106. }