1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2026-01-27 05:02:47 +00:00

Created CharacterTemplate object for all classes

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 16:39:33 -03:00
parent d8d561688b
commit e886165b89
137 changed files with 6472 additions and 97 deletions

View File

@@ -27,7 +27,7 @@ import com.l2jserver.service.database.MySQLDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.MySQLDatabaseService.Mapper;
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* {@link CharacterDAO} implementation for MySQL5
@@ -66,9 +66,10 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
public static final String EXPERIENCE = "experience";
public static final String SP = "sp";
public static final String COORD_X = "position_x";
public static final String COORD_Y = "position_y";
public static final String COORD_Z = "position_z";
public static final String POINT_X = "point_x";
public static final String POINT_Y = "point_y";
public static final String POINT_Z = "point_z";
public static final String POINT_ANGLE = "point_angle";
public static final String APPEARANCE_HAIR_STYLE = "appearance_hair_style";
public static final String APPEARANCE_HAIR_COLOR = "appearance_hair_color";
@@ -121,8 +122,9 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
// TODO load experience
// TODO load sp
character.setPosition(Coordinate.fromXYZ(rs.getInt(COORD_X),
rs.getInt(COORD_Y), rs.getInt(COORD_Z)));
character.setPoint(Point.fromXYZA(rs.getInt(POINT_X),
rs.getInt(POINT_Y), rs.getInt(POINT_Z),
rs.getDouble(POINT_ANGLE)));
// appearance
character.getAppearance().setHairStyle(
@@ -228,8 +230,8 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
protected String query() {
return "INSERT INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
+ ACCOUNT_ID + "`,`" + NAME + "`,`" + RACE + "`,`"
+ CLASS + "`,`" + SEX + "`,`" + LEVEL + "`,`" + COORD_X
+ "`,`" + COORD_Y + "`,`" + COORD_Z + "`,`"
+ CLASS + "`,`" + SEX + "`,`" + LEVEL + "`,`" + POINT_X
+ "`,`" + POINT_Y + "`,`" + POINT_ANGLE + "`,`"
+ APPEARANCE_HAIR_STYLE + "`,`" + APPEARANCE_HAIR_COLOR
+ "`,`" + APPEARANCE_FACE
+ "`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";

View File

@@ -1,5 +1,6 @@
package com.l2jserver.model.id;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
/**
@@ -15,6 +16,7 @@ public class AccountID extends ID<String> {
* @param login
* the login
*/
@Inject
public AccountID(@Assisted String login) {
super(login);
}

View File

@@ -8,7 +8,7 @@ import com.l2jserver.model.world.AbstractActor.Race;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterBaseAttributes;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* Template for {@link L2Character}
@@ -33,7 +33,7 @@ public abstract class CharacterTemplate extends AbstractTemplate<L2Character> {
/**
* The initial location for the character to be spawned
*/
protected final Coordinate spawnLocation;
protected final Point spawnLocation;
/**
* The base attributes instance
*/
@@ -45,7 +45,7 @@ public abstract class CharacterTemplate extends AbstractTemplate<L2Character> {
int physicalAttack, int magicalAttack, int physicalDefense,
int magicalDefense, int attackSpeed, int castSpeed, int accuracy,
int criticalChance, int evasionChance, int moveSpeed,
int maxWeigth, boolean craft, Coordinate spawnLocation) {
int maxWeigth, boolean craft, Point spawnLocation) {
super(id);
this.race = characterClass.race;
this.characterClass = characterClass;
@@ -64,7 +64,7 @@ public abstract class CharacterTemplate extends AbstractTemplate<L2Character> {
character.setRace(race);
character.setCharacterClass(characterClass);
character.setPosition(spawnLocation);
character.setPoint(spawnLocation);
// character.getBaseAttributes().setIntelligence(intelligence);
// character.getBaseAttributes().setStrength(strength);
@@ -91,9 +91,9 @@ public abstract class CharacterTemplate extends AbstractTemplate<L2Character> {
}
/**
* @return the spawnLocation
* @return the initial spawn location
*/
public Coordinate getSpawnLocation() {
public Point getSpawnLocation() {
return spawnLocation;
}

View File

@@ -8,7 +8,8 @@ import com.l2jserver.model.world.capability.Attacker;
import com.l2jserver.model.world.capability.Castable;
import com.l2jserver.model.world.capability.Equipable;
import com.l2jserver.model.world.capability.Equiper;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* Abstract {@link Actor} class.
@@ -83,9 +84,9 @@ public abstract class AbstractActor extends AbstractObject implements Actor {
*/
protected int hp;
/**
* The actor coordinate
* The actor coordinate point
*/
protected Coordinate position;
protected Point point;
/**
* The currently effects active on the actor
*/
@@ -138,14 +139,29 @@ public abstract class AbstractActor extends AbstractObject implements Actor {
return false;
}
/**
* @return the coordinate point
*/
public Point getPoint() {
return point;
}
/**
* @param point
* the coordinate point to set
*/
public void setPoint(Point point) {
this.point = point;
}
@Override
public Coordinate getPosition() {
return position;
return point.getCoordinate();
}
@Override
public void setPosition(Coordinate coord) {
this.position = coord;
this.point = new Point(coord, (point != null ? point.getAngle() : 0));
}
/**

View File

@@ -10,7 +10,7 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.model.world.item.ItemEvent;
import com.l2jserver.model.world.item.ItemListener;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* This class represents an {@link Item} in the Lineage II World. The item can

View File

@@ -3,7 +3,7 @@ package com.l2jserver.model.world;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ItemID;
import com.l2jserver.model.world.capability.Summonable;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* This class represents an Pet in the Lineage II World

View File

@@ -3,7 +3,7 @@ package com.l2jserver.model.world;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Playable;
import com.l2jserver.model.world.capability.Teleportable;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* {@link Player} is any object that can be controlled by the player. The most

View File

@@ -12,7 +12,7 @@ import com.l2jserver.model.world.actor.ActorListener;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Actor extends Listenable<ActorListener, ActorEvent>,
Spawnable, Positionable, Damagable, Attackable, Attacker, Castable,
Spawnable, Pointable, Damagable, Attackable, Attacker, Castable,
Caster, Levelable, Killable, Equiper, Equipable {
ActorEffects getEffects();
}

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Defines an {@link AbstractObject} that can be dropped on the ground.

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.dimensional.Point;
/**
* Defines an {@link AbstractObject} that can be positioned and pointed in the
* world.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Pointable extends Positionable {
Point getPoint();
void setPoint(Point point);
}

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Defines an {@link AbstractObject} that can be positioned in the world.

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Represents an {@link AbstractObject} that can be spawned.

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Represents an {@link AbstractObject} that can be summoned.

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Defines an {@link AbstractObject} that can be teleported by

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Defines an {@link AbstractObject} that can teleport {@link Teleportable}

View File

@@ -285,7 +285,7 @@ public enum CharacterClass {
* the class id
* @return the {@link CharacterClass} instance found
*/
public CharacterClass fromID(int id) {
public static CharacterClass fromID(int id) {
for (final CharacterClass c : values()) {
if (c.id == id)
return c;

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.event;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Event for objects spawning

View File

@@ -2,7 +2,7 @@ package com.l2jserver.model.world.filter.impl;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Filter objects that are in the <tt>range</tt> of <tt>coordinate</tt>

View File

@@ -5,7 +5,7 @@ import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Event dispatcher once an player has spawned in the world

View File

@@ -1,7 +1,7 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.Player;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Event dispatched once an player is teleported.

View File

@@ -1,4 +1,6 @@
package com.l2jserver.util;
package com.l2jserver.util.dimensional;
import org.apache.commons.math.geometry.Vector3D;
/**
* Represents an coordinate in the game world.
@@ -8,18 +10,12 @@ package com.l2jserver.util;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Coordinate {
private static final long serialVersionUID = 1L;
/**
* The X point
* The backing vector of this Coordinate
*/
private final int x;
/**
* The Y point
*/
private final int y;
/**
* The Z point
*/
private final int z;
protected final Vector3D vector;
/**
* Creates a new coordinate
@@ -32,30 +28,19 @@ public class Coordinate {
* the z point
*/
protected Coordinate(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
this.vector = new Vector3D(x, y, z);
}
/**
* @return the x point
*/
public int getX() {
return x;
return (int) vector.getX();
}
/**
* @return the y point
*/
public int getY() {
return y;
return (int) vector.getY();
}
/**
* @return the z point
*/
public int getZ() {
return z;
return (int) vector.getZ();
}
/**
@@ -63,12 +48,11 @@ public class Coordinate {
* <tt>other</tt>
*
* @param other
* the other coodinate
* @return the computed distance
* the other coordinate
* @return the calculated distance
*/
public int getDistance(Coordinate other) {
// TODO calculation
return x + y + z;
public double getDistance(Coordinate other) {
return Vector3D.distance(vector, other.vector);
}
/**

View File

@@ -0,0 +1,142 @@
package com.l2jserver.util.dimensional;
import org.apache.commons.math.geometry.Rotation;
/**
* An point is composed of an Coordinate and an angle. The angle represents the
* facing angle of the point, that is, the direction the point is "looking".
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Point {
/**
* The point coordinate
*/
protected final Coordinate coordinate;
/**
* Te point rotation
*/
protected final Rotation rotation;
/**
* Creates a new point
*
* @param coordinate
* the coordinate
* @param angle
* the angle
*/
public Point(Coordinate coordinate, double angle) {
this.coordinate = coordinate;
this.rotation = new Rotation(coordinate.vector, angle);
}
/**
* @return the x
* @see com.l2jserver.util.dimensional.Coordinate#getX()
*/
public int getX() {
return coordinate.getX();
}
/**
* @return the y
* @see com.l2jserver.util.dimensional.Coordinate#getY()
*/
public int getY() {
return coordinate.getY();
}
/**
* @return the z
* @see com.l2jserver.util.dimensional.Coordinate#getZ()
*/
public int getZ() {
return coordinate.getZ();
}
/**
* @param other
* the other coordinate
* @return the distance
* @see com.l2jserver.util.dimensional.Coordinate#getDistance(com.l2jserver.util.dimensional.Coordinate)
*/
public double getDistance(Coordinate other) {
return coordinate.getDistance(other);
}
/**
* @param other
* the other point
* @return the distance
* @see com.l2jserver.util.dimensional.Coordinate#getDistance(com.l2jserver.util.dimensional.Coordinate)
*/
public double getDistance(Point other) {
return coordinate.getDistance(other.coordinate);
}
/**
* @return the angle
* @see org.apache.commons.math.geometry.Rotation#getAngle()
*/
public double getAngle() {
return rotation.getAngle();
}
/**
* @param other
* the other point
* @return the angle difference between the two points
* @see org.apache.commons.math.geometry.Rotation#distance(Rotation,
* Rotation)
*/
public double getAngleDifference(Point other) {
return Rotation.distance(this.rotation, other.rotation);
}
/**
* @return the coordinate
*/
public Coordinate getCoordinate() {
return coordinate;
}
/**
* @return the rotation
*/
public Rotation getRotation() {
return rotation;
}
/**
* Creates a new instance from the 3 points and an angle
*
* @param x
* the x point
* @param y
* the y point
* @param z
* the z point
* @param angle
* the angle
* @return the new {@link Point} object created
*/
public static Point fromXYZA(int x, int y, int z, double angle) {
return new Point(Coordinate.fromXYZ(x, y, z), angle);
}
/**
* Creates a new instance from the 3 points. The angle will be zero.
*
* @param x
* the x point
* @param y
* the y point
* @param z
* the z point
* @return the new {@link Point} object created
*/
public static Point fromXYZ(int x, int y, int z) {
return fromXYZA(x, y, z, 0);
}
}

View File

@@ -8,9 +8,10 @@ CREATE TABLE `character` (
`level` int(3) NOT NULL,
`experience` int(15) NOT NULL,
`sp` int(15) NOT NULL,
`position_x` int(10) NOT NULL,
`position_y` int(10) NOT NULL,
`position_z` int(10) NOT NULL,
`point_x` int(10) NOT NULL,
`point_y` int(10) NOT NULL,
`point_z` int(10) NOT NULL,
`point_angle` DOUBLE NOT NULL,
`appearance_hair_style` enum('STYLE_A','STYLE_B','STYLE_C','STYLE_D','STYLE_E') NOT NULL DEFAULT 'STYLE_A',
`appearance_hair_color` enum('COLOR_A','COLOR_B','COLOR_C','COLOR_D') NOT NULL DEFAULT 'COLOR_A',
`apperance_face` enum('FACE_A','FACE_B','FACE_C') NOT NULL DEFAULT 'FACE_A',

View File

@@ -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;
}
}

View File

@@ -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();
}
}