1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

NPC Chatting

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-25 02:38:15 -03:00
parent ad6a2e89d2
commit 7033518023
21 changed files with 613 additions and 75 deletions

View File

@@ -21,14 +21,17 @@ 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.Lineage2Connection;
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.model.world.npc.controller.TeleporterController;
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.service.network.NetworkService;
import com.l2jserver.util.exception.L2Exception;
/**
* Default {@link NPCService} implementation
@@ -40,15 +43,23 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
* The {@link SpawnService} used to spawn the {@link NPC} instances
*/
private final SpawnService spawnService;
/**
* The {@link NetworkService} used to discover {@link Lineage2Connection}
*/
private final NetworkService networkService;
/**
* The {@link NPCDAO}
*/
private final NPCDAO npcDao;
private final TeleporterController controller = new TeleporterController();
@Inject
public NPCServiceImpl(SpawnService spawnService, NPCDAO npcDao) {
public NPCServiceImpl(SpawnService spawnService,
NetworkService networkService, NPCDAO npcDao) {
this.spawnService = spawnService;
this.networkService = networkService;
this.npcDao = npcDao;
}
@@ -59,12 +70,13 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(action, "action");
final NPCTemplate template = npc.getTemplate();
// try {
// // template.action(npc, character, new String[0]);
// } catch (L2Exception e) {
// throw new ActionServiceException(e);
// }
final Lineage2Connection conn = networkService.discover(character
.getID());
try {
controller.action(npc, conn, character, new String[0]);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}
}
@Override
@@ -75,12 +87,13 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
if (args == null)
args = new String[0];
final NPCTemplate template = npc.getTemplate();
// try {
// // template.action(npc, character, args);
// } catch (L2Exception e) {
// throw new ActionServiceException(e);
// }
final Lineage2Connection conn = networkService.discover(character
.getID());
try {
controller.action(npc, conn, character, args);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}
}
@Override

View File

@@ -18,11 +18,17 @@ package com.l2jserver.service.game.template;
import java.io.File;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.apache.commons.io.FileUtils;
@@ -79,7 +85,7 @@ public class XMLTemplateService extends AbstractService implements
try {
context = JAXBContext.newInstance(CharacterTemplate.class,
NPCTemplate.class, ItemTemplate.class,
TeleportationTemplate.class);
TeleportationTemplateContainer.class);
unmarshaller = context.createUnmarshaller();
unmarshaller.setAdapter(NPCTemplateIDAdapter.class,
@@ -98,6 +104,12 @@ public class XMLTemplateService extends AbstractService implements
for (final File file : files) {
loadTemplate(file);
}
TeleportationTemplateContainer container = (TeleportationTemplateContainer) unmarshaller
.unmarshal(new File(config.getTemplateDirectory(),
"../teleports.xml"));
for (final TeleportationTemplate template : container.templates) {
templates.put(template.getID(), template);
}
} catch (JAXBException e) {
throw new ServiceStartException(e);
}
@@ -134,4 +146,12 @@ public class XMLTemplateService extends AbstractService implements
unmarshaller = null;
context = null;
}
@XmlRootElement(name = "teleports")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "teleports")
public static class TeleportationTemplateContainer {
@XmlElement(name = "teleport")
private List<TeleportationTemplate> templates;
}
}