mirror of
https://github.com/Rogiel/l2jserver2
synced 2026-01-26 21:02:46 +00:00
Implemented XML templates
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tool.conversor.chartemplate;
|
||||
package com.l2jserver.model.template;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -33,7 +33,7 @@ import com.l2jserver.model.world.Actor.ActorRace;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
public class CharacterTemplateConverter {
|
||||
public class CharacterOldTemplateConverter {
|
||||
private static final String JDBC_URL = "jdbc:mysql://localhost/l2j-old";
|
||||
private static final String JDBC_USERNAME = "l2j";
|
||||
private static final String JDBC_PASSWORD = "changeme";
|
||||
@@ -47,7 +47,7 @@ public class CharacterTemplateConverter {
|
||||
ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
template = IOUtils.toString(CharacterTemplateConverter.class
|
||||
template = IOUtils.toString(CharacterOldTemplateConverter.class
|
||||
.getResourceAsStream("CharacterTemplateBase.txt"));
|
||||
System.out.println("Generating template classes...");
|
||||
|
||||
@@ -75,7 +75,7 @@ public class CharacterTemplateConverter {
|
||||
|
||||
private static String[] generateJavaClass(ResultSet rs) throws SQLException {
|
||||
String name = "";
|
||||
String template = CharacterTemplateConverter.template;
|
||||
String template = CharacterOldTemplateConverter.template;
|
||||
for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) {
|
||||
template = replace(template, rs.getMetaData().getColumnName(i),
|
||||
rs.getString(i));
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.model.template;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.AttackMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.AttackMetadata.AttackValueMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.BaseMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.DefenseMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.DefenseMetadata.DefenseValueMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.MoveMetadata;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CharacterStatsMetadata.Stat;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CollitionMetadataContainer;
|
||||
import com.l2jserver.model.template.CharacterTemplate.CollitionMetadataContainer.CollisionMetadata;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
|
||||
/**
|
||||
* The need to use this package to get access to protected fields.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterTemplateConverter {
|
||||
private static final String JDBC_URL = "jdbc:mysql://localhost/l2j-old";
|
||||
private static final String JDBC_USERNAME = "l2j";
|
||||
private static final String JDBC_PASSWORD = "changeme";
|
||||
|
||||
public static void main(String[] args) throws SQLException, IOException,
|
||||
ClassNotFoundException, JAXBException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
final File target = new File("generated/template");
|
||||
|
||||
System.out.println("Generating template classes...");
|
||||
|
||||
final JAXBContext c = JAXBContext.newInstance(CharacterTemplate.class);
|
||||
c.generateSchema(new SchemaOutputResolver() {
|
||||
@Override
|
||||
public Result createOutput(String namespaceUri,
|
||||
String suggestedFileName) throws IOException {
|
||||
return new StreamResult(new File(target, "character.xsd"));
|
||||
}
|
||||
});
|
||||
|
||||
final Marshaller m = c.createMarshaller();
|
||||
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "character");
|
||||
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
|
||||
"character ../character.xsd");
|
||||
|
||||
final Connection conn = DriverManager.getConnection(JDBC_URL,
|
||||
JDBC_USERNAME, JDBC_PASSWORD);
|
||||
try {
|
||||
final PreparedStatement st = conn
|
||||
.prepareStatement("SELECT * FROM char_templates "
|
||||
+ "LEFT JOIN lvlupgain ON (char_templates.Classid = lvlupgain.classid)");
|
||||
try {
|
||||
st.execute();
|
||||
final ResultSet rs = st.getResultSet();
|
||||
while (rs.next()) {
|
||||
CharacterTemplate t = fillTemplate(rs);
|
||||
|
||||
final File file = new File(target, "character/"
|
||||
+ camelCase(t.characterClass.name()) + ".xml");
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
m.marshal(t, file);
|
||||
|
||||
// m.marshal(t, System.out);
|
||||
// System.exit(0);
|
||||
}
|
||||
} finally {
|
||||
st.close();
|
||||
}
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static CharacterTemplate fillTemplate(ResultSet rs)
|
||||
throws SQLException {
|
||||
final CharacterTemplate t = new CharacterTemplate();
|
||||
|
||||
t.characterClass = CharacterClass.fromID(rs.getInt("ClassId"));
|
||||
// this.hpBase = ${defaulthpbase};
|
||||
t.stats = new CharacterStatsMetadata();
|
||||
t.stats.hp = new Stat();
|
||||
t.stats.hp.base = rs.getDouble("defaulthpbase");
|
||||
t.stats.hp.modifier = rs.getDouble("defaulthpmod");
|
||||
t.stats.hp.add = rs.getDouble("defaulthpadd");
|
||||
|
||||
t.stats.mp = new Stat();
|
||||
t.stats.mp.base = rs.getDouble("defaultmpbase");
|
||||
t.stats.mp.modifier = rs.getDouble("defaultmpmod");
|
||||
t.stats.mp.add = rs.getDouble("defaultmpadd");
|
||||
|
||||
t.stats.cp = new Stat();
|
||||
t.stats.cp.base = rs.getDouble("defaultcpbase");
|
||||
t.stats.cp.modifier = rs.getDouble("defaultcpmod");
|
||||
t.stats.cp.add = rs.getDouble("defaultcpadd");
|
||||
|
||||
t.stats.base = new BaseMetadata();
|
||||
t.stats.base.intelligence = rs.getInt("_INT");
|
||||
t.stats.base.strength = rs.getInt("STR");
|
||||
t.stats.base.concentration = rs.getInt("CON");
|
||||
t.stats.base.mentality = rs.getInt("MEN");
|
||||
t.stats.base.dexterity = rs.getInt("DEX");
|
||||
t.stats.base.witness = rs.getInt("WIT");
|
||||
|
||||
t.stats.attack = new AttackMetadata();
|
||||
t.stats.attack.critical = rs.getInt("CRITICAL");
|
||||
t.stats.attack.evasion = rs.getInt("EVASION");
|
||||
t.stats.attack.accuracy = rs.getInt("ACC");
|
||||
|
||||
t.stats.attack.physical = new AttackValueMetadata();
|
||||
t.stats.attack.physical.damage = rs.getDouble("P_ATK");
|
||||
t.stats.attack.physical.speed = rs.getDouble("P_SPD");
|
||||
t.stats.attack.magical = new AttackValueMetadata();
|
||||
t.stats.attack.magical.damage = rs.getDouble("M_ATK");
|
||||
t.stats.attack.magical.speed = rs.getDouble("M_SPD");
|
||||
|
||||
t.stats.defense = new DefenseMetadata();
|
||||
t.stats.defense.physical = new DefenseValueMetadata();
|
||||
t.stats.defense.physical.value = rs.getDouble("P_DEF");
|
||||
t.stats.defense.magical = new DefenseValueMetadata();
|
||||
t.stats.defense.magical.value = rs.getDouble("M_DEF");
|
||||
|
||||
t.stats.move = new MoveMetadata();
|
||||
t.stats.move.run = rs.getInt("MOVE_SPD");
|
||||
// TODO this is not really the same
|
||||
t.stats.move.walk = rs.getInt("MOVE_SPD");
|
||||
|
||||
t.stats.level = rs.getInt("class_lvl");
|
||||
t.stats.maximumLoad = rs.getInt("_LOAD");
|
||||
t.stats.crafter = rs.getBoolean("canCraft");
|
||||
|
||||
t.collision = new CollitionMetadataContainer();
|
||||
t.collision.male = new CollisionMetadata();
|
||||
t.collision.male.radius = rs.getDouble("M_COL_R");
|
||||
t.collision.male.height = rs.getDouble("M_COL_H");
|
||||
t.collision.female = new CollisionMetadata();
|
||||
t.collision.female.radius = rs.getDouble("F_COL_R");
|
||||
t.collision.female.height = rs.getDouble("F_COL_H");
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
private static String camelCase(String c) {
|
||||
Pattern p = Pattern.compile("[a-zA-Z0-9]+");
|
||||
Matcher m = p.matcher(c.replaceAll("_", " "));
|
||||
StringBuffer result = new StringBuffer();
|
||||
String word;
|
||||
while (m.find()) {
|
||||
word = m.group();
|
||||
result.append(word.substring(0, 1).toUpperCase()
|
||||
+ word.substring(1).toLowerCase());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.tool.conversor.npctemplate;
|
||||
package com.l2jserver.model.template;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -32,7 +32,7 @@ import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
public class NPCTemplateConverter {
|
||||
public class NPCOldTemplateConverter {
|
||||
private static final String JDBC_URL = "jdbc:mysql://localhost/l2j-old";
|
||||
private static final String JDBC_USERNAME = "l2j";
|
||||
private static final String JDBC_PASSWORD = "changeme";
|
||||
@@ -45,7 +45,7 @@ public class NPCTemplateConverter {
|
||||
ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
template = IOUtils.toString(NPCTemplateConverter.class
|
||||
template = IOUtils.toString(NPCOldTemplateConverter.class
|
||||
.getResourceAsStream("NPCTemplateBase.txt"));
|
||||
System.out.println("Generating template classes...");
|
||||
|
||||
@@ -87,7 +87,7 @@ public class NPCTemplateConverter {
|
||||
|
||||
String name = "";
|
||||
String folder = "";
|
||||
String template = NPCTemplateConverter.template;
|
||||
String template = NPCOldTemplateConverter.template;
|
||||
for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) {
|
||||
template = replace(template, rs.getMetaData().getColumnName(i),
|
||||
rs.getString(i));
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.model.template;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.SchemaOutputResolver;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import com.l2jserver.model.id.template.ItemTemplateID;
|
||||
import com.l2jserver.model.template.NPCTemplate.DropItemMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.CollisionMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.ItemMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCNameMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.AttackMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.AttackMetadata.AttackValueMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.BaseMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.DefenseMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.DefenseMetadata.DefenseValueMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.MoveMetadata;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsMetadata.Stat;
|
||||
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCTitleMetadata;
|
||||
import com.l2jserver.model.world.Actor.ActorSex;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
public class NPCTemplateConverter {
|
||||
private static final String JDBC_URL = "jdbc:mysql://localhost/l2j-old";
|
||||
private static final String JDBC_USERNAME = "l2j";
|
||||
private static final String JDBC_PASSWORD = "changeme";
|
||||
|
||||
private static List<NPCTemplate> templates = CollectionFactory.newList();
|
||||
|
||||
public static void main(String[] args) throws SQLException, IOException,
|
||||
ClassNotFoundException, JAXBException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
final File target = new File("generated/template");
|
||||
|
||||
System.out.println("Generating template classes...");
|
||||
|
||||
final JAXBContext c = JAXBContext.newInstance(NPCTemplate.class);
|
||||
c.generateSchema(new SchemaOutputResolver() {
|
||||
@Override
|
||||
public Result createOutput(String namespaceUri,
|
||||
String suggestedFileName) throws IOException {
|
||||
return new StreamResult(new File(target, "npc.xsd"));
|
||||
}
|
||||
});
|
||||
|
||||
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 PreparedStatement st = conn
|
||||
.prepareStatement("SELECT * FROM npc");
|
||||
st.execute();
|
||||
final ResultSet rs = st.getResultSet();
|
||||
while (rs.next()) {
|
||||
NPCTemplate t = fillNPC(rs);
|
||||
|
||||
String folder = createFolder(t.type);
|
||||
if (folder.isEmpty()) {
|
||||
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
|
||||
"npc ../npc.xsd");
|
||||
} else {
|
||||
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
|
||||
"npc ../../npc.xsd");
|
||||
}
|
||||
|
||||
final File file = new File(target, "npc/"
|
||||
+ folder
|
||||
+ "/"
|
||||
+ t.id
|
||||
+ (t.info.nameMetadata != null ? "-"
|
||||
+ camelCase(t.info.nameMetadata.name) : "")
|
||||
+ ".xml");
|
||||
file.getParentFile().mkdirs();
|
||||
templates.add(t);
|
||||
|
||||
// m.marshal(t, file);
|
||||
|
||||
// m.marshal(t, System.out);
|
||||
// System.exit(0);
|
||||
}
|
||||
|
||||
System.gc();
|
||||
System.out.println("Free: " + Runtime.getRuntime().freeMemory()
|
||||
/ 1024 / 1024 + " MB");
|
||||
System.out.println("Total: " + Runtime.getRuntime().totalMemory()
|
||||
/ 1024 / 1024 + " MB");
|
||||
System.out.println("Used: "
|
||||
+ (Runtime.getRuntime().totalMemory() - Runtime
|
||||
.getRuntime().freeMemory()) / 1024 / 1024 + " MB");
|
||||
System.out.println("Max: " + Runtime.getRuntime().maxMemory()
|
||||
/ 1024 / 1024 + " MB");
|
||||
} finally {
|
||||
conn.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static NPCTemplate fillNPC(ResultSet rs) throws SQLException {
|
||||
final NPCTemplate template = new NPCTemplate();
|
||||
template.id = null;
|
||||
template.type = createParentType(rs.getString("type"));
|
||||
template.info = new NPCInformationMetadata();
|
||||
|
||||
template.info.nameMetadata = new NPCNameMetadata();
|
||||
template.info.nameMetadata.name = rs.getString("name");
|
||||
template.info.nameMetadata.display = rs.getBoolean("show_name");
|
||||
template.info.nameMetadata.send = rs.getBoolean("serverSideName");
|
||||
|
||||
template.info.titleMetadata = new NPCTitleMetadata();
|
||||
template.info.titleMetadata.title = rs.getString("title");
|
||||
template.info.titleMetadata.send = rs.getBoolean("serverSideTitle");
|
||||
|
||||
if (template.info.titleMetadata.title.length() == 0)
|
||||
template.info.titleMetadata = null;
|
||||
if (template.info.nameMetadata.name.length() == 0)
|
||||
template.info.nameMetadata = null;
|
||||
|
||||
template.info.level = rs.getInt("level");
|
||||
if (!rs.getString("sex").equals("etc"))
|
||||
template.info.sex = ActorSex.valueOf(rs.getString("sex")
|
||||
.toUpperCase());
|
||||
// template.info.attackable = rs.getBoolean("attackable");
|
||||
template.info.targetable = rs.getBoolean("targetable");
|
||||
template.info.aggressive = rs.getBoolean("aggro");
|
||||
|
||||
template.info.stats = new NPCStatsMetadata();
|
||||
|
||||
template.info.stats.hp = new Stat();
|
||||
template.info.stats.hp.max = rs.getDouble("hp");
|
||||
template.info.stats.hp.regen = rs.getDouble("hpreg");
|
||||
|
||||
template.info.stats.mp = new Stat();
|
||||
template.info.stats.mp.max = rs.getDouble("mp");
|
||||
template.info.stats.mp.regen = rs.getDouble("mpreg");
|
||||
|
||||
template.info.stats.attack = new AttackMetadata();
|
||||
template.info.stats.attack.range = rs.getInt("attackrange");
|
||||
template.info.stats.attack.critical = rs.getInt("critical");
|
||||
|
||||
template.info.stats.attack.physical = new AttackValueMetadata();
|
||||
template.info.stats.attack.physical.damage = rs.getDouble("patk");
|
||||
template.info.stats.attack.physical.speed = rs.getDouble("atkspd");
|
||||
|
||||
template.info.stats.attack.magical = new AttackValueMetadata();
|
||||
template.info.stats.attack.magical.damage = rs.getDouble("matk");
|
||||
template.info.stats.attack.magical.speed = rs.getDouble("matkspd");
|
||||
|
||||
template.info.stats.defense = new DefenseMetadata();
|
||||
template.info.stats.defense.physical = new DefenseValueMetadata();
|
||||
template.info.stats.defense.physical.value = rs.getDouble("pdef");
|
||||
template.info.stats.defense.magical = new DefenseValueMetadata();
|
||||
template.info.stats.defense.magical.value = rs.getDouble("mdef");
|
||||
|
||||
template.info.stats.move = new MoveMetadata();
|
||||
template.info.stats.move.run = rs.getDouble("runspd");
|
||||
template.info.stats.move.walk = rs.getDouble("walkspd");
|
||||
|
||||
template.info.stats.base = new BaseMetadata();
|
||||
template.info.stats.base.intelligence = rs.getInt("int");
|
||||
template.info.stats.base.strength = rs.getInt("str");
|
||||
template.info.stats.base.concentration = rs.getInt("con");
|
||||
template.info.stats.base.dexterity = rs.getInt("dex");
|
||||
template.info.stats.base.witness = rs.getInt("wit");
|
||||
template.info.stats.base.mentality = rs.getInt("men");
|
||||
|
||||
template.info.experience = rs.getLong("exp");
|
||||
template.info.sp = rs.getInt("sp");
|
||||
|
||||
if (rs.getInt("rhand") > 0 || rs.getInt("lhand") > 0)
|
||||
template.info.item = new ItemMetadata();
|
||||
if (rs.getInt("rhand") > 0)
|
||||
template.info.item.rightHand = new ItemTemplateID(
|
||||
rs.getInt("rhand"), null);
|
||||
if (rs.getInt("lhand") > 0)
|
||||
template.info.item.leftHand = new ItemTemplateID(
|
||||
rs.getInt("lhand"), null);
|
||||
|
||||
template.info.collision = new CollisionMetadata();
|
||||
template.info.collision.radius = rs.getDouble("collision_radius");
|
||||
template.info.collision.height = rs.getDouble("collision_height");
|
||||
|
||||
// TODO import teleporter data
|
||||
// TODO import html files
|
||||
|
||||
template.droplist = fillDropList(rs, template.id.getID());
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
private static List<DropItemMetadata> fillDropList(ResultSet npcRs,
|
||||
int npcId) throws SQLException {
|
||||
final Connection conn = npcRs.getStatement().getConnection();
|
||||
final List<DropItemMetadata> drops = CollectionFactory.newList();
|
||||
|
||||
final PreparedStatement st = conn
|
||||
.prepareStatement("SELECT * FROM droplist WHERE mobId = ?");
|
||||
st.setInt(1, npcId);
|
||||
st.execute();
|
||||
final ResultSet rs = st.getResultSet();
|
||||
while (rs.next()) {
|
||||
DropItemMetadata m = new DropItemMetadata();
|
||||
m.item = new ItemTemplateID(rs.getInt("itemId"), null);
|
||||
m.min = rs.getInt("min");
|
||||
m.max = rs.getInt("max");
|
||||
m.chance = rs.getInt("chance");
|
||||
drops.add(m);
|
||||
// TODO category
|
||||
}
|
||||
if (drops.size() == 0)
|
||||
return null;
|
||||
return drops;
|
||||
}
|
||||
|
||||
private static String camelCase(String c) {
|
||||
Pattern p = Pattern.compile("[a-zA-Z0-9]+");
|
||||
Matcher m = p.matcher(c.replaceAll("_", " ").replaceAll("\\.", " "));
|
||||
StringBuffer result = new StringBuffer();
|
||||
String word;
|
||||
while (m.find()) {
|
||||
word = m.group();
|
||||
result.append(word.substring(0, 1).toUpperCase()
|
||||
+ word.substring(1).toLowerCase());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static String createParentType(String l2j) {
|
||||
if (l2j.startsWith("L2"))
|
||||
l2j = l2j.substring(2);
|
||||
if (l2j.equals("Npc"))
|
||||
return "";
|
||||
if (l2j.contains("VillageMaster"))
|
||||
return (l2j.replaceAll("VillageMaster", "") + "VillageMaster");
|
||||
if (l2j.contains("Npc"))
|
||||
l2j = l2j.replaceAll("Npc", "");
|
||||
return l2j;
|
||||
}
|
||||
|
||||
private static String createFolder(String l2j) {
|
||||
if (l2j.startsWith("L2"))
|
||||
l2j = l2j.substring(2);
|
||||
if (l2j.equals("Npc"))
|
||||
return "";
|
||||
if (l2j.toLowerCase().contains("monster"))
|
||||
return "monster";
|
||||
if (l2j.toLowerCase().contains("castle"))
|
||||
return "castle";
|
||||
if (l2j.toLowerCase().contains("fort"))
|
||||
return "fort";
|
||||
if (l2j.toLowerCase().contains("xmasstree"))
|
||||
return "misc";
|
||||
return l2j.toLowerCase();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user