mirror of
https://github.com/Rogiel/l2jserver2
synced 2026-01-26 21:02:46 +00:00
Created CharacterTemplate object for all classes
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package script.template.character;
|
||||
|
||||
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;
|
||||
|
||||
public class ${javaClassName}Template extends ${parent}Template {
|
||||
@Inject
|
||||
public ${javaClassName}Template(CharacterTemplateIDFactory factory) {
|
||||
super(factory.createID(${ClassId}.id),
|
||||
${ClassId},
|
||||
// ATTRIBUTES
|
||||
${_INT},// INT
|
||||
${STR},// STR
|
||||
${CON},// CON
|
||||
${MEN},// MEN
|
||||
${DEX},// DEX
|
||||
${WIT},// WIT
|
||||
${P_ATK},// physical attack
|
||||
${M_ATK},// magical attack
|
||||
${P_DEF},// physical def
|
||||
${M_DEF},// magical def
|
||||
${P_SPD},// attack speed
|
||||
${M_SPD},// cast speed
|
||||
${ACC},// accuracy
|
||||
${CRITICAL},// critical
|
||||
${EVASION},// evasion
|
||||
${MOVE_SPD},// move speed
|
||||
${_LOAD},// max inventory weight
|
||||
${canCraft},// can craft
|
||||
Point.fromXYZ(${x}, ${y}, ${z})// spawn location
|
||||
);
|
||||
}
|
||||
|
||||
protected ${javaClassName}Template(CharacterTemplateID id,
|
||||
CharacterClass characterClass, int intelligence, int strength,
|
||||
int concentration, int mentality, int dexterity, int witness,
|
||||
int physicalAttack, int magicalAttack, int physicalDefense,
|
||||
int magicalDefense, int attackSpeed, int castSpeed, int accuracy,
|
||||
int criticalChance, int evasionChance, int moveSpeed,
|
||||
int maxWeigth, boolean craft, Point spawnLocation) {
|
||||
super(id, characterClass, intelligence, strength, concentration,
|
||||
mentality, dexterity, witness, physicalAttack, magicalAttack,
|
||||
physicalDefense, magicalDefense, attackSpeed, castSpeed,
|
||||
accuracy, criticalChance, evasionChance, moveSpeed, maxWeigth,
|
||||
craft, spawnLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2Character create() {
|
||||
final L2Character character = super.create();
|
||||
// TODO register skills
|
||||
return character;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.l2jserver.tool.conversor;
|
||||
|
||||
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.AbstractActor.Race;
|
||||
import com.l2jserver.model.world.character.CharacterClass;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
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";
|
||||
|
||||
private static String template;
|
||||
|
||||
private static Map<CharacterClass, String> parents = CollectionFactory
|
||||
.newMap(CharacterClass.class, String.class);
|
||||
|
||||
public static void main(String[] args) throws SQLException, IOException,
|
||||
ClassNotFoundException {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
||||
template = IOUtils.toString(CharacterTemplateConverter.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");
|
||||
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 = CharacterTemplateConverter.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 = Race.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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user