1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2026-01-26 21:02:46 +00:00

NPC skills added, updated item template

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-06-03 14:04:57 -03:00
parent b188f054df
commit fe7373ba29
10110 changed files with 181889 additions and 39634 deletions

View File

@@ -1,127 +0,0 @@
/*
* 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.FileOutputStream;
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.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import com.l2jserver.model.world.Actor.ActorRace;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.util.factory.CollectionFactory;
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";
private static String template;
private static Map<CharacterClass, String> parents = CollectionFactory
.newMap();
public static void main(String[] args) throws SQLException, IOException,
ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
template = IOUtils.toString(CharacterOldTemplateConverter.class
.getResourceAsStream("CharacterTemplateBase.txt"));
System.out.println("Generating template classes...");
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()) {
String[] result = generateJavaClass(rs);
IOUtils.write(result[0], new FileOutputStream(
"generated/template/character/" + result[1]));
}
} finally {
st.close();
}
} finally {
conn.close();
}
}
private static String[] generateJavaClass(ResultSet rs) throws SQLException {
String name = "";
String template = CharacterOldTemplateConverter.template;
for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) {
template = replace(template, rs.getMetaData().getColumnName(i),
rs.getString(i));
if (rs.getMetaData().getColumnName(i).equals("ClassId")) {
final CharacterClass c = CharacterClass.fromID(Integer
.parseInt(rs.getString(i)));
name = camelCase(c.name()) + "Template.java";
}
}
return new String[] { template, name };
}
private static String replace(String template, String key, String value) {
if (key.equals("ClassId")) {
final CharacterClass c = CharacterClass.fromID(Integer
.parseInt(value));
value = "CharacterClass." + c.name();
String parent;
if (c.parent != null) {
parent = parents.get(c.parent);
} else {
parent = "Abstract" + camelCase(c.race.name()) + "Character";
}
parents.put(c, camelCase(c.name()));
template = template.replaceAll("\\$\\{parent\\}", parent);
template = template.replaceAll("\\$\\{javaClassName\\}",
camelCase(c.name()));
}
if (key.equals("RaceId"))
value = ActorRace.fromOption(Integer.parseInt(value)).name();
if (key.equals("canCraft"))
value = (value.equals("1") ? "true" : "false");
return template.replaceAll("\\$\\{" + key + "\\}", value);
}
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();
}
}

View File

@@ -1,80 +0,0 @@
/*
* 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 script.template.actor.character;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.util.dimensional.Point;
public class ${javaClassName}Template extends ${parent}Template {
@Inject
public ${javaClassName}Template(CharacterTemplateIDProvider provider) {
super(provider.createID(${ClassId}.id), ${ClassId}, Point.fromXYZ(${x}, ${y}, ${z}));
this.hpBase = ${defaulthpbase};
this.hpAdd = ${defaulthpadd};
this.hpMultiplier = ${defaulthpmod};
this.mpBase = ${defaultmpbase};
this.mpAdd = ${defaultmpadd};
this.mpMultiplier = ${defaultmpmod};
this.cpBase = ${defaultcpbase};
this.cpAdd = ${defaultcpadd};
this.cpMultiplier = ${defaultcpmod};
this.minimumLevel = ${class_lvl};
// ATTRIBUTES
attributes.intelligence = ${_INT};
attributes.strength = ${STR};
attributes.concentration = ${CON};
attributes.mentality = ${MEN};
attributes.dexterity = ${DEX};
attributes.witness = ${WIT};
attributes.physicalAttack = ${P_ATK};
attributes.magicalAttack = ${M_ATK};
attributes.physicalDefense = ${P_DEF};
attributes.magicalDefense = ${M_DEF};
attributes.attackSpeed = ${P_SPD};
attributes.castSpeed = ${M_SPD};
attributes.accuracy = ${ACC};
attributes.criticalChance = ${CRITICAL};
attributes.evasionChance = ${EVASION};
attributes.runSpeed = ${MOVE_SPD};
attributes.walkSpeed = ${MOVE_SPD};
attributes.maxWeigth = ${_LOAD};
attributes.craft = ${canCraft};
this.maleCollisionRadius = ${M_COL_R};
this.maleCollisionHeight = ${M_COL_H};
this.femaleCollisionRadius = ${F_COL_R};
this.femaleCollisionHeight = ${F_COL_H};
}
protected ${javaClassName}Template(CharacterTemplateID id,
CharacterClass characterClass, Point spawnLocation) {
super(id, characterClass, spawnLocation);
}
@Override
public L2Character create() {
final L2Character character = super.create();
// TODO register skills
return character;
}
}

View File

@@ -1,213 +0,0 @@
/*
* 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.FileOutputStream;
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.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import com.l2jserver.util.factory.CollectionFactory;
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";
private static String template;
private static Set<String> names = CollectionFactory.newSet();
public static void main(String[] args) throws SQLException, IOException,
ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
template = IOUtils.toString(NPCOldTemplateConverter.class
.getResourceAsStream("NPCTemplateBase.txt"));
System.out.println("Generating template classes...");
final Connection conn = DriverManager.getConnection(JDBC_URL,
JDBC_USERNAME, JDBC_PASSWORD);
try {
final PreparedStatement st = conn
.prepareStatement("SELECT * FROM npc");
try {
st.execute();
final ResultSet rs = st.getResultSet();
// final Set<String> directories = CollectionFactory.newSet();
while (rs.next()) {
String[] result = generateJavaClass(rs);
if (result == null)
continue;
// directories.add(result[1]);
// System.out.println(result[0]);
// System.exit(0);
final File file = new File("generated/script/template/npc"
+ result[1] + result[2]);
file.getParentFile().mkdirs();
IOUtils.write(result[0], new FileOutputStream(file));
}
// System.out.println(directories);
} finally {
st.close();
}
} finally {
conn.close();
}
}
private static String[] generateJavaClass(ResultSet rs) throws SQLException {
String npcName = "";
@SuppressWarnings("unused")
String npcClass = "";
String npcTitle = "";
String npcType = "";
String name = "";
String folder = "";
String template = NPCOldTemplateConverter.template;
for (int i = 1; i < rs.getMetaData().getColumnCount() + 1; i++) {
template = replace(template, rs.getMetaData().getColumnName(i),
rs.getString(i));
if (rs.getMetaData().getColumnName(i).equals("name")) {
npcName = rs.getString(i);
} else if (rs.getMetaData().getColumnName(i).equals("class")) {
npcClass = rs.getString(i);
} else if (rs.getMetaData().getColumnName(i).equals("title")) {
npcTitle = rs.getString(i);
} else if (rs.getMetaData().getColumnName(i).equals("type")) {
npcType = rs.getString(i);
}
}
if (npcType.equals("L2Pet"))
return null;
// generate class and file name
if (npcName.length() == 0)
return null;
String className = camelCase(prepareName(npcName));
if (npcTitle.equals("Gatekeeper")) {
className += npcTitle;
}
if (!names.add(className)) {
int i = 2;
String nameAppend = className + i;
while (names.add(nameAppend) == false) {
i++;
nameAppend = className + i;
}
className = nameAppend;
// System.out.println("Name already taken: " + className);
// System.exit(0);
}
className += "Template";
folder = "";
name = className + ".java";
folder = createFolder(npcType);
if (folder.contains("villagemaster")) {
folder = "villagemaster";
}
String packageName = "";
if (folder.length() > 0)
packageName = "." + folder;
template = replace(template, "javaClassName", className);
template = replace(template, "javaPackage", packageName);
return new String[] { template, "/" + folder + "/", name };
}
private static String replace(String template, String key, String value) {
if (key.equals("class")) {
// template = template.replaceAll("\\$\\{javaClassName\\}",
// camelCase(c.name()));
}
if (key.equals("sex"))
value = value.toUpperCase();
if (key.equals("type"))
template = template.replaceAll("\\$\\{javaParentClassName\\}",
createParentType(value));
if (key.equals("serverSideName") || key.equals("serverSideTitle")
|| key.equals("aggro") || key.equals("targetable")
|| key.equals("show_name") || key.equals("basestats")
|| key.equals("serverSideName") || key.equals("serverSideName")
|| key.equals("serverSideName"))
value = (value.equals("1") ? "true" : "false");
return template.replaceAll("\\$\\{" + key + "\\}", value);
}
private static String prepareName(String name) {
return name.replaceAll("'", "");
}
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();
}
}

View File

@@ -1,78 +0,0 @@
/*
* 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 script.template.actor.npc${javaPackage};
import com.google.inject.Inject;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
import com.l2jserver.model.template.*;
import com.l2jserver.model.template.npc.*;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.util.exception.L2Exception;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ${javaClassName} extends ${javaParentClassName}NPCTemplate {
public static final int ID = ${idTemplate};
@Inject
protected ${javaClassName}(NPCTemplateIDProvider provider, ItemTemplateIDProvider itemProvider) {
super(provider.createID(ID));
this.name = "${name}";
this.serverSideName = ${serverSideName};
this.title = "${title}";
this.serverSideTitle = ${serverSideTitle};
this.collisionRadius = ${collision_radius};
this.collisionHeight = ${collision_height};
this.level = ${level};
this.sex = ActorSex.${sex};
this.attackRange = ${attackrange};
this.maxHP = ${hp};
this.maxMP = ${mp};
this.hpRegeneration = ${hpreg};
this.mpRegeneration = ${mpreg};
this.experience = ${exp};
this.sp = ${sp};
this.aggressive = ${aggro};
this.rightHand = itemProvider.createID(${rhand});
this.leftHand = itemProvider.createID(${lhand});
this.enchantLevel = ${enchant};
this.targetable = ${targetable};
this.showName = ${show_name};
this.dropHerbGroup = ${dropHerbGroup};
this.baseAttributes = ${basestats};
attributes.intelligence = ${int};
attributes.strength = ${str};
attributes.concentration = ${con};
attributes.mentality = ${men};
attributes.dexterity = ${dex};
attributes.witness = ${wit};
attributes.physicalAttack = ${patk};
attributes.magicalAttack = ${matk};
attributes.physicalDefense = ${pdef};
attributes.magicalDefense = ${mdef};
attributes.attackSpeed = ${atkspd};
attributes.castSpeed = ${matkspd};
attributes.criticalChance = ${critical};
attributes.walkSpeed = ${walkspd};
attributes.runSpeed = ${runspd};
}
}

View File

@@ -44,9 +44,11 @@ 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.SkillTemplateID;
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.DropItemMetadata.DropCategory;
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata;
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.CollisionMetadata;
import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.ItemMetadata;
@@ -60,8 +62,10 @@ import com.l2jserver.model.template.NPCTemplate.NPCInformationMetadata.NPCStatsM
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.template.NPCTemplate.SkillMetadata;
import com.l2jserver.model.template.NPCTemplate.TalkMetadata;
import com.l2jserver.model.template.TeleportationTemplate.TeleportRestriction;
import com.l2jserver.model.template.npc.NPCRace;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.npc.controller.BaseNPCController;
import com.l2jserver.model.world.npc.controller.MonsterController;
@@ -75,7 +79,7 @@ import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
public class NPCTemplateConverter {
private static final String JDBC_URL = "jdbc:mysql://localhost/l2j-old";
private static final String JDBC_URL = "jdbc:mysql://localhost/l2jlegacy";
private static final String JDBC_USERNAME = "l2j";
private static final String JDBC_PASSWORD = "changeme";
private static final File L2J_HTML_FOLDER = new File(
@@ -161,7 +165,11 @@ public class NPCTemplateConverter {
m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "npc");
final PreparedStatement st = conn
.prepareStatement("SELECT * FROM npc");
.prepareStatement("SELECT npc.*, npcskills.level AS race "
+ "FROM npc "
+ "LEFT JOIN npcskills "
+ "ON(npc.idTemplate = npcskills.npcid AND npcskills.skillid = ?)");
st.setInt(1, 4416);
st.execute();
final ResultSet rs = st.getResultSet();
while (rs.next()) {
@@ -245,6 +253,7 @@ public class NPCTemplateConverter {
template.info.nameMetadata = null;
template.info.level = rs.getInt("level");
template.info.race = getRace(rs.getInt("race"));
if (!rs.getString("sex").equals("etc"))
template.info.sex = ActorSex.valueOf(rs.getString("sex")
.toUpperCase());
@@ -310,6 +319,7 @@ public class NPCTemplateConverter {
template.info.collision.height = rs.getDouble("collision_height");
template.droplist = fillDropList(rs, template.id.getID());
template.skills = fillSkillList(rs, template.id.getID());
template.talk = fillHtmlChat(template.id.getID());
return new Object[] { template, createParentType(rs.getString("type")) };
@@ -331,8 +341,8 @@ public class NPCTemplateConverter {
m.min = rs.getInt("min");
m.max = rs.getInt("max");
m.chance = rs.getInt("chance");
m.category = getCategory(rs.getInt("category"));
drops.add(m);
// TODO category
}
if (drops.size() == 0)
return null;
@@ -366,6 +376,27 @@ public class NPCTemplateConverter {
return talk;
}
private static List<SkillMetadata> fillSkillList(ResultSet npcRs, int npcId)
throws SQLException {
final Connection conn = npcRs.getStatement().getConnection();
final List<SkillMetadata> skills = CollectionFactory.newList();
final PreparedStatement st = conn
.prepareStatement("SELECT * FROM npcskills WHERE npcid = ?");
st.setInt(1, npcId);
st.execute();
final ResultSet rs = st.getResultSet();
while (rs.next()) {
SkillMetadata m = new SkillMetadata();
m.skill = new SkillTemplateID(rs.getInt("skillid"), null);
m.level = rs.getInt("level");
skills.add(m);
}
if (skills.size() == 0)
return null;
return skills;
}
private static String camelCase(String c) {
Pattern p = Pattern.compile("[a-zA-Z0-9]+");
Matcher m = p.matcher(c.replaceAll("_", " ").replaceAll("\\.", " "));
@@ -428,4 +459,72 @@ public class NPCTemplateConverter {
return serializer;
}
public static NPCRace getRace(int id) {
switch (id) {
case 1:
return NPCRace.UNDEAD;
case 2:
return NPCRace.MAGIC_CREATURE;
case 3:
return NPCRace.BEAST;
case 4:
return NPCRace.ANIMAL;
case 5:
return NPCRace.PLANT;
case 6:
return NPCRace.HUMANOID;
case 7:
return NPCRace.SPIRIT;
case 8:
return NPCRace.ANGEL;
case 9:
return NPCRace.DEMON;
case 10:
return NPCRace.DRAGON;
case 11:
return NPCRace.GIANT;
case 12:
return NPCRace.BUG;
case 13:
return NPCRace.FAIRIE;
case 14:
return NPCRace.HUMAN;
case 15:
return NPCRace.ELVEN;
case 16:
return NPCRace.DARKELVEN;
case 17:
return NPCRace.ORC;
case 18:
return NPCRace.DWARVEN;
case 19:
return NPCRace.OTHER;
case 20:
return NPCRace.NON_LIVING;
case 21:
return NPCRace.SIEGE_WEAPON;
case 22:
return NPCRace.DEFENDING_ARMY;
case 23:
return NPCRace.MERCENARIE;
case 24:
return NPCRace.UNKNOWN;
case 25:
return NPCRace.KAMAEL;
default:
return NPCRace.NONE;
}
}
public static DropCategory getCategory(int id) {
switch (id) {
case -1:
return DropCategory.SPOIL;
case 0:
return DropCategory.DROP;
default:
return DropCategory.valueOf("UNK_" + id);
}
}
}