1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 00:13:11 +00:00

Very simple skill templates implemented

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-06-03 14:58:07 -03:00
parent fe7373ba29
commit 4d6289b12c
8068 changed files with 49586 additions and 8 deletions

View File

@@ -124,4 +124,41 @@ public class Skill extends AbstractModel {
public SkillTemplate getSkillTemplate() {
return skillTemplateID.getTemplate();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((actorID == null) ? 0 : actorID.hashCode());
result = prime * result
+ ((skillTemplateID == null) ? 0 : skillTemplateID.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
Skill other = (Skill) obj;
if (actorID == null) {
if (other.actorID != null)
return false;
} else if (!actorID.equals(other.actorID))
return false;
if (skillTemplateID == null) {
if (other.skillTemplateID != null)
return false;
} else if (!skillTemplateID.equals(other.skillTemplateID))
return false;
return true;
}
}

View File

@@ -304,6 +304,7 @@ public class NPCTemplate extends ActorTemplate<NPC> {
continue;
final Skill skill = template.create();
skill.setLevel(metadata.level);
skill.setActorID(npc.getID());
skills.add(skill);
}
npc.getSkills().load(skills);

View File

@@ -16,19 +16,47 @@
*/
package com.l2jserver.model.template;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.l2jserver.model.game.Skill;
import com.l2jserver.model.id.template.SkillTemplateID;
import com.l2jserver.util.jaxb.SkillTemplateIDAdapter;
/**
* Template for {@link Skill} object
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@XmlRootElement(name = "skill")
@XmlType(namespace = "skill", name = "skill")
@XmlAccessorType(XmlAccessType.FIELD)
public class SkillTemplate extends AbstractTemplate<Skill> {
@XmlAttribute(name = "id")
@XmlJavaTypeAdapter(value = SkillTemplateIDAdapter.class)
protected SkillTemplateID id;
@XmlAttribute(name = "name")
protected String name;
@XmlAttribute(name = "delay")
protected int delay;
@XmlAttribute(name = "cooldown")
protected int cooldown;
/**
* The maximum level supported by this skill
*/
protected int maximumLevel = 1;
@Override
public Skill create() {
final Skill skill = new Skill(id);
skill.setLevel(1);
return skill;
}
/**
* @return the maximumLevel
@@ -37,15 +65,36 @@ public class SkillTemplate extends AbstractTemplate<Skill> {
return maximumLevel;
}
@Override
public Skill create() {
final Skill skill = new Skill(null);
return skill;
/**
* @return the id
*/
public SkillTemplateID getId() {
return id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @return the delay
*/
public int getDelay() {
return delay;
}
/**
* @return the cooldown
*/
public int getCooldown() {
return cooldown;
}
@Override
public SkillTemplateID getID() {
// TODO Auto-generated method stub
return null;
return id;
}
}

View File

@@ -16,6 +16,8 @@
*/
package com.l2jserver.model.world.actor.stat;
import com.l2jserver.model.world.Actor;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@@ -81,7 +83,11 @@ public enum BaseStats {
2.17, 2.2, 2.22, 2.24, 2.26, 2.29, 2.31, 2.33, 2.35, 2.38, 2.4,
2.43, 2.45, 2.47, 2.5, 2.52, 2.55, 2.58, 2.6, 2.63, 2.65, 2.68);
public double[] bonus;
/**
* Bonus array for the base stat. The key represents the value of the
* attribute.
*/
public final double[] bonus;
BaseStats(double... bonus) {
this.bonus = bonus;
@@ -90,4 +96,26 @@ public enum BaseStats {
public double calculateBonus(int n) {
return bonus[n];
}
public double calculateBonus(Actor actor) {
return calculateBonus(actor.getStats());
}
public double calculateBonus(ActorStats<?> stats) {
switch (this) {
case CON:
return calculateBonus(stats.getConcentration());
case DEX:
return calculateBonus(stats.getDexterity());
case INT:
return calculateBonus(stats.getIntelligence());
case MEN:
return calculateBonus(stats.getMentality());
case STR:
return calculateBonus(stats.getStrength());
case WIT:
return calculateBonus(stats.getWitness());
}
return 0;
}
}

View File

@@ -39,6 +39,7 @@ import com.l2jserver.model.id.TemplateID;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.template.SkillTemplate;
import com.l2jserver.model.template.TeleportationTemplate;
import com.l2jserver.model.template.Template;
import com.l2jserver.service.AbstractService;
@@ -103,7 +104,7 @@ public class XMLTemplateService extends AbstractService implements
try {
log.debug("Creating JAXBContext instance");
context = JAXBContext.newInstance(CharacterTemplate.class,
NPCTemplate.class, ItemTemplate.class,
NPCTemplate.class, ItemTemplate.class, SkillTemplate.class,
TeleportationTemplateContainer.class);
log.debug("Creating Unmarshaller instance");

View File

@@ -0,0 +1,187 @@
/*
* 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.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Collection;
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.MarshalException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.io.FileUtils;
import com.l2jserver.model.id.template.SkillTemplateID;
import com.l2jserver.util.factory.CollectionFactory;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
public class SkillTemplateConverter {
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 String LEGACY_SKILL_FOLDER = "../L2J_DataPack_BETA/data/stats/skills";
private static List<SkillTemplate> 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("data/templates");
final JAXBContext c = JAXBContext.newInstance(SkillTemplate.class,
LegacySkillList.class);
final Connection conn = DriverManager.getConnection(JDBC_URL,
JDBC_USERNAME, JDBC_PASSWORD);
System.out.println("Generating template XML files...");
c.generateSchema(new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri,
String suggestedFileName) throws IOException {
return new StreamResult(new File(target, suggestedFileName));
}
});
try {
final Unmarshaller u = c.createUnmarshaller();
final Marshaller m = c.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "skill");
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "skill ../skill.xsd");
Collection<File> files = FileUtils.listFiles(new File(
LEGACY_SKILL_FOLDER), new String[] { "xml" }, true);
for (final File legacyFile : files) {
LegacySkillList list = (LegacySkillList) u
.unmarshal(legacyFile);
for (final LegacySkill legacySkill : list.skills) {
SkillTemplate t = fillSkill(legacySkill);
final File file = new File(target, "skill/"
+ t.id.getID()
+ (t.getName() != null ? "-"
+ camelCase(t.getName()) : "") + ".xml");
templates.add(t);
try {
m.marshal(t,
getXMLSerializer(new FileOutputStream(file)));
} catch (MarshalException e) {
System.err
.println("Could not generate XML template file for "
+ t.getName() + " - " + t.getID());
file.delete();
}
}
}
System.out.println("Generated " + templates.size() + " templates");
System.gc();
System.out.println("Free: "
+ FileUtils.byteCountToDisplaySize(Runtime.getRuntime()
.freeMemory()));
System.out.println("Total: "
+ FileUtils.byteCountToDisplaySize(Runtime.getRuntime()
.totalMemory()));
System.out
.println("Used: "
+ FileUtils.byteCountToDisplaySize(Runtime
.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory()));
System.out.println("Max: "
+ FileUtils.byteCountToDisplaySize(Runtime.getRuntime()
.maxMemory()));
} finally {
conn.close();
}
}
private static SkillTemplate fillSkill(LegacySkill legacy)
throws SQLException, IOException {
final SkillTemplate template = new SkillTemplate();
template.id = new SkillTemplateID(legacy.id, null);
template.name = legacy.name;
return template;
}
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 XMLSerializer getXMLSerializer(OutputStream w) {
// configure an OutputFormat to handle CDATA
OutputFormat of = new OutputFormat();
// specify which of your elements you want to be handled as CDATA.
// The use of the '^' between the namespaceURI and the localname
// seems to be an implementation detail of the xerces code.
// When processing xml that doesn't use namespaces, simply omit the
// namespace prefix as shown in the third CDataElement below.
of.setCDataElements(new String[] { "^chat" });
// set any other options you'd like
of.setPreserveSpace(false);
of.setIndenting(true);
// create the serializer
XMLSerializer serializer = new XMLSerializer(of);
serializer.setOutputByteStream(w);
return serializer;
}
@XmlRootElement(name = "list")
public static class LegacySkillList {
@XmlElement(name = "skill")
private List<LegacySkill> skills;
}
public static class LegacySkill {
@XmlAttribute(name = "id")
private int id;
@XmlAttribute(name = "name")
private String name;
}
}