mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-05 23:22:47 +00:00
Monster can now be killed. Their corpses disappear after 5 seconds and
respawn in the specified time. Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
83229
dist/sql/npc.sql
vendored
83229
dist/sql/npc.sql
vendored
File diff suppressed because it is too large
Load Diff
@@ -67,14 +67,16 @@ public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
|
||||
public static final String NPC_ID = "npc_id";
|
||||
public static final String NPC_TEMPLATE_ID = "npc_template_id";
|
||||
|
||||
public static final String NPC_HP = "hp";
|
||||
public static final String NPC_MP = "mp";
|
||||
public static final String HP = "hp";
|
||||
public static final String MP = "mp";
|
||||
|
||||
public static final String POINT_X = "point_x";
|
||||
public static final String POINT_Y = "point_y";
|
||||
public static final String POINT_Z = "point_z";
|
||||
public static final String POINT_ANGLE = "point_angle";
|
||||
|
||||
public static final String RESPAWN_TIME = "respawn_time";
|
||||
|
||||
@Inject
|
||||
public JDBCNPCDAO(DatabaseService database, final NPCIDProvider idProvider,
|
||||
NPCTemplateIDProvider templateIdProvider) {
|
||||
@@ -116,15 +118,17 @@ public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
|
||||
|
||||
npc.setID(id);
|
||||
|
||||
if (rs.getString(NPC_HP) != null)
|
||||
npc.setHP(rs.getDouble(NPC_HP));
|
||||
if (rs.getString(NPC_MP) != null)
|
||||
npc.setMP(rs.getDouble(NPC_MP));
|
||||
if (rs.getString(HP) != null)
|
||||
npc.setHP(rs.getDouble(HP));
|
||||
if (rs.getString(MP) != null)
|
||||
npc.setMP(rs.getDouble(MP));
|
||||
|
||||
npc.setPoint(Point3D.fromXYZA(rs.getInt(POINT_X),
|
||||
rs.getInt(POINT_Y), rs.getInt(POINT_Z),
|
||||
rs.getDouble(POINT_ANGLE)));
|
||||
|
||||
npc.setRespawnInterval(rs.getLong(RESPAWN_TIME));
|
||||
|
||||
return npc;
|
||||
}
|
||||
};
|
||||
@@ -207,9 +211,10 @@ public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
|
||||
@Override
|
||||
protected String query() {
|
||||
return "INSERT INTO `" + TABLE + "` (`" + NPC_ID + "`,`"
|
||||
+ NPC_TEMPLATE_ID + "`,`" + NPC_HP + "`, `" + NPC_MP
|
||||
+ "`,`" + POINT_X + "`,`" + POINT_Y + "`,`" + POINT_Z
|
||||
+ "`,`" + POINT_ANGLE + "`) VALUES(?,?,?,?,?,?,?,?)";
|
||||
+ NPC_TEMPLATE_ID + "`,`" + HP + "`, `" + MP + "`,`"
|
||||
+ POINT_X + "`,`" + POINT_Y + "`,`" + POINT_Z + "`,`"
|
||||
+ POINT_ANGLE + "`,`" + RESPAWN_TIME
|
||||
+ "`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,6 +232,8 @@ public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
|
||||
st.setInt(i++, npc.getPoint().getY());
|
||||
st.setInt(i++, npc.getPoint().getZ());
|
||||
st.setDouble(i++, npc.getPoint().getAngle());
|
||||
|
||||
st.setLong(i++, npc.getRespawnInterval());
|
||||
}
|
||||
}) > 0;
|
||||
}
|
||||
@@ -237,10 +244,10 @@ public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
|
||||
@Override
|
||||
protected String query() {
|
||||
return "UPDATE `" + TABLE + "` SET `" + NPC_TEMPLATE_ID
|
||||
+ "` = ?,`" + NPC_HP + "` = ?, `" + NPC_MP + "` = ?,`"
|
||||
+ "` = ?,`" + HP + "` = ?, `" + MP + "` = ?,`"
|
||||
+ POINT_X + "` = ?,`" + POINT_Y + "` = ?,`" + POINT_Z
|
||||
+ "` = ?,`" + POINT_ANGLE + "` = ? WHERE `" + NPC_ID
|
||||
+ "` = ?";
|
||||
+ "` = ?,`" + POINT_ANGLE + "` = ?, `" + RESPAWN_TIME
|
||||
+ "` = ? WHERE `" + NPC_ID + "` = ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -258,6 +265,8 @@ public abstract class JDBCNPCDAO extends AbstractJDBCDAO<NPC, NPCID> implements
|
||||
st.setInt(i++, npc.getPoint().getY());
|
||||
st.setInt(i++, npc.getPoint().getZ());
|
||||
st.setDouble(i++, npc.getPoint().getAngle());
|
||||
|
||||
st.setLong(i++, npc.getRespawnInterval());
|
||||
|
||||
// WHERE
|
||||
st.setInt(i++, npc.getID().getID());
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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;
|
||||
import com.l2jserver.model.server.AttackHit;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
|
||||
/**
|
||||
* This packet informs the client of an attack issued
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see AttackHit
|
||||
*/
|
||||
public class SM_DIE extends AbstractServerPacket {
|
||||
/**
|
||||
* The packet OPCODE
|
||||
*/
|
||||
public static final int OPCODE = 0x00;
|
||||
|
||||
/**
|
||||
* The attacker actor
|
||||
*/
|
||||
private final Actor actor;
|
||||
|
||||
public SM_DIE(Actor actor) {
|
||||
super(OPCODE);
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
|
||||
buffer.writeInt(actor.getID().getID());
|
||||
buffer.writeInt(0x00); // to hide away
|
||||
buffer.writeInt(0x00); // to castle
|
||||
buffer.writeInt(0x00); // to siege HQ
|
||||
buffer.writeInt(0x00); // sweepable (blue glow)
|
||||
buffer.writeInt(0x00); // to FIXED
|
||||
buffer.writeInt(0x00); // to fortress
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class SM_NPC_INFO extends AbstractServerPacket {
|
||||
buffer.writeByte(1); // name above char 1=true ... ??
|
||||
buffer.writeByte(0x00); // is running
|
||||
buffer.writeByte((npc.isAttacking() ? 0x01 : 0x00)); // is in combat
|
||||
buffer.writeByte(0x00); // is like dead (faking)
|
||||
buffer.writeByte((npc.isDead() ? 0x01 : 0x00)); // is like dead (faking)
|
||||
buffer.writeByte(0x00); // 0=teleported 1=default 2=summoned
|
||||
BufferUtils.writeString(buffer, template.getName());
|
||||
BufferUtils.writeString(buffer, template.getTitle());
|
||||
|
||||
@@ -121,6 +121,39 @@ public abstract class Actor extends PositionableObject {
|
||||
*/
|
||||
protected int sp;
|
||||
|
||||
/**
|
||||
* State of the actor. Will be null if it is idle
|
||||
*/
|
||||
private transient ActorState state;
|
||||
|
||||
/**
|
||||
* The valid states for an actor
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum ActorState {
|
||||
/**
|
||||
* This state indicates the actor is being teleported
|
||||
*/
|
||||
TELEPORTING,
|
||||
/**
|
||||
* This state indicates the actor is casting a skill
|
||||
*/
|
||||
CASTING,
|
||||
/**
|
||||
* This state indicates the actor is attacking
|
||||
*/
|
||||
ATTACKING,
|
||||
/**
|
||||
* This state indicates the actor is moving
|
||||
*/
|
||||
MOVING,
|
||||
/**
|
||||
* This state indicates the actor is dead
|
||||
*/
|
||||
DEAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* The currently effects active on the actor
|
||||
*/
|
||||
@@ -133,7 +166,7 @@ public abstract class Actor extends PositionableObject {
|
||||
protected Actor(ActorTemplateID<?> templateID) {
|
||||
this.templateID = templateID;
|
||||
}
|
||||
|
||||
|
||||
public abstract ActorStats<?> getStats();
|
||||
|
||||
/**
|
||||
@@ -248,6 +281,63 @@ public abstract class Actor extends PositionableObject {
|
||||
this.sp = sp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state
|
||||
*/
|
||||
public ActorState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state
|
||||
* the state to set
|
||||
*/
|
||||
public void setState(ActorState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is doing nothing
|
||||
*/
|
||||
public boolean isIdle() {
|
||||
return state == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is being teleported
|
||||
*/
|
||||
public boolean isTeleporting() {
|
||||
return state == ActorState.TELEPORTING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is moving
|
||||
*/
|
||||
public boolean isMoving() {
|
||||
return state == ActorState.MOVING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is dead
|
||||
*/
|
||||
public boolean isDead() {
|
||||
return state == ActorState.DEAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is casting
|
||||
*/
|
||||
public boolean isCasting() {
|
||||
return state == ActorState.CASTING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is attacking
|
||||
*/
|
||||
public boolean isAttacking() {
|
||||
return state == ActorState.ATTACKING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the active effects on this actor
|
||||
*/
|
||||
|
||||
@@ -143,38 +143,6 @@ public class L2Character extends Player {
|
||||
* The character target, if any.
|
||||
*/
|
||||
private transient ActorID<?> targetID;
|
||||
/**
|
||||
* State of the character. Will be null if it is idle
|
||||
*/
|
||||
private transient CharacterState state;
|
||||
|
||||
/**
|
||||
* The valid states for an character
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum CharacterState {
|
||||
/**
|
||||
* This state indicates the character is being teleported
|
||||
*/
|
||||
TELEPORTING,
|
||||
/**
|
||||
* This state indicates the character is casting a skill
|
||||
*/
|
||||
CASTING,
|
||||
/**
|
||||
* This state indicates the character is attacking
|
||||
*/
|
||||
ATTACKING,
|
||||
/**
|
||||
* This state indicates the character is moving
|
||||
*/
|
||||
MOVING,
|
||||
/**
|
||||
* This state indicates the character is dead
|
||||
*/
|
||||
DEAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* The point the player is moving, teleporting etc...
|
||||
@@ -447,63 +415,6 @@ public class L2Character extends Player {
|
||||
this.targetID = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state
|
||||
*/
|
||||
public CharacterState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state
|
||||
* the state to set
|
||||
*/
|
||||
public void setState(CharacterState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is doing nothing
|
||||
*/
|
||||
public boolean isIdle() {
|
||||
return state == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is being teleported
|
||||
*/
|
||||
public boolean isTeleporting() {
|
||||
return state == CharacterState.TELEPORTING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is moving
|
||||
*/
|
||||
public boolean isMoving() {
|
||||
return state == CharacterState.MOVING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is dead
|
||||
*/
|
||||
public boolean isDead() {
|
||||
return state == CharacterState.DEAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is casting
|
||||
*/
|
||||
public boolean isCasting() {
|
||||
return state == CharacterState.CASTING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is attacking
|
||||
*/
|
||||
public boolean isAttacking() {
|
||||
return state == CharacterState.ATTACKING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if character is alive
|
||||
*/
|
||||
|
||||
@@ -30,20 +30,16 @@ import com.l2jserver.service.game.ai.AIScript;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class NPC extends Actor {
|
||||
/**
|
||||
* The {@link NPC} respawn interval
|
||||
*/
|
||||
private long respawnInterval;
|
||||
|
||||
/**
|
||||
* This NPC stats
|
||||
*/
|
||||
private final NPCStats stats = new NPCStats(this);
|
||||
|
||||
/**
|
||||
* The npc state
|
||||
*/
|
||||
private NPCState state;
|
||||
|
||||
public enum NPCState {
|
||||
MOVING, ATTACKING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
@@ -54,47 +50,27 @@ public class NPC extends Actor {
|
||||
super(templateID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the respawnInterval
|
||||
*/
|
||||
public long getRespawnInterval() {
|
||||
return respawnInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param respawnInterval
|
||||
* the respawnInterval to set
|
||||
*/
|
||||
public void setRespawnInterval(long respawnInterval) {
|
||||
desireUpdate();
|
||||
this.respawnInterval = respawnInterval;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCStats getStats() {
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the state
|
||||
*/
|
||||
public NPCState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if NPC is idle
|
||||
*/
|
||||
public boolean isIdle() {
|
||||
return state == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if NPC is idle
|
||||
*/
|
||||
public boolean isMoving() {
|
||||
return state == NPCState.MOVING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if NPC is idle
|
||||
*/
|
||||
public boolean isAttacking() {
|
||||
return state == NPCState.ATTACKING;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state
|
||||
* the state to set
|
||||
*/
|
||||
public void setState(NPCState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
// TEMPLATE WRAPPERS
|
||||
@Override
|
||||
public ActorSex getSex() {
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.model.world.actor.event;
|
||||
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
|
||||
/**
|
||||
* Event dispatcher once an actor has died.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ActorDieEvent implements ActorEvent {
|
||||
/**
|
||||
* The actor that died
|
||||
*/
|
||||
private final Actor actor;
|
||||
/**
|
||||
* The actor who killed the <tt>actor</tt>
|
||||
*/
|
||||
private final Actor killer;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param actor
|
||||
* the actor that died
|
||||
* @param killer
|
||||
* the actor who killed the <tt>actor</tt>
|
||||
*/
|
||||
public ActorDieEvent(Actor actor, Actor killer) {
|
||||
this.actor = actor;
|
||||
this.killer = killer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actor who killed the <tt>actor</tt>
|
||||
*/
|
||||
public Actor getKiller() {
|
||||
return killer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldObject getObject() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Actor getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectID<?>[] getDispatchableObjects() {
|
||||
return new ObjectID<?>[] { actor.getID() };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.model.world.actor.event;
|
||||
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.model.world.event.UnspawnEvent;
|
||||
import com.l2jserver.util.geometry.Point3D;
|
||||
|
||||
/**
|
||||
* Event dispatcher once an actor has unspawned in the world
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ActorUnspawnEvent implements ActorEvent, UnspawnEvent {
|
||||
/**
|
||||
* The unspawned actor
|
||||
*/
|
||||
private final Actor actor;
|
||||
/**
|
||||
* The unspawning point
|
||||
*/
|
||||
private final Point3D point;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param actor
|
||||
* the spawned actor
|
||||
* @param point
|
||||
* the unspawn point
|
||||
*/
|
||||
public ActorUnspawnEvent(Actor actor, Point3D point) {
|
||||
this.actor = actor;
|
||||
this.point = point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldObject getObject() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Actor getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point3D getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectID<?>[] getDispatchableObjects() {
|
||||
return new ObjectID<?>[] { actor.getID() };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.model.world.event;
|
||||
|
||||
import com.l2jserver.service.game.world.event.WorldEvent;
|
||||
import com.l2jserver.util.geometry.Point3D;
|
||||
|
||||
/**
|
||||
* Event for objects unspawning
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface UnspawnEvent extends WorldEvent {
|
||||
/**
|
||||
* @return the point the object was at
|
||||
*/
|
||||
Point3D getPoint();
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.model.world.npc.event;
|
||||
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.actor.event.ActorDieEvent;
|
||||
|
||||
/**
|
||||
* Event dispatched once a {@link NPC} has died.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class NPCDieEvent extends ActorDieEvent implements NPCEvent {
|
||||
/**
|
||||
* @param npc
|
||||
* the died npc
|
||||
* @param the
|
||||
* actor who killed the <tt>npc</tt>
|
||||
*/
|
||||
public NPCDieEvent(NPC npc, Actor killer) {
|
||||
super(npc, killer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return (NPC) super.getActor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.model.world.npc.event;
|
||||
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.actor.event.ActorUnspawnEvent;
|
||||
import com.l2jserver.util.geometry.Point3D;
|
||||
|
||||
/**
|
||||
* Event dispatched once a {@link NPC} has unspawned in the world.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class NPCUnspawnEvent extends ActorUnspawnEvent implements NPCEvent {
|
||||
/**
|
||||
* @param npc
|
||||
* the npc
|
||||
* @param point
|
||||
* the unspawn point
|
||||
*/
|
||||
public NPCUnspawnEvent(NPC npc, Point3D point) {
|
||||
super(npc, point);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPC getNPC() {
|
||||
return (NPC) super.getActor();
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,8 @@ public class Log4JLoggingService extends AbstractService implements
|
||||
|
||||
l2jLogger.setLevel(Level.INFO);
|
||||
nettyLogger.setLevel(Level.DEBUG);
|
||||
Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(Level.WARN);
|
||||
Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(
|
||||
Level.WARN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.core.threading;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
@@ -30,10 +31,10 @@ public interface AsyncFuture<T> extends Future<T> {
|
||||
/**
|
||||
* Waits until the task is executed
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* @throws ExecutionException
|
||||
* if the thread has been interrupted while waiting
|
||||
*/
|
||||
void await() throws InterruptedException;
|
||||
void await() throws ExecutionException;
|
||||
|
||||
/**
|
||||
* Waits until the task is executed
|
||||
|
||||
@@ -149,10 +149,10 @@ public class ThreadServiceImpl extends AbstractService implements ThreadService
|
||||
}
|
||||
|
||||
@Override
|
||||
public void await() throws InterruptedException {
|
||||
public void await() throws ExecutionException {
|
||||
try {
|
||||
this.get();
|
||||
} catch (ExecutionException e) {
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@ import com.l2jserver.model.server.attack.AttackCalculator.AttackCalculatorType;
|
||||
import com.l2jserver.model.server.attack.AttackCalculatorContext;
|
||||
import com.l2jserver.model.server.attack.PhysicalAttackCalculator;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.actor.event.ActorAttackHitEvent;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.core.threading.AsyncFuture;
|
||||
import com.l2jserver.service.core.threading.ThreadService;
|
||||
import com.l2jserver.service.game.npc.NPCService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
|
||||
/**
|
||||
@@ -47,6 +49,11 @@ public class AttackServiceImpl extends AbstractService implements AttackService
|
||||
* The {@link ThreadService} is used to schedule asynchronous attacks
|
||||
*/
|
||||
private final ThreadService threadService;
|
||||
/**
|
||||
* The {@link NPCService}
|
||||
*/
|
||||
private final NPCService npcService;
|
||||
|
||||
/**
|
||||
* The {@link WorldEventDispatcher} is used to dispatch attack events to the
|
||||
* world
|
||||
@@ -55,8 +62,9 @@ public class AttackServiceImpl extends AbstractService implements AttackService
|
||||
|
||||
@Inject
|
||||
public AttackServiceImpl(ThreadService threadService,
|
||||
WorldEventDispatcher eventDispatcher) {
|
||||
NPCService npcService, WorldEventDispatcher eventDispatcher) {
|
||||
this.threadService = threadService;
|
||||
this.npcService = npcService;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@@ -91,15 +99,25 @@ public class AttackServiceImpl extends AbstractService implements AttackService
|
||||
|
||||
@Override
|
||||
public AttackHit call() throws Exception {
|
||||
final double hp = target.getHP();
|
||||
final double damage = PHYSICAL_ATTACK_CALCULATOR.calculate(
|
||||
AttackCalculatorType.DAMAGE, new AttackCalculatorContext(
|
||||
attacker, target));
|
||||
final double dealDamage = (hp < damage ? hp : damage);
|
||||
// TODO calculate miss
|
||||
// TODO calculate critical
|
||||
// TODO calculate soulshot
|
||||
|
||||
// reduce target life
|
||||
target.setHP(target.getHP() - dealDamage);
|
||||
|
||||
final AttackHit hit = new AttackHit(attacker, target, damage);
|
||||
eventDispatcher.dispatch(new ActorAttackHitEvent(hit));
|
||||
|
||||
if (target.getHP() <= 0) {
|
||||
if (target instanceof NPC)
|
||||
npcService.die((NPC) target, attacker);
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ import com.l2jserver.game.net.packet.server.SM_MOVE_TYPE;
|
||||
import com.l2jserver.game.net.packet.server.SM_TARGET;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.Actor.ActorState;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.L2Character.CharacterMoveType;
|
||||
import com.l2jserver.model.world.L2Character.CharacterState;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.character.event.CharacterEnterWorldEvent;
|
||||
import com.l2jserver.model.world.character.event.CharacterEvent;
|
||||
@@ -325,7 +325,7 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// we don't set the character coordinate here, this will be done by
|
||||
// validation packets, sent by client
|
||||
|
||||
character.setState(CharacterState.MOVING);
|
||||
character.setState(ActorState.MOVING);
|
||||
character.setTargetLocation(coordinate.toPoint());
|
||||
|
||||
// for now, let's just write the packet, we don't have much validation
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.client.CM_CHAR_ACTION.CharacterAction;
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.service.Service;
|
||||
@@ -68,6 +69,17 @@ public interface NPCService extends Service {
|
||||
void action(NPC npc, L2Character character, String... args)
|
||||
throws ActionServiceException, CannotSetTargetServiceException;
|
||||
|
||||
/**
|
||||
* Kills the given <tt>npc</tt>. If "nobody" killed the NPC (i.e. died by
|
||||
* admin command), <tt>killer</tt> can be null.
|
||||
*
|
||||
* @param npc
|
||||
* the npc being killed
|
||||
* @param killer
|
||||
* the killer actor
|
||||
*/
|
||||
void die(NPC npc, Actor killer);
|
||||
|
||||
/**
|
||||
* Moves an given <tt>npc</tt> to an <tt>point</tt>
|
||||
*
|
||||
|
||||
@@ -28,10 +28,12 @@ import com.l2jserver.db.dao.NPCDAO;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.client.CM_CHAR_ACTION.CharacterAction;
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.Actor.ActorState;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.NPC.NPCState;
|
||||
import com.l2jserver.model.world.npc.controller.NPCController;
|
||||
import com.l2jserver.model.world.npc.event.NPCDieEvent;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.core.threading.AsyncFuture;
|
||||
@@ -43,6 +45,8 @@ import com.l2jserver.service.game.character.CharacterService;
|
||||
import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
|
||||
import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
|
||||
import com.l2jserver.service.game.spawn.SpawnService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
import com.l2jserver.service.network.NetworkService;
|
||||
import com.l2jserver.util.exception.L2Exception;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
@@ -77,6 +81,10 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
*/
|
||||
private final AttackService attackService;
|
||||
|
||||
/**
|
||||
* The {@link WorldService} event dispatcher
|
||||
*/
|
||||
private final WorldEventDispatcher eventDispatcher;
|
||||
/**
|
||||
* The {@link NPCDAO}
|
||||
*/
|
||||
@@ -98,12 +106,14 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
public NPCServiceImpl(SpawnService spawnService,
|
||||
NetworkService networkService, CharacterService characterService,
|
||||
ThreadService threadService, AttackService attackService,
|
||||
NPCDAO npcDao, Injector injector) {
|
||||
WorldEventDispatcher eventDispatcher, NPCDAO npcDao,
|
||||
Injector injector) {
|
||||
this.spawnService = spawnService;
|
||||
this.networkService = networkService;
|
||||
this.characterService = characterService;
|
||||
this.threadService = threadService;
|
||||
this.attackService = attackService;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.npcDao = npcDao;
|
||||
this.injector = injector;
|
||||
}
|
||||
@@ -143,12 +153,34 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void die(NPC npc, Actor killer) {
|
||||
Preconditions.checkNotNull(npc, "npc");
|
||||
Preconditions.checkNotNull(killer, "killer");
|
||||
|
||||
// set npc as dead
|
||||
npc.setState(ActorState.DEAD);
|
||||
|
||||
// dispatch die event
|
||||
eventDispatcher.dispatch(new NPCDieEvent(npc, killer));
|
||||
|
||||
// schedule corpse removal -- npc will be kept in the world until then
|
||||
spawnService.unspawn(npc, 5, TimeUnit.SECONDS);
|
||||
// schedule an respawn
|
||||
spawnService.spawn(npc, null, npc.getRespawnInterval(),
|
||||
TimeUnit.MILLISECONDS);
|
||||
|
||||
// reset hp and cp
|
||||
npc.setHP(npc.getStats().getMaxHP());
|
||||
npc.setMP(npc.getStats().getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncFuture<Boolean> move(final NPC npc, final Point3D point) {
|
||||
if (!npc.isIdle())
|
||||
// TODO throw an exception
|
||||
return null;
|
||||
npc.setState(NPCState.MOVING);
|
||||
npc.setState(ActorState.MOVING);
|
||||
// calculate walking time
|
||||
final Point3D start = npc.getPoint();
|
||||
final double distance = start.getDistance(point);
|
||||
|
||||
@@ -16,14 +16,17 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.spawn;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.l2jserver.model.world.Actor.ActorState;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.L2Character.CharacterState;
|
||||
import com.l2jserver.model.world.Player;
|
||||
import com.l2jserver.model.world.PositionableObject;
|
||||
import com.l2jserver.model.world.event.SpawnEvent;
|
||||
import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
|
||||
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.service.core.threading.AsyncFuture;
|
||||
import com.l2jserver.util.geometry.Coordinate;
|
||||
import com.l2jserver.util.geometry.Point3D;
|
||||
|
||||
@@ -40,13 +43,13 @@ public interface SpawnService extends Service {
|
||||
* registered in the world (if it isn't already)
|
||||
*
|
||||
* @param object
|
||||
* the spawnable object
|
||||
* the PositionableObject object
|
||||
* @param point
|
||||
* the spawning point. If null, will try to use
|
||||
* {@link Spawnable#getPoint()}.
|
||||
* {@link PositionableObject#getPoint()}.
|
||||
* @throws SpawnPointNotFoundServiceException
|
||||
* if could not find an spawn point (i.e <tt>point</tt> and
|
||||
* {@link Spawnable#getPoint()} are null)
|
||||
* {@link PositionableObject#getPoint()} are null)
|
||||
* @throws AlreadySpawnedServiceException
|
||||
* if the object is already spawned in the world
|
||||
*/
|
||||
@@ -54,6 +57,48 @@ public interface SpawnService extends Service {
|
||||
throws SpawnPointNotFoundServiceException,
|
||||
AlreadySpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Schedules an {@link PositionableObject} object to be spawned in a certain
|
||||
* time.
|
||||
*
|
||||
* @param object
|
||||
* the PositionableObject object
|
||||
* @param point
|
||||
* the spawning point. If null, will try to use
|
||||
* {@link PositionableObject#getPoint()}.
|
||||
* @param time
|
||||
* the amount of time to wait before spawn
|
||||
* @param unit
|
||||
* the unit of <tt>time</tt>
|
||||
* @return an future that can be used to obtain spawn exceptions
|
||||
*/
|
||||
AsyncFuture<?> spawn(PositionableObject object, Point3D point, long time,
|
||||
TimeUnit unit);
|
||||
|
||||
/**
|
||||
* Unspawns an {@link PositionableObject} object from the world
|
||||
*
|
||||
* @param object
|
||||
* the PositionableObject object
|
||||
* @throws NotSpawnedServiceException
|
||||
* if the object is not spawned
|
||||
*/
|
||||
void unspawn(PositionableObject object) throws NotSpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Schedules an {@link PositionableObject} object to be spawned in a certain
|
||||
* time.
|
||||
*
|
||||
* @param object
|
||||
* the PositionableObject object
|
||||
* @param time
|
||||
* the amount of time to wait before respawn
|
||||
* @param unit
|
||||
* the unit of <tt>time</tt>
|
||||
* @return an future that can be used to obtain spawn exceptions
|
||||
*/
|
||||
AsyncFuture<?> unspawn(PositionableObject object, long time, TimeUnit unit);
|
||||
|
||||
/**
|
||||
* Teleports the object to the given <tt>point</tt>.
|
||||
* <p>
|
||||
@@ -85,29 +130,8 @@ public interface SpawnService extends Service {
|
||||
* the character object
|
||||
* @throws CharacterNotTeleportingServiceException
|
||||
* if the character state is not
|
||||
* {@link CharacterState#TELEPORTING}
|
||||
* {@link ActorState#TELEPORTING}
|
||||
*/
|
||||
void finishTeleport(L2Character character)
|
||||
throws CharacterNotTeleportingServiceException;
|
||||
|
||||
/**
|
||||
* Schedules an {@link Spawnable} object to be respawn in a certain time.
|
||||
* <p>
|
||||
* TODO this is not complete
|
||||
*
|
||||
* @param spawnable
|
||||
* the spawnable object
|
||||
*/
|
||||
void scheduleRespawn(PositionableObject spawnable);
|
||||
|
||||
/**
|
||||
* Unspawns an object from the world
|
||||
*
|
||||
* @param spawnable
|
||||
* the spawnable object
|
||||
* @throws NotSpawnedServiceException
|
||||
* if the object is not spawned
|
||||
*/
|
||||
void unspawn(PositionableObject spawnable)
|
||||
throws NotSpawnedServiceException;
|
||||
}
|
||||
|
||||
@@ -16,24 +16,32 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.spawn;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_EXTRA;
|
||||
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO;
|
||||
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_EXTRA;
|
||||
import com.l2jserver.game.net.packet.server.SM_TELEPORT;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.Actor.ActorState;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.L2Character.CharacterState;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.Player;
|
||||
import com.l2jserver.model.world.PositionableObject;
|
||||
import com.l2jserver.model.world.event.SpawnEvent;
|
||||
import com.l2jserver.model.world.event.UnspawnEvent;
|
||||
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
|
||||
import com.l2jserver.model.world.npc.event.NPCUnspawnEvent;
|
||||
import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
|
||||
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.core.threading.AsyncFuture;
|
||||
import com.l2jserver.service.core.threading.ThreadService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
import com.l2jserver.service.network.NetworkService;
|
||||
@@ -45,7 +53,7 @@ import com.l2jserver.util.geometry.Point3D;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ WorldService.class })
|
||||
@Depends({ WorldService.class, NetworkService.class, ThreadService.class })
|
||||
public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
/**
|
||||
* The {@link WorldService}
|
||||
@@ -59,18 +67,25 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
* The {@link NetworkService}
|
||||
*/
|
||||
private final NetworkService networkService;
|
||||
/**
|
||||
* The {@link ThreadService}
|
||||
*/
|
||||
private final ThreadService threadService;
|
||||
|
||||
@Inject
|
||||
public SpawnServiceImpl(WorldService worldService,
|
||||
WorldEventDispatcher eventDispatcher, NetworkService networkService) {
|
||||
WorldEventDispatcher eventDispatcher,
|
||||
NetworkService networkService, ThreadService threadService) {
|
||||
this.worldService = worldService;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.networkService = networkService;
|
||||
this.threadService = threadService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(PositionableObject object, Point3D point)
|
||||
throws SpawnPointNotFoundServiceException {
|
||||
throws SpawnPointNotFoundServiceException,
|
||||
AlreadySpawnedServiceException {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
// sanitize
|
||||
if (point == null)
|
||||
@@ -83,11 +98,13 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
|
||||
// set the spawning point
|
||||
object.setPoint(point);
|
||||
// reset actor state
|
||||
if (object instanceof Actor) {
|
||||
((Actor) object).setState(null);
|
||||
}
|
||||
// register object in the world
|
||||
if (!worldService.add(object))
|
||||
// TODO this should throw an exception
|
||||
// object was already in world
|
||||
return;
|
||||
throw new AlreadySpawnedServiceException();
|
||||
|
||||
// create the SpawnEvent
|
||||
SpawnEvent event = null;
|
||||
@@ -95,6 +112,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
final NPC npc = (NPC) object;
|
||||
event = new NPCSpawnEvent(npc, point);
|
||||
} else if (object instanceof L2Character) {
|
||||
// TODO character spawn event
|
||||
event = null;
|
||||
}
|
||||
|
||||
@@ -105,6 +123,68 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
// remember: broadcasting is done through events!
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncFuture<?> spawn(final PositionableObject object,
|
||||
final Point3D point, long time, TimeUnit unit) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkArgument(time > 0, "time < 0");
|
||||
Preconditions.checkNotNull(unit, "unit");
|
||||
return threadService.async(time, unit,
|
||||
new Callable<PositionableObject>() {
|
||||
@Override
|
||||
public PositionableObject call() throws Exception {
|
||||
spawn(object, point);
|
||||
return object;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unspawn(PositionableObject object)
|
||||
throws NotSpawnedServiceException {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
|
||||
if (object.getPoint() == null)
|
||||
throw new NotSpawnedServiceException();
|
||||
|
||||
// unregister object in the world
|
||||
if (!worldService.remove(object))
|
||||
throw new NotSpawnedServiceException();
|
||||
|
||||
final Point3D point = object.getPoint();
|
||||
|
||||
// create the SpawnEvent
|
||||
UnspawnEvent event = null;
|
||||
if (object instanceof NPC) {
|
||||
final NPC npc = (NPC) object;
|
||||
event = new NPCUnspawnEvent(npc, point);
|
||||
} else if (object instanceof L2Character) {
|
||||
// TODO character unspawn event
|
||||
event = null;
|
||||
}
|
||||
|
||||
// TODO throw an exception if event is null
|
||||
if (event != null)
|
||||
// dispatch unspawn event
|
||||
eventDispatcher.dispatch(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AsyncFuture<?> unspawn(final PositionableObject object, long time,
|
||||
TimeUnit unit) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkArgument(time > 0, "time <= 0");
|
||||
Preconditions.checkNotNull(unit, "unit");
|
||||
return threadService.async(time, unit,
|
||||
new Callable<PositionableObject>() {
|
||||
@Override
|
||||
public PositionableObject call() throws Exception {
|
||||
unspawn(object);
|
||||
return object;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Player player, Coordinate coordinate)
|
||||
throws CharacterAlreadyTeleportingServiceException {
|
||||
@@ -119,9 +199,9 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
if (conn == null)
|
||||
// TODO throw an exception here
|
||||
return;
|
||||
conn.write(new SM_TELEPORT(conn.getCharacter(),
|
||||
coordinate.toPoint()));
|
||||
((L2Character) player).setState(CharacterState.TELEPORTING);
|
||||
conn.write(new SM_TELEPORT(conn.getCharacter(), coordinate
|
||||
.toPoint()));
|
||||
((L2Character) player).setState(ActorState.TELEPORTING);
|
||||
((L2Character) player).setTargetLocation(coordinate.toPoint());
|
||||
} else {
|
||||
player.setPosition(coordinate);
|
||||
@@ -153,18 +233,4 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
conn.write(new SM_CHAR_INFO(character));
|
||||
conn.write(new SM_CHAR_INFO_EXTRA(character));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scheduleRespawn(PositionableObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unspawn(PositionableObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public interface WorldService extends Service, Iterable<WorldObject> {
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if object was not present in the world
|
||||
*/
|
||||
boolean add(WorldObject object);
|
||||
|
||||
@@ -45,6 +46,7 @@ public interface WorldService extends Service, Iterable<WorldObject> {
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if object was present in the world
|
||||
*/
|
||||
boolean remove(WorldObject object);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.SystemMessage;
|
||||
import com.l2jserver.game.net.packet.server.SM_ATTACK;
|
||||
import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_BROADCAST;
|
||||
import com.l2jserver.game.net.packet.server.SM_DIE;
|
||||
import com.l2jserver.game.net.packet.server.SM_MOVE;
|
||||
import com.l2jserver.game.net.packet.server.SM_MOVE_TYPE;
|
||||
import com.l2jserver.game.net.packet.server.SM_NPC_INFO;
|
||||
@@ -32,6 +33,8 @@ import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.PositionableObject;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.model.world.actor.event.ActorAttackHitEvent;
|
||||
import com.l2jserver.model.world.actor.event.ActorDieEvent;
|
||||
import com.l2jserver.model.world.actor.event.ActorUnspawnEvent;
|
||||
import com.l2jserver.model.world.character.event.CharacterEnterWorldEvent;
|
||||
import com.l2jserver.model.world.character.event.CharacterLeaveWorldEvent;
|
||||
import com.l2jserver.model.world.character.event.CharacterMoveEvent;
|
||||
@@ -76,7 +79,7 @@ public class BroadcastServiceImpl extends AbstractService implements
|
||||
final CharacterID id = character.getID();
|
||||
|
||||
// broadcast everything nearby
|
||||
//broadcast(conn);
|
||||
// broadcast(conn);
|
||||
|
||||
// event broadcast listener
|
||||
// this listener will be filtered so that only interesting events are
|
||||
@@ -96,7 +99,8 @@ public class BroadcastServiceImpl extends AbstractService implements
|
||||
|| e instanceof CharacterEnterWorldEvent) {
|
||||
broadcast(conn, e.getObject());
|
||||
} else if (e instanceof PlayerTeleportingEvent
|
||||
|| e instanceof CharacterLeaveWorldEvent) {
|
||||
|| e instanceof CharacterLeaveWorldEvent
|
||||
|| e instanceof ActorUnspawnEvent) {
|
||||
// object is now out of sight
|
||||
conn.write(new SM_OBJECT_REMOVE(object));
|
||||
} else if (e instanceof CharacterWalkingEvent) {
|
||||
@@ -105,6 +109,8 @@ public class BroadcastServiceImpl extends AbstractService implements
|
||||
} else if (e instanceof CharacterRunningEvent) {
|
||||
conn.write(new SM_MOVE_TYPE(((CharacterRunningEvent) e)
|
||||
.getCharacter()));
|
||||
} else if (e instanceof ActorDieEvent) {
|
||||
conn.write(new SM_DIE(((ActorDieEvent) e).getActor()));
|
||||
}
|
||||
// keep listener alive
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user