mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Fix 317 revision npc interaction packets, fixed npc indexes being +1 and added npc action verification.
This commit is contained in:
@@ -90,4 +90,10 @@
|
||||
<handler>org.apollo.game.event.handler.impl.ItemVerificationHandler</handler>
|
||||
</chain>
|
||||
</event>
|
||||
<event>
|
||||
<type>org.apollo.game.event.impl.NpcActionEvent</type>
|
||||
<chain>
|
||||
<handler>org.apollo.game.event.handler.impl.NpcActionVerificationHandler</handler>
|
||||
</chain>
|
||||
</event>
|
||||
</events>
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.apollo.game.event.handler.impl;
|
||||
|
||||
import org.apollo.game.event.handler.EventHandler;
|
||||
import org.apollo.game.event.handler.EventHandlerContext;
|
||||
import org.apollo.game.event.impl.NpcActionEvent;
|
||||
import org.apollo.game.model.Npc;
|
||||
import org.apollo.game.model.Player;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.WorldConstants;
|
||||
|
||||
/**
|
||||
* An {@link EventHandler} that verifies {@link org.apollo.game.event.impl.NpcActionEvent}
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public class NpcActionVerificationHandler extends EventHandler<NpcActionEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) {
|
||||
if(event.getIndex() < 0 || event.getIndex() > WorldConstants.MAXIMUM_NPCS) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
Npc npc = (Npc)World.getWorld().getNpcRepository().get(event.getIndex());
|
||||
|
||||
if(npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public abstract class NpcActionEvent extends Event {
|
||||
*/
|
||||
public NpcActionEvent(int option, int index) {
|
||||
this.option = option;
|
||||
this.index = index;
|
||||
this.index = index - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.event.impl.FirstNpcActionEvent;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketReader;
|
||||
import org.apollo.net.codec.game.*;
|
||||
import org.apollo.net.release.EventDecoder;
|
||||
|
||||
/**
|
||||
@@ -17,7 +14,7 @@ public final class FirstNpcActionEventDecoder extends EventDecoder<FirstNpcActio
|
||||
@Override
|
||||
public FirstNpcActionEvent decode(GamePacket packet) {
|
||||
GamePacketReader reader = new GamePacketReader(packet);
|
||||
int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
|
||||
int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE);
|
||||
return new FirstNpcActionEvent(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,9 +139,9 @@ public final class Release317 extends Release {
|
||||
register(210, spamEventDecoder);
|
||||
register(226, spamEventDecoder);
|
||||
|
||||
register(72, new FirstNpcActionEventDecoder());
|
||||
register(155, new SecondNpcActionEventDecoder());
|
||||
register(17, new ThirdNpcActionEventDecoder());
|
||||
register(155, new FirstNpcActionEventDecoder());
|
||||
register(17, new SecondNpcActionEventDecoder());
|
||||
register(21, new ThirdNpcActionEventDecoder());
|
||||
register(236, new TakeTileItemEventDecoder());
|
||||
register(192, new ItemOnObjectEventDecoder());
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.event.impl.SecondNpcActionEvent;
|
||||
import org.apollo.net.codec.game.DataOrder;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketReader;
|
||||
import org.apollo.net.codec.game.*;
|
||||
import org.apollo.net.release.EventDecoder;
|
||||
|
||||
/**
|
||||
@@ -17,7 +14,7 @@ public final class SecondNpcActionEventDecoder extends EventDecoder<SecondNpcAct
|
||||
@Override
|
||||
public SecondNpcActionEvent decode(GamePacket packet) {
|
||||
GamePacketReader reader = new GamePacketReader(packet);
|
||||
int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
|
||||
int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
|
||||
return new SecondNpcActionEvent(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.apollo.net.release.r317;
|
||||
|
||||
import org.apollo.game.event.impl.ThirdNpcActionEvent;
|
||||
import org.apollo.net.codec.game.DataOrder;
|
||||
import org.apollo.net.codec.game.DataTransformation;
|
||||
import org.apollo.net.codec.game.DataType;
|
||||
import org.apollo.net.codec.game.GamePacket;
|
||||
import org.apollo.net.codec.game.GamePacketReader;
|
||||
@@ -18,7 +16,7 @@ public final class ThirdNpcActionEventDecoder extends EventDecoder<ThirdNpcActio
|
||||
@Override
|
||||
public ThirdNpcActionEvent decode(GamePacket packet) {
|
||||
GamePacketReader reader = new GamePacketReader(packet);
|
||||
int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
|
||||
int index = (int) reader.getSigned(DataType.SHORT);
|
||||
return new ThirdNpcActionEvent(index);
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +178,20 @@ public final class MobRepository<T extends Mob> implements Iterable<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mob at the given index
|
||||
*
|
||||
* @param index The index of the mob
|
||||
* @return The mob instance
|
||||
*/
|
||||
public Mob get(int index) {
|
||||
if (index < 0 || index >= mobs.length) {
|
||||
throw new IndexOutOfBoundsException("Mob index is out of bounds.");
|
||||
}
|
||||
|
||||
return mobs[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of this repository.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user