implements
}
/**
- * @return the movementSpeedMultiplier
- */
- public double getMovementSpeedMultiplier() {
- return movementSpeedMultiplier;
- }
-
- /**
- * @return the attackSpeedMultiplier
- */
- public double getAttackSpeedMultiplier() {
- return attackSpeedMultiplier;
- }
-
- /**
- * @return the collisionRadius
+ * @return the collision radius
*/
public double getCollisionRadius() {
return collisionRadius;
}
/**
- * @return the collisionHeight
+ * @return the collision height
*/
public double getCollisionHeight() {
return collisionHeight;
}
- /**
- * @return the maxHp
- */
- public int getMaxHP() {
- return maxHp;
- }
-
/**
* @return the race
*/
diff --git a/src/main/java/com/l2jserver/model/template/npc/TeleporterNPCTemplate.java b/src/main/java/com/l2jserver/model/template/npc/TeleporterNPCTemplate.java
index 85d14229b..d5e7f7ea0 100644
--- a/src/main/java/com/l2jserver/model/template/npc/TeleporterNPCTemplate.java
+++ b/src/main/java/com/l2jserver/model/template/npc/TeleporterNPCTemplate.java
@@ -77,6 +77,15 @@ public class TeleporterNPCTemplate extends NPCTemplate {
public static final Coordinate CAVE_OF_TRIALS = Coordinate.fromXYZ(9340,
-112509, -2536);
+ public static final Coordinate DARK_FOREST = Coordinate.fromXYZ(-22224,
+ 14168, -3232);
+ public static final Coordinate SPIDER_NEST = Coordinate.fromXYZ(-61095,
+ 75104, -3352);
+ public static final Coordinate SWAMPLAND = Coordinate.fromXYZ(-21966,
+ 40544, -3192);
+ public static final Coordinate NEUTRAL_ZONE = Coordinate.fromXYZ(-10612,
+ 75881, -3592);
+
@Inject
protected SpawnService spawnService;
diff --git a/src/main/java/com/l2jserver/model/world/Actor.java b/src/main/java/com/l2jserver/model/world/Actor.java
index c0155beb5..9dcfc1cfb 100644
--- a/src/main/java/com/l2jserver/model/world/Actor.java
+++ b/src/main/java/com/l2jserver/model/world/Actor.java
@@ -17,9 +17,10 @@
package com.l2jserver.model.world;
import com.l2jserver.model.id.object.ActorID;
+import com.l2jserver.model.id.template.ActorTemplateID;
+import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.actor.ActorEffects;
import com.l2jserver.model.world.actor.ActorSkillContainer;
-import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
@@ -28,6 +29,8 @@ import com.l2jserver.util.dimensional.Point;
* @author Rogiel
*/
public abstract class Actor extends PositionableObject {
+ protected ActorTemplateID> templateID;
+
/**
* The actor race
*/
@@ -117,6 +120,10 @@ public abstract class Actor extends PositionableObject {
*/
protected final ActorSkillContainer skills = new ActorSkillContainer(this);
+ public Actor(ActorTemplateID> templateID) {
+ this.templateID = templateID;
+ }
+
public int getHP() {
return hp;
}
@@ -174,6 +181,20 @@ public abstract class Actor extends PositionableObject {
return skills;
}
+ /**
+ * @return the templateID
+ */
+ public ActorTemplateID> getTemplateID() {
+ return templateID;
+ }
+
+ /**
+ * @return the template
+ */
+ public ActorTemplate> getTemplate() {
+ return templateID.getTemplate();
+ }
+
@Override
public ActorID> getID() {
return (ActorID>) super.getID();
diff --git a/src/main/java/com/l2jserver/model/world/Item.java b/src/main/java/com/l2jserver/model/world/Item.java
index f970026c6..5c0808910 100644
--- a/src/main/java/com/l2jserver/model/world/Item.java
+++ b/src/main/java/com/l2jserver/model/world/Item.java
@@ -21,8 +21,6 @@ import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
-import com.l2jserver.util.dimensional.Coordinate;
-import com.l2jserver.util.dimensional.Point;
/**
* This class represents an {@link Item} in the Lineage II World. The item can
@@ -37,10 +35,13 @@ import com.l2jserver.util.dimensional.Point;
* Equipped by the {@link L2Character character}: location
* is {@link InventoryLocation#PAPERDOLL}, paperdoll is not null and
* coordinate is null.
- * Dropped on the ground: location and paperdoll
+ * Dropped on the ground: location and paperdoll
* are null, coordinate is not null and represents the dropping
* location.
*
+ *
+ * Please note that {@link PositionableObject} values are only set if the object
+ * is dropped on the ground.
*
* @author Rogiel
*/
@@ -62,10 +63,6 @@ public class Item extends PositionableObject {
* Paperdoll slot for this item
*/
private InventoryPaperdoll paperdoll;
- /**
- * Drop coordinate of this item
- */
- private Coordinate coordinate;
/**
* Count of items
@@ -144,12 +141,4 @@ public class Item extends PositionableObject {
public void setOwnerID(CharacterID ownerID) {
this.ownerID = ownerID;
}
-
- public Point getPoint() {
- return null;
- }
-
- public void setPoint(Point point) {
-
- }
}
diff --git a/src/main/java/com/l2jserver/model/world/L2Character.java b/src/main/java/com/l2jserver/model/world/L2Character.java
index a181f218e..bb696f98d 100644
--- a/src/main/java/com/l2jserver/model/world/L2Character.java
+++ b/src/main/java/com/l2jserver/model/world/L2Character.java
@@ -23,6 +23,7 @@ import com.l2jserver.model.id.object.ActorID;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.id.object.PetID;
+import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.actor.ActorAttributes;
import com.l2jserver.model.world.character.CharacterAppearance;
@@ -138,7 +139,9 @@ public class L2Character extends Player {
* @param baseAttributes
* the base attribute for this character
*/
- public L2Character(CharacterTemplate.ActorBaseAttributes baseAttributes) {
+ public L2Character(CharacterTemplateID templateID,
+ CharacterTemplate.ActorBaseAttributes baseAttributes) {
+ super(templateID);
this.baseAttributes = baseAttributes;
this.attributes = new CharacterCalculatedAttributes(this);
}
@@ -369,6 +372,16 @@ public class L2Character extends Player {
return shortcuts;
}
+ @Override
+ public CharacterTemplateID getTemplateID() {
+ return (CharacterTemplateID) super.getTemplateID();
+ }
+
+ @Override
+ public CharacterTemplate getTemplate() {
+ return (CharacterTemplate) super.getTemplate();
+ }
+
@Override
public CharacterID getID() {
return (CharacterID) super.getID();
diff --git a/src/main/java/com/l2jserver/model/world/NPC.java b/src/main/java/com/l2jserver/model/world/NPC.java
index 531734e16..20f485afa 100644
--- a/src/main/java/com/l2jserver/model/world/NPC.java
+++ b/src/main/java/com/l2jserver/model/world/NPC.java
@@ -30,11 +30,6 @@ import com.l2jserver.service.game.ai.AIScript;
* @author Rogiel
*/
public class NPC extends Actor {
- /**
- * The NPC template ID
- */
- private final NPCTemplateID templateID;
-
/**
* Creates a new instance
*
@@ -42,21 +37,21 @@ public class NPC extends Actor {
* the {@link NPC} {@link TemplateID}
*/
public NPC(NPCTemplateID templateID) {
- this.templateID = templateID;
+ super(templateID);
}
/**
* @return the NPC template ID
*/
public NPCTemplateID getTemplateID() {
- return templateID;
+ return (NPCTemplateID) templateID;
}
/**
* @return the NPC template
*/
public NPCTemplate getTemplate() {
- return templateID.getTemplate();
+ return (NPCTemplate) templateID.getTemplate();
}
@Override
diff --git a/src/main/java/com/l2jserver/model/world/Pet.java b/src/main/java/com/l2jserver/model/world/Pet.java
index 1844c0586..396f80f96 100644
--- a/src/main/java/com/l2jserver/model/world/Pet.java
+++ b/src/main/java/com/l2jserver/model/world/Pet.java
@@ -18,6 +18,7 @@ package com.l2jserver.model.world;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ItemID;
+import com.l2jserver.model.id.template.ActorTemplateID;
/**
* This class represents an Pet in the Lineage II World
@@ -34,6 +35,10 @@ public class Pet extends Player {
*/
private ItemID itemID;
+ public Pet(ActorTemplateID> templateID) {
+ super(templateID);
+ }
+
/**
* @return the owner ID
*/
diff --git a/src/main/java/com/l2jserver/model/world/Player.java b/src/main/java/com/l2jserver/model/world/Player.java
index 58180b511..5bd9d9eb5 100644
--- a/src/main/java/com/l2jserver/model/world/Player.java
+++ b/src/main/java/com/l2jserver/model/world/Player.java
@@ -16,6 +16,8 @@
*/
package com.l2jserver.model.world;
+import com.l2jserver.model.id.template.ActorTemplateID;
+
/**
* {@link Player} is any object that can be controlled by the player. The most
* common implementation is {@link L2Character}.
@@ -23,5 +25,7 @@ package com.l2jserver.model.world;
* @author Rogiel
*/
public abstract class Player extends Actor {
-
+ public Player(ActorTemplateID> templateID) {
+ super(templateID);
+ }
}
diff --git a/src/main/java/com/l2jserver/model/world/PositionableObject.java b/src/main/java/com/l2jserver/model/world/PositionableObject.java
index 674b2289a..8a0fa4226 100644
--- a/src/main/java/com/l2jserver/model/world/PositionableObject.java
+++ b/src/main/java/com/l2jserver/model/world/PositionableObject.java
@@ -20,10 +20,15 @@ import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
- * @author Rogiel
+ * This is an abstract object that objects that can be placed in world should
+ * extend.
*
+ * @author Rogiel
*/
public abstract class PositionableObject extends AbstractObject {
+ /**
+ * The point this object is currently in
+ */
private Point point;
/**
diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java
index ac5689bf9..32046f041 100644
--- a/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java
+++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java
@@ -34,7 +34,7 @@ public class CharacterMoveEvent implements CharacterEvent {
*/
private final L2Character character;
/**
- * The new point of the character
+ * The old point of the character
*/
private final Point point;
@@ -44,7 +44,7 @@ public class CharacterMoveEvent implements CharacterEvent {
* @param character
* the character
* @param point
- * the character point
+ * the character point before moving
*/
public CharacterMoveEvent(L2Character character, Point point) {
this.character = character;
@@ -52,7 +52,7 @@ public class CharacterMoveEvent implements CharacterEvent {
}
/**
- * @return the new point
+ * @return the old point
*/
public Point getPoint() {
return point;
diff --git a/src/main/java/com/l2jserver/service/ServiceManager.java b/src/main/java/com/l2jserver/service/ServiceManager.java
index 2cb7a6597..66a2be465 100644
--- a/src/main/java/com/l2jserver/service/ServiceManager.java
+++ b/src/main/java/com/l2jserver/service/ServiceManager.java
@@ -57,6 +57,10 @@ public class ServiceManager {
}
logger = LoggerFactory.getLogger(ServiceManager.class);
}
+
+ public T get(Class serviceClass) {
+ return injector.getInstance(serviceClass);
+ }
public T start(Class serviceClass)
throws ServiceStartException {
diff --git a/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java b/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java
index 8f5c75f0c..f77799393 100644
--- a/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java
+++ b/src/main/java/com/l2jserver/service/core/Log4JLoggingService.java
@@ -54,9 +54,10 @@ public class Log4JLoggingService extends AbstractService implements
rootLogger.setLevel(Level.WARN);
rootLogger.addAppender(new ConsoleAppender(layout, "System.err"));
- l2jLogger.setLevel(Level.DEBUG);
- scriptLogger.setLevel(Level.DEBUG);
+ l2jLogger.setLevel(Level.INFO);
+ scriptLogger.setLevel(Level.INFO);
nettyLogger.setLevel(Level.DEBUG);
+ Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(Level.WARN);
}
@Override
diff --git a/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java b/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java
index 920c0ed51..e5559b3d5 100644
--- a/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java
+++ b/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java
@@ -329,7 +329,9 @@ public class MySQLDatabaseService extends AbstractService implements
final List list = CollectionFactory.newList();
final ResultSet rs = st.getResultSet();
while (rs.next()) {
- list.add(mapper().map(rs));
+ final T obj = mapper().map(rs);
+ if (obj != null)
+ list.add(obj);
}
return list;
}
diff --git a/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java b/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java
index f6f24341f..8149abd29 100644
--- a/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java
@@ -23,6 +23,7 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.SystemMessage;
import com.l2jserver.game.net.packet.server.ActorChatMessagePacket;
import com.l2jserver.game.net.packet.server.ActorMovementPacket;
+import com.l2jserver.game.net.packet.server.CharacterInformationBroadcastPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationExtraPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationPacket;
import com.l2jserver.game.net.packet.server.CharacterInventoryPacket;
@@ -30,6 +31,7 @@ import com.l2jserver.game.net.packet.server.CharacterMovementTypePacket;
import com.l2jserver.game.net.packet.server.CharacterTargetSelectedPacket;
import com.l2jserver.game.net.packet.server.GameGuardQueryPacket;
import com.l2jserver.game.net.packet.server.NPCInformationPacket;
+import com.l2jserver.game.net.packet.server.ObjectRemove;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.Actor;
@@ -50,6 +52,7 @@ import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
import com.l2jserver.model.world.character.event.CharacterWalkingEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
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.game.chat.ChatChannel;
@@ -65,7 +68,9 @@ import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.event.WorldListener;
+import com.l2jserver.service.game.world.filter.impl.IDFilter;
import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
+import com.l2jserver.service.game.world.filter.impl.KnownListUpdateFilter;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
@@ -133,7 +138,7 @@ public class CharacterServiceImpl extends AbstractService implements
return;
itemDao.loadInventory(character);
-
+
character.setOnline(true);
// chat listener
@@ -158,9 +163,10 @@ public class CharacterServiceImpl extends AbstractService implements
// this listener will be filtered so that only interesting events are
// dispatched, once a event arrives will be possible to check check if
// the given event will be broadcasted or not
- // TODO this should not be here, it should be i world service or a newly
+ // TODO this should not be here, it should be in world service or a
+ // newly
// created broadcast service.
- final WorldListener broadcastListener = new FilteredWorldListener(
+ final WorldListener neighboorListener = new FilteredWorldListener(
new KnownListFilter(character)) {
@Override
protected boolean dispatch(WorldEvent e, PositionableObject object) {
@@ -168,29 +174,64 @@ public class CharacterServiceImpl extends AbstractService implements
conn.write(new NPCInformationPacket((NPC) object));
} else if (e instanceof CharacterMoveEvent) {
final CharacterMoveEvent evt = (CharacterMoveEvent) e;
- if (object.equals(character))
- return true;
conn.write(new ActorMovementPacket((L2Character) object,
evt.getPoint().getCoordinate()));
} else if (e instanceof PlayerTeleportedEvent
|| e instanceof CharacterEnterWorldEvent) {
- // TODO this should not be here!
- for (final PositionableObject o : worldService
- .iterable(new KnownListFilter(character))) {
- if (o instanceof NPC) {
- conn.write(new NPCInformationPacket((NPC) o));
- }
+ if (object instanceof NPC) {
+ conn.write(new NPCInformationPacket((NPC) object));
+ } else if (object instanceof L2Character) {
+ conn.write(new CharacterInformationBroadcastPacket(
+ (L2Character) object));
}
- } else if (e instanceof CharacterWalkingEvent
- || e instanceof CharacterRunningEvent) {
+ } else if (e instanceof PlayerTeleportingEvent
+ || e instanceof CharacterLeaveWorldEvent) {
+ // object is not out of sight
+ conn.write(new ObjectRemove(object));
+ } else if (e instanceof CharacterWalkingEvent) {
conn.write(new CharacterMovementTypePacket(
((CharacterWalkingEvent) e).getCharacter()));
+ } else if (e instanceof CharacterRunningEvent) {
+ conn.write(new CharacterMovementTypePacket(
+ ((CharacterRunningEvent) e).getCharacter()));
}
// keep listener alive
return true;
}
};
- eventDispatcher.addListener(broadcastListener);
+ eventDispatcher.addListener(neighboorListener);
+ final WorldListener sendPacketListener = new FilteredWorldListener(
+ new IDFilter(character.getID())) {
+ @Override
+ protected boolean dispatch(WorldEvent e, WorldObject object) {
+ if (e instanceof CharacterMoveEvent) {
+ final CharacterMoveEvent evt = (CharacterMoveEvent) e;
+ // process update known list
+ for (final WorldObject o : worldService
+ .iterable(new KnownListUpdateFilter(character, evt
+ .getPoint()))) {
+ if (o instanceof NPC) {
+ conn.write(new NPCInformationPacket((NPC) o));
+ } else if (o instanceof L2Character) {
+ conn.write(new CharacterInformationBroadcastPacket(
+ (L2Character) o));
+ }
+ }
+ } else if (e instanceof PlayerTeleportedEvent
+ || e instanceof CharacterEnterWorldEvent) {
+ broadcast(conn, character);
+ } else if (e instanceof CharacterWalkingEvent) {
+ conn.write(new CharacterMovementTypePacket(
+ ((CharacterWalkingEvent) e).getCharacter()));
+ } else if (e instanceof CharacterRunningEvent) {
+ conn.write(new CharacterMovementTypePacket(
+ ((CharacterRunningEvent) e).getCharacter()));
+ }
+ // keep listener alive
+ return true;
+ }
+ };
+ eventDispatcher.addListener(sendPacketListener);
// leave world event
eventDispatcher.addListener(id, new CharacterListener() {
@@ -206,7 +247,8 @@ public class CharacterServiceImpl extends AbstractService implements
tradeChatListener);
// remove broadcast listener
- eventDispatcher.removeListener(broadcastListener);
+ eventDispatcher.removeListener(neighboorListener);
+ eventDispatcher.removeListener(sendPacketListener);
// we can kill this listener now
return false;
@@ -236,22 +278,29 @@ public class CharacterServiceImpl extends AbstractService implements
// we can ignore this one
}
- // broadcast knownlist -- trashy implementation
- // TODO should be moved to world service or a newly created broadcast
- // service, whichever fits the purpose
- for (final WorldObject o : worldService.iterable(new KnownListFilter(
- character))) {
- if (o instanceof NPC) {
- conn.write(new NPCInformationPacket((NPC) o));
- }
- }
-
- // dispatch enter world event
- eventDispatcher.dispatch(new CharacterEnterWorldEvent(character));
+ broadcast(conn, character);
// spawn the player -- this will also dispatch a spawn event
// here the object is registered in the world
spawnService.spawn(character, null);
+
+ // dispatch enter world event
+ eventDispatcher.dispatch(new CharacterEnterWorldEvent(character));
+ }
+
+ // broadcast knownlist -- trashy implementation
+ // TODO should be moved to world service or a newly created broadcast
+ // service, whichever fits the purpose
+ private void broadcast(Lineage2Connection conn, L2Character character) {
+ for (final WorldObject o : worldService.iterable(new KnownListFilter(
+ character))) {
+ if (o instanceof NPC) {
+ conn.write(new NPCInformationPacket((NPC) o));
+ } else if (o instanceof L2Character) {
+ conn.write(new CharacterInformationBroadcastPacket(
+ (L2Character) o));
+ }
+ }
}
@Override
@@ -303,7 +352,8 @@ public class CharacterServiceImpl extends AbstractService implements
@Override
public void attack(L2Character character, Actor target)
- throws CannotSetTargetServiceException, ActorIsNotAttackableServiceException {
+ throws CannotSetTargetServiceException,
+ ActorIsNotAttackableServiceException {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(target, "target");
final CharacterID id = character.getID();
@@ -388,9 +438,10 @@ public class CharacterServiceImpl extends AbstractService implements
// ignore while teleporting, for some reason the client sends a
// validation just before teleport packet
return;
+ final Point old = character.getPoint();
character.setPoint(point);
character.setState(CharacterState.MOVING);
- eventDispatcher.dispatch(new CharacterMoveEvent(character, point));
+ eventDispatcher.dispatch(new CharacterMoveEvent(character, old));
}
@Override
diff --git a/src/main/java/com/l2jserver/service/game/npc/NPCService.java b/src/main/java/com/l2jserver/service/game/npc/NPCService.java
index 58e60206a..cf66f4661 100644
--- a/src/main/java/com/l2jserver/service/game/npc/NPCService.java
+++ b/src/main/java/com/l2jserver/service/game/npc/NPCService.java
@@ -16,11 +16,15 @@
*/
package com.l2jserver.service.game.npc;
+import java.util.List;
+
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.Service;
+import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
+import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
/**
* This service manages {@link NPC} instances
@@ -56,6 +60,17 @@ public interface NPCService extends Service {
void action(NPC npc, L2Character character, String... args)
throws ActionServiceException;
+ /**
+ * Load from database and spawn all {@link NPC NPCs} instances
+ *
+ * @throws AlreadySpawnedServiceException
+ * if one of the NPCs is already spawned
+ * @throws SpawnPointNotFoundServiceException
+ * if one of the NPCs does not have an spawn point defined
+ */
+ List spawnAll() throws SpawnPointNotFoundServiceException,
+ AlreadySpawnedServiceException;
+
/**
* Attacks an given NPC, if possible.
*
diff --git a/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java
index 4180f6904..8d68093f5 100644
--- a/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java
+++ b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java
@@ -16,12 +16,19 @@
*/
package com.l2jserver.service.game.npc;
+import java.util.List;
+
import com.google.common.base.Preconditions;
+import com.google.inject.Inject;
+import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.AbstractService;
+import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException;
+import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException;
+import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.util.exception.L2Exception;
/**
@@ -30,6 +37,22 @@ import com.l2jserver.util.exception.L2Exception;
* @author Rogiel
*/
public class NPCServiceImpl extends AbstractService implements NPCService {
+ /**
+ * The {@link SpawnService} used to spawn the {@link NPC} instances
+ */
+ private final SpawnService spawnService;
+
+ /**
+ * The {@link NPCDAO}
+ */
+ private final NPCDAO npcDao;
+
+ @Inject
+ public NPCServiceImpl(SpawnService spawnService, NPCDAO npcDao) {
+ this.spawnService = spawnService;
+ this.npcDao = npcDao;
+ }
+
@Override
public void action(NPC npc, L2Character character, CharacterAction action)
throws ActionServiceException {
@@ -61,6 +84,16 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
}
}
+ @Override
+ public List spawnAll() throws SpawnPointNotFoundServiceException,
+ AlreadySpawnedServiceException {
+ final List npcs = npcDao.loadAll();
+ for (final NPC npc : npcs) {
+ spawnService.spawn(npc, null);
+ }
+ return null;
+ }
+
@Override
public void attack(NPC npc, L2Character attacker)
throws NotAttackableNPCServiceException {
diff --git a/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java b/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java
index 28ce43070..182a3e03a 100644
--- a/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java
+++ b/src/main/java/com/l2jserver/service/game/world/CachedWorldIDService.java
@@ -27,6 +27,7 @@ import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.ItemDAO;
+import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.model.id.ID;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.allocator.IDAllocator;
@@ -64,6 +65,10 @@ public class CachedWorldIDService extends AbstractService implements
* The {@link ItemDAO}
*/
private final ItemDAO itemDao;
+ /**
+ * The {@link NPCDAO}
+ */
+ private final NPCDAO npcDao;
/**
* The ID cache
@@ -77,11 +82,12 @@ public class CachedWorldIDService extends AbstractService implements
@Inject
public CachedWorldIDService(CacheService cacheService,
- IDAllocator allocator, CharacterDAO characterDao, ItemDAO itemDao) {
+ IDAllocator allocator, CharacterDAO characterDao, ItemDAO itemDao, NPCDAO npcDao) {
this.cacheService = cacheService;
this.allocator = allocator;
this.characterDao = characterDao;
this.itemDao = itemDao;
+ this.npcDao = npcDao;
}
@Override
@@ -99,6 +105,7 @@ public class CachedWorldIDService extends AbstractService implements
public void load() {
load(characterDao.listIDs());
load(itemDao.listIDs());
+ //load(npcDao.listIDs());
loaded = true;
}
diff --git a/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java b/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java
index 29445c384..5ad256a45 100644
--- a/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java
+++ b/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java
@@ -39,7 +39,7 @@ public abstract class FilteredWorldListener implements
@SuppressWarnings("unchecked")
public boolean dispatch(WorldEvent e) {
if (!filter.accept((T) e.getObject()))
- return false;
+ return true;
return dispatch(e, (T) e.getObject());
}
diff --git a/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java b/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java
index 149e0618f..e42e5a9fb 100644
--- a/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java
+++ b/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java
@@ -21,6 +21,7 @@ import java.util.Queue;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -63,32 +64,35 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
/**
* The events pending dispatch
*/
- private Queue events = CollectionFactory
- .newConcurrentQueue();
+ private Queue events = new ArrayBlockingQueue(
+ 100 * 1000);
public void start() {
timer = new Timer();
- timer.scheduleAtFixedRate(new TimerTask() {
+ final TimerTask task = new TimerTask() {
@Override
public void run() {
- final EventContainer event = events.poll();
- if (event == null)
- return;
- try {
- // set state
- event.future.running = true;
- event.future.complete = false;
+ EventContainer event;
+ while ((event = events.poll()) != null) {
+ try {
+ log.debug("Dispatching event {}", event.event);
- // dispatch
- if (doDispatch(event))
- // the set will update state
- event.future.set(event.event);
- } catch (Throwable t) {
- event.future.setException(t);
- log.warn("Exception in WorldEventDispatcher thread", t);
+ // set state
+ event.future.running = true;
+ event.future.complete = false;
+
+ // dispatch
+ if (doDispatch(event))
+ // the set will update state
+ event.future.set(event.event);
+ } catch (Throwable t) {
+ event.future.setException(t);
+ log.warn("Exception in WorldEventDispatcher thread", t);
+ }
}
}
- }, 0, 50);
+ };
+ timer.scheduleAtFixedRate(task, 0, 50);
}
@Override
@@ -97,6 +101,9 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
log.debug("Queing dispatch for event {}", event);
final WorldEventFutureImpl future = new WorldEventFutureImpl();
events.add(new EventContainer(event, future));
+ // final WorldEventFutureImpl future = new WorldEventFutureImpl();
+ // final EventContainer c = new EventContainer(event, future);
+ // doDispatch(c);
return future;
}
@@ -107,12 +114,24 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
* the event
* @return true if dispatch was not canceled
*/
- public boolean doDispatch(EventContainer event) {
- log.debug("Dispatching event {}", event);
+ public synchronized boolean doDispatch(EventContainer event) {
final ObjectID>[] objects = event.event.getDispatchableObjects();
for (ObjectID> obj : objects) {
if (obj == null)
continue;
+ for (final WorldListener listener : globalListeners) {
+ if (event.future.isCancelled())
+ return false;
+ try {
+ if (!listener.dispatch(event.event))
+ // remove listener if return value is false
+ globalListeners.remove(listener);
+ } catch (Throwable t) {
+ log.warn("Exception in listener", t);
+ // always remove any listener that throws an exception
+ globalListeners.remove(listener);
+ }
+ }
final Set listeners = getListeners(obj);
for (final WorldListener listener : listeners) {
if (event.future.isCancelled())
@@ -200,10 +219,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
set = CollectionFactory.newSet();
listeners.put(id, set);
}
- final Set union = CollectionFactory.newSet();
- union.addAll(set);
- union.addAll(globalListeners);
- return union;
+ return set;
}
public void stop() {
diff --git a/src/main/java/com/l2jserver/service/game/world/filter/ExcludeFilter.java b/src/main/java/com/l2jserver/service/game/world/filter/ExcludeFilter.java
index 15f620055..8a1536fbc 100644
--- a/src/main/java/com/l2jserver/service/game/world/filter/ExcludeFilter.java
+++ b/src/main/java/com/l2jserver/service/game/world/filter/ExcludeFilter.java
@@ -60,6 +60,6 @@ public class ExcludeFilter implements
@Override
public boolean accept(O object) {
- return objects.contains(object);
+ return !objects.contains(object);
}
}
diff --git a/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java b/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java
index 6129bb1fc..4c9440ae0 100644
--- a/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java
+++ b/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java
@@ -19,6 +19,7 @@ package com.l2jserver.service.game.world.filter.impl;
import com.l2jserver.model.world.PositionableObject;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.game.world.filter.AndFilter;
+import com.l2jserver.service.game.world.filter.ExcludeFilter;
/**
* This filter will only accept {@link WorldObject} which are in vision of
@@ -32,6 +33,7 @@ public class KnownListFilter extends AndFilter {
@SuppressWarnings("unchecked")
public KnownListFilter(PositionableObject object) {
super(new InstanceFilter(PositionableObject.class),
- new RangeFilter(object, KNOWNLIST_RANGE));
+ new RangeFilter(object, KNOWNLIST_RANGE),
+ new ExcludeFilter(object));
}
}
diff --git a/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java b/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java
new file mode 100644
index 000000000..9215df940
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java
@@ -0,0 +1,39 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.game.world.filter.impl;
+
+import com.l2jserver.model.world.PositionableObject;
+import com.l2jserver.model.world.WorldObject;
+import com.l2jserver.service.game.world.filter.AndFilter;
+import com.l2jserver.service.game.world.filter.NotFilter;
+import com.l2jserver.util.dimensional.Point;
+
+/**
+ * This filter will only accept {@link WorldObject} which are in vision of
+ * another object.
+ *
+ * @author Rogiel
+ */
+public class KnownListUpdateFilter extends AndFilter {
+ public static final int KNOWNLIST_RANGE = 2000;
+
+ @SuppressWarnings("unchecked")
+ public KnownListUpdateFilter(PositionableObject object, Point old) {
+ super(new KnownListFilter(object), new NotFilter(
+ new RangePointFilter(old, KNOWNLIST_RANGE)));
+ }
+}
diff --git a/src/main/java/com/l2jserver/service/game/world/filter/impl/RangePointFilter.java b/src/main/java/com/l2jserver/service/game/world/filter/impl/RangePointFilter.java
new file mode 100644
index 000000000..7a260bee8
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/game/world/filter/impl/RangePointFilter.java
@@ -0,0 +1,60 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.game.world.filter.impl;
+
+import com.google.common.base.Preconditions;
+import com.l2jserver.model.world.PositionableObject;
+import com.l2jserver.service.game.world.filter.WorldObjectFilter;
+import com.l2jserver.util.dimensional.Point;
+
+/**
+ * Filter objects that are in the range of coordinate
+ *
+ * @author Rogiel
+ */
+public class RangePointFilter implements WorldObjectFilter {
+ /**
+ * The coordinate point
+ */
+ private final Point point;
+ /**
+ * The desired maximum distance of the object
+ */
+ private final int range;
+
+ /**
+ * Creates a new instance
+ *
+ * @param objcect
+ * the positionable object as center point for range search
+ * @param range
+ * the desired maximum distance of the object
+ */
+ public RangePointFilter(final Point point, final int range) {
+ Preconditions.checkNotNull(point, "point");
+ Preconditions.checkState(range >= 0, "range < 0");
+ this.point = point;
+ this.range = range;
+ }
+
+ @Override
+ public boolean accept(PositionableObject other) {
+ if (other == null)
+ return false;
+ return other.getPosition().getDistance(point.getCoordinate()) <= range;
+ }
+}
diff --git a/src/main/java/com/l2jserver/util/factory/CollectionFactory.java b/src/main/java/com/l2jserver/util/factory/CollectionFactory.java
index 3d563fb03..00ac9fa57 100644
--- a/src/main/java/com/l2jserver/util/factory/CollectionFactory.java
+++ b/src/main/java/com/l2jserver/util/factory/CollectionFactory.java
@@ -19,6 +19,7 @@ package com.l2jserver.util.factory;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.WeakHashMap;
@@ -69,6 +70,17 @@ public class CollectionFactory {
return new ConcurrentLinkedQueue();
}
+ /**
+ * Creates a new priority queue of type T
+ *
+ * @param
+ * the type
+ * @return the created queue
+ */
+ public static final PriorityQueue newPriorityQueue() {
+ return new PriorityQueue();
+ }
+
/**
* Creates a new map.
*
diff --git a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java
index aa3fec3ab..875345101 100644
--- a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java
+++ b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java
@@ -69,9 +69,9 @@ public class WorldEventDispatcherImplTest {
@Test
public void testListeners1() throws InterruptedException {
- final L2Character character1 = new L2Character(null);
+ final L2Character character1 = new L2Character(null, null);
character1.setID(cidFactory.createID());
- final L2Character character2 = new L2Character(null);
+ final L2Character character2 = new L2Character(null, null);
character2.setID(cidFactory.createID());
final Item item1 = new Item(null);
item1.setID(iidFactory.createID());
@@ -110,9 +110,9 @@ public class WorldEventDispatcherImplTest {
@Test
public void testListeners2() throws InterruptedException {
- final L2Character character1 = new L2Character(null);
+ final L2Character character1 = new L2Character(null, null);
character1.setID(cidFactory.createID());
- final L2Character character2 = new L2Character(null);
+ final L2Character character2 = new L2Character(null, null);
character2.setID(cidFactory.createID());
final Item item1 = new Item(null);
item1.setID(iidFactory.createID());
diff --git a/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java b/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java
index 471ea4969..57fa3857e 100644
--- a/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java
+++ b/src/test/java/com/l2jserver/service/world/WorldServiceImplTest.java
@@ -57,28 +57,28 @@ public class WorldServiceImplTest {
@Test
public void testAdd() {
- final L2Character character = new L2Character(null);
+ final L2Character character = new L2Character(null, null);
world.add(character);
}
@Test
public void testRemove() {
- final L2Character character = new L2Character(null);
+ final L2Character character = new L2Character(null, null);
world.add(character);
world.remove(character);
}
@Test
public void testContains() {
- final L2Character character = new L2Character(null);
+ final L2Character character = new L2Character(null, null);
world.add(character);
Assert.assertTrue(world.contains(character));
}
@Test
public void testIterator() {
- final L2Character character1 = new L2Character(null);
- final L2Character character2 = new L2Character(null);
+ final L2Character character1 = new L2Character(null, null);
+ final L2Character character2 = new L2Character(null, null);
final Item item1 = new Item(null);
world.add(character1);
world.add(character2);
diff --git a/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateBase.txt b/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateBase.txt
index b28412a03..a5060a9dd 100644
--- a/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateBase.txt
+++ b/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateBase.txt
@@ -18,15 +18,15 @@ package script.template.actor.character;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.CharacterTemplateID;
-import com.l2jserver.model.id.template.factory.CharacterTemplateIDFactory;
+import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.util.dimensional.Point;
public class ${javaClassName}Template extends ${parent}Template {
@Inject
- public ${javaClassName}Template(CharacterTemplateIDFactory factory) {
- super(factory.createID(${ClassId}.id), ${ClassId}, Point.fromXYZ(${x}, ${y}, ${z}));
+ public ${javaClassName}Template(CharacterTemplateIDProvider provider) {
+ super(provider.createID(${ClassId}.id), ${ClassId}, Point.fromXYZ(${x}, ${y}, ${z}));
// ATTRIBUTES
attributes.intelligence = ${_INT};
attributes.strength = ${STR};
@@ -46,6 +46,11 @@ public class ${javaClassName}Template extends ${parent}Template {
attributes.moveSpeed = ${MOVE_SPD};
attributes.maxWeigth = ${_LOAD};
attributes.craft = ${canCraft};
+
+ this.maleCollisionRadius = ${M_COL_R};
+ this.maleCollisionHeight = ${M_COL_H};
+ this.femaleCollisionRadius = ${F_COL_R};
+ this.femaleCollisionHeight = ${F_COL_H};
}
protected ${javaClassName}Template(CharacterTemplateID id,
diff --git a/src/tool/java/com/l2jserver/tool/conversor/npctemplate/NPCTemplateBase.txt b/src/tool/java/com/l2jserver/tool/conversor/npctemplate/NPCTemplateBase.txt
index b28412a03..bafdd0996 100644
--- a/src/tool/java/com/l2jserver/tool/conversor/npctemplate/NPCTemplateBase.txt
+++ b/src/tool/java/com/l2jserver/tool/conversor/npctemplate/NPCTemplateBase.txt
@@ -46,6 +46,11 @@ public class ${javaClassName}Template extends ${parent}Template {
attributes.moveSpeed = ${MOVE_SPD};
attributes.maxWeigth = ${_LOAD};
attributes.craft = ${canCraft};
+
+ this.maleCollisionRadius = ${M_COL_R};
+ this.maleCollisionHeight = ${M_COL_H};
+ this.femaleCollisionRadius = ${F_COL_R};
+ this.femaleCollisionHeight = ${F_COL_H};
}
protected ${javaClassName}Template(CharacterTemplateID id,