diff --git a/data/teleports.xml b/data/teleports.xml index 3c110895c..d0ea8a90a 100644 --- a/data/teleports.xml +++ b/data/teleports.xml @@ -1,10 +1,3405 @@ - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + NOBLE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + NOBLE + + + + NOBLE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/templates/npc.xsd b/data/templates/npc.xsd index 5535fc214..e69de29bb 100644 --- a/data/templates/npc.xsd +++ b/data/templates/npc.xsd @@ -1,185 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java b/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java index a9149c35f..9104ae1fa 100644 --- a/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java +++ b/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java @@ -100,29 +100,33 @@ public class Lineage2PacketHandler extends SimpleChannelHandler { public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event) throws Exception { final Throwable e = event.getCause(); - if (e instanceof ChannelException) - return; - if (e instanceof IOException) - return; - if (!connection.isConnected()) - // no point sending error messages if the client is disconnected - return; - - // TODO only send exception stack trace in development mode! - final String exception = Throwables.getStackTraceAsString(e) - .replaceAll("\n", "
").replace(" ", ""); - final HtmlTemplate template = new HtmlTemplate("Java Exception") { - @Override - public void build(MarkupTag body) { - body.text(exception); + try { + if (e instanceof ChannelException) + return; + if (e instanceof IOException) + return; + if (!connection.isConnected()) + // no point sending error messages if the client is disconnected + return; + + // TODO only send exception stack trace in development mode! + final String exception = Throwables.getStackTraceAsString(e) + .replaceAll("\n", "
").replace(" ", ""); + final HtmlTemplate template = new HtmlTemplate("Java Exception") { + @Override + public void build(MarkupTag body) { + body.text(exception); + } + }; + connection.write(new NPCHtmlMessagePacket(null, template)); + connection.sendActionFailed(); // order client not to wait any packet + + final String[] lines = Throwables.getStackTraceAsString(e).split("\n"); + for(final String line : lines) { + connection.sendMessage(line); } - }; - connection.write(new NPCHtmlMessagePacket(null, template)); - connection.sendActionFailed(); // order client not to wait any packet - - final String[] lines = Throwables.getStackTraceAsString(e).split("\n"); - for(final String line : lines) { - connection.sendMessage(line); + } finally { + e.printStackTrace(); } } } diff --git a/src/main/java/com/l2jserver/model/id/template/TeleportationTemplateID.java b/src/main/java/com/l2jserver/model/id/template/TeleportationTemplateID.java index f31b59fa8..d858481da 100644 --- a/src/main/java/com/l2jserver/model/id/template/TeleportationTemplateID.java +++ b/src/main/java/com/l2jserver/model/id/template/TeleportationTemplateID.java @@ -33,14 +33,14 @@ import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter; */ @XmlJavaTypeAdapter(TeleportationTemplateIDAdapter.class) public class TeleportationTemplateID extends - TemplateID { + TemplateID { /** * The template service */ private final TemplateService templateService; @Inject - public TeleportationTemplateID(@Assisted String id, + public TeleportationTemplateID(@Assisted int id, TemplateService templateService) { super(id); this.templateService = templateService; diff --git a/src/main/java/com/l2jserver/model/id/template/provider/TeleportationTemplateIDProvider.java b/src/main/java/com/l2jserver/model/id/template/provider/TeleportationTemplateIDProvider.java index 595d0f8e8..5483d7b43 100644 --- a/src/main/java/com/l2jserver/model/id/template/provider/TeleportationTemplateIDProvider.java +++ b/src/main/java/com/l2jserver/model/id/template/provider/TeleportationTemplateIDProvider.java @@ -25,5 +25,5 @@ import com.l2jserver.model.id.template.TeleportationTemplateID; * @author Rogiel */ public interface TeleportationTemplateIDProvider extends - TemplateIDProvider { + TemplateIDProvider { } diff --git a/src/main/java/com/l2jserver/model/template/NPCTemplate.java b/src/main/java/com/l2jserver/model/template/NPCTemplate.java index b81dfe170..c10faf4e3 100644 --- a/src/main/java/com/l2jserver/model/template/NPCTemplate.java +++ b/src/main/java/com/l2jserver/model/template/NPCTemplate.java @@ -16,7 +16,6 @@ */ package com.l2jserver.model.template; -import java.util.Collections; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -33,19 +32,16 @@ import org.eclipse.persistence.oxm.annotations.XmlCDATA; import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.id.template.NPCTemplateID; -import com.l2jserver.model.id.template.TeleportationTemplateID; -import com.l2jserver.model.template.NPCTemplate.TeleporterMetadata.TeleporterTeleportMetadata; import com.l2jserver.model.world.Actor.ActorSex; import com.l2jserver.model.world.NPC; import com.l2jserver.util.jaxb.ItemTemplateIDAdapter; import com.l2jserver.util.jaxb.NPCTemplateIDAdapter; -import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter; /** * @author Rogiel */ @XmlRootElement(name = "npc") -@XmlType(namespace = "npc") +@XmlType(namespace = "npc", name = "npc") @XmlAccessorType(XmlAccessType.FIELD) public class NPCTemplate extends ActorTemplate { @XmlAttribute(name = "id") @@ -226,60 +222,6 @@ public class NPCTemplate extends ActorTemplate { protected String script = null; } - @XmlElement(name = "teleporter") - protected TeleporterMetadata teleporter = null; - - @XmlType(namespace = "npc") - protected static class TeleporterMetadata { - @XmlAttribute(name = "default") - protected String defaultTeleport = null; - @XmlElement(name = "teleport") - protected List teleports = null; - - @XmlType(namespace = "npc") - protected static class TeleporterTeleportMetadata { - @XmlAttribute(name = "id") - protected String id; - @XmlElement(name = "region") - protected List regions = null; - } - } - - @XmlType(namespace = "npc") - public static class TeleportRegion { - @XmlAttribute(name = "id") - @XmlJavaTypeAdapter(value = TeleportationTemplateIDAdapter.class) - protected TeleportationTemplateID id; - @XmlAttribute(name = "price") - protected int price = 0; - @XmlAttribute(name = "item") - @XmlJavaTypeAdapter(ItemTemplateIDAdapter.class) - protected ItemTemplateID item; - - /** - * @return the id - */ - public TeleportationTemplateID getID() { - return id; - } - - /** - * @return the price - */ - public int getPrice() { - return price; - } - - /** - * @return the item - */ - public ItemTemplateID getItem() { - return item; - } - - // TODO implement conditions - } - @XmlElement(name = "talk") protected TalkMetadata talk = null; @@ -746,28 +688,6 @@ public class NPCTemplate extends ActorTemplate { return ai.script; } - public List getTeleportRegions(String id) { - if (teleporter == null) - return Collections.emptyList(); - for (final TeleporterTeleportMetadata teleport : teleporter.teleports) { - if (teleport.id.equals(id)) { - return Collections.unmodifiableList(teleport.regions); - } - } - return null; - } - - public List getTeleportRegions() { - if (teleporter == null) - return Collections.emptyList(); - for (final TeleporterTeleportMetadata teleport : teleporter.teleports) { - if (teleport.id.equals(teleporter.defaultTeleport)) { - return Collections.unmodifiableList(teleport.regions); - } - } - return null; - } - public String getHTML(String id) { if (talk == null) return null; diff --git a/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java b/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java index 71af9703b..8ce8430ca 100644 --- a/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java +++ b/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java @@ -16,6 +16,8 @@ */ package com.l2jserver.model.template; +import java.util.List; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -24,9 +26,11 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.id.template.TeleportationTemplateID; import com.l2jserver.util.dimensional.Coordinate; import com.l2jserver.util.jaxb.CoordinateAdapter; +import com.l2jserver.util.jaxb.ItemTemplateIDAdapter; import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter; /** @@ -40,12 +44,25 @@ import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter; public class TeleportationTemplate extends AbstractTemplate { @XmlAttribute(name = "id") @XmlJavaTypeAdapter(TeleportationTemplateIDAdapter.class) - private TeleportationTemplateID id; - @XmlElement(name = "name") - private String name; - @XmlElement(name = "coordinate") + protected TeleportationTemplateID id; + @XmlAttribute(name = "name") + protected String name; + + @XmlAttribute(name = "item") + @XmlJavaTypeAdapter(ItemTemplateIDAdapter.class) + protected ItemTemplateID itemTemplateID; + @XmlAttribute(name = "price") + protected int price; + + @XmlElement(name = "point") @XmlJavaTypeAdapter(CoordinateAdapter.class) - private Coordinate coordinate; + protected Coordinate coordinate; + + protected List restrictions; + + public enum TeleportRestriction { + NOBLE; + } @Override public Coordinate create() { @@ -59,6 +76,27 @@ public class TeleportationTemplate extends AbstractTemplate { return name; } + /** + * @return the id + */ + public TeleportationTemplateID getId() { + return id; + } + + /** + * @return the itemTemplateID + */ + public ItemTemplateID getItemTemplateID() { + return itemTemplateID; + } + + /** + * @return the price + */ + public int getPrice() { + return price; + } + /** * @return the coordinate */ diff --git a/src/main/java/com/l2jserver/model/world/npc/controller/TeleporterController.java b/src/main/java/com/l2jserver/model/world/npc/controller/TeleporterController.java index 2e68d607d..81ff68902 100644 --- a/src/main/java/com/l2jserver/model/world/npc/controller/TeleporterController.java +++ b/src/main/java/com/l2jserver/model/world/npc/controller/TeleporterController.java @@ -16,20 +16,14 @@ */ package com.l2jserver.model.world.npc.controller; -import java.util.List; - import com.google.inject.Inject; import com.l2jserver.game.net.Lineage2Connection; -import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket; import com.l2jserver.model.id.template.provider.TeleportationTemplateIDProvider; -import com.l2jserver.model.template.NPCTemplate.TeleportRegion; import com.l2jserver.model.template.TeleportationTemplate; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.NPC; import com.l2jserver.service.game.spawn.SpawnService; import com.l2jserver.util.exception.L2Exception; -import com.l2jserver.util.html.markup.HtmlTemplate; -import com.l2jserver.util.html.markup.MarkupTag; /** * This controller is used to control teleporters (e.g. gatekeepers) @@ -49,29 +43,9 @@ public class TeleporterController extends AbstractNPCController { public void action(NPC npc, Lineage2Connection conn, L2Character character, String... args) throws L2Exception { if (args.length >= 2) { - if (args[0].equals("TeleportList")) { - final List regions = getTeleportRegions(npc, - args[1]); - final HtmlTemplate template = new HtmlTemplate() { - @Override - protected void build(MarkupTag body) { - body.textcode(556); - for (final TeleportRegion region : regions) { - body.addLink( - region.getID().getTemplate().getName() - + " - " - + region.getPrice() - + " " - + region.getItem().getTemplate() - .getName(), - "Teleport " + region.getID().getID()).br(); - } - } - }; - conn.write(new NPCHtmlMessagePacket(npc, template)); - } else if (args[0].equals("Teleport")) { + if (args[0].equals("goto")) { final TeleportationTemplate tele = teleportationIdProvider - .createID(args[1]).getTemplate(); + .createID(Integer.parseInt(args[1])).getTemplate(); if (tele == null) { // TODO chat conn.sendActionFailed(); @@ -83,8 +57,4 @@ public class TeleporterController extends AbstractNPCController { } super.action(npc, conn, character, args); } - - protected List getTeleportRegions(NPC npc, String id) { - return npc.getTemplate().getTeleportRegions(id); - } } 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 38079c1a8..9d32ae8d0 100644 --- a/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/npc/NPCServiceImpl.java @@ -53,7 +53,11 @@ public class NPCServiceImpl extends AbstractService implements NPCService { */ private final NPCDAO npcDao; - private final TeleporterController controller = new TeleporterController(); + /** + * Temporary only + */ + @Inject + private TeleporterController controller; @Inject public NPCServiceImpl(SpawnService spawnService, diff --git a/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java b/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java index 35f561974..a86479e92 100644 --- a/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java +++ b/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java @@ -163,6 +163,6 @@ public class XMLTemplateService extends AbstractService implements @XmlType(namespace = "teleports") public static class TeleportationTemplateContainer { @XmlElement(name = "teleport") - private List templates; + public List templates; } } diff --git a/src/main/java/com/l2jserver/util/jaxb/TeleportationTemplateIDAdapter.java b/src/main/java/com/l2jserver/util/jaxb/TeleportationTemplateIDAdapter.java index 3ce9180bc..8943f69ce 100644 --- a/src/main/java/com/l2jserver/util/jaxb/TeleportationTemplateIDAdapter.java +++ b/src/main/java/com/l2jserver/util/jaxb/TeleportationTemplateIDAdapter.java @@ -29,7 +29,7 @@ import com.l2jserver.model.id.template.provider.TeleportationTemplateIDProvider; * @author Rogiel */ public class TeleportationTemplateIDAdapter extends - XmlAdapter { + XmlAdapter { private final TeleportationTemplateIDProvider provider; public TeleportationTemplateIDAdapter() { @@ -43,7 +43,7 @@ public class TeleportationTemplateIDAdapter extends } @Override - public TeleportationTemplateID unmarshal(String v) throws Exception { + public TeleportationTemplateID unmarshal(Integer v) throws Exception { if (v == null) return null; if (provider == null) @@ -52,7 +52,7 @@ public class TeleportationTemplateIDAdapter extends } @Override - public String marshal(TeleportationTemplateID v) throws Exception { + public Integer marshal(TeleportationTemplateID v) throws Exception { if (v == null) return null; return v.getID(); diff --git a/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java b/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java index 5bc018e6e..ae1016c01 100644 --- a/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java +++ b/src/tool/java/com/l2jserver/model/template/NPCTemplateConverter.java @@ -25,6 +25,7 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.regex.Matcher; @@ -32,7 +33,6 @@ import java.util.regex.Pattern; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; -import javax.xml.bind.MarshalException; import javax.xml.bind.Marshaller; import javax.xml.bind.SchemaOutputResolver; import javax.xml.transform.Result; @@ -42,6 +42,7 @@ import org.apache.commons.io.FileUtils; import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.id.template.NPCTemplateID; +import com.l2jserver.model.id.template.TeleportationTemplateID; import com.l2jserver.model.template.NPCTemplate.Chat; import com.l2jserver.model.template.NPCTemplate.DropItemMetadata; import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata; @@ -58,7 +59,10 @@ import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsM import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.Stat; import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCTitleMetadata; import com.l2jserver.model.template.NPCTemplate.TalkMetadata; +import com.l2jserver.model.template.TeleportationTemplate.TeleportRestriction; import com.l2jserver.model.world.Actor.ActorSex; +import com.l2jserver.service.game.template.XMLTemplateService.TeleportationTemplateContainer; +import com.l2jserver.util.dimensional.Coordinate; import com.l2jserver.util.factory.CollectionFactory; import com.sun.org.apache.xml.internal.serialize.OutputFormat; import com.sun.org.apache.xml.internal.serialize.XMLSerializer; @@ -72,6 +76,7 @@ public class NPCTemplateConverter { private static List templates = CollectionFactory.newList(); private static Collection htmlScannedFiles; + private static TeleportationTemplateContainer teleportation = new TeleportationTemplateContainer(); @SuppressWarnings("unchecked") public static void main(String[] args) throws SQLException, IOException, @@ -83,24 +88,63 @@ public class NPCTemplateConverter { htmlScannedFiles = FileUtils.listFiles(L2J_HTML_FOLDER, new String[] { "html", "htm" }, true); - System.out.println("Generating template XML files..."); + final JAXBContext c = JAXBContext.newInstance(NPCTemplate.class, + TeleportationTemplateContainer.class); - final JAXBContext c = JAXBContext.newInstance(NPCTemplate.class); + final Connection conn = DriverManager.getConnection(JDBC_URL, + JDBC_USERNAME, JDBC_PASSWORD); + { + System.out.println("Converting teleport templates..."); + teleportation.templates = CollectionFactory.newList(); + + final Marshaller m = c.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, + "teleportation"); + m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, + "teleportation teleportation.xsd"); + + final PreparedStatement st = conn + .prepareStatement("SELECT * FROM teleport"); + st.execute(); + final ResultSet rs = st.getResultSet(); + while (rs.next()) { + final TeleportationTemplate template = new TeleportationTemplate(); + + template.id = new TeleportationTemplateID(rs.getInt("id"), null); + template.name = rs.getString("Description"); + template.coordinate = Coordinate.fromXYZ(rs.getInt("loc_x"), + rs.getInt("loc_y"), rs.getInt("loc_z")); + template.price = rs.getInt("price"); + template.itemTemplateID = new ItemTemplateID( + rs.getInt("itemId"), null); + if (rs.getBoolean("fornoble")) { + template.restrictions = Arrays + .asList(TeleportRestriction.NOBLE); + } + teleportation.templates.add(template); + } + m.marshal(teleportation, getXMLSerializer(new FileOutputStream( + new File(target, "../teleports.xml")))); + // System.exit(0); + } + + System.out.println("Generating template XML files..."); c.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException { - return new StreamResult(new File(target, "npc.xsd")); + // System.out.println(new File(target, suggestedFileName)); + // return null; + return new StreamResult(new File(target, suggestedFileName)); } }); - final Marshaller m = c.createMarshaller(); - m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "npc"); - - final Connection conn = DriverManager.getConnection(JDBC_URL, - JDBC_USERNAME, JDBC_PASSWORD); try { + final Marshaller m = c.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "npc"); + final PreparedStatement st = conn .prepareStatement("SELECT * FROM npc"); st.execute(); @@ -127,19 +171,14 @@ public class NPCTemplateConverter { file.getParentFile().mkdirs(); templates.add(t); - // if (t.id.getID() == 30059) { - // m.marshal(t, getXMLSerializer(System.out)); - // System.exit(0); + // try { + // m.marshal(t, getXMLSerializer(new FileOutputStream(file))); + // } catch (MarshalException e) { + // System.err + // .println("Could not generate XML template file for " + // + t.getName() + " - " + t.getID()); + // file.delete(); // } - - try { - m.marshal(t, getXMLSerializer(new FileOutputStream(file))); - } catch (MarshalException e) { - System.err - .println("Could not generate XML template file for " - + t.getName() + " - " + t.getID()); - file.delete(); - } } System.out.println("Generated " + templates.size() + " templates"); @@ -168,6 +207,7 @@ public class NPCTemplateConverter { IOException { final NPCTemplate template = new NPCTemplate(); template.id = new NPCTemplateID(rs.getInt("idTemplate"), null); + template.type = createParentType(rs.getString("type")); template.info = new NPCInformationMetadata(); @@ -249,8 +289,6 @@ public class NPCTemplateConverter { template.info.collision.radius = rs.getDouble("collision_radius"); template.info.collision.height = rs.getDouble("collision_height"); - // TODO import teleporter data - template.droplist = fillDropList(rs, template.id.getID()); template.talk = fillHtmlChat(template.id.getID());