AbstractMovementPacketHandler.java
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:7k
源码类别:

游戏

开发平台:

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 java.util.ArrayList;
  21. import java.util.List;
  22. import net.sf.odinms.net.AbstractMaplePacketHandler;
  23. import net.sf.odinms.server.maps.AnimatedMapleMapObject;
  24. import net.sf.odinms.server.movement.AbsoluteLifeMovement;
  25. import net.sf.odinms.server.movement.ChairMovement;
  26. import net.sf.odinms.server.movement.ChangeEquipSpecialAwesome;
  27. import net.sf.odinms.server.movement.JumpDownMovement;
  28. import net.sf.odinms.server.movement.LifeMovement;
  29. import net.sf.odinms.server.movement.LifeMovementFragment;
  30. import net.sf.odinms.server.movement.RelativeLifeMovement;
  31. import net.sf.odinms.server.movement.TeleportMovement;
  32. import net.sf.odinms.tools.data.input.LittleEndianAccessor;
  33. public abstract class AbstractMovementPacketHandler extends AbstractMaplePacketHandler {
  34. // private static Logger log = LoggerFactory.getLogger(AbstractMovementPacketHandler.class);
  35.     protected List<LifeMovementFragment> parseMovement(LittleEndianAccessor lea) {
  36.         List<LifeMovementFragment> res = new ArrayList<LifeMovementFragment>();
  37.         int numCommands = lea.readByte();
  38.         for (int i = 0; i < numCommands; i++) {
  39.             int command = lea.readByte();
  40.             switch (command) {
  41.                 case 0: // normal move
  42.                 case 5:
  43.                 case 17: // Float
  44.                 {
  45.                     int xpos = lea.readShort();
  46.                     int ypos = lea.readShort();
  47.                     int xwobble = lea.readShort();
  48.                     int ywobble = lea.readShort();
  49.                     int unk = lea.readShort();
  50.                     int newstate = lea.readByte();
  51.                     int duration = lea.readShort();
  52.                     AbsoluteLifeMovement alm = new AbsoluteLifeMovement(command, new Point(xpos, ypos), duration, newstate);
  53.                     alm.setUnk(unk);
  54.                     alm.setPixelsPerSecond(new Point(xwobble, ywobble));
  55.                     // log.trace("Move to {},{} command {} wobble {},{} ? {} state {} duration {}", new Object[] { xpos,
  56.                     // xpos, command, xwobble, ywobble, newstate, duration });
  57.                     res.add(alm);
  58.                     break;
  59.                 }
  60.                 case 1:
  61.                 case 2:
  62.                 case 6: // fj
  63.                 case 12:
  64.                 case 13: // Shot-jump-back thing
  65.                 case 16: // Float
  66.                 {
  67.                     int xmod = lea.readShort();
  68.                     int ymod = lea.readShort();
  69.                     int newstate = lea.readByte();
  70.                     int duration = lea.readShort();
  71.                     RelativeLifeMovement rlm = new RelativeLifeMovement(command, new Point(xmod, ymod), duration, newstate);
  72.                     res.add(rlm);
  73.                     // log.trace("Relative move {},{} state {}, duration {}", new Object[] { xmod, ymod, newstate,
  74.                     // duration });
  75.                     break;
  76.                 }
  77.                 case 3:
  78.                 case 4: // tele... -.-
  79.                 case 7: // assaulter
  80.                 case 8: // assassinate
  81.                 case 9: // rush
  82.                 case 14: {
  83.                     int xpos = lea.readShort();
  84.                     int ypos = lea.readShort();
  85.                     int xwobble = lea.readShort();
  86.                     int ywobble = lea.readShort();
  87.                     int newstate = lea.readByte();
  88.                     TeleportMovement tm = new TeleportMovement(command, new Point(xpos, ypos), newstate);
  89.                     tm.setPixelsPerSecond(new Point(xwobble, ywobble));
  90.                     res.add(tm);
  91.                     break;
  92.                 }
  93.                 case 10: // change equip ???
  94.                 {
  95.                     res.add(new ChangeEquipSpecialAwesome(lea.readByte()));
  96.                     break;
  97.                 }
  98.                 case 11: // chair
  99.                 {
  100.                     int xpos = lea.readShort();
  101.                     int ypos = lea.readShort();
  102.                     int unk = lea.readShort();
  103.                     int newstate = lea.readByte();
  104.                     int duration = lea.readShort();
  105.                     ChairMovement cm = new ChairMovement(command, new Point(xpos, ypos), duration, newstate);
  106.                     cm.setUnk(unk);
  107.                     res.add(cm);
  108.                     break;
  109.                 }
  110.                 case 15: {
  111.                     int xpos = lea.readShort();
  112.                     int ypos = lea.readShort();
  113.                     int xwobble = lea.readShort();
  114.                     int ywobble = lea.readShort();
  115.                     int unk = lea.readShort();
  116.                     int fh = lea.readShort();
  117.                     int newstate = lea.readByte();
  118.                     int duration = lea.readShort();
  119.                     JumpDownMovement jdm = new JumpDownMovement(command, new Point(xpos, ypos), duration, newstate);
  120.                     jdm.setUnk(unk);
  121.                     jdm.setPixelsPerSecond(new Point(xwobble, ywobble));
  122.                     jdm.setFH(fh);
  123.                     // log.trace("Move to {},{} command {} wobble {},{} ? {} state {} duration {}", new Object[] { xpos,
  124.                     // xpos, command, xwobble, ywobble, newstate, duration });
  125.                     res.add(jdm);
  126.                     break;
  127.                 }
  128.                 default: {
  129. // log.warn("Unhandeled movement command {} received", command);
  130. // log.warn("Movement packet: {}", lea.toString());
  131.                     return null;
  132.                 }
  133.             }
  134.         }
  135.         if (numCommands != res.size()) {
  136. // log.warn("numCommands ({}) does not match the number of deserialized movement commands ({})", numCommands, res.size());
  137.         }
  138.         return res;
  139.     }
  140.     protected void updatePosition(List<LifeMovementFragment> movement, AnimatedMapleMapObject target, int yoffset) {
  141.         for (LifeMovementFragment move : movement) {
  142.             if (move instanceof LifeMovement) {
  143.                 if (move instanceof AbsoluteLifeMovement) {
  144.                     Point position = ((LifeMovement) move).getPosition();
  145.                     position.y += yoffset;
  146.                     target.setPosition(position);
  147.                 }
  148.                 target.setStance(((LifeMovement) move).getNewstate());
  149.             }
  150.         }
  151.     }
  152. }