mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-10 09:22:49 +00:00
Initial work in the attack service
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import com.l2jserver.game.net.packet.client.AdminCommandPacket;
|
||||
import com.l2jserver.game.net.packet.client.AuthLoginPacket;
|
||||
import com.l2jserver.game.net.packet.client.CharacterActionPacket;
|
||||
import com.l2jserver.game.net.packet.client.CharacterAppearingPacket;
|
||||
import com.l2jserver.game.net.packet.client.CharacterAttackRequestPacket;
|
||||
import com.l2jserver.game.net.packet.client.CharacterChatMessagePacket;
|
||||
import com.l2jserver.game.net.packet.client.CharacterCreatePacket;
|
||||
import com.l2jserver.game.net.packet.client.CharacterRequestActionUse;
|
||||
@@ -181,6 +182,8 @@ public class Lineage2PacketReader extends OneToOneDecoder {
|
||||
return CharacterRequestActionUse.class;
|
||||
case CharacterRequestOpenMap.OPCODE:
|
||||
return CharacterRequestOpenMap.class;
|
||||
case CharacterAttackRequestPacket.OPCODE:
|
||||
return CharacterAttackRequestPacket.class;
|
||||
default:
|
||||
logger.warn("Unknown opcode: 0x{}", Integer.toHexString(opcode));
|
||||
break;
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.service.game.character.ActorIsNotAttackableServiceException;
|
||||
import com.l2jserver.service.game.character.CannotSetTargetServiceException;
|
||||
import com.l2jserver.service.game.character.CharacterService;
|
||||
import com.l2jserver.service.game.npc.NotAttackableNPCServiceException;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
|
||||
/**
|
||||
@@ -121,7 +122,7 @@ public class CharacterAttackRequestPacket extends AbstractClientPacket {
|
||||
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",
|
||||
log.warn("Player {} is trying to attack {}, which is not an actor",
|
||||
character, id);
|
||||
return;
|
||||
}
|
||||
@@ -132,6 +133,8 @@ public class CharacterAttackRequestPacket extends AbstractClientPacket {
|
||||
conn.sendActionFailed();
|
||||
} catch (ActorIsNotAttackableServiceException e) {
|
||||
conn.sendActionFailed();
|
||||
} catch (NotAttackableNPCServiceException e) {
|
||||
conn.sendActionFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.AbstractServerPacket;
|
||||
import com.l2jserver.model.server.AttackHit;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* This packet informs the client of an attack issued
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see AttackHit
|
||||
*/
|
||||
public class ActorAttackPacket extends AbstractServerPacket {
|
||||
/**
|
||||
* The packet OPCODE
|
||||
*/
|
||||
public static final int OPCODE = 0x33;
|
||||
|
||||
/**
|
||||
* The attacker actor
|
||||
*/
|
||||
private final Actor attacker;
|
||||
/**
|
||||
* List of hits to be sent
|
||||
*/
|
||||
private final List<AttackHit> hits = CollectionFactory.newList();
|
||||
|
||||
public ActorAttackPacket(Actor attacker, AttackHit... hits) {
|
||||
super(OPCODE);
|
||||
this.attacker = attacker;
|
||||
Collections.addAll(this.hits, hits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||
buffer.writeInt(attacker.getID().getID());
|
||||
|
||||
final AttackHit first = hits.get(0);
|
||||
buffer.writeInt(first.getTarget().getID().getID());
|
||||
buffer.writeInt((int) first.getDamage());
|
||||
buffer.writeByte(first.getFlagsByte());
|
||||
|
||||
buffer.writeInt(attacker.getPoint().getX());
|
||||
buffer.writeInt(attacker.getPoint().getY());
|
||||
buffer.writeInt(attacker.getPoint().getZ());
|
||||
|
||||
buffer.writeShort(hits.size() - 1);
|
||||
if (hits.size() > 1) {
|
||||
boolean skipFirst = false;
|
||||
for (final AttackHit hit : hits) {
|
||||
if (!skipFirst) {
|
||||
skipFirst = true;
|
||||
continue;
|
||||
}
|
||||
buffer.writeInt(hit.getTarget().getID().getID());
|
||||
buffer.writeInt((int) hit.getDamage());
|
||||
buffer.writeByte(hit.getFlagsByte());
|
||||
}
|
||||
}
|
||||
|
||||
buffer.writeInt(first.getTarget().getPoint().getX());
|
||||
buffer.writeInt(first.getTarget().getPoint().getY());
|
||||
buffer.writeInt(first.getTarget().getPoint().getZ());
|
||||
}
|
||||
|
||||
public ActorAttackPacket add(AttackHit hit) {
|
||||
hits.add(hit);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
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.Actor;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* This packet notifies the client that the chosen character has been
|
||||
* successfully selected.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see Reason
|
||||
*/
|
||||
public class ActorStatusUpdatePacket extends AbstractServerPacket {
|
||||
/**
|
||||
* The packet OPCODE
|
||||
*/
|
||||
public static final int OPCODE = 0x18;
|
||||
|
||||
/**
|
||||
* The stats the can be updated with the packet
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum Stat {
|
||||
LEVEL(0x01), EXPERIENCE(0x02), STR(0x03), DEX(0x04), CON(0x05), INT(
|
||||
0x06), WIT(0x07), MEN(0x08),
|
||||
|
||||
HP(0x09), MAX_HP(0x0a), MP(0x0b), MAX_MP(0x0c),
|
||||
|
||||
SP(0x0d), LOAD(0x0e), MAX_LOAD(0x0f),
|
||||
|
||||
PHYSICAL_ATK(0x11), ATTACK_SPEED(0x12), PHYSICAL_DEFENSE(0x13), EVASION(
|
||||
0x14), ACCURACY(0x15), CRITICAL(0x16), MAGICAL_ATTACK(0x17), CAST_SPEED(
|
||||
0x18), MAGICAL_DEFENSE(0x19), PVP_FLAG(0x1a), KARMA(0x1b),
|
||||
|
||||
CP(0x21), MAX_CP(0x22);
|
||||
|
||||
public final int id;
|
||||
|
||||
Stat(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<Stat, Integer> update = CollectionFactory.newMap();
|
||||
private final Actor actor;
|
||||
|
||||
public ActorStatusUpdatePacket(Actor actor) {
|
||||
super(OPCODE);
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||
buffer.writeInt(actor.getID().getID());
|
||||
buffer.writeInt(update.size());
|
||||
|
||||
for (Entry<Stat, Integer> entry : update.entrySet()) {
|
||||
buffer.writeInt(entry.getKey().id);
|
||||
buffer.writeInt(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public ActorStatusUpdatePacket add(Stat stat, int value) {
|
||||
update.put(stat, value);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -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.Actor;
|
||||
|
||||
/**
|
||||
* This packet notifies the client that the chosen character has been
|
||||
@@ -30,7 +30,7 @@ import com.l2jserver.model.world.L2Character;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see Reason
|
||||
*/
|
||||
public class CharacterPositionPacket extends AbstractServerPacket {
|
||||
public class ActorUpdatePositionPacket extends AbstractServerPacket {
|
||||
/**
|
||||
* The packet OPCODE
|
||||
*/
|
||||
@@ -39,19 +39,19 @@ public class CharacterPositionPacket extends AbstractServerPacket {
|
||||
/**
|
||||
* The selected character
|
||||
*/
|
||||
private final L2Character character;
|
||||
private final Actor actor;
|
||||
|
||||
public CharacterPositionPacket(L2Character character) {
|
||||
public ActorUpdatePositionPacket(Actor actor) {
|
||||
super(OPCODE);
|
||||
this.character = character;
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||
buffer.writeInt(character.getID().getID());
|
||||
buffer.writeInt(character.getPoint().getX());
|
||||
buffer.writeInt(character.getPoint().getY());
|
||||
buffer.writeInt(character.getPoint().getZ());
|
||||
buffer.writeInt((int) character.getPoint().getAngle());
|
||||
buffer.writeInt(actor.getID().getID());
|
||||
buffer.writeInt(actor.getPoint().getX());
|
||||
buffer.writeInt(actor.getPoint().getY());
|
||||
buffer.writeInt(actor.getPoint().getZ());
|
||||
buffer.writeInt((int) actor.getPoint().getAngle());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user