1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2026-03-14 06:38:09 +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

@@ -33,10 +33,10 @@ import com.l2jserver.model.id.provider.AccountIDProvider;
import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.Actor.ActorRace;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.Clan;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterRace;
import com.l2jserver.model.world.character.CharacterAppearance;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
@@ -151,7 +151,7 @@ public abstract class JDBCCharacterDAO extends
character.setName(rs.getString(NAME));
character.setRace(ActorRace.valueOf(rs.getString(RACE)));
character.setRace(CharacterRace.valueOf(rs.getString(RACE)));
character.setCharacterClass(CharacterClass.valueOf(rs
.getString(CLASS)));
character.setSex(ActorSex.valueOf(rs.getString(SEX)));

View File

@@ -26,7 +26,6 @@ package com.l2jserver.game.ai.desires;
* @see com.l2jserver.game.ai.AI#handleDesire(Desire)
*/
public abstract class AbstractDesire implements Desire {
/**
* Desire power. It's used to calculate what npc whants to do most of all.
*/

View File

@@ -31,9 +31,9 @@ import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.Actor.ActorRace;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterRace;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
@@ -80,7 +80,7 @@ public class CM_CHAR_CREATE extends AbstractClientPacket {
/**
* The race of the new character
*/
private ActorRace race;
private CharacterRace race;
/**
* The sex of the new character
*/
@@ -146,7 +146,7 @@ public class CM_CHAR_CREATE extends AbstractClientPacket {
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
name = BufferUtils.readString(buffer);
race = ActorRace.fromOption(buffer.readInt());
race = CharacterRace.fromOption(buffer.readInt());
sex = ActorSex.fromOption(buffer.readInt());
characterClass = CharacterClass.fromID(buffer.readInt());
@@ -252,7 +252,7 @@ public class CM_CHAR_CREATE extends AbstractClientPacket {
/**
* @return the race
*/
public ActorRace getRace() {
public CharacterRace getRace() {
return race;
}
@@ -260,7 +260,7 @@ public class CM_CHAR_CREATE extends AbstractClientPacket {
* @param race
* the race to set
*/
public void setRace(ActorRace race) {
public void setRace(CharacterRace race) {
this.race = race;
}

View File

@@ -35,15 +35,15 @@ public interface Model<T extends ID<?>> {
void setID(T ID);
/**
* @return the database object state
* @return the database object desire
*/
ObjectDesire getObjectDesire();
/**
* @param state
* the database object state to set
* @param desire
* the database object desire to set
*/
void setObjectDesire(ObjectDesire state);
void setObjectDesire(ObjectDesire desire);
public enum ObjectDesire {
NONE, INSERT, UPDATE, DELETE;

View File

@@ -28,10 +28,257 @@ public class PhysicalAttackCalculator extends AttackCalculator {
super(new AttackCalculatorFunction(0x000, AttackCalculatorType.DAMAGE) {
@Override
public double calculate(Actor attacker, Actor target, double value) {
// TODO this is certainly not right!!!
// this is just an simple calculator for testing!
return attacker.getStats().getPhysicalAttack()
- target.getStats().getPhysicalDefense();
// // final boolean isPvP = (attacker instanceof L2Playable) &&
// // (target instanceof L2Playable);
// // TODO soulshot charge
// boolean soulshot = false;
//
// double damage = attacker.getStats().getPhysicalAttack();
// double defense = target.getStats().getPhysicalDefense();
// // damage += calcValakasAttribute(attacker, target, skill);
// // if (attacker instanceof NPC) {
// // if (((NPC) attacker)._soulshotcharged) {
// // ss = true;
// // } else
// // ss = false;
// // ((L2Npc) attacker)._soulshotcharged = false;
// // }
// // TODO implement pvp
// // Def bonusses in PvP fight
// // if (isPvP) {
// // if (skill == null)
// // defence *= target.calcStat(Stats.PVP_PHYSICAL_DEF, 1,
// // null, null);
// // else
// // defence *= target.calcStat(Stats.PVP_PHYS_SKILL_DEF, 1,
// // null, null);
// // }
//
// // TODO implement shield
// // switch (shld) {
// // case SHIELD_DEFENSE_SUCCEED:
// // if (!Config.ALT_GAME_SHIELD_BLOCKS)
// // defense += target.getShldDef();
// // break;
// // case SHIELD_DEFENSE_PERFECT_BLOCK: // perfect block
// // return 1.;
// // }
//
// if (soulshot)
// damage *= 2;
// // if (skill != null) {
// // double skillpower = skill.getPower(attacker, target,
// isPvP);
// // float ssboost = skill.getSSBoost();
// // if (ssboost <= 0)
// // damage += skillpower;
// // else if (ssboost > 0) {
// // if (ss) {
// // skillpower *= ssboost;
// // damage += skillpower;
// // } else
// // damage += skillpower;
// // }
// // }
//
// // defense modifier depending of the attacker weapon
// ItemTemplate weapon = attacker.getActiveWeaponItem();
// boolean isBow = false;
// if (weapon != null/* && !attacker.isTransformed()*/) {
// switch (null) {
// case BOW:
// isBow = true;
// stat = StatType.BOW_WPN_VULN;
// break;
// case CROSSBOW:
// isBow = true;
// stat = StatType.CROSSBOW_WPN_VULN;
// break;
// case BLUNT:
// stat = StatType.BLUNT_WPN_VULN;
// break;
// case DAGGER:
// stat = StatType.DAGGER_WPN_VULN;
// break;
// case DUAL:
// stat = StatType.DUAL_WPN_VULN;
// break;
// case DUALFIST:
// stat = StatType.DUALFIST_WPN_VULN;
// break;
// case ETC:
// stat = StatType.ETC_WPN_VULN;
// break;
// case FIST:
// stat = StatType.FIST_WPN_VULN;
// break;
// case POLE:
// stat = StatType.POLE_WPN_VULN;
// break;
// case SWORD:
// stat = StatType.SWORD_WPN_VULN;
// break;
// case BIGSWORD:
// stat = StatType.BIGSWORD_WPN_VULN;
// break;
// case BIGBLUNT:
// stat = StatType.BIGBLUNT_WPN_VULN;
// break;
// case DUALDAGGER:
// stat = StatType.DUALDAGGER_WPN_VULN;
// break;
// case RAPIER:
// stat = StatType.RAPIER_WPN_VULN;
// break;
// case ANCIENTSWORD:
// stat = StatType.ANCIENT_WPN_VULN;
// break;
// /*
// * case PET: stat = Stats.PET_WPN_VULN; break;
// */
// }
// }
//
// // for summon use pet weapon vuln, since they cant hold
// weapon
// // if (attacker instanceof L2SummonInstance)
// // stat = Stats.PET_WPN_VULN;
//
// // if (crit) {
// // // Finally retail like formula
// // damage = 2
// // * attacker.calcStat(Stats.CRITICAL_DAMAGE, 1,
// // target, skill)
// // * target.calcStat(Stats.CRIT_VULN,
// // target.getTemplate().baseCritVuln, target,
// // null) * (70 * damage / defense);
// // // Crit dmg add is almost useless in normal hits...
// // damage += (attacker.calcStat(Stats.CRITICAL_DAMAGE_ADD, 0,
// // target, skill) * 70 / defense);
// // } else
// // damage = 70 * damage / defense;
//
// if (stat != null) {
// // get the vulnerability due to skills (buffs, passives,
// // toggles, etc)
// damage = target.calcStat(stat, damage, target, null);
// /*
// * if (target instanceof L2Npc) { // get the natural
// * vulnerability for the template damage *= ((L2Npc)
// * target).getTemplate().getVulnerability(stat); }
// */
// }
//
// // Weapon random damage
// damage *= attacker.getRandomDamageMultiplier();
//
// // damage += Rnd.nextDouble() * damage / 10;
// // damage += _rnd.nextDouble()*
// // attacker.getRandomDamage(target);
// // }
// if (shld > 0 && Config.ALT_GAME_SHIELD_BLOCKS) {
// damage -= target.getShldDef();
// if (damage < 0)
// damage = 0;
// }
//
// if (target instanceof L2Npc) {
// switch (((L2Npc) target).getTemplate().getRace()) {
// case BEAST:
// damage *= attacker.getPAtkMonsters(target);
// break;
// case ANIMAL:
// damage *= attacker.getPAtkAnimals(target);
// break;
// case PLANT:
// damage *= attacker.getPAtkPlants(target);
// break;
// case DRAGON:
// damage *= attacker.getPAtkDragons(target);
// break;
// case BUG:
// damage *= attacker.getPAtkInsects(target);
// break;
// case GIANT:
// damage *= attacker.getPAtkGiants(target);
// break;
// case MAGICCREATURE:
// damage *= attacker.getPAtkMagicCreatures(target);
// break;
// default:
// // nothing
// break;
// }
// }
//
// if (damage > 0 && damage < 1) {
// damage = 1;
// } else if (damage < 0) {
// damage = 0;
// }
//
// // Dmg bonusses in PvP fight
// if (isPvP) {
// if (skill == null)
// damage *= attacker.calcStat(Stats.PVP_PHYSICAL_DMG, 1,
// null, null);
// else
// damage *= attacker.calcStat(Stats.PVP_PHYS_SKILL_DMG,
// 1, null, null);
// }
//
// // Physical skill dmg boost
// if (skill != null)
// damage *= attacker.calcStat(Stats.PHYSICAL_SKILL_POWER, 1,
// null, null);
//
// damage *= calcElemental(attacker, target, skill);
// if (target instanceof L2Attackable) {
// if (isBow) {
// if (skill != null)
// damage *= attacker.calcStat(
// Stats.PVE_BOW_SKILL_DMG, 1, null, null);
// else
// damage *= attacker.calcStat(Stats.PVE_BOW_DMG, 1,
// null, null);
// } else
// damage *= attacker.calcStat(Stats.PVE_PHYSICAL_DMG, 1,
// null, null);
// if (!target.isRaid()
// && !target.isRaidMinion()
// && target.getLevel() >= Config.MIN_NPC_LVL_DMG_PENALTY
// && attacker.getActingPlayer() != null
// && (target.getLevel() - attacker.getActingPlayer()
// .getLevel()) >= 2) {
// int lvlDiff = target.getLevel()
// - attacker.getActingPlayer().getLevel() - 1;
// if (skill != null) {
// if (lvlDiff > Config.NPC_SKILL_DMG_PENALTY.size())
// damage *= Config.NPC_SKILL_DMG_PENALTY
// .get(Config.NPC_SKILL_DMG_PENALTY
// .size());
// else
// damage *= Config.NPC_SKILL_DMG_PENALTY
// .get(lvlDiff);
// } else if (crit) {
// if (lvlDiff > Config.NPC_CRIT_DMG_PENALTY.size())
// damage *= Config.NPC_CRIT_DMG_PENALTY
// .get(Config.NPC_CRIT_DMG_PENALTY.size());
// else
// damage *= Config.NPC_CRIT_DMG_PENALTY
// .get(lvlDiff);
// } else {
// if (lvlDiff > Config.NPC_DMG_PENALTY.size())
// damage *= Config.NPC_DMG_PENALTY
// .get(Config.NPC_DMG_PENALTY.size());
// else
// damage *= Config.NPC_DMG_PENALTY.get(lvlDiff);
// }
// }
// }
//
// return damage;
return 10;
}
}, new AttackCalculatorFunction(Integer.MAX_VALUE,
AttackCalculatorType.DAMAGE) {

View File

@@ -25,8 +25,8 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.l2jserver.model.id.template.CharacterTemplateID;
import com.l2jserver.model.world.Actor.ActorRace;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterRace;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter;
@@ -185,7 +185,7 @@ public class CharacterTemplate extends ActorTemplate<L2Character> {
/**
* @return the character race
*/
public ActorRace getRace() {
public CharacterRace getRace() {
return getCharacterClass().race;
}

View File

@@ -30,6 +30,10 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.calculator.ItemSetActorCalculator;
import com.l2jserver.model.template.item.ArmorType;
import com.l2jserver.model.template.item.ItemMaterial;
import com.l2jserver.model.template.item.ItemType;
import com.l2jserver.model.template.item.WeaponType;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
@@ -87,14 +91,14 @@ public class ItemTemplate extends AbstractTemplate<Item> {
protected ItemMaterial material;
public enum ItemMaterial {
COTTON, WOOD, PAPER, FISH, ORIHARUKON, HORN, ADAMANTAITE, CHRYSOLITE, MITHRIL, COBWEB, RUNE_XP, CLOTH, SCALE_OF_DRAGON, BONE, GOLD, LEATHER, FINE_STEEL, SILVER, DYESTUFF, CRYSTAL, RUNE_REMOVE_PENALTY, STEEL, BRONZE, RUNE_SP, LIQUID, BLOOD_STEEL, DAMASCUS;
}
public enum EffectType {
IMMEDIATE;
}
protected ItemType itemType = ItemType.NONE;
protected WeaponType weaponType = WeaponType.NONE;
protected ArmorType armorType = ArmorType.NONE;
@XmlType(namespace = "item")
public static class StatAttribute {
@XmlElement(name = "set")

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.model.template;
import java.util.Collection;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
@@ -28,13 +29,18 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.l2jserver.model.game.Skill;
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.template.npc.NPCRace;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.controller.NPCController;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
import com.l2jserver.util.jaxb.SkillTemplateIDAdapter;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -80,6 +86,8 @@ public class NPCTemplate extends ActorTemplate<NPC> {
@XmlElement(name = "level")
protected int level = 0;
@XmlElement(name = "race")
protected NPCRace race = NPCRace.NONE;
@XmlElement(name = "sex")
protected ActorSex sex = null;
@@ -259,13 +267,26 @@ public class NPCTemplate extends ActorTemplate<NPC> {
protected DropCategory category = null;
public enum DropCategory {
KILL;
DROP, SPOIL, UNK_1, UNK_2, UNK_3, UNK_4, UNK_5, UNK_6, UNK_7, UNK_8, UNK_9, UNK_10, UNK_11, UNK_12, UNK_13, UNK_14, UNK_15, UNK_16, UNK_17, UNK_18, UNK_19, UNK_20, UNK_21, UNK_22, UNK_23, UNK_24, UNK_25, UNK_26, UNK_27, UNK_28, UNK_29, UNK_30, UNK_31, UNK_32, UNK_33, UNK_34, UNK_35, UNK_36, UNK_100, UNK_101, UNK_102, UNK_200;
}
@XmlAttribute(name = "chance")
protected int chance = 0;
}
@XmlElementWrapper(name = "skills")
@XmlElement(name = "skill")
protected List<SkillMetadata> skills = null;
@XmlType(namespace = "npc")
protected static class SkillMetadata {
@XmlAttribute(name = "id")
@XmlJavaTypeAdapter(value = SkillTemplateIDAdapter.class)
protected SkillTemplateID skill = null;
@XmlAttribute(name = "level")
protected int level = 0;
}
@Override
protected NPC createInstance() {
final NPC npc = new NPC(this.id);
@@ -274,6 +295,19 @@ public class NPCTemplate extends ActorTemplate<NPC> {
npc.setHP(getMaximumHP());
npc.setMP(getMaximumMP());
// load skills
final Collection<Skill> skills = CollectionFactory.newSet();
for (final SkillMetadata metadata : this.skills) {
final SkillTemplate template = metadata.skill.getTemplate();
if (template == null)
// FIXME this should thrown an exception!
continue;
final Skill skill = template.create();
skill.setLevel(metadata.level);
skills.add(skill);
}
npc.getSkills().load(skills);
return npc;
}
@@ -333,6 +367,15 @@ public class NPCTemplate extends ActorTemplate<NPC> {
return info.level;
}
/**
* @return the race
*/
public NPCRace getRace() {
if (info == null)
return NPCRace.NONE;
return info.race;
}
/**
* @return the sex
*/

View File

@@ -0,0 +1,26 @@
/*
* 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.item;
/**
* Enum of all available armor types
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum ArmorType {
NONE, LIGHT, HEAVY, MAGIC, SIGILO;
}

View File

@@ -0,0 +1,21 @@
/*
* 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.item;
public enum ItemMaterial {
COTTON, WOOD, PAPER, FISH, ORIHARUKON, HORN, ADAMANTAITE, CHRYSOLITE, MITHRIL, COBWEB, RUNE_XP, CLOTH, SCALE_OF_DRAGON, BONE, GOLD, LEATHER, FINE_STEEL, SILVER, DYESTUFF, CRYSTAL, RUNE_REMOVE_PENALTY, STEEL, BRONZE, RUNE_SP, LIQUID, BLOOD_STEEL, DAMASCUS;
}

View File

@@ -0,0 +1,139 @@
/*
* 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.item;
/**
* Enum for all available item types
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum ItemType {
/**
* No specific item type
*/
NONE(1),
/**
* An arrow for bows
*/
ARROW(2),
/**
* An potion used to regen cp, hp, mp or cure something
*/
POTION(3),
/**
* Enchant scroll for weapons
*/
WEAPON_ENCHANT_SCROLL(4),
/**
* Enchant scroll for armors
*/
ARMOR_ENCHANT_SCROLL(5),
/**
* An all purpose scroll
*/
SCROLL(6),
/**
* An item recipe
*/
RECIPE(7),
/**
* An material used to craft another item
*/
MATERIAL(8),
/**
* Pet collar
*/
PET_COLLAR(9),
/**
* Castle guard?????
*/
CASTLE_GUARD(10),
/**
* An lottery ticket
*/
LOTTERY_TICKET(11),
/**
* An race ticket
*/
RACE_TICKET(12),
/**
* An dye
*/
DYE(13),
/**
* A seed
*/
SEED(14),
/**
* A crop
*/
CROP(15),
/**
* An mature crop
*/
MATURECROP(16),
/**
* An harvest
*/
HARVEST(17),
/**
* An seed
*/
SEED2(18),
/**
* An ticket of lord
*/
TICKET_OF_LORD(19),
/**
* An lure
*/
LURE(20),
/**
* An blessed weapon enchant scroll
*/
BLESSED_WEAPON_ENCHANT_SCROLL(21),
/**
* An blessed armor enchant scroll
*/
BLESSED_ARMOR_ENCHANT_SCROLL(22),
/**
* An coupon
*/
COUPON(23),
/**
* An elixir
*/
ELIXIR(24),
/**
* Scroll used for enchanting attributes
*/
ATTRIBUTE_ENCHANT_SCROLL(25),
/**
* Bolt? unk.
*/
BOLT(26), SCRL_INC_ENCHANT_PROP_WP(27), SCRL_INC_ENCHANT_PROP_AM(28), ANCIENT_CRYSTAL_ENCHANT_WP(
29), ANCIENT_CRYSTAL_ENCHANT_AM(30), RUNE_SELECT(31), RUNE(32);
/**
* The packet id for this item type
*/
public final int id;
ItemType(int id) {
this.id = id;
}
}

View File

@@ -0,0 +1,92 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.world.actor.stat.StatType;
/**
* Enum of all available weapon types
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum WeaponType {
/**
* The Sword weapon type
*/
SWORD(StatType.SWORD_WPN_VULN),
/**
* The blunt weapon type
*/
BLUNT(StatType.BLUNT_WPN_VULN),
/**
* The dagger weapon type
*/
DAGGER(StatType.DAGGER_WPN_VULN),
/**
* The bow weapon type
*/
BOW(StatType.BOW_WPN_VULN),
/**
* The pole weapon type
*/
POLE(StatType.POLE_WPN_VULN),
/**
* An dummy entry for a none-weapon
*/
NONE(StatType.NONE_WPN_VULN),
/**
* The dual sword weapon type
*/
DUAL(StatType.DUAL_WPN_VULN),
/**
* An other type of weapon
*/
ETC(StatType.ETC_WPN_VULN),
/**
* The fist weapon type
*/
FIST(StatType.FIST_WPN_VULN),
/**
* The dual fist weapon type
*/
DUALFIST(StatType.DUALFIST_WPN_VULN),
/**
* The fishing tools
*/
FISHINGROD(null),
/**
* The rapier weapon type
*/
RAPIER(StatType.RAPIER_WPN_VULN),
/**
* The ancient sword type
*/
ANCIENTSWORD(StatType.ANCIENT_WPN_VULN),
/**
* The crossbow type
*/
CROSSBOW(StatType.CROSSBOW_WPN_VULN),
/**
* Unk
*/
FLAG(null),
/**
* Unk
*/
OWNTHING(null),
/**
* The dual dagger weapon type
*/
DUALDAGGER(StatType.DUALDAGGER_WPN_VULN);
/**
* This weapon type weaknesses
*/
public final StatType weaknessesStat;
/**
* @param weaknesses
* the weapon weaknesses
*/
WeaponType(StatType weaknessesStat) {
this.weaknessesStat = weaknessesStat;
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.npc;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum NPCRace {
// character races
HUMAN, ELVEN, DARKELVEN, ORC, DWARVEN, KAMAEL,
// npc exclusive
UNDEAD, MAGIC_CREATURE, BEAST, ANIMAL, PLANT, HUMANOID, SPIRIT,
ANGEL, DEMON, DRAGON, GIANT, BUG, FAIRIE, OTHER, NON_LIVING,
SIEGE_WEAPON, DEFENDING_ARMY, MERCENARIE, UNKNOWN, NONE;
}

View File

@@ -31,45 +31,6 @@ import com.l2jserver.model.world.actor.stat.ActorStats;
public abstract class Actor extends PositionableObject {
protected ActorTemplateID<?> templateID;
/**
* The actor race
*/
protected ActorRace race;
/**
* Represents the actor race.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum ActorRace {
HUMAN(0x00), ELF(0x01), DARK_ELF(0x02), ORC(0x03), DWARF(0x04), KAMAEL(
0x05);
/**
* The numeric ID representing this race
*/
public final int id;
ActorRace(int id) {
this.id = id;
}
/**
* Finds the race based on the <tt>id</tt>
*
* @param id
* the id
* @return the race constant
*/
public static ActorRace fromOption(int id) {
for (final ActorRace race : values()) {
if (race.id == id)
return race;
}
return null;
}
}
/**
* The actor sex
*/
@@ -169,22 +130,6 @@ public abstract class Actor extends PositionableObject {
public abstract ActorStats<?> getStats();
/**
* @return the race
*/
public ActorRace getRace() {
return race;
}
/**
* @param race
* the race to set
*/
public void setRace(ActorRace race) {
desireUpdate();
this.race = race;
}
/**
* @return the sex
*/

View File

@@ -52,6 +52,45 @@ public class L2Character extends Player {
*/
private PetID petID;
/**
* The character race
*/
protected CharacterRace race;
/**
* Represents the character race.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum CharacterRace {
HUMAN(0x00), ELF(0x01), DARK_ELF(0x02), ORC(0x03), DWARF(0x04), KAMAEL(
0x05);
/**
* The numeric ID representing this race
*/
public final int id;
CharacterRace(int id) {
this.id = id;
}
/**
* Finds the race based on the <tt>id</tt>
*
* @param id
* the id
* @return the race constant
*/
public static CharacterRace fromOption(int id) {
for (final CharacterRace race : values()) {
if (race.id == id)
return race;
}
return null;
}
}
/**
* This character's inventory
*/
@@ -224,6 +263,22 @@ public class L2Character extends Player {
desireUpdate();
this.petID = petID;
}
/**
* @return the race
*/
public CharacterRace getRace() {
return race;
}
/**
* @param race
* the race to set
*/
public void setRace(CharacterRace race) {
desireUpdate();
this.race = race;
}
/**
* @return the name

View File

@@ -16,7 +16,7 @@
*/
package com.l2jserver.model.world.character;
import com.l2jserver.model.world.Actor.ActorRace;
import com.l2jserver.model.world.L2Character.CharacterRace;
/**
* Defines all the possible classes for an character
@@ -27,7 +27,7 @@ public enum CharacterClass {
/**
* Human fighter
*/
HUMAN_FIGHTER(0x00, ClassType.FIGHTER, ActorRace.HUMAN), WARRIOR(0x01,
HUMAN_FIGHTER(0x00, ClassType.FIGHTER, CharacterRace.HUMAN), WARRIOR(0x01,
HUMAN_FIGHTER), GLADIATOR(0x02, WARRIOR), WARLORD(0x03, WARRIOR), KNIGHT(
0x04, HUMAN_FIGHTER), PALADIN(0x05, KNIGHT), DARK_AVENGER(0x06,
KNIGHT), ROGUE(0x07, HUMAN_FIGHTER), TREASURE_HUNTER(0x08, ROGUE), HAWKEYE(
@@ -38,7 +38,7 @@ public enum CharacterClass {
/**
* Human mystic
*/
HUMAN_MYSTIC(0x0a, ClassType.MYSTIC, ActorRace.HUMAN), WIZARD(0x0b,
HUMAN_MYSTIC(0x0a, ClassType.MYSTIC, CharacterRace.HUMAN), WIZARD(0x0b,
HUMAN_MYSTIC), SORCEROR(0x0c, WIZARD), NECROMANCER(0x0d, WIZARD), WARLOCK(
0x0e, true, WIZARD), CLERIC(0x0f, ClassType.PRIEST, HUMAN_MYSTIC), BISHOP(
0x10, CLERIC), PROPHET(0x11, CLERIC), ARCHMAGE(0x5e, SORCEROR), SOULTAKER(
@@ -48,7 +48,7 @@ public enum CharacterClass {
/**
* Elven fighter
*/
ELVEN_FIGHTER(0x12, ClassType.FIGHTER, ActorRace.ELF), ELVEN_KNIGHT(0x13,
ELVEN_FIGHTER(0x12, ClassType.FIGHTER, CharacterRace.ELF), ELVEN_KNIGHT(0x13,
ELVEN_FIGHTER), TEMPLE_KNIGHT(0x14, ELVEN_KNIGHT), SWORD_SINGER(
0x15, ELVEN_KNIGHT), ELVEN_SCOUT(0x16, ELVEN_FIGHTER), PLAINS_WALKER(
0x17, ELVEN_SCOUT), SILVER_RANGER(0x18, ELVEN_SCOUT), EVA_TEMPLAR(
@@ -57,7 +57,7 @@ public enum CharacterClass {
/**
* Elven mystic
*/
ELVEN_MYSTIC(0x19, ClassType.MYSTIC, ActorRace.ELF), ELVEN_WIZARD(0x1a,
ELVEN_MYSTIC(0x19, ClassType.MYSTIC, CharacterRace.ELF), ELVEN_WIZARD(0x1a,
ELVEN_MYSTIC), SPELLSINGER(0x1b, ELVEN_WIZARD), ELEMENTAL_SUMMONER(
0x1c, true, ELVEN_WIZARD), ORACLE(0x1d, ClassType.PRIEST,
ELVEN_MYSTIC), ELDER(0x1e, ORACLE), MYSTIC_MUSE(0x67, SPELLSINGER), ELEMENTAL_MASTER(
@@ -66,7 +66,7 @@ public enum CharacterClass {
/**
* Dark elf fighter
*/
DARK_FIGHTER(0x1f, ClassType.FIGHTER, ActorRace.DARK_ELF), PALUS_KNIGHT(
DARK_FIGHTER(0x1f, ClassType.FIGHTER, CharacterRace.DARK_ELF), PALUS_KNIGHT(
0x20, DARK_FIGHTER), SHILLIEN_KNIGHT(0x21, PALUS_KNIGHT), BLADEDANCER(
0x22, PALUS_KNIGHT), ASSASSIN(0x23, DARK_FIGHTER), ABYSS_WALKER(
0x24, ASSASSIN), PHANTOM_RANGER(0x25, ASSASSIN), SHILLIEN_TEMPLAR(
@@ -76,7 +76,7 @@ public enum CharacterClass {
/**
* Dark elf mystic
*/
DARK_MYSTIC(0x26, ClassType.MYSTIC, ActorRace.DARK_ELF), DARK_WIZARD(0x27,
DARK_MYSTIC(0x26, ClassType.MYSTIC, CharacterRace.DARK_ELF), DARK_WIZARD(0x27,
DARK_MYSTIC), SPELLHOWLER(0x28, DARK_WIZARD), PHANTOM_SUMMONER(
0x29, true, DARK_WIZARD), SHILLIEN_ORACLE(0x2a, ClassType.PRIEST,
DARK_MYSTIC), SHILLIEN_ELDER(0x2b, SHILLIEN_ORACLE), STORM_SCREAMER(
@@ -86,7 +86,7 @@ public enum CharacterClass {
/**
* Orc fighter
*/
ORC_FIGHTER(0x2c, ClassType.FIGHTER, ActorRace.ORC), ORC_RAIDER(0x2d,
ORC_FIGHTER(0x2c, ClassType.FIGHTER, CharacterRace.ORC), ORC_RAIDER(0x2d,
ORC_FIGHTER), DESTROYER(0x2e, ORC_RAIDER), ORC_MONK(0x2f,
ORC_FIGHTER), TYRANT(0x30, ORC_RAIDER), TITAN(0x71, DESTROYER), GRAND_KHAUATARI(
0x72, TYRANT),
@@ -94,7 +94,7 @@ public enum CharacterClass {
/**
* Orc mystic
*/
ORC_MYSTIC(0x31, ClassType.FIGHTER, ActorRace.ORC), ORC_SHAMAN(0x32,
ORC_MYSTIC(0x31, ClassType.FIGHTER, CharacterRace.ORC), ORC_SHAMAN(0x32,
ClassType.MYSTIC, ORC_MYSTIC), OVERLORD(0x33, ORC_SHAMAN), WARCRYER(
0x34, ORC_SHAMAN), DOMINATOR(0x73, OVERLORD), DOOMCRYER(0x74,
WARCRYER),
@@ -102,7 +102,7 @@ public enum CharacterClass {
/**
* Dwarf fighter
*/
DWARVEN_FIGHTER(0x35, ClassType.FIGHTER, ActorRace.DWARF), SCAVENGER(0x36,
DWARVEN_FIGHTER(0x35, ClassType.FIGHTER, CharacterRace.DWARF), SCAVENGER(0x36,
DWARVEN_FIGHTER), BOUNTY_HUNTER(0x37, SCAVENGER), ARTISAN(0x38,
DWARVEN_FIGHTER), WARSMITH(0x39, ARTISAN), FORTUNE_SEEKER(0x75,
BOUNTY_HUNTER), MAESTRO(0x76, WARSMITH),
@@ -110,7 +110,7 @@ public enum CharacterClass {
/**
* Kamael male soldier
*/
MALE_SOLDIER(0x7b, ClassType.FIGHTER, ActorRace.KAMAEL), TROOPER(0x7D,
MALE_SOLDIER(0x7b, ClassType.FIGHTER, CharacterRace.KAMAEL), TROOPER(0x7D,
MALE_SOLDIER), BERSEKER(0x7F, TROOPER), MALE_SOULBREAKER(0x80,
TROOPER), DOOMBRINGER(0x83, BERSEKER), MALE_SOULDHOUND(0x84,
MALE_SOULBREAKER),
@@ -118,7 +118,7 @@ public enum CharacterClass {
/**
* Kamael female soldier
*/
FEMALE_SOLDIER(0x7C, ClassType.FIGHTER, ActorRace.KAMAEL), WARDER(0x7E,
FEMALE_SOLDIER(0x7C, ClassType.FIGHTER, CharacterRace.KAMAEL), WARDER(0x7E,
FEMALE_SOLDIER), FEMALE_SOULBREAKER(0x81, WARDER), ARBALESTER(0x82,
WARDER), FEMALE_SOULDHOUND(0x85, FEMALE_SOULBREAKER), TRICKSTER(
0x86, ARBALESTER), INSPECTOR(0x87, WARDER), JUDICATOR(0x88,
@@ -164,7 +164,7 @@ public enum CharacterClass {
/**
* The class race
*/
public final ActorRace race;
public final CharacterRace race;
/**
* The parent class
*/
@@ -185,7 +185,7 @@ public enum CharacterClass {
* the parent
*/
private CharacterClass(int id, ClassType type, boolean summoner,
ActorRace race, CharacterClass parent) {
CharacterRace race, CharacterClass parent) {
this.id = id;
this.type = type;
this.summoner = summoner;
@@ -232,7 +232,7 @@ public enum CharacterClass {
* @param parent
* the parent class
*/
private CharacterClass(int id, ActorRace race, CharacterClass parent) {
private CharacterClass(int id, CharacterRace race, CharacterClass parent) {
this(id, parent.type, parent.summoner, race, parent);
}
@@ -247,7 +247,7 @@ public enum CharacterClass {
* @param race
* the class race
*/
private CharacterClass(int id, ClassType type, ActorRace race) {
private CharacterClass(int id, ClassType type, CharacterRace race) {
this(id, type, false, race, null);
}

View File

@@ -0,0 +1,49 @@
/*
* 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.service.game;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
/**
* This service handles lottery. Bets and results are done trough this service.
* Please note that implementations can be complete random or they can use an
* algorithm that manipulate results so that an character is more likely to win.
* Even if the algorithm is manipulating results, it should not try to
* discriminate players and chances of winning must be equal per ticket.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface LotteryService extends Service {
/**
* Bets an certain number sequence.
*
* @param character
* the character betting
* @param n1
* the first number
* @param n2
* the second number
* @param n3
* the third number
* @param n4
* the fourth number
* @param n5
* the fifth number
*/
void bet(L2Character character, int n1, int n2, int n3, int n4, int n5);
}

View File

@@ -87,17 +87,23 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
throws SpawnPointNotFoundServiceException,
AlreadySpawnedServiceException {
Preconditions.checkNotNull(object, "object");
// only set the new position if needed, this could cause a lot of
// database updates if update is done unnecessarily
boolean updatePoint = true;
// sanitize
if (point == null)
if (point == null) {
// retrieving stored point
point = object.getPoint();
updatePoint = false;
}
if (point == null) {
// not point send and no point stored, aborting
// not point in argument and no point stored, aborting
throw new SpawnPointNotFoundServiceException();
}
// set the spawning point
object.setPoint(point);
if (updatePoint)
object.setPoint(point);
// reset actor state
if (object instanceof Actor) {
((Actor) object).setState(null);

View File

@@ -53,6 +53,7 @@ import com.l2jserver.service.core.vfs.VFSService;
import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
import com.l2jserver.util.jaxb.SkillTemplateIDAdapter;
import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
import com.l2jserver.util.vfs.ExtensionFileSelector;
@@ -68,6 +69,7 @@ public class XMLTemplateService extends AbstractService implements
private final XMLTemplateServiceConfiguration config;
private final NPCTemplateIDAdapter npcTemplateIdAdapter;
private final ItemTemplateIDAdapter itemTemplateIdAdapter;
private final SkillTemplateIDAdapter skillTemplateIdAdapter;
private final CharacterTemplateIDAdapter charIdTemplateAdapter;
private final TeleportationTemplateIDAdapter teleportationIdTemplateAdapter;
@@ -82,6 +84,7 @@ public class XMLTemplateService extends AbstractService implements
CacheService cacheService, ConfigurationService configService,
NPCTemplateIDAdapter npcTemplateIdAdapter,
ItemTemplateIDAdapter itemTemplateIdAdapter,
SkillTemplateIDAdapter skillTemplateIdAdapter,
CharacterTemplateIDAdapter charIdTemplateAdapter,
TeleportationTemplateIDAdapter teleportationIdTemplateAdapter) {
this.vfsService = vfsService;
@@ -89,6 +92,7 @@ public class XMLTemplateService extends AbstractService implements
this.config = configService.get(XMLTemplateServiceConfiguration.class);
this.npcTemplateIdAdapter = npcTemplateIdAdapter;
this.itemTemplateIdAdapter = itemTemplateIdAdapter;
this.skillTemplateIdAdapter = skillTemplateIdAdapter;
this.charIdTemplateAdapter = charIdTemplateAdapter;
this.teleportationIdTemplateAdapter = teleportationIdTemplateAdapter;
}
@@ -109,6 +113,8 @@ public class XMLTemplateService extends AbstractService implements
npcTemplateIdAdapter);
unmarshaller.setAdapter(ItemTemplateIDAdapter.class,
itemTemplateIdAdapter);
unmarshaller.setAdapter(SkillTemplateIDAdapter.class,
skillTemplateIdAdapter);
unmarshaller.setAdapter(CharacterTemplateIDAdapter.class,
charIdTemplateAdapter);
unmarshaller.setAdapter(TeleportationTemplateIDAdapter.class,

View File

@@ -0,0 +1,58 @@
/*
* 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.util.jaxb;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import com.google.inject.Inject;
import com.l2jserver.model.id.template.SkillTemplateID;
import com.l2jserver.model.id.template.provider.SkillTemplateIDProvider;
/**
* This class is an JAXB Adapter for {@link SkillTemplateIDProvider}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SkillTemplateIDAdapter extends
XmlAdapter<Integer, SkillTemplateID> {
private final SkillTemplateIDProvider provider;
public SkillTemplateIDAdapter() {
provider = null;
}
@Inject
public SkillTemplateIDAdapter(SkillTemplateIDProvider provider) {
this.provider = provider;
}
@Override
public SkillTemplateID unmarshal(Integer v) throws Exception {
if (v == 0)
return null;
if (provider == null)
return new SkillTemplateID(v, null);
return provider.createID(v);
}
@Override
public Integer marshal(SkillTemplateID v) throws Exception {
if (v == null)
return 0;
return v.getID();
}
}

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