1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

Event dispatcher changes and packet implementations

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-19 13:08:32 -03:00
parent 2c4af6d91d
commit 2d1181483a
77 changed files with 796 additions and 519 deletions

View File

@@ -256,7 +256,7 @@ public class Lineage2Connection {
* @return an {@link Set} containing all {@link ChannelFuture} instances.
*/
public Set<ChannelFuture> broadcast(ServerPacket packet) {
final Set<ChannelFuture> futures = CollectionFactory.newSet(null);
final Set<ChannelFuture> futures = CollectionFactory.newSet();
for (final L2Character character : worldService
.iterable(new CharacterBroadcastFilter(characterID.getObject()))) {
final Lineage2Connection conn = networkService.discover(character

View File

@@ -0,0 +1,129 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.client;
import org.jboss.netty.buffer.ChannelBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.ActorID;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Completes the creation of an character. Creates the object, inserts into the
* database and notifies the client about the status of the operation.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterAttackRequestPacket extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x01;
/**
* The Logger
*/
private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* The {@link CharacterService}
*/
private final CharacterService charService;
/**
* The {@link ObjectID} resolver
*/
private final ObjectIDResolver idResolver;
/**
* The {@link ObjectID} being attacked
*/
private int objectId;
/**
* The position of the target
*/
@SuppressWarnings("unused")
private Coordinate origin;
/**
* The attack action type
*/
@SuppressWarnings("unused")
private CharacterAttackAction action;
public enum CharacterAttackAction {
/**
* Normal click
*/
CLICK(0),
/**
* Clicked with shift-click
*/
SHIFT_CLICK(1);
public final int id;
CharacterAttackAction(int id) {
this.id = id;
}
public static CharacterAttackAction fromID(int id) {
for (final CharacterAttackAction action : values())
if (action.id == id)
return action;
return null;
}
}
@Inject
public CharacterAttackRequestPacket(CharacterService charService,
ObjectIDResolver idResolver) {
this.charService = charService;
this.idResolver = idResolver;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
this.objectId = buffer.readInt();
this.origin = Coordinate.fromXYZ(buffer.readInt(), buffer.readInt(),
buffer.readInt());
this.action = CharacterAttackAction.fromID(buffer.readByte());
}
@Override
public void process(final Lineage2Connection conn) {
final L2Character character = conn.getCharacter();
// since this is an erasure type, this is safe.
final ObjectID<Actor> id = idResolver.resolve(objectId);
if (!(id instanceof ActorID)) {
conn.write(ActionFailedPacket.SHARED_INSTANCE);
log.warn("Player {} is trying to attack {} which is not an actor",
character, id);
return;
}
final Actor actor = id.getObject();
charService.attack(character, actor);
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.server;
import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
/**
* This packet responds to the Restart request
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ActionFailedPacket extends AbstractServerPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x1f;
/**
* The {@link ActionFailedPacket} shared instance
*/
public static final ActionFailedPacket SHARED_INSTANCE = new ActionFailedPacket();
/**
* Creates a new instance
*/
public ActionFailedPacket() {
super(OPCODE);
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
}
}

View File

@@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.CharacterCreateFailPacket.Reason;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.util.dimensional.Coordinate;
/**
@@ -40,22 +40,25 @@ public class ActorMovementPacket extends AbstractServerPacket {
/**
* The selected character
*/
private final L2Character character;
private final Actor actor;
/**
* The source coordinate
*/
private Coordinate source;
public ActorMovementPacket(L2Character character, Coordinate source) {
public ActorMovementPacket(Actor actor, Coordinate source) {
super(OPCODE);
this.character = character;
this.actor = actor;
this.source = source;
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
buffer.writeInt(character.getID().getID());
buffer.writeInt(actor.getID().getID());
buffer.writeInt(character.getPoint().getX());
buffer.writeInt(character.getPoint().getY());
buffer.writeInt(character.getPoint().getZ());
buffer.writeInt(actor.getPoint().getX());
buffer.writeInt(actor.getPoint().getY());
buffer.writeInt(actor.getPoint().getZ());
buffer.writeInt(source.getX());
buffer.writeInt(source.getY());

View File

@@ -29,7 +29,7 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class InventoryPacket extends AbstractServerPacket {
public class CharacterInventoryPacket extends AbstractServerPacket {
/**
* The packet OPCODE
*/
@@ -44,7 +44,7 @@ public class InventoryPacket extends AbstractServerPacket {
*/
private boolean showWindow = false;
public InventoryPacket(CharacterInventory inventory) {
public CharacterInventoryPacket(CharacterInventory inventory) {
super(OPCODE);
this.inventory = inventory;
}

View File

@@ -68,7 +68,7 @@ public class NPCInformationPacket extends AbstractServerPacket {
buffer.writeDouble(template.getMovementSpeedMultiplier());
buffer.writeDouble(template.getAttackSpeedMultiplier());
buffer.writeDouble(template.getCollisionRadius());
buffer.writeDouble(template.getCollisionHeigth());
buffer.writeDouble(template.getCollisionHeight());
buffer.writeInt(0x00); // right hand weapon
buffer.writeInt(0x00); // chest
buffer.writeInt(0x00); // left hand weapon
@@ -92,7 +92,7 @@ public class NPCInformationPacket extends AbstractServerPacket {
buffer.writeByte(0x00); // title color 0=client
buffer.writeDouble(template.getCollisionRadius());
buffer.writeDouble(template.getCollisionHeigth());
buffer.writeDouble(template.getCollisionHeight());
buffer.writeInt(0x00); // C4 - enchant effect
buffer.writeInt(0x00); // C6 -- is flying
buffer.writeInt(0x00); // unk

View File

@@ -58,7 +58,7 @@ public class ServerObjectPacket extends AbstractServerPacket {
buffer.writeDouble(template.getMovementSpeedMultiplier());
buffer.writeDouble(template.getAttackSpeedMultiplier());
buffer.writeDouble(template.getCollisionRadius()); // coll radius
buffer.writeDouble(template.getCollisionHeigth()); // coll height
buffer.writeDouble(template.getCollisionHeight()); // coll height
buffer.writeInt((template.isAttackable() ? npc.getHP() : 0x00));
buffer.writeInt((template.isAttackable() ? template.getMaxHP() : 0x00));
buffer.writeInt(0x01); // object type