mirror of
https://github.com/Rogiel/l2jserver2
synced 2026-01-28 05:32:48 +00:00
Template classes for all NPC instances
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -43,7 +43,8 @@ public class ${javaClassName}Template extends ${parent}Template {
|
||||
attributes.accuracy = ${ACC};
|
||||
attributes.criticalChance = ${CRITICAL};
|
||||
attributes.evasionChance = ${EVASION};
|
||||
attributes.moveSpeed = ${MOVE_SPD};
|
||||
attributes.runSpeed = ${MOVE_SPD};
|
||||
attributes.walkSpeed = ${MOVE_SPD};
|
||||
attributes.maxWeigth = ${_LOAD};
|
||||
attributes.craft = ${canCraft};
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.l2jserver.model.world.Actor.Race;
|
||||
import com.l2jserver.model.world.Actor.ActorRace;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@@ -104,7 +104,7 @@ public class CharacterTemplateConverter {
|
||||
camelCase(c.name()));
|
||||
}
|
||||
if (key.equals("RaceId"))
|
||||
value = Race.fromOption(Integer.parseInt(value)).name();
|
||||
value = ActorRace.fromOption(Integer.parseInt(value)).name();
|
||||
if (key.equals("canCraft"))
|
||||
value = (value.equals("1") ? "true" : "false");
|
||||
|
||||
|
||||
@@ -14,54 +14,65 @@
|
||||
* 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;
|
||||
package script.template.actor.npc${javaPackage};
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.id.template.CharacterTemplateID;
|
||||
import com.l2jserver.model.id.template.factory.CharacterTemplateIDFactory;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
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};
|
||||
|
||||
public class ${javaClassName}Template extends ${parent}Template {
|
||||
@Inject
|
||||
public ${javaClassName}Template(CharacterTemplateIDFactory factory) {
|
||||
super(factory.createID(${ClassId}.id), ${ClassId}, Point.fromXYZ(${x}, ${y}, ${z}));
|
||||
// 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.moveSpeed = ${MOVE_SPD};
|
||||
attributes.maxWeigth = ${_LOAD};
|
||||
attributes.craft = ${canCraft};
|
||||
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};
|
||||
|
||||
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;
|
||||
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};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.tool.conversor.npctemplate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
@@ -23,14 +24,12 @@ import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.l2jserver.model.world.Actor.Race;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
public class NPCTemplateConverter {
|
||||
@@ -40,30 +39,38 @@ public class NPCTemplateConverter {
|
||||
|
||||
private static String template;
|
||||
|
||||
private static Map<CharacterClass, String> parents = CollectionFactory
|
||||
.newMap();
|
||||
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(NPCTemplateConverter.class
|
||||
.getResourceAsStream("CharacterTemplateBase.txt"));
|
||||
.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 char_templates");
|
||||
.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);
|
||||
IOUtils.write(result[0], new FileOutputStream(
|
||||
"generated/template/character/" + result[1]));
|
||||
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();
|
||||
}
|
||||
@@ -73,47 +80,95 @@ public class NPCTemplateConverter {
|
||||
}
|
||||
|
||||
private static String[] generateJavaClass(ResultSet rs) throws SQLException {
|
||||
String npcName = "";
|
||||
String npcClass = "";
|
||||
String npcTitle = "";
|
||||
String npcType = "";
|
||||
|
||||
String name = "";
|
||||
String folder = "";
|
||||
String template = NPCTemplateConverter.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";
|
||||
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);
|
||||
}
|
||||
}
|
||||
return new String[] { template, name };
|
||||
|
||||
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";
|
||||
template = replace(template, "javaClassName", className);
|
||||
|
||||
folder = "";
|
||||
name = className + ".java";
|
||||
|
||||
folder = createFolder(npcType);
|
||||
|
||||
String packageName = "";
|
||||
if (folder.length() > 0)
|
||||
packageName = "." + folder;
|
||||
template = replace(template, "javaPackage", packageName);
|
||||
|
||||
return new String[] { template, "/" + folder + "/", 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("class")) {
|
||||
|
||||
// template = template.replaceAll("\\$\\{javaClassName\\}",
|
||||
// camelCase(c.name()));
|
||||
}
|
||||
if (key.equals("RaceId"))
|
||||
value = Race.fromOption(Integer.parseInt(value)).name();
|
||||
if (key.equals("canCraft"))
|
||||
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("_", " "));
|
||||
Matcher m = p.matcher(c.replaceAll("_", " ").replaceAll("\\.", " "));
|
||||
StringBuffer result = new StringBuffer();
|
||||
String word;
|
||||
while (m.find()) {
|
||||
@@ -123,4 +178,28 @@ public class NPCTemplateConverter {
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static String createParentType(String l2j) {
|
||||
if (l2j.startsWith("L2"))
|
||||
l2j = l2j.substring(2);
|
||||
if (l2j.equals("Npc"))
|
||||
return "";
|
||||
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