mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Improve existing verification handlers and add PlayerActionVerificationHandler.
This commit is contained in:
@@ -96,6 +96,12 @@
|
|||||||
<handler>org.apollo.game.message.handler.impl.NpcActionVerificationHandler</handler>
|
<handler>org.apollo.game.message.handler.impl.NpcActionVerificationHandler</handler>
|
||||||
</chain>
|
</chain>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<type>org.apollo.game.message.impl.PlayerActionMessage</type>
|
||||||
|
<chain>
|
||||||
|
<handler>org.apollo.game.message.handler.impl.PlayerActionVerificationHandler</handler>
|
||||||
|
</chain>
|
||||||
|
</message>
|
||||||
<message>
|
<message>
|
||||||
<type>org.apollo.game.message.impl.ObjectActionMessage</type>
|
<type>org.apollo.game.message.impl.ObjectActionMessage</type>
|
||||||
<chain>
|
<chain>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import org.apollo.game.message.handler.MessageHandler;
|
|||||||
import org.apollo.game.message.handler.MessageHandlerContext;
|
import org.apollo.game.message.handler.MessageHandlerContext;
|
||||||
import org.apollo.game.message.impl.NpcActionMessage;
|
import org.apollo.game.message.impl.NpcActionMessage;
|
||||||
import org.apollo.game.model.World;
|
import org.apollo.game.model.World;
|
||||||
|
import org.apollo.game.model.def.NpcDefinition;
|
||||||
import org.apollo.game.model.entity.Npc;
|
import org.apollo.game.model.entity.Npc;
|
||||||
import org.apollo.game.model.entity.Player;
|
import org.apollo.game.model.entity.Player;
|
||||||
import org.apollo.util.MobRepository;
|
import org.apollo.util.MobRepository;
|
||||||
@@ -16,9 +17,13 @@ import org.apollo.util.MobRepository;
|
|||||||
*/
|
*/
|
||||||
public final class NpcActionVerificationHandler extends MessageHandler<NpcActionMessage> {
|
public final class NpcActionVerificationHandler extends MessageHandler<NpcActionMessage> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The world's npc repository.
|
||||||
|
*/
|
||||||
|
private final MobRepository<Npc> repository = World.getWorld().getNpcRepository();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MessageHandlerContext ctx, Player player, NpcActionMessage message) {
|
public void handle(MessageHandlerContext ctx, Player player, NpcActionMessage message) {
|
||||||
MobRepository<Npc> repository = World.getWorld().getNpcRepository();
|
|
||||||
int index = message.getIndex();
|
int index = message.getIndex();
|
||||||
|
|
||||||
if (index < 0 || index >= repository.capacity()) {
|
if (index < 0 || index >= repository.capacity()) {
|
||||||
@@ -28,12 +33,14 @@ public final class NpcActionVerificationHandler extends MessageHandler<NpcAction
|
|||||||
|
|
||||||
Npc npc = repository.get(index);
|
Npc npc = repository.get(index);
|
||||||
|
|
||||||
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
|
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), player.getViewingDistance() + 1)) {
|
||||||
|
// +1 in case it was decremented after the player clicked the action.
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getOption() >= npc.getDefinition().getInteractions().length) {
|
NpcDefinition definition = npc.getDefinition();
|
||||||
|
if (message.getOption() >= definition.getInteractions().length) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.apollo.game.message.impl.ObjectActionMessage;
|
|||||||
import org.apollo.game.model.Position;
|
import org.apollo.game.model.Position;
|
||||||
import org.apollo.game.model.World;
|
import org.apollo.game.model.World;
|
||||||
import org.apollo.game.model.area.Sector;
|
import org.apollo.game.model.area.Sector;
|
||||||
|
import org.apollo.game.model.area.SectorRepository;
|
||||||
import org.apollo.game.model.def.ObjectDefinition;
|
import org.apollo.game.model.def.ObjectDefinition;
|
||||||
import org.apollo.game.model.entity.Entity.EntityType;
|
import org.apollo.game.model.entity.Entity.EntityType;
|
||||||
import org.apollo.game.model.entity.GameObject;
|
import org.apollo.game.model.entity.GameObject;
|
||||||
@@ -20,6 +21,11 @@ import org.apollo.game.model.entity.Player;
|
|||||||
*/
|
*/
|
||||||
public final class ObjectActionVerificationHandler extends MessageHandler<ObjectActionMessage> {
|
public final class ObjectActionVerificationHandler extends MessageHandler<ObjectActionMessage> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The world's sector repository.
|
||||||
|
*/
|
||||||
|
private final SectorRepository repository = World.getWorld().getSectorRepository();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(MessageHandlerContext ctx, Player player, ObjectActionMessage message) {
|
public void handle(MessageHandlerContext ctx, Player player, ObjectActionMessage message) {
|
||||||
int id = message.getId();
|
int id = message.getId();
|
||||||
@@ -29,7 +35,7 @@ public final class ObjectActionVerificationHandler extends MessageHandler<Object
|
|||||||
}
|
}
|
||||||
|
|
||||||
Position position = message.getPosition();
|
Position position = message.getPosition();
|
||||||
Sector sector = World.getWorld().getSectorRepository().fromPosition(position);
|
Sector sector = repository.fromPosition(position);
|
||||||
List<GameObject> objects = sector.getEntities(position, EntityType.GAME_OBJECT);
|
List<GameObject> objects = sector.getEntities(position, EntityType.GAME_OBJECT);
|
||||||
|
|
||||||
if (!containsObject(id, objects)) {
|
if (!containsObject(id, objects)) {
|
||||||
@@ -42,8 +48,8 @@ public final class ObjectActionVerificationHandler extends MessageHandler<Object
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO is this right?
|
ObjectDefinition definition = ObjectDefinition.lookup(id);
|
||||||
if (message.getOption() >= ObjectDefinition.lookup(id).getMenuActions().length) {
|
if (message.getOption() >= definition.getMenuActions().length) {
|
||||||
ctx.breakHandlerChain();
|
ctx.breakHandlerChain();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.apollo.game.message.handler.impl;
|
||||||
|
|
||||||
|
import org.apollo.game.message.handler.MessageHandler;
|
||||||
|
import org.apollo.game.message.handler.MessageHandlerContext;
|
||||||
|
import org.apollo.game.message.impl.PlayerActionMessage;
|
||||||
|
import org.apollo.game.model.World;
|
||||||
|
import org.apollo.game.model.entity.Player;
|
||||||
|
import org.apollo.util.MobRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A verification {@link MessageHandler} for the {@link PlayerActionMessage}.
|
||||||
|
*
|
||||||
|
* @author Major
|
||||||
|
*/
|
||||||
|
public final class PlayerActionVerificationHandler extends MessageHandler<PlayerActionMessage> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The world's player repository.
|
||||||
|
*/
|
||||||
|
private final MobRepository<Player> repository = World.getWorld().getPlayerRepository();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(MessageHandlerContext ctx, Player player, PlayerActionMessage message) {
|
||||||
|
int index = message.getIndex();
|
||||||
|
|
||||||
|
if (index < 0 || index >= repository.capacity()) {
|
||||||
|
ctx.breakHandlerChain();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player other = repository.get(index);
|
||||||
|
if (other == null
|
||||||
|
|| !player.getPosition().isWithinDistance(other.getPosition(), player.getViewingDistance() + 1)) {
|
||||||
|
// +1 in case it was decremented after the player clicked the action.
|
||||||
|
ctx.breakHandlerChain();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user