MoveLifeHandler
CollectionUtilCode:/* This file is part of the OdinMS Maple Story Server Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> Matthias Butz <matze@odinms.de> Jan Christian Meyer <vimes@odinms.de> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation version 3 as published by the Free Software Foundation. You may not use, modify or distribute this program under any other version of the GNU Affero General Public License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.server.channel.handlers; import client.MapleClient; import java.awt.Point; import java.util.List; import server.life.MapleMonster; import server.life.MobAttackInfo; import server.life.MobAttackInfoFactory; import server.life.MobSkill; import server.life.MobSkillFactory; import server.maps.MapleMapObject; import server.maps.MapleMapObjectType; import server.movement.LifeMovementFragment; import tools.CollectionUtil; import tools.MaplePacketCreator; import tools.Pair; import tools.Randomizer; import tools.data.input.SeekableLittleEndianAccessor; /** * * @author Danny (Leifde) * @author ExtremDevilz */ public final class MoveLifeHandler extends AbstractMovementPacketHandler { @Override public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) { int objectid = slea.readInt(); short moveid = slea.readShort(); MapleMapObject mmo = c.getPlayer().getMap().getMapObject(objectid); if (mmo == null || mmo.getType() != MapleMapObjectType.MONSTER) { return; } MapleMonster monster = (MapleMonster) mmo; List<LifeMovementFragment> res = null; byte pNibbles = slea.readByte(); byte rawActivity = slea.readByte(); byte useSkillId = slea.readByte(); byte useSkillLevel = slea.readByte(); short pOption = slea.readShort(); byte parsedActivity = rawActivity; if (parsedActivity >= 0) { parsedActivity = (byte) (parsedActivity & 0xFF >> 1); } boolean isAttack = CollectionUtil.inRangeInclusive(parsedActivity, 12, 20); boolean isSkill = CollectionUtil.inRangeInclusive(parsedActivity, 21, 25); byte attackId = (byte) (isAttack ? parsedActivity - 12 : -1); boolean nextMovementCouldBeSkill = (pNibbles & 0x0F) != 0; boolean pUnk = (pNibbles & 0xF0) != 0; int nextCastSkill = useSkillId; int nextCastSkillLevel = useSkillLevel; MobAttackInfo mobAttack = null; MobSkill toUse = null; if (isAttack) { mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId); System.out.println("Attacked"); } if (isSkill) { if (monster.getNoSkills() > 0) { int Random = Randomizer.nextInt(monster.getNoSkills()); // Random Monster Skill Pair<Integer, Integer> skillToUse = monster.getSkills().get(Random); nextCastSkill = skillToUse.getLeft(); nextCastSkillLevel = skillToUse.getRight(); toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel); int percHpLeft = (int) ((monster.getHp() / monster.getMaxHp()) * 100); if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) { // Match The Client Response Packet ? toUse.resetAnticipatedSkill(); System.out.println("Nope"); return; } if (monster.hasSkill(nextCastSkill, nextCastSkillLevel) && monster.canUseSkill(toUse) && toUse != null) { if (toUse.getHP() < percHpLeft || !monster.canUseSkill(toUse)) { toUse = null; System.out.println("toUse == Null"); } else { toUse.applyEffect(c.getPlayer(), monster, true); System.out.println("Appiled: " + nextCastSkill + "Level: " + nextCastSkillLevel); } } } } slea.readByte(); slea.readInt(); // whatever short start_x = slea.readShort(); // hmm.. startpos? short start_y = slea.readShort(); // hmm... Point startPos = new Point(start_x, start_y); res = parseMovement(slea); if (monster.getController() != c.getPlayer()) { if (monster.isAttackedBy(c.getPlayer())) {// aggro and controller change monster.switchController(c.getPlayer(), true); } else { return; } } else if (parsedActivity == -1 && monster.isControllerKnowsAboutAggro() && !monster.isMobile() && !monster.isFirstAttack()) { monster.setControllerHasAggro(false); monster.setControllerKnowsAboutAggro(false); } boolean aggro = monster.isControllerHasAggro(); if (toUse != null) { c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro, toUse.getSkillId(), toUse.getSkillLevel())); } else { c.announce(MaplePacketCreator.moveMonsterResponse(objectid, moveid, monster.getMp(), aggro)); } if (aggro) { monster.setControllerKnowsAboutAggro(true); } if (res != null) { c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.moveMonster(objectid, nextMovementCouldBeSkill, rawActivity, useSkillId, useSkillLevel, pOption , startPos, res), monster.getPosition()); updatePosition(res, monster, -1); c.getPlayer().getMap().moveMonster(monster, monster.getPosition()); } } }
MaplePacketCreatorCode:public static boolean inRangeInclusive(Byte pVal, Integer pMin, Integer pMax) { return !(pVal < pMin) || (pVal > pMax); }
before you go around writing rubbish let me explain my old release had some glitches while It took me awhile to get this working It is still but it was way better then how it was written as the old version was totally wrong and inaccuracy, I don't know how prefect is this but it was based on Vana which the developer said it is quite accuracy, now if you wish to improve this you can go ahead and respect the decision that I have actually release this as it took me countless of effort to get this working.Code:public static byte[] moveMonster(int oid, boolean skillPossible, byte rawAction, byte skill, byte level, short option, Point startPos, List<LifeMovementFragment> moves) { final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); mplew.writeShort(SendOpcode.MOVE_MONSTER.getValue()); mplew.writeInt(oid); mplew.writeBool(skillPossible); mplew.write(rawAction); mplew.write(skill); mplew.write(level); mplew.writeShort(option); mplew.writePos(startPos); serializeMovementList(mplew, moves); return mplew.getPacket(); }![]()



Reply With Quote

pro

