use of server.movement.LifeMovementFragment in project HeavenMS by ronancpl.
the class MoveDragonHandler method handlePacket.
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
final MapleCharacter chr = c.getPlayer();
final Point startPos = new Point(slea.readShort(), slea.readShort());
List<LifeMovementFragment> res = parseMovement(slea);
final MapleDragon dragon = chr.getDragon();
if (dragon != null && res != null && res.size() > 0) {
updatePosition(res, dragon, 0);
if (chr.isHidden()) {
chr.getMap().broadcastGMMessage(chr, MaplePacketCreator.moveDragon(dragon, startPos, res));
} else {
chr.getMap().broadcastMessage(chr, MaplePacketCreator.moveDragon(dragon, startPos, res), dragon.getPosition());
}
}
}
use of server.movement.LifeMovementFragment in project HeavenMS by ronancpl.
the class MoveLifeHandler method handlePacket.
@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;
List<MapleCharacter> banishPlayers = new ArrayList<>();
byte pNibbles = slea.readByte();
byte rawActivity = slea.readByte();
byte useSkillId = slea.readByte();
byte useSkillLevel = slea.readByte();
short pOption = slea.readShort();
slea.skip(8);
if (rawActivity >= 0) {
rawActivity = (byte) (rawActivity & 0xFF >> 1);
}
boolean isAttack = inRangeInclusive(rawActivity, 12, 20);
boolean isSkill = inRangeInclusive(rawActivity, 21, 25);
byte attackId = (byte) (isAttack ? rawActivity - 12 : -1);
boolean nextMovementCouldBeSkill = (pNibbles & 0x0F) != 0;
boolean pUnk = (pNibbles & 0xF0) != 0;
int nextCastSkill = useSkillId;
int nextCastSkillLevel = useSkillLevel;
MobSkill toUse = null;
int percHpLeft = (int) (((float) monster.getHp() / monster.getMaxHp()) * 100);
if (nextMovementCouldBeSkill && monster.getNoSkills() > 0) {
int Random = Randomizer.nextInt(monster.getNoSkills());
Pair<Integer, Integer> skillToUse = monster.getSkills().get(Random);
nextCastSkill = skillToUse.getLeft();
nextCastSkillLevel = skillToUse.getRight();
toUse = MobSkillFactory.getMobSkill(nextCastSkill, nextCastSkillLevel);
if (isSkill || isAttack) {
if (nextCastSkill != toUse.getSkillId() || nextCastSkillLevel != toUse.getSkillLevel()) {
// toUse.resetAnticipatedSkill();
return;
} else if (toUse.getHP() < percHpLeft) {
toUse = null;
} else if (monster.canUseSkill(toUse)) {
toUse.applyEffect(c.getPlayer(), monster, true, banishPlayers);
// System.out.println("Applied: " + nextCastSkill + " Level: " + nextCastSkillLevel);
}
} else {
MobAttackInfo mobAttack = MobAttackInfoFactory.getMobAttackInfo(monster, attackId);
// System.out.println("Attacked");
}
}
slea.readByte();
// whatever
slea.readInt();
// hmm.. startpos?
short start_x = slea.readShort();
// hmm...
short start_y = slea.readShort();
Point startPos = new Point(start_x, start_y);
res = parseMovement(slea);
if (monster.getController() != c.getPlayer()) {
if (monster.isAttackedBy(c.getPlayer())) {
monster.switchController(c.getPlayer(), true);
} else {
return;
}
} else if (rawActivity == -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());
}
for (MapleCharacter chr : banishPlayers) {
chr.changeMapBanish(monster.getBanish().getMap(), monster.getBanish().getPortal(), monster.getBanish().getMsg());
}
}
use of server.movement.LifeMovementFragment in project HeavenMS by ronancpl.
the class AbstractMovementPacketHandler method updatePosition.
protected void updatePosition(List<LifeMovementFragment> movement, AnimatedMapleMapObject target, int yoffset) {
for (LifeMovementFragment move : movement) {
if (move instanceof LifeMovement) {
if (move instanceof AbsoluteLifeMovement) {
Point position = ((LifeMovement) move).getPosition();
position.y += yoffset;
target.setPosition(position);
}
target.setStance(((LifeMovement) move).getNewstate());
}
}
}
use of server.movement.LifeMovementFragment in project HeavenMS by ronancpl.
the class AbstractMovementPacketHandler method parseMovement.
protected List<LifeMovementFragment> parseMovement(LittleEndianAccessor lea) {
List<LifeMovementFragment> res = new ArrayList<>();
byte numCommands = lea.readByte();
for (byte i = 0; i < numCommands; i++) {
byte command = lea.readByte();
switch(command) {
// normal move
case 0:
case 5:
case 17:
{
// Float
short xpos = lea.readShort();
short ypos = lea.readShort();
short xwobble = lea.readShort();
short ywobble = lea.readShort();
short unk = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
AbsoluteLifeMovement alm = new AbsoluteLifeMovement(command, new Point(xpos, ypos), duration, newstate);
alm.setUnk(unk);
alm.setPixelsPerSecond(new Point(xwobble, ywobble));
res.add(alm);
break;
}
case 1:
case 2:
// fj
case 6:
case 12:
// Shot-jump-back thing
case 13:
// Float
case 16:
case 18:
// Springs on maps
case 19:
// Aran Combat Step
case 20:
case 22:
{
short xpos = lea.readShort();
short ypos = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
RelativeLifeMovement rlm = new RelativeLifeMovement(command, new Point(xpos, ypos), duration, newstate);
res.add(rlm);
break;
}
case 3:
// tele... -.-
case 4:
// assaulter
case 7:
// assassinate
case 8:
// rush
case 9:
case // chair
11:
{
// case 14: {
short xpos = lea.readShort();
short ypos = lea.readShort();
short xwobble = lea.readShort();
short ywobble = lea.readShort();
byte newstate = lea.readByte();
TeleportMovement tm = new TeleportMovement(command, new Point(xpos, ypos), newstate);
tm.setPixelsPerSecond(new Point(xwobble, ywobble));
res.add(tm);
break;
}
case 14:
// jump down (?)
lea.skip(9);
break;
case // Change Equip
10:
res.add(new ChangeEquip(lea.readByte()));
break;
/*case 11: { // Chair
short xpos = lea.readShort();
short ypos = lea.readShort();
short unk = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
ChairMovement cm = new ChairMovement(command, new Point(xpos, ypos), duration, newstate);
cm.setUnk(unk);
res.add(cm);
break;
}*/
case 15:
{
short xpos = lea.readShort();
short ypos = lea.readShort();
short xwobble = lea.readShort();
short ywobble = lea.readShort();
short unk = lea.readShort();
short fh = lea.readShort();
byte newstate = lea.readByte();
short duration = lea.readShort();
JumpDownMovement jdm = new JumpDownMovement(command, new Point(xpos, ypos), duration, newstate);
jdm.setUnk(unk);
jdm.setPixelsPerSecond(new Point(xwobble, ywobble));
jdm.setFH(fh);
res.add(jdm);
break;
}
case 21:
{
// Causes aran to do weird stuff when attacking o.o
/*byte newstate = lea.readByte();
short unk = lea.readShort();
AranMovement am = new AranMovement(command, null, unk, newstate);
res.add(am);*/
lea.skip(3);
break;
}
default:
System.out.println("Unhandled Case:" + command);
return null;
}
}
return res;
}
use of server.movement.LifeMovementFragment in project HeavenMS by ronancpl.
the class MovePetHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int petId = slea.readInt();
slea.readLong();
// Point startPos = StreamUtil.readShortPoint(slea);
List<LifeMovementFragment> res = parseMovement(slea);
if (res.isEmpty()) {
return;
}
MapleCharacter player = c.getPlayer();
byte slot = player.getPetIndex(petId);
if (slot == -1) {
return;
}
player.getPet(slot).updatePosition(res);
player.getMap().broadcastMessage(player, MaplePacketCreator.movePet(player.getId(), petId, slot, res), false);
}
Aggregations