1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00
Instead of replacing WorldService in the NPCID, it has been added
NPCDAO as an alternative route just in case the NPC is not located
within WorldService (i.e. is in the database but not spawned).
This commit is contained in:
2011-10-09 13:23:06 -03:00
parent 6f680acd2c
commit 8b787349d4

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.id.object;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.l2jserver.model.dao.NPCDAO;
import com.l2jserver.model.id.ObjectID; import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.provider.IDProvider; import com.l2jserver.model.id.provider.IDProvider;
import com.l2jserver.model.world.NPC; 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 * An {@link ObjectID} instance representing an {@link NPC} object. Since NPC
* instances are stores in run-time only, the search is performed in the * instances can be stored in run-time only, the search is performed first in
* {@link WorldService} instead of using a {@link DataAccessObject}. * the {@link WorldService}, if no match is found, search is descended to an
* {@link DataAccessObject}.
* <p>
* <h1>Search order</h1>
* <ol>
* <li>{@link WorldService}: for run-time only {@link NPC NPCs}, but will also
* include all spawned {@link NPC NPCs};</li>
* <li>{@link NPCDAO}: for persisted {@link NPC NPCs}. Only for {@link NPC NPCs}
* that are not currently spawned in the world.</li>
* </ol>
* <p> * <p>
* Please, do not directly instantiate this class, use an {@link IDProvider} * Please, do not directly instantiate this class, use an {@link IDProvider}
* instead. * instead.
@@ -39,21 +49,32 @@ public final class NPCID extends ActorID<NPC> {
* {@link WorldService} used to locate objects * {@link WorldService} used to locate objects
*/ */
private final WorldService worldService; private final WorldService worldService;
/**
* {@link NPCDAO} used to locate objects if not located first by
* {@link WorldService}
*/
private final NPCDAO npcDao;
/** /**
* @param id * @param id
* the raw id * the raw id
* @param worldService * @param worldService
* the world service * the world service
* @param npcDao
* the {@link NPC} {@link DataAccessObject DAO}
*/ */
@Inject @Inject
public NPCID(@Assisted int id, WorldService worldService) { public NPCID(@Assisted int id, WorldService worldService, NPCDAO npcDao) {
super(id); super(id);
this.worldService = worldService; this.worldService = worldService;
this.npcDao = npcDao;
} }
@Override @Override
public NPC getObject() { public NPC getObject() {
return worldService.find(this); NPC npc = worldService.find(this);
if (npc == null)
npc = npcDao.select(this);
return npc;
} }
} }