diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/id/object/NPCID.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/id/object/NPCID.java index 10bf5a4cd..9f0921742 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/id/object/NPCID.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/id/object/NPCID.java @@ -18,6 +18,7 @@ package com.l2jserver.model.id.object; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; +import com.l2jserver.model.dao.NPCDAO; import com.l2jserver.model.id.ObjectID; import com.l2jserver.model.id.provider.IDProvider; import com.l2jserver.model.world.NPC; @@ -26,8 +27,17 @@ import com.l2jserver.service.game.world.WorldService; /** * An {@link ObjectID} instance representing an {@link NPC} object. Since NPC - * instances are stores in run-time only, the search is performed in the - * {@link WorldService} instead of using a {@link DataAccessObject}. + * instances can be stored in run-time only, the search is performed first in + * the {@link WorldService}, if no match is found, search is descended to an + * {@link DataAccessObject}. + *

+ *

Search order

+ *
    + *
  1. {@link WorldService}: for run-time only {@link NPC NPCs}, but will also + * include all spawned {@link NPC NPCs};
  2. + *
  3. {@link NPCDAO}: for persisted {@link NPC NPCs}. Only for {@link NPC NPCs} + * that are not currently spawned in the world.
  4. + *
*

* Please, do not directly instantiate this class, use an {@link IDProvider} * instead. @@ -39,21 +49,32 @@ public final class NPCID extends ActorID { * {@link WorldService} used to locate objects */ private final WorldService worldService; + /** + * {@link NPCDAO} used to locate objects if not located first by + * {@link WorldService} + */ + private final NPCDAO npcDao; /** * @param id * the raw id * @param worldService * the world service + * @param npcDao + * the {@link NPC} {@link DataAccessObject DAO} */ @Inject - public NPCID(@Assisted int id, WorldService worldService) { + public NPCID(@Assisted int id, WorldService worldService, NPCDAO npcDao) { super(id); this.worldService = worldService; + this.npcDao = npcDao; } @Override public NPC getObject() { - return worldService.find(this); + NPC npc = worldService.find(this); + if (npc == null) + npc = npcDao.select(this); + return npc; } }