1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 08:52:51 +00:00

Character calculators

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-23 23:49:19 -03:00
parent 1909bb06cc
commit a1b1211616
206 changed files with 4749 additions and 1170 deletions

View File

@@ -138,21 +138,22 @@ public class CharacterInformationBroadcastPacket extends AbstractServerPacket {
// end of t1 new h's
buffer.writeInt(0x00); // pvp flag
buffer.writeInt(0x00); // karma
buffer.writeInt(character.getKarma()); // karma
buffer.writeInt(character.getAttributes().getCastSpeed());
buffer.writeInt(character.getAttributes().getAttackSpeed());
buffer.writeInt(character.getStats().getMagicalAttackSpeed());
buffer.writeInt(character.getStats().getPhysicalAttackSpeed());
buffer.writeInt(0x00); // unk
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
// FIXME half of those are walk speed
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeDouble(0x01); // move speed multiplier
buffer.writeDouble(0x01); // attack speed multiplier
@@ -171,7 +172,7 @@ public class CharacterInformationBroadcastPacket extends AbstractServerPacket {
buffer.writeInt(character.getAppearance().getHairColor().option);
buffer.writeInt(character.getAppearance().getFace().option);
BufferUtils.writeString(buffer, "TODO"); // TODO title
BufferUtils.writeString(buffer, character.getTitle());
// dont send those 4 if using cursed weapon
buffer.writeInt(0); // clan id
@@ -182,11 +183,12 @@ public class CharacterInformationBroadcastPacket extends AbstractServerPacket {
buffer.writeByte(0x01); // sitting
buffer.writeByte((character.getMoveType() == CharacterMoveType.RUN ? 0x01
: 0x00));
buffer.writeByte(0x00); // is in combat
buffer.writeByte((character.isAttacking() ? 0x01 : 0x00)); // is in
// combat
buffer.writeByte(0x00); // alike dead
buffer.writeByte(0x00); // invisible = 1 visible =0
buffer.writeByte((character.getAppearance().isVisible() ? 0x00 : 0x01));
// 1-on Strider, 2-on Wyvern,
// 3-on Great Wolf, 0-no mount
@@ -233,7 +235,6 @@ public class CharacterInformationBroadcastPacket extends AbstractServerPacket {
buffer.writeInt(character.getAppearance().getTitleColor().toInteger());
buffer.writeInt(0x00); // cursed weapon id
buffer.writeInt(0x00); // clan reputation
// T1

View File

@@ -46,9 +46,9 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.actor.ActorExperience;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.util.BufferUtils;
@@ -89,17 +89,17 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeInt(character.getLevel());
buffer.writeLong(ActorExperience.LEVEL_1.experience);
buffer.writeInt(character.getAttributes().getStrength());
buffer.writeInt(character.getAttributes().getDexterity());
buffer.writeInt(character.getAttributes().getConcentration());
buffer.writeInt(character.getAttributes().getIntelligence());
buffer.writeInt(character.getAttributes().getWitness());
buffer.writeInt(character.getAttributes().getMentality());
buffer.writeInt(200); // max hp
buffer.writeInt(character.getHP()); // cur hp
buffer.writeInt(200); // max mp
buffer.writeInt((int) 200); // cur mp
buffer.writeInt(0); // sp
buffer.writeInt(character.getStats().getStrength());
buffer.writeInt(character.getStats().getDexterity());
buffer.writeInt(character.getStats().getConcentration());
buffer.writeInt(character.getStats().getIntelligence());
buffer.writeInt(character.getStats().getWitness());
buffer.writeInt(character.getStats().getMentality());
buffer.writeInt(character.getStats().getMaxHP()); // max hp
buffer.writeInt((int) character.getHP()); // cur hp
buffer.writeInt(character.getStats().getMaxMP()); // max mp
buffer.writeInt((int) character.getMP()); // cur mp
buffer.writeInt(character.getSP()); // sp
buffer.writeInt(0); // load
buffer.writeInt(character.getAttributes().getMaxWeigth()); // max load
@@ -189,26 +189,26 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeInt(0x00); // (max?) talismans count
buffer.writeInt(0x00); // cloak sratus
buffer.writeInt((int) character.getAttributes().getPhysicalAttack());
buffer.writeInt(character.getAttributes().getAttackSpeed());
buffer.writeInt((int) character.getAttributes().getPhysicalDefense());
buffer.writeInt(character.getStats().getPhysicalAttack());
buffer.writeInt(character.getStats().getPhysicalAttackSpeed());
buffer.writeInt(character.getStats().getPhysicalDefense());
buffer.writeInt(character.getAttributes().getEvasionChance()); // evasion
buffer.writeInt(character.getAttributes().getAccuracy());
buffer.writeInt(character.getAttributes().getCriticalChance());
buffer.writeInt(character.getStats().getEvasionRate()); // evasion
buffer.writeInt(character.getStats().getAccuracy());
buffer.writeInt(character.getStats().getPhysicalCriticalRate());
buffer.writeInt((int) character.getAttributes().getMagicalAttack());
buffer.writeInt(character.getAttributes().getCastSpeed());
buffer.writeInt(character.getAttributes().getAttackSpeed());
buffer.writeInt((int) character.getAttributes().getMagicalDefense());
buffer.writeInt(character.getStats().getMagicalAttack());
buffer.writeInt(character.getStats().getMagicalAttackSpeed());
buffer.writeInt(character.getStats().getPhysicalAttackSpeed());
buffer.writeInt(character.getStats().getMagicalDefense());
buffer.writeInt(0x00); // 0-non-pvp 1-pvp = violett name
buffer.writeInt(0x00); // karma
buffer.writeInt(character.getKarma()); // karma
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getWalkSpeed());
buffer.writeInt((int) character.getAttributes().getRunSpeed());
buffer.writeInt((int) character.getAttributes().getWalkSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getWalkSpeed());
buffer.writeInt((int) character.getStats().getRunSpeed());
buffer.writeInt((int) character.getStats().getWalkSpeed());
buffer.writeInt(0); // unk
buffer.writeInt(0); // unk
buffer.writeInt(0); // fly speed -only if flying
@@ -243,8 +243,7 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeInt(character.getAppearance().getFace().option);
buffer.writeInt(0x01); // is gm
String title = "Testing"; // title
BufferUtils.writeString(buffer, title);
BufferUtils.writeString(buffer, character.getTitle());
buffer.writeInt((character.getClanID() != null ? character.getClanID()
.getID() : 0x00)); // clanid
@@ -258,8 +257,8 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeByte(0x00); // mount type
buffer.writeByte(0x00); // private store type
buffer.writeByte(0x00); // dwarven craft
buffer.writeInt(0x00); // pk kills
buffer.writeInt(0x00); // pvp kills
buffer.writeInt(character.getPkKills()); // pk kills
buffer.writeInt(character.getPvpKills()); // pvp kills
buffer.writeShort(0x00); // cubics size
// short:cubicsid[cubicssize]
@@ -279,8 +278,8 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeInt(character.getCharacterClass().id);
buffer.writeInt(0x00); // special effects? circles around player...
buffer.writeInt(200); // max cp
buffer.writeInt(200); // cur cp
buffer.writeInt(character.getStats().getMaxCP());
buffer.writeInt((int) character.getCP()); // cur cp
buffer.writeByte(0x00); // is mount or is airshilhelp = 0; otherwise
// enchant effect (minimum 127)

View File

@@ -128,16 +128,16 @@ public class CharacterSelectionListPacket extends AbstractServerPacket {
buffer.writeInt(character.getPoint().getY()); // y
buffer.writeInt(character.getPoint().getZ()); // z
buffer.writeDouble(20); // hp cur
buffer.writeDouble(20); // mp cur
buffer.writeDouble(character.getHP()); // hp cur
buffer.writeDouble(character.getMP()); // mp cur
buffer.writeInt(320); // sp
buffer.writeLong(4640); // exp
buffer.writeInt(5); // level
buffer.writeInt(character.getSP()); // sp
buffer.writeLong(character.getExperience()); // exp
buffer.writeInt(character.getLevel()); // level
buffer.writeInt(0x00); // karma
buffer.writeInt(0x00); // pk
buffer.writeInt(0x00); // pvp
buffer.writeInt(character.getKarma()); // karma
buffer.writeInt(character.getPkKills()); // pk
buffer.writeInt(character.getPvpKills()); // pvp
for (int n = 0; n < 7; n++) {
buffer.writeInt(0x00); // unk
@@ -184,8 +184,8 @@ public class CharacterSelectionListPacket extends AbstractServerPacket {
// face
buffer.writeInt(character.getAppearance().getFace().option);
buffer.writeDouble(30); // hp max
buffer.writeDouble(30); // mp max
buffer.writeDouble(character.getStats().getMaxHP()); // hp max
buffer.writeDouble(character.getStats().getMaxMP()); // mp max
buffer.writeInt(0x0); // seconds left before delete
buffer.writeInt(character.getCharacterClass().id); // class

View File

@@ -59,7 +59,7 @@ public class ServerObjectPacket extends AbstractServerPacket {
buffer.writeDouble(template.getAttackSpeedMultiplier());
buffer.writeDouble(template.getCollisionRadius()); // coll radius
buffer.writeDouble(template.getCollisionHeight()); // coll height
buffer.writeInt((template.isAttackable() ? npc.getHP() : 0x00));
buffer.writeInt((int) (template.isAttackable() ? npc.getHP() : 0x00));
buffer.writeInt((int) (template.isAttackable() ? template.getMaxHP()
: 0x00));
buffer.writeInt(0x01); // object type

View File

@@ -19,8 +19,9 @@ package com.l2jserver.model.id.compound;
import com.l2jserver.model.id.ID;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
* The compound {@link ID} is composed of two IDs.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AbstractCompoundID<T1, T2> extends ID<AbstractCompoundID<T1, T2>> {
/**
@@ -33,8 +34,12 @@ public class AbstractCompoundID<T1, T2> extends ID<AbstractCompoundID<T1, T2>> {
private final T2 id2;
/**
* Creates a new compound ID
*
* @param id1
* the first id
* @param id2
* the second id
*/
protected AbstractCompoundID(T1 id1, T2 id2) {
super(null);

View File

@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.model.id.template.ActorTemplateID;
import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.ActorAttributes;
import com.l2jserver.model.world.actor.stat.Stats;
/**
* Template for {@link Actor}
@@ -72,6 +73,8 @@ public abstract class ActorTemplate<T extends Actor> extends
}
protected abstract T createInstance();
public abstract Stats getTemplateStat();
/**
* @return the baseAttributes
@@ -488,5 +491,4 @@ public abstract class ActorTemplate<T extends Actor> extends
return craft;
}
}
}

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.template;
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.actor.stat.Stats;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.util.dimensional.Point;
@@ -37,6 +38,20 @@ public abstract class CharacterTemplate extends ActorTemplate<L2Character> {
*/
protected final Point spawnLocation;
protected double hpBase;
protected double hpAdd;
protected double hpMultiplier;
protected double mpBase;
protected double mpAdd;
protected double mpMultiplier;
protected double cpBase;
protected double cpAdd;
protected double cpMultiplier;
protected int minimumLevel;
protected Integer attackDamage = null;
protected AttackType attackType;
@@ -70,7 +85,7 @@ public abstract class CharacterTemplate extends ActorTemplate<L2Character> {
@Override
public L2Character createInstance() {
final L2Character character = new L2Character(this.getID(), attributes);
final L2Character character = new L2Character(this.getID());
character.setRace(getRace());
character.setCharacterClass(characterClass);
@@ -79,6 +94,11 @@ public abstract class CharacterTemplate extends ActorTemplate<L2Character> {
return character;
}
@Override
public Stats getTemplateStat() {
return null;
}
/**
* @return the race
*/
@@ -100,6 +120,90 @@ public abstract class CharacterTemplate extends ActorTemplate<L2Character> {
return spawnLocation;
}
/**
* @return the hpBase
*/
public double getHpBase() {
return hpBase;
}
/**
* @return the hpAdd
*/
public double getHpAdd() {
return hpAdd;
}
/**
* @return the hpMultiplier
*/
public double getHpMultiplier() {
return hpMultiplier;
}
/**
* @return the mpBase
*/
public double getMpBase() {
return mpBase;
}
/**
* @return the mpAdd
*/
public double getMpAdd() {
return mpAdd;
}
/**
* @return the mpMultiplier
*/
public double getMpMultiplier() {
return mpMultiplier;
}
/**
* @return the cpBase
*/
public double getCpBase() {
return cpBase;
}
/**
* @return the cpAdd
*/
public double getCpAdd() {
return cpAdd;
}
/**
* @return the cpMultiplier
*/
public double getCpMultiplier() {
return cpMultiplier;
}
/**
* @return the minimumLevel
*/
public int getMinimumLevel() {
return minimumLevel;
}
/**
* @return the attackDamage
*/
public Integer getAttackDamage() {
return attackDamage;
}
/**
* @return the attackType
*/
public AttackType getAttackType() {
return attackType;
}
/**
* @return the male collision radius
*/

View File

@@ -28,6 +28,7 @@ import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.Actor.ActorSex;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.actor.stat.Stats;
import com.l2jserver.service.game.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.network.NetworkService;
@@ -57,6 +58,8 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> implements
*/
@Inject
protected ItemTemplateIDProvider itemTemplateIdProvider;
protected Stats stats;
/**
* The NPC name
@@ -118,7 +121,7 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> implements
/**
* The NPC sp
*/
protected long sp;
protected int sp;
/**
* The NPC agressive state
@@ -228,11 +231,20 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> implements
public void receiveAttack(NPC npc, Calculator calculator, Actor attacker) {
// TODO add attributes to calculator!
}
@Override
public NPC createInstance() {
return new NPC(this.getID());
}
@Override
public Stats getTemplateStat() {
return null;
}
/**
* @return the name
@@ -328,7 +340,7 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> implements
/**
* @return the sp
*/
public long getSp() {
public int getSp() {
return sp;
}

View File

@@ -16,21 +16,14 @@
*/
package com.l2jserver.model.template.item;
import java.util.Map;
import java.util.Map.Entry;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.actor.stat.Stats;
import com.l2jserver.model.world.actor.stat.Stats.StatType;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.calculator.DivisionFunction;
import com.l2jserver.util.calculator.Function;
import com.l2jserver.util.calculator.MultiplicationFunction;
import com.l2jserver.util.calculator.SetFunction;
import com.l2jserver.util.calculator.SubtractFunction;
import com.l2jserver.util.calculator.SumFunction;
import com.l2jserver.util.factory.CollectionFactory;
/**
* Template for Weapon {@link Item}
@@ -59,7 +52,7 @@ public abstract class WeaponTemplate extends ItemTemplate {
/**
* The weapon's attributes
*/
protected final WeaponAttribute attribute = new WeaponAttribute();
protected final Stats stats = new Stats();
/**
* This weapon random damage
@@ -130,145 +123,8 @@ public abstract class WeaponTemplate extends ItemTemplate {
* @param calc
* the calculator
*/
public void calculator(WeaponAttributeType type, Calculator calc) {
attribute.calculator(type, calc);
}
/**
* Attribute types for weapons
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum WeaponAttributeType {
PHYSICAL_ATTACK, MAGICAL_ATTACK, R_CRITICAL, PHYSICAL_ATTACK_SPEED;
}
/**
* This class handles the Weapon attributes an can add operations to the
* calculator
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class WeaponAttribute {
private final Map<WeaponAttributeType, Map<Integer, Function<Double>>> operations = CollectionFactory
.newMap();
/**
* Sets the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to set
*/
public void set(WeaponAttributeType type, int order, double value) {
getMap(type).put(order, new SetFunction(value));
}
/**
* Adds <tt>value</tt> to the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be summed
*/
public void add(WeaponAttributeType type, int order, double value) {
getMap(type).put(order, new SumFunction(value));
}
/**
* Subtracts <tt>value</tt> from the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be subtracted
*/
public void sub(WeaponAttributeType type, int order, double value) {
getMap(type).put(order, new SubtractFunction(value));
}
/**
* Multiply <tt>value</tt> the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be multiplied
*/
public void mult(WeaponAttributeType type, int order, double value) {
getMap(type).put(order, new MultiplicationFunction(value));
}
/**
* Divides by <tt>value</tt> the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be divided by
*/
public void div(WeaponAttributeType type, int order, double value) {
getMap(type).put(order, new DivisionFunction(value));
}
/**
* Performs an enchant operation. Note that this is not implemented yet!
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* TODO
*/
public void enchant(WeaponAttributeType type, int order, double value) {
// TODO enchant operation for weapon
}
/**
* Returns the Order-Operation map for <tt>type</tt>
*
* @param type
* the type
* @return the order-operation map
*/
private Map<Integer, Function<Double>> getMap(WeaponAttributeType type) {
Map<Integer, Function<Double>> map = operations.get(type);
if (map == null) {
map = CollectionFactory.newMap();
operations.put(type, map);
}
return map;
}
/**
* Creates the calculator object for this weapon
*
* @param type
* the type
* @param calculator
* the calculator
*/
private void calculator(WeaponAttributeType type, Calculator calculator) {
final Map<Integer, Function<Double>> operations = this.operations
.get(type);
for (final Entry<Integer, Function<Double>> entry : operations
.entrySet()) {
calculator.add(entry.getKey(), entry.getValue());
}
}
public void calculator(StatType type, Calculator calc) {
stats.calculator(type, calc);
}
/**
@@ -409,7 +265,7 @@ public abstract class WeaponTemplate extends ItemTemplate {
/**
* @return the attribute
*/
public WeaponAttribute getAttribute() {
return attribute;
public Stats getAttribute() {
return stats;
}
}

View File

@@ -105,11 +105,21 @@ public abstract class Actor extends PositionableObject {
/**
* The actor HP
*/
protected int hp;
protected double HP;
/**
* The actor MP
*/
protected int mp;
protected double MP;
/**
* The actor experience points
*/
protected long experience;
/**
* The actor sp points
*/
protected int sp;
/**
* The currently effects active on the actor
*/
@@ -119,33 +129,10 @@ public abstract class Actor extends PositionableObject {
*/
protected final ActorSkillContainer skills = new ActorSkillContainer(this);
public Actor(ActorTemplateID<?> templateID) {
protected Actor(ActorTemplateID<?> templateID) {
this.templateID = templateID;
}
public int getHP() {
return hp;
}
public void setHP(int hp) {
this.hp = hp;
}
/**
* @return the mp
*/
public int getMP() {
return mp;
}
/**
* @param mp
* the mp to set
*/
public void setMP(int mp) {
this.mp = mp;
}
/**
* @return the race
*/
@@ -176,14 +163,81 @@ public abstract class Actor extends PositionableObject {
this.sex = sex;
}
/**
* @return the level
*/
public int getLevel() {
return level;
}
/**
* @param level
* the level to set
*/
public void setLevel(int level) {
this.level = level;
}
/**
* @return the hP
*/
public double getHP() {
return HP;
}
/**
* @param hP
* the hP to set
*/
public void setHP(double hP) {
HP = hP;
}
/**
* @return the mP
*/
public double getMP() {
return MP;
}
/**
* @param mP
* the mP to set
*/
public void setMP(double mP) {
MP = mP;
}
/**
* @return the experience
*/
public long getExperience() {
return experience;
}
/**
* @param experience
* the experience to set
*/
public void setExperience(long experience) {
this.experience = experience;
}
/**
* @return the sp
*/
public int getSP() {
return sp;
}
/**
* @param sp
* the sp to set
*/
public void setSP(int sp) {
this.sp = sp;
}
/**
* @return the active effects on this actor
*/

View File

@@ -32,6 +32,7 @@ import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.model.world.character.CharacterFriendList;
import com.l2jserver.model.world.character.CharacterInventory;
import com.l2jserver.model.world.character.CharacterShortcutContainer;
import com.l2jserver.model.world.character.CharacterStats;
import com.l2jserver.util.dimensional.Point;
/**
@@ -83,10 +84,20 @@ public class L2Character extends Player {
* The character name
*/
private String name;
/**
* The character title. Can be null.
*/
private String title;
/**
* The class of the character
*/
private CharacterClass characterClass;
/**
* The character CP
*/
private double CP;
/**
* The character's status
*/
@@ -96,6 +107,24 @@ public class L2Character extends Player {
*/
private Date lastAccess;
/**
* The character stat
*/
private final CharacterStats stats = new CharacterStats(this);
/**
* The character karma points
*/
private int karma;
/**
* The character PK kills
*/
private int pkKills;
/**
* The character PVP kills
*/
private int pvpKills;
// ////////////////////////////////////
// / RUNTIME
// ////////////////////////////////////
@@ -136,7 +165,26 @@ public class L2Character extends Player {
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum CharacterState {
TELEPORTING, CASTING, ATTACKING, MOVING;
/**
* This state indicates the character is being teleported
*/
TELEPORTING,
/**
* This state indicates the character is casting a skill
*/
CASTING,
/**
* This state indicates the character is attacking
*/
ATTACKING,
/**
* This state indicates the character is moving
*/
MOVING,
/**
* This state indicates the character is dead
*/
DEAD;
}
/**
@@ -150,10 +198,9 @@ public class L2Character extends Player {
* @param baseAttributes
* the base attribute for this character
*/
public L2Character(CharacterTemplateID templateID,
CharacterTemplate.ActorBaseAttributes baseAttributes) {
public L2Character(CharacterTemplateID templateID) {
super(templateID);
this.baseAttributes = baseAttributes;
this.baseAttributes = templateID.getTemplate().getBaseAttributes();
this.attributes = new CharacterCalculatedAttributes(this);
}
@@ -235,6 +282,21 @@ public class L2Character extends Player {
this.name = name;
}
/**
* @return the title
*/
public String getTitle() {
return title;
}
/**
* @param title
* the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the characterClass
*/
@@ -250,6 +312,21 @@ public class L2Character extends Player {
this.characterClass = characterClass;
}
/**
* @return the character CP
*/
public double getCP() {
return CP;
}
/**
* @param CP
* the character CP to set
*/
public void setCP(double CP) {
this.CP = CP;
}
/**
* @return the online
*/
@@ -280,6 +357,58 @@ public class L2Character extends Player {
this.lastAccess = lastAccess;
}
/**
* @return the stats
*/
public CharacterStats getStats() {
return stats;
}
/**
* @return the character karma points
*/
public int getKarma() {
return karma;
}
/**
* @param karma
* the character karma points to set
*/
public void setKarma(int karma) {
this.karma = karma;
}
/**
* @return the character PK kills
*/
public int getPkKills() {
return pkKills;
}
/**
* @param pkKills
* the character PK kills to set
*/
public void setPkKills(int pkKills) {
this.pkKills = pkKills;
}
/**
* @return the character PVP kills
*/
public int getPvpKills() {
return pvpKills;
}
/**
* @param pvpKills
* the character PVP kills to set
*/
public void setPvpKills(int pvpKills) {
this.pvpKills = pvpKills;
}
/**
* @return the moveType
*/
@@ -348,6 +477,34 @@ public class L2Character extends Player {
return state == CharacterState.MOVING;
}
/**
* @return true if character is dead
*/
public boolean isDead() {
return state == CharacterState.DEAD;
}
/**
* @return true if character is casting
*/
public boolean isCasting() {
return state == CharacterState.CASTING;
}
/**
* @return true if character is attacking
*/
public boolean isAttacking() {
return state == CharacterState.ATTACKING;
}
/**
* @return true if character is alive
*/
public boolean isAlive() {
return !isDead();
}
/**
* @return the targetLocation
*/

View File

@@ -30,11 +30,6 @@ import com.l2jserver.service.game.ai.AIScript;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NPC extends Actor {
public int oldId;
public int tpl;
/**
* Creates a new instance
*
@@ -45,6 +40,62 @@ public class NPC extends Actor {
super(templateID);
}
@Override
public ActorSex getSex() {
return this.getTemplate().getSex();
}
@Override
public void setSex(ActorSex sex) {
throw new UnsupportedOperationException();
}
@Override
public int getLevel() {
return this.getTemplate().getLevel();
}
@Override
public void setLevel(int level) {
throw new UnsupportedOperationException();
}
public double getMaxHP() {
return this.getTemplate().getMaxHP();
}
public void setMaxHP(double maxHP) {
throw new UnsupportedOperationException();
}
public double getMaxMP() {
return this.getTemplate().getMaxHP();
}
public void setMaxMP(double maxMP) {
throw new UnsupportedOperationException();
}
@Override
public long getExperience() {
return this.getTemplate().getExperience();
}
@Override
public void setExperience(long experience) {
throw new UnsupportedOperationException();
}
@Override
public int getSP() {
return this.getTemplate().getSp();
}
@Override
public void setSP(int sp) {
throw new UnsupportedOperationException();
}
/**
* @return the NPC template ID
*/

View File

@@ -0,0 +1,34 @@
/*
* 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.world.actor.calculator;
import com.l2jserver.model.world.Actor;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ActorCalculator {
private final Actor actor;
public ActorCalculator(Actor actor) {
this.actor = actor;
}
public double calculateMaxHP() {
return 0;
}
}

View File

@@ -0,0 +1,35 @@
/*
* 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.world.actor.calculator;
import com.l2jserver.model.world.Actor;
import com.l2jserver.util.calculator.CalculatorContext;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class ActorCalculatorContext extends CalculatorContext {
/**
* The character instance
*/
public final Actor actor;
public ActorCalculatorContext(Actor actor) {
this.actor = actor;
}
}

View File

@@ -0,0 +1,93 @@
/*
* 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.world.actor.stat;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum BaseStats {
STR(0.29, 0.3, 0.31, 0.32, 0.34, 0.35, 0.36, 0.37, 0.39, 0.4, 0.42, 0.43,
0.45, 0.46, 0.48, 0.5, 0.51, 0.53, 0.55, 0.57, 0.59, 0.61, 0.63,
0.66, 0.68, 0.71, 0.73, 0.76, 0.78, 0.81, 0.84, 0.87, 0.9, 0.94,
0.97, 1.01, 1.04, 1.08, 1.12, 1.16, 1.2, 1.24, 1.29, 1.33, 1.38,
1.43, 1.48, 1.54, 1.59, 1.65, 1.71, 1.77, 1.83, 1.9, 1.97, 2.04,
2.11, 2.19, 2.27, 2.35, 2.43, 2.52, 2.61, 2.71, 2.8, 2.91, 3.01,
3.12, 3.23, 3.35, 3.47, 3.59, 3.72, 3.86, 3.99, 4.14, 4.29, 4.44,
4.6, 4.77, 4.94, 5.12, 5.3, 5.49, 5.69, 5.89, 6.11, 6.33, 6.55,
6.79, 7.03, 7.29, 7.55, 7.82, 8.1, 8.39, 8.7, 9.01, 9.33, 9.67),
INT(0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.61, 0.62, 0.63, 0.64, 0.65, 0.67,
0.68, 0.69, 0.71, 0.72, 0.74, 0.75, 0.77, 0.78, 0.8, 0.81, 0.83,
0.85, 0.86, 0.88, 0.9, 0.92, 0.94, 0.95, 0.97, 0.99, 1.01, 1.03,
1.05, 1.07, 1.1, 1.12, 1.14, 1.16, 1.19, 1.21, 1.23, 1.26, 1.28,
1.31, 1.34, 1.36, 1.39, 1.42, 1.45, 1.47, 1.5, 1.53, 1.57, 1.6,
1.63, 1.66, 1.69, 1.73, 1.76, 1.8, 1.83, 1.87, 1.91, 1.95, 1.99,
2.02, 2.07, 2.11, 2.15, 2.19, 2.24, 2.28, 2.33, 2.37, 2.42, 2.47,
2.52, 2.57, 2.62, 2.67, 2.73, 2.78, 2.84, 2.89, 2.95, 3.01, 3.07,
3.13, 3.19, 3.26, 3.32, 3.39, 3.46, 3.53, 3.6, 3.67, 3.74, 3.82),
DEX(0.84, 0.85, 0.86, 0.86, 0.87, 0.88, 0.89, 0.9, 0.9, 0.91, 0.92, 0.93,
0.94, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1, 1.01, 1.01, 1.02,
1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.09, 1.1, 1.11, 1.12, 1.13,
1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.2, 1.21, 1.22, 1.24, 1.25,
1.26, 1.27, 1.28, 1.29, 1.3, 1.32, 1.33, 1.34, 1.35, 1.36, 1.38,
1.39, 1.4, 1.41, 1.43, 1.44, 1.45, 1.47, 1.48, 1.49, 1.51, 1.52,
1.53, 1.55, 1.56, 1.57, 1.59, 1.6, 1.62, 1.63, 1.65, 1.66, 1.68,
1.69, 1.71, 1.72, 1.74, 1.75, 1.77, 1.78, 1.8, 1.82, 1.83, 1.85,
1.87, 1.88, 1.9, 1.92, 1.93, 1.95, 1.97, 1.99, 2, 2.02, 2.04),
WIT(0.39, 0.4, 0.42, 0.44, 0.46, 0.48, 0.51, 0.53, 0.56, 0.58, 0.61, 0.64,
0.68, 0.71, 0.75, 0.78, 0.82, 0.86, 0.91, 0.95, 1, 1.05, 1.1, 1.16,
1.22, 1.28, 1.34, 1.41, 1.48, 1.55, 1.63, 1.71, 1.8, 1.89, 1.98,
2.08, 2.18, 2.29, 2.41, 2.53, 2.65, 2.79, 2.93, 3.07, 3.23, 3.39,
3.56, 3.73, 3.92, 4.12, 4.32, 4.54, 4.76, 5, 5.25, 5.52, 5.79,
6.08, 6.39, 6.7, 7.04, 7.39, 7.76, 8.15, 8.56, 8.99, 9.43, 9.91,
10.4, 10.92, 11.47, 12.04, 12.64, 13.27, 13.94, 14.64, 15.37,
16.14, 16.94, 17.79, 18.68, 19.61, 20.59, 21.62, 22.7, 23.84,
25.03, 26.28, 27.6, 28.98, 30.43, 31.95, 33.55, 35.22, 36.98,
38.83, 40.77, 42.81, 44.95, 47.2),
CON(0.45, 0.46, 0.47, 0.48, 0.5, 0.51, 0.53, 0.54, 0.56, 0.58, 0.59, 0.61,
0.63, 0.65, 0.67, 0.69, 0.71, 0.73, 0.75, 0.77, 0.8, 0.82, 0.85,
0.87, 0.9, 0.93, 0.95, 0.98, 1.01, 1.04, 1.07, 1.1, 1.14, 1.17,
1.21, 1.24, 1.28, 1.32, 1.36, 1.4, 1.44, 1.48, 1.53, 1.58, 1.62,
1.67, 1.72, 1.77, 1.83, 1.88, 1.94, 2, 2.06, 2.12, 2.18, 2.25,
2.31, 2.38, 2.45, 2.53, 2.6, 2.68, 2.76, 2.84, 2.93, 3.02, 3.11,
3.2, 3.3, 3.4, 3.5, 3.6, 3.71, 3.82, 3.94, 4.06, 4.18, 4.3, 4.43,
4.56, 4.7, 4.84, 4.99, 5.14, 5.29, 5.45, 5.61, 5.78, 5.96, 6.13,
6.32, 6.51, 6.7, 6.9, 7.11, 7.33, 7.54, 7.77, 8, 8.24),
MEN(1, 1.01, 1.02, 1.03, 1.04, 1.05, 1.06, 1.07, 1.08, 1.09, 1.11, 1.12,
1.13, 1.14, 1.15, 1.16, 1.17, 1.19, 1.2, 1.21, 1.22, 1.23, 1.25,
1.26, 1.27, 1.28, 1.3, 1.31, 1.32, 1.34, 1.35, 1.36, 1.38, 1.39,
1.4, 1.42, 1.43, 1.45, 1.46, 1.48, 1.49, 1.5, 1.52, 1.53, 1.55,
1.57, 1.58, 1.6, 1.61, 1.63, 1.65, 1.66, 1.68, 1.7, 1.71, 1.73,
1.75, 1.76, 1.78, 1.8, 1.82, 1.84, 1.85, 1.87, 1.89, 1.91, 1.93,
1.95, 1.97, 1.99, 2.01, 2.03, 2.05, 2.07, 2.09, 2.11, 2.13, 2.15,
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;
BaseStats(double... bonus) {
this.bonus = bonus;
}
public double calculateBonus(int n) {
return bonus[n];
}
}

View File

@@ -0,0 +1,264 @@
package com.l2jserver.model.world.actor.stat;
import java.util.List;
import java.util.Map;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.calculator.CalculatorContext;
import com.l2jserver.util.calculator.DivisionFunction;
import com.l2jserver.util.calculator.Function;
import com.l2jserver.util.calculator.MultiplicationFunction;
import com.l2jserver.util.calculator.SetFunction;
import com.l2jserver.util.calculator.SubtractFunction;
import com.l2jserver.util.calculator.SumFunction;
import com.l2jserver.util.factory.CollectionFactory;
/**
* This class handles the stats an can add operations to the calculator
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Stats {
/**
* Attribute types for weapons
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum StatType {
MAX_HP, MAX_MP, MAX_CP, REGENERATE_HP_RATE, REGENERATE_CP_RATE, REGENERATE_MP_RATE, RECHARGE_MP_RATE, HEAL_EFFECTIVNESS, HEAL_PROFICIENCY, HEAL_STATIC_BONUS,
// Atk & Def
POWER_DEFENSE, MAGIC_DEFENSE, POWER_ATTACK, MAGIC_ATTACK, PHYSICAL_SKILL_POWER, POWER_ATTACK_SPEED, MAGIC_ATTACK_SPEED, // how
// fast
// a
// spell
// is
// casted
MAGIC_REUSE_RATE, // how fast spells becomes ready to reuse
SHIELD_DEFENCE, CRITICAL_DAMAGE, CRITICAL_DAMAGE_ADD, // this is another
// type for
// special
// critical
// damage mods -
// vicious
// stance, crit
// power and
// crit damage
// SA
// it was totally bad since now...
MAGIC_CRIT_DMG,
PVP_PHYSICAL_DMG, PVP_MAGICAL_DMG, PVP_PHYS_SKILL_DMG,
PVP_PHYSICAL_DEF, PVP_MAGICAL_DEF, PVP_PHYS_SKILL_DEF,
PVE_PHYSICAL_DMG, PVE_PHYS_SKILL_DMG, PVE_BOW_DMG, PVE_BOW_SKILL_DMG, PVE_MAGICAL_DMG,
// Atk & Def rates
EVASION_RATE, P_SKILL_EVASION, CRIT_DAMAGE_EVASION, SHIELD_RATE, CRITICAL_RATE, BLOW_RATE, LETHAL_RATE, MCRITICAL_RATE, EXPSP_RATE, ATTACK_CANCEL,
// Accuracy and range
ACCURACY_COMBAT, POWER_ATTACK_RANGE, MAGIC_ATTACK_RANGE, POWER_ATTACK_ANGLE, ATTACK_COUNT_MAX,
// Run speed,
// walk & escape speed are calculated proportionally,
// magic speed is a buff
RUN_SPEED, WALK_SPEED,
//
// Player-only stats
//
STAT_STR, STAT_CON, STAT_DEX, STAT_INT, STAT_WIT, STAT_MEN,
//
// Special stats, share one slot in Calculator
//
// stats of various abilities
BREATH, FALL, LIMIT_HP, // non-displayed hp limit
//
AGGRESSION, // locks a mob on tank caster
BLEED, // by daggers, like poison
POISON, // by magic, hp dmg over time
STUN, // disable move/ATTACK for a period of time
ROOT, // disable movement, but not ATTACK
MOVEMENT, // slowdown movement, debuff
CONFUSION, // mob changes target, opposite to aggression/hate
SLEEP, // sleep until attacked
VALAKAS, VALAKAS_RES,
//
AGGRESSION_VULN, BLEED_VULN, POISON_VULN, STUN_VULN, PARALYZE_VULN, ROOT_VULN, SLEEP_VULN, CONFUSION_VULN, MOVEMENT_VULN, FIRE_RES, WIND_RES, WATER_RES, EARTH_RES, HOLY_RES, DARK_RES,
// Skills Power
FIRE_POWER, WATER_POWER, WIND_POWER, EARTH_POWER, HOLY_POWER, DARK_POWER, CANCEL_VULN, // Resistance
// for
// cancel
// type
// skills
DERANGEMENT_VULN, DEBUFF_VULN, BUFF_VULN, CRIT_VULN, // Resistence to
// Crit DMG in
// percent.
CRIT_ADD_VULN, // Resistence to Crit DMG in value .
MAGIC_DAMAGE_VULN, MAGIC_SUCCESS_RES, MAGIC_FAILURE_RATE,
AGGRESSION_PROF, BLEED_PROF, POISON_PROF, STUN_PROF, PARALYZE_PROF, ROOT_PROF, SLEEP_PROF, CONFUSION_PROF, PROF, CANCEL_PROF, DERANGEMENT_PROF, DEBUFF_PROF, CRIT_PROF,
NONE_WPN_VULN, // Shields!!!
SWORD_WPN_VULN, BLUNT_WPN_VULN, DAGGER_WPN_VULN, BOW_WPN_VULN, CROSSBOW_WPN_VULN, POLE_WPN_VULN, ETC_WPN_VULN, FIST_WPN_VULN, DUAL_WPN_VULN, DUALFIST_WPN_VULN, BIGSWORD_WPN_VULN, BIGBLUNT_WPN_VULN, DUALDAGGER_WPN_VULN, RAPIER_WPN_VULN, ANCIENT_WPN_VULN, PET_WPN_VULN,
REFLECT_DAMAGE_PERCENT, REFLECT_SKILL_MAGIC, REFLECT_SKILL_PHYSIC, VENGEANCE_SKILL_MAGIC_DAMAGE, VENGEANCE_SKILL_PHYSICAL_DAMAGE, ABSORB_DAMAGE_PERCENT, TRANSFER_DAMAGE_PERCENT, ABSORB_MANA_DAMAGE_PERCENT,
MAX_LOAD, WEIGHT_LIMIT,
PATK_PLANTS, PATK_INSECTS, PATK_ANIMALS, PATK_MONSTERS, PATK_DRAGONS, PATK_GIANTS, PATK_MCREATURES,
PDEF_PLANTS, PDEF_INSECTS, PDEF_ANIMALS, PDEF_MONSTERS, PDEF_DRAGONS, PDEF_GIANTS, PDEF_MCREATURES,
ATK_REUSE, P_REUSE,
// ExSkill :)
INV_LIM, WH_LIM, FREIGHT_LIM, P_SELL_LIM, P_BUY_LIM, REC_D_LIM, REC_C_LIM,
// C4 Stats
PHYSICAL_MP_CONSUME_RATE, MAGICAL_MP_CONSUME_RATE, DANCE_MP_CONSUME_RATE, BOW_MP_CONSUME_RATE, HP_CONSUME_RATE, MP_CONSUME, SOULSHOT_COUNT,
// T1 stats
transformId, TALISMAN_SLOTS, CLOAK_SLOT,
// Shield Stats
SHIELD_DEFENCE_ANGLE,
// Skill mastery
SKILL_MASTERY,
// vitality
VITALITY_CONSUME_RATE;
// PHYSICAL_ATTACK, MAGICAL_ATTACK, CRITICAL_RATE,
// PHYSICAL_ATTACK_SPEED;
}
private final Map<StatType, List<Function<CalculatorContext>>> operations = CollectionFactory
.newMap();
/**
* Sets the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to set
*/
public void set(Stats.StatType type, int order, double value) {
func(type, new SetFunction(order, value));
}
/**
* Adds <tt>value</tt> to the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be summed
*/
public void add(Stats.StatType type, int order, double value) {
func(type, new SumFunction(order, value));
}
/**
* Subtracts <tt>value</tt> from the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be subtracted
*/
public void sub(Stats.StatType type, int order, double value) {
func(type, new SubtractFunction(order, value));
}
/**
* Multiply <tt>value</tt> the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be multiplied
*/
public void mult(Stats.StatType type, int order, double value) {
func(type, new MultiplicationFunction(order, value));
}
/**
* Divides by <tt>value</tt> the result of an calculator
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* the value to be divided by
*/
public void div(Stats.StatType type, int order, double value) {
func(type, new DivisionFunction(order, value));
}
/**
* Performs an enchant operation. Note that this is not implemented yet!
*
* @param type
* the attribute type
* @param order
* the calculation order
* @param value
* TODO
*/
public void enchant(Stats.StatType type, int order, double value) {
// TODO enchant operation for weapon
}
public void func(StatType type, Function<CalculatorContext> function) {
getMap(type).add(function);
}
/**
* Returns the Order-Operation map for <tt>type</tt>
*
* @param type
* the type
* @return the order-operation map
*/
private List<Function<CalculatorContext>> getMap(Stats.StatType type) {
List<Function<CalculatorContext>> list = operations.get(type);
if (list == null) {
list = CollectionFactory.newList();
operations.put(type, list);
}
return list;
}
/**
* Creates the calculator object for this weapon
*
* @param type
* the type
* @param calculator
* the calculator
*/
public void calculator(Stats.StatType type,
Calculator<CalculatorContext> calculator) {
final List<Function<CalculatorContext>> operations = this.operations
.get(type);
if (operations == null || operations.size() == 0)
return;
for (final Function<CalculatorContext> func : operations) {
calculator.add(func);
}
}
}

View File

@@ -157,6 +157,10 @@ public class CharacterAppearance {
* <b>This is not persisted!</b>
*/
private RGBColor titleColor = RGBColor.fromInteger(0xFFFF77);
/**
* The visibility status
*/
private boolean visible;
public CharacterAppearance(L2Character character) {
this.character = character;
@@ -267,6 +271,21 @@ public class CharacterAppearance {
this.titleColor = titleColor;
}
/**
* @return the visibility state
*/
public boolean isVisible() {
return visible;
}
/**
* @param visible
* the visibility state to set
*/
public void setVisible(boolean visible) {
this.visible = visible;
}
/**
* @return the character
*/

View File

@@ -31,22 +31,19 @@ public enum CharacterClass {
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(
0x09, ROGUE),
// 3rd classes
DUELIST(0x58, GLADIATOR), DREADNOUGHT(0x59, WARLORD), PHOENIX_KNIGHT(0x5a,
PALADIN), HELL_KNIGHT(0x5b, DARK_AVENGER), SAGITTARIUS(0x5c,
0x09, ROGUE), DUELIST(0x58, GLADIATOR), DREADNOUGHT(0x59, WARLORD), PHOENIX_KNIGHT(
0x5a, PALADIN), HELL_KNIGHT(0x5b, DARK_AVENGER), SAGITTARIUS(0x5c,
HAWKEYE), ADVENTURER(0x5d, TREASURE_HUNTER),
/**
* Human mystic
*/
HUMAN_MYSTIC(0x0a, ClassType.MYSTIC, ActorRace.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),
// 3rd classes
ARCHMAGE(0x5e, SORCEROR), SOULTAKER(0x5f, NECROMANCER), ARCANA_LORD(0x60,
WARLOCK), CARDINAL(0x61, BISHOP), HIEROPHANT(0x62, PROPHET),
HUMAN_MYSTIC(0x0a, ClassType.MYSTIC, ActorRace.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(
0x5f, NECROMANCER), ARCANA_LORD(0x60, WARLOCK), CARDINAL(0x61,
BISHOP), HIEROPHANT(0x62, PROPHET),
/**
* Elven fighter
@@ -54,9 +51,8 @@ public enum CharacterClass {
ELVEN_FIGHTER(0x12, ClassType.FIGHTER, ActorRace.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),
// 3rd classes
EVA_TEMPLAR(0x63, TEMPLE_KNIGHT), SWORD_MUSE(0x64, SWORD_SINGER), WIND_RIDER(
0x17, ELVEN_SCOUT), SILVER_RANGER(0x18, ELVEN_SCOUT), EVA_TEMPLAR(
0x63, TEMPLE_KNIGHT), SWORD_MUSE(0x64, SWORD_SINGER), WIND_RIDER(
0x65, PLAINS_WALKER), MOONLIGHT_SENTINEL(0x66, SILVER_RANGER),
/**
* Elven mystic
@@ -64,20 +60,17 @@ public enum CharacterClass {
ELVEN_MYSTIC(0x19, ClassType.MYSTIC, ActorRace.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),
// 3rd classes
MYSTIC_MUSE(0x67, SPELLSINGER), ELEMENTAL_MASTER(0x68, ELEMENTAL_SUMMONER), EVA_SAINT(
0x69, ELDER),
ELVEN_MYSTIC), ELDER(0x1e, ORACLE), MYSTIC_MUSE(0x67, SPELLSINGER), ELEMENTAL_MASTER(
0x68, ELEMENTAL_SUMMONER), EVA_SAINT(0x69, ELDER),
/**
* Dark elf fighter
*/
DARK_FIGHTER(0x1f, ClassType.FIGHTER, ActorRace.DARK_ELF), PALUS_KNIGHT(0x20,
DARK_FIGHTER), SHILLIEN_KNIGHT(0x21, PALUS_KNIGHT), BLADEDANCER(
DARK_FIGHTER(0x1f, ClassType.FIGHTER, ActorRace.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),
// 3rd classes
SHILLIEN_TEMPLAR(0x6a, SHILLIEN_KNIGHT), spectralDancer(0x6b, BLADEDANCER), GHOST_HUNTER(
0x24, ASSASSIN), PHANTOM_RANGER(0x25, ASSASSIN), SHILLIEN_TEMPLAR(
0x6a, SHILLIEN_KNIGHT), spectralDancer(0x6b, BLADEDANCER), GHOST_HUNTER(
0x6c, ABYSS_WALKER), GHOST_SENTINEL(0x6d, PHANTOM_RANGER),
/**
@@ -86,9 +79,8 @@ public enum CharacterClass {
DARK_MYSTIC(0x26, ClassType.MYSTIC, ActorRace.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),
// 3rd classes
STORM_SCREAMER(0x6e, SPELLHOWLER), SPECTRAL_MASTER(0x6f, PHANTOM_SUMMONER), SHILLIEAN_SAINT(
DARK_MYSTIC), SHILLIEN_ELDER(0x2b, SHILLIEN_ORACLE), STORM_SCREAMER(
0x6e, SPELLHOWLER), SPECTRAL_MASTER(0x6f, PHANTOM_SUMMONER), SHILLIEAN_SAINT(
0x70, SHILLIEN_ELDER),
/**
@@ -96,26 +88,24 @@ public enum CharacterClass {
*/
ORC_FIGHTER(0x2c, ClassType.FIGHTER, ActorRace.ORC), ORC_RAIDER(0x2d,
ORC_FIGHTER), DESTROYER(0x2e, ORC_RAIDER), ORC_MONK(0x2f,
ORC_FIGHTER), TYRANT(0x30, ORC_RAIDER),
// 3rd classes
TITAN(0x71, DESTROYER), GRAND_KHAUATARI(0x72, TYRANT),
ORC_FIGHTER), TYRANT(0x30, ORC_RAIDER), TITAN(0x71, DESTROYER), GRAND_KHAUATARI(
0x72, TYRANT),
/**
* Orc mystic
*/
ORC_MYSTIC(0x31, ClassType.MYSTIC, ActorRace.ORC), ORC_SHAMAN(0x32, ORC_MYSTIC), OVERLORD(
0x33, ORC_SHAMAN), WARCRYER(0x34, ORC_SHAMAN),
// 3rd classes
DOMINATOR(0x73, OVERLORD), DOOMCRYER(0x74, WARCRYER),
ORC_MYSTIC(0x31, ClassType.FIGHTER, ActorRace.ORC), ORC_SHAMAN(0x32,
ClassType.MYSTIC, ORC_MYSTIC), OVERLORD(0x33, ORC_SHAMAN), WARCRYER(
0x34, ORC_SHAMAN), DOMINATOR(0x73, OVERLORD), DOOMCRYER(0x74,
WARCRYER),
/**
* Dwarf fighter
*/
DWARVEN_FIGHTER(0x35, ClassType.FIGHTER, ActorRace.DWARF), SCAVENGER(0x36,
DWARVEN_FIGHTER), BOUNTY_HUNTER(0x37, SCAVENGER), ARTISAN(0x38,
DWARVEN_FIGHTER), WARSMITH(0x39, ARTISAN),
// 3rd classes
FORTUNE_SEEKER(0x75, BOUNTY_HUNTER), MAESTRO(0x76, WARSMITH),
DWARVEN_FIGHTER), WARSMITH(0x39, ARTISAN), FORTUNE_SEEKER(0x75,
BOUNTY_HUNTER), MAESTRO(0x76, WARSMITH),
/**
* Kamael male soldier
@@ -194,8 +184,8 @@ public enum CharacterClass {
* @param parent
* the parent
*/
private CharacterClass(int id, ClassType type, boolean summoner, ActorRace race,
CharacterClass parent) {
private CharacterClass(int id, ClassType type, boolean summoner,
ActorRace race, CharacterClass parent) {
this.id = id;
this.type = type;
this.summoner = summoner;

View File

@@ -65,6 +65,10 @@ public class CharacterInventory implements Iterable<Item> {
return null;
}
public boolean has(InventoryPaperdoll paperdoll) {
return getItem(paperdoll) != null;
}
/**
* This method will add new items to the inventory. This is normally called
* from the DAO object.

View File

@@ -17,6 +17,8 @@
package com.l2jserver.model.world.character;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -57,6 +59,7 @@ public class CharacterShortcutContainer implements Iterable<Shortcut> {
*/
public void register(Shortcut shortcut) {
shortcuts.add(shortcut);
Collections.sort(shortcuts, new ShortcutSlotComparator());
}
/**
@@ -67,6 +70,7 @@ public class CharacterShortcutContainer implements Iterable<Shortcut> {
*/
public void unregister(Shortcut shortcut) {
shortcuts.remove(shortcut);
Collections.sort(shortcuts, new ShortcutSlotComparator());
}
/**
@@ -90,6 +94,8 @@ public class CharacterShortcutContainer implements Iterable<Shortcut> {
shortcut1.setPage(shortcut2.getPage());
shortcut2.setSlot(slot1);
shortcut2.setPage(page1);
Collections.sort(shortcuts, new ShortcutSlotComparator());
}
/**
@@ -115,6 +121,7 @@ public class CharacterShortcutContainer implements Iterable<Shortcut> {
*/
public void load(Collection<Shortcut> shortcuts) {
this.shortcuts.addAll(shortcuts);
Collections.sort(this.shortcuts, new ShortcutSlotComparator());
}
@Override
@@ -128,4 +135,12 @@ public class CharacterShortcutContainer implements Iterable<Shortcut> {
public L2Character getCharacter() {
return character;
}
public static class ShortcutSlotComparator implements Comparator<Shortcut> {
@Override
public int compare(Shortcut o1, Shortcut o2) {
return ((o1.getPage() * o1.getSlot()) - (o2.getPage() * o2
.getSlot()));
}
}
}

View File

@@ -0,0 +1,230 @@
/*
* 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.world.character;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.Stats.StatType;
import com.l2jserver.model.world.character.calculator.BaseAttackAccuracyCalculator;
import com.l2jserver.model.world.character.calculator.BaseAttackEvasionCalculator;
import com.l2jserver.model.world.character.calculator.BaseCPCalculator;
import com.l2jserver.model.world.character.calculator.BaseConcentrationCalculator;
import com.l2jserver.model.world.character.calculator.BaseDexterityCalculator;
import com.l2jserver.model.world.character.calculator.BaseHPCalculator;
import com.l2jserver.model.world.character.calculator.BaseIntelligenceCalculator;
import com.l2jserver.model.world.character.calculator.BaseMPCalculator;
import com.l2jserver.model.world.character.calculator.BaseMagicalAttackCalculator;
import com.l2jserver.model.world.character.calculator.BaseMagicalAttackSpeedCalculator;
import com.l2jserver.model.world.character.calculator.BaseMagicalCriticalRateCalculator;
import com.l2jserver.model.world.character.calculator.BaseMagicalDefenseCalculator;
import com.l2jserver.model.world.character.calculator.BaseMentalityCalculator;
import com.l2jserver.model.world.character.calculator.BasePhysicalAttackCalculator;
import com.l2jserver.model.world.character.calculator.BasePhysicalAttackSpeedCalculator;
import com.l2jserver.model.world.character.calculator.BasePhysicalCriticalRateCalculator;
import com.l2jserver.model.world.character.calculator.BasePhysicalDefenseCalculator;
import com.l2jserver.model.world.character.calculator.BaseRunSpeedCalculator;
import com.l2jserver.model.world.character.calculator.BaseStrengthCalculator;
import com.l2jserver.model.world.character.calculator.BaseWalkSpeedCalculator;
import com.l2jserver.model.world.character.calculator.BaseWitnessCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext;
import com.l2jserver.util.calculator.Calculator;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class CharacterStats {
private static final CharacterCalculator BASE_HP_CALCULATOR = new BaseHPCalculator();
private static final CharacterCalculator BASE_MP_CALCULATOR = new BaseMPCalculator();
private static final CharacterCalculator BASE_CP_CALCULATOR = new BaseCPCalculator();
private static final CharacterCalculator BASE_INT_CALCULATOR = new BaseIntelligenceCalculator();
private static final CharacterCalculator BASE_STR_CALCULATOR = new BaseStrengthCalculator();
private static final CharacterCalculator BASE_CON_CALCULATOR = new BaseConcentrationCalculator();
private static final CharacterCalculator BASE_MEN_CALCULATOR = new BaseMentalityCalculator();
private static final CharacterCalculator BASE_DEX_CALCULATOR = new BaseDexterityCalculator();
private static final CharacterCalculator BASE_WIT_CALCULATOR = new BaseWitnessCalculator();
private static final CharacterCalculator BASE_RUN_SPEED_CALCULATOR = new BaseRunSpeedCalculator();
private static final CharacterCalculator BASE_WALK_SPEED_CALCULATOR = new BaseWalkSpeedCalculator();
private static final CharacterCalculator BASE_PHYSICAL_ATTACK_CALCULATOR = new BasePhysicalAttackCalculator();
private static final CharacterCalculator BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR = new BasePhysicalAttackSpeedCalculator();
private static final CharacterCalculator BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR = new BasePhysicalCriticalRateCalculator();
private static final CharacterCalculator BASE_PHYSICAL_DEFENSE_CALCULATOR = new BasePhysicalDefenseCalculator();
private static final CharacterCalculator BASE_MAGICAL_ATTACK_CALCULATOR = new BaseMagicalAttackCalculator();
private static final CharacterCalculator BASE_MAGICAL_ATTACK_SPEED_CALCULATOR = new BaseMagicalAttackSpeedCalculator();
private static final CharacterCalculator BASE_MAGICAL_CRITICAL_RATE_CALCULATOR = new BaseMagicalCriticalRateCalculator();
private static final CharacterCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new BaseMagicalDefenseCalculator();
private static final CharacterCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new BaseAttackAccuracyCalculator();
private static final CharacterCalculator BASE_ATTACK_EVASION_CALCULATOR = new BaseAttackEvasionCalculator();
private final L2Character character;
@SuppressWarnings("unchecked")
private final Calculator<CharacterCalculatorContext>[] calculators = new Calculator[StatType
.values().length];
public CharacterStats(L2Character character) {
this.character = character;
for (int i = 0; i < calculators.length; i++) {
calculators[i] = new Calculator<CharacterCalculatorContext>();
}
// bind default functions
getCalculator(StatType.MAX_HP).importFunctions(BASE_HP_CALCULATOR);
getCalculator(StatType.MAX_MP).importFunctions(BASE_MP_CALCULATOR);
getCalculator(StatType.MAX_CP).importFunctions(BASE_CP_CALCULATOR);
getCalculator(StatType.STAT_INT).importFunctions(BASE_INT_CALCULATOR);
getCalculator(StatType.STAT_STR).importFunctions(BASE_STR_CALCULATOR);
getCalculator(StatType.STAT_CON).importFunctions(BASE_CON_CALCULATOR);
getCalculator(StatType.STAT_MEN).importFunctions(BASE_MEN_CALCULATOR);
getCalculator(StatType.STAT_DEX).importFunctions(BASE_DEX_CALCULATOR);
getCalculator(StatType.STAT_WIT).importFunctions(BASE_WIT_CALCULATOR);
getCalculator(StatType.RUN_SPEED).importFunctions(
BASE_RUN_SPEED_CALCULATOR);
getCalculator(StatType.WALK_SPEED).importFunctions(
BASE_WALK_SPEED_CALCULATOR);
getCalculator(StatType.POWER_ATTACK).importFunctions(
BASE_PHYSICAL_ATTACK_CALCULATOR);
getCalculator(StatType.POWER_ATTACK_SPEED).importFunctions(
BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR);
getCalculator(StatType.CRITICAL_RATE).importFunctions(
BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR);
getCalculator(StatType.POWER_DEFENSE).importFunctions(
BASE_PHYSICAL_DEFENSE_CALCULATOR);
getCalculator(StatType.MAGIC_ATTACK).importFunctions(
BASE_MAGICAL_ATTACK_CALCULATOR);
getCalculator(StatType.MAGIC_ATTACK_SPEED).importFunctions(
BASE_MAGICAL_ATTACK_SPEED_CALCULATOR);
getCalculator(StatType.MCRITICAL_RATE).importFunctions(
BASE_MAGICAL_CRITICAL_RATE_CALCULATOR);
getCalculator(StatType.MAGIC_DEFENSE).importFunctions(
BASE_MAGICAL_DEFENSE_CALCULATOR);
getCalculator(StatType.ACCURACY_COMBAT).importFunctions(
BASE_ATTACK_ACCURACY_CALCULATOR);
getCalculator(StatType.EVASION_RATE).importFunctions(
BASE_ATTACK_EVASION_CALCULATOR);
// TODO henna stats calculators
}
public int getMaxHP() {
return (int) calc(StatType.MAX_HP);
}
public int getMaxMP() {
return (int) calc(StatType.MAX_MP);
}
public int getMaxCP() {
return (int) calc(StatType.MAX_CP);
}
public int getIntelligence() {
return (int) calc(StatType.STAT_INT);
}
public int getStrength() {
return (int) calc(StatType.STAT_STR);
}
public int getConcentration() {
return (int) calc(StatType.STAT_CON);
}
public int getMentality() {
return (int) calc(StatType.STAT_MEN);
}
public int getDexterity() {
return (int) calc(StatType.STAT_DEX);
}
public int getWitness() {
return (int) calc(StatType.STAT_WIT);
}
public int getRunSpeed() {
return (int) calc(StatType.RUN_SPEED);
}
public int getWalkSpeed() {
return (int) calc(StatType.WALK_SPEED);
}
public int getPhysicalAttack() {
return (int) calc(StatType.POWER_ATTACK);
}
public int getPhysicalAttackSpeed() {
return (int) calc(StatType.POWER_ATTACK_SPEED);
}
public int getPhysicalCriticalRate() {
return (int) calc(StatType.CRITICAL_RATE);
}
public int getPhysicalDefense() {
return (int) calc(StatType.POWER_DEFENSE);
}
public int getMagicalAttack() {
return (int) calc(StatType.MAGIC_ATTACK);
}
public int getMagicalAttackSpeed() {
return (int) calc(StatType.MAGIC_ATTACK_SPEED);
}
public int getMagicalCriticalRate() {
return (int) calc(StatType.MCRITICAL_RATE);
}
public int getMagicalDefense() {
return (int) calc(StatType.MAGIC_DEFENSE);
}
public int getAccuracy() {
return (int) calc(StatType.ACCURACY_COMBAT);
}
public int getEvasionRate() {
return (int) calc(StatType.EVASION_RATE);
}
// public void add(StatType type, Calculator<?> calculator) {
// getCalculator(type).importFunctions(calculator);
// }
protected Calculator<CharacterCalculatorContext> getCalculator(StatType type) {
return calculators[type.ordinal()];
}
public double calc(StatType type) {
final CharacterCalculatorContext ctx = new CharacterCalculatorContext(
character);
getCalculator(type).calculate(ctx);
return ctx.result;
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.world.character.calculator;
import org.apache.commons.math.util.FastMath;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseAttackAccuracyCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseAttackAccuracyCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getAccuracy();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x100) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
final int level = c.getLevel();
ctx.result += FastMath.sqrt(c.getStats().getDexterity()) * 6;
ctx.result += level;
if (level > 77)
ctx.result += (level - 77) + 1;
if (level > 69)
ctx.result += (level - 69);
}
});
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.world.character.calculator;
import org.apache.commons.math.util.FastMath;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseAttackEvasionCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseAttackEvasionCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getEvasionChance();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x100) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
final int level = c.getLevel();
ctx.result += FastMath.sqrt(c.getStats().getDexterity()) * 6;
ctx.result += level;
if (level > 77)
ctx.result += (level - 77) + 1;
if (level > 69)
ctx.result += (level - 69);
}
});
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseCPCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseCPCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getCpBase();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x100) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final CharacterTemplate template = ctx.character.getTemplate();
int lvl = ctx.character.getLevel() - template.getMinimumLevel();
double mod = template.getCpMultiplier() * lvl;
double max = (template.getCpAdd() + mod) * lvl;
double min = (template.getCpAdd() * lvl) + mod;
ctx.result += (max + min) / 2;
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.CON.calculateBonus(ctx.character
.getStats().getConcentration());
}
});
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseConcentrationCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseConcentrationCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getConcentration();
}
});
}
}

View File

@@ -0,0 +1,35 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseDexterityCalculator extends
CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseDexterityCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getDextry();
}
});
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseHPCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseHPCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getHpBase();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x100) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final CharacterTemplate template = ctx.character.getTemplate();
int lvl = ctx.character.getLevel() - template.getMinimumLevel();
double mod = template.getHpMultiplier() * lvl;
double max = (template.getHpAdd() + mod) * lvl;
double min = (template.getHpAdd() * lvl) + mod;
ctx.result += (max + min) / 2;
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.CON.calculateBonus(ctx.character
.getStats().getConcentration());
}
});
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseIntelligenceCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseIntelligenceCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getIntelligence();
}
});
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseMPCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseMPCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getMpBase();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x100) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final CharacterTemplate template = ctx.character.getTemplate();
int lvl = ctx.character.getLevel() - template.getMinimumLevel();
double mod = template.getMpMultiplier() * lvl;
double max = (template.getMpAdd() + mod) * lvl;
double min = (template.getMpAdd() * lvl) + mod;
ctx.result += (max + min) / 2;
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.MEN.calculateBonus(ctx.character
.getStats().getMentality());
}
});
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseMagicalAttackCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseMagicalAttackCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getMagicalAttack();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
ctx.result *= Math
.pow(((100.0 - 11 + c.getLevel()) / 100.0), 2)
* Math.pow(BaseStats.INT.calculateBonus(c.getStats()
.getIntelligence()), 2);
}
});
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseMagicalAttackSpeedCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseMagicalAttackSpeedCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getCastSpeed();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.WIT.calculateBonus(ctx.character
.getStats().getWitness());
}
});
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseMagicalCriticalRateCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseMagicalCriticalRateCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
// XXX is the same as physical????
ctx.result = ctx.character.getTemplate().getCriticalChance();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x300) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
// TODO only apply if using a weapon
ctx.result *= BaseStats.WIT.calculateBonus(c.getStats()
.getWitness());
}
});
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.world.character.calculator;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEFT_EAR;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEFT_FINGER;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.NECK;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_EAR;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_FINGER;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.character.CharacterInventory;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseMagicalDefenseCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseMagicalDefenseCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getMagicalDefense();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
final CharacterInventory inv = c.getInventory();
if (inv.has(LEFT_FINGER))
ctx.result -= 5;
if (inv.has(RIGHT_FINGER))
ctx.result -= 5;
if (inv.has(LEFT_EAR))
ctx.result -= 9;
if (inv.has(RIGHT_EAR))
ctx.result -= 9;
if (inv.has(NECK))
ctx.result -= 13;
ctx.result *= BaseStats.MEN.calculateBonus(c.getStats()
.getMentality())
* ((100.0 - 11 + c.getLevel()) / 100.0);
}
});
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseMentalityCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseMentalityCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getMentality();
}
});
}
}

View File

@@ -0,0 +1,44 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BasePhysicalAttackCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BasePhysicalAttackCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getPhysicalAttack();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x100) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
ctx.result *= BaseStats.STR.calculateBonus(c.getStats()
.getStrength()) * ((100.0 - 11 + c.getLevel()) / 100.0);
}
});
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BasePhysicalAttackSpeedCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BasePhysicalAttackSpeedCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getAttackSpeed();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.DEX.calculateBonus(ctx.character
.getStats().getDexterity());
}
});
}
}

View File

@@ -0,0 +1,47 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BasePhysicalCriticalRateCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BasePhysicalCriticalRateCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getCriticalChance();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x090) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
ctx.result *= BaseStats.DEX.calculateBonus(c.getStats()
.getDexterity());
ctx.result *= 10;
// TODO l2j uses another variable here, must check why
}
});
}
}

View File

@@ -0,0 +1,69 @@
/*
* 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.world.character.calculator;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.CHEST;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.FEET;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.GLOVES;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.HEAD;
import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEGS;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterClass;
import com.l2jserver.model.world.character.CharacterClass.ClassType;
import com.l2jserver.model.world.character.CharacterInventory;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BasePhysicalDefenseCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BasePhysicalDefenseCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getPhysicalDefense();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x200) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
final L2Character c = ctx.character;
final CharacterInventory inv = c.getInventory();
// orc mystics are a special case
boolean hasMagePDef = (c.getCharacterClass().type == ClassType.MYSTIC || c
.getCharacterClass() == CharacterClass.ORC_MYSTIC);
if (inv.has(HEAD))
ctx.result -= 12;
final Item chest = inv.getItem(CHEST);
if (chest != null)
ctx.result -= hasMagePDef ? 15 : 31;
if (inv.has(LEGS))
// FIXME full armor also applies here
ctx.result -= hasMagePDef ? 8 : 18;
if (inv.has(GLOVES))
ctx.result -= 8;
if (inv.has(FEET))
ctx.result -= 7;
ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0);
}
});
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseRunSpeedCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseRunSpeedCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getRunSpeed();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x300) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.DEX.calculateBonus(ctx.character
.getStats().getDexterity());
}
});
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseStrengthCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseStrengthCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getStrength();
}
});
}
}

View File

@@ -0,0 +1,42 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class BaseWalkSpeedCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseWalkSpeedCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getWalkSpeed();
}
}, new AbstractFunction<CharacterCalculatorContext>(0x300) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result *= BaseStats.DEX.calculateBonus(ctx.character
.getStats().getDexterity());
}
});
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.AbstractFunction;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class BaseWitnessCalculator extends CharacterCalculator {
@SuppressWarnings("unchecked")
public BaseWitnessCalculator() {
super(new AbstractFunction<CharacterCalculatorContext>(0x000) {
@Override
public void calculate(CharacterCalculatorContext ctx) {
ctx.result = ctx.character.getTemplate().getMentality();
}
});
}
}

View File

@@ -0,0 +1,31 @@
/*
* 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.world.character.calculator;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.calculator.Function;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class CharacterCalculator extends Calculator<CharacterCalculatorContext> {
public CharacterCalculator(
Function<CharacterCalculatorContext>... functions) {
super(functions);
}
}

View File

@@ -0,0 +1,36 @@
/*
* 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.world.character.calculator;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorContext;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class CharacterCalculatorContext extends ActorCalculatorContext {
/**
* The character instance
*/
public final L2Character character;
public CharacterCalculatorContext(L2Character character) {
super(character);
this.character = character;
}
}

View File

@@ -36,7 +36,7 @@ import com.l2jserver.service.game.npc.NPCServiceImpl;
import com.l2jserver.service.game.pathing.MapperPathingService;
import com.l2jserver.service.game.pathing.PathingService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.scripting.PreCompiledScriptingService;
import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.spawn.SpawnServiceImpl;
import com.l2jserver.service.game.template.ScriptTemplateService;
@@ -78,7 +78,7 @@ public class ServiceModule extends AbstractModule {
.in(Scopes.SINGLETON);
bind(NetworkService.class).to(NettyNetworkService.class).in(
Scopes.SINGLETON);
bind(ScriptingService.class).to(PreCompiledScriptingService.class).in(
bind(ScriptingService.class).to(ScriptingServiceImpl.class).in(
Scopes.SINGLETON);
bind(TemplateService.class).to(ScriptTemplateService.class).in(
Scopes.SINGLETON);

View File

@@ -16,17 +16,23 @@
*/
package com.l2jserver.service.database;
import java.util.Iterator;
import com.google.inject.Inject;
import com.l2jserver.model.Model;
import com.l2jserver.model.id.ID;
/**
* Abstract DAO implementations. Store an instance of {@link DatabaseService}.
* Default {@link Iterator} implementation in this class supports
* {@link Iterator#remove()} and will delete the row from the database.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
* @param <T>
* the dao object type
* @param <I>
* the object id type
*/
public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
implements DataAccessObject<T, I> {
@@ -53,6 +59,39 @@ public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
return false;
}
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
/**
* The Iterator that will return the ID objects
*/
private final Iterator<I> iterator = AbstractDAO.this.selectIDs()
.iterator();
/**
* The last used ID (will be used to remove the last element)
*/
private I lastID;
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public T next() {
lastID = iterator.next();
if (lastID == null)
return null;
return select(lastID);
}
@Override
public void remove() {
AbstractDAO.this.delete(select(lastID));
}
};
}
/**
* @return the database service
*/

View File

@@ -16,23 +16,32 @@
*/
package com.l2jserver.service.database;
import java.util.Iterator;
import java.util.List;
import com.l2jserver.model.Model;
import com.l2jserver.model.id.ID;
import com.l2jserver.service.cache.IgnoreCaching;
/**
* The DAO interface
* The Data Access Object interface used used to retrieve, save and remove
* objects from the database. The underlying storage engine can be an plain text
* file, SQL Database or an serialized version of the object. This layer will
* abstract the translation of the data and ease the transition from one engine
* to another.
* <p>
* TODO make DAO an {@link Iterable}. So if we want to select all objects we can
* do like this: <code><pre>
* for(final Object o : daoInstance) {
* ...
* }
* </pre></code>
* Every DAO is also an {@link Iterable}. If you wish you can iterate through
* all objects in the database very abstractly. But please note that the default
* {@link Iterator} implementation in {@link AbstractDAO} will load all the
* {@link ID} objects and for every call {@link Iterator#next()}, a new database
* query will be made requesting the given object. In a large dataset, this
* could be a huge performance issue. DAO implementations are encouraged to
* override the iterator implementation with a more specific implementation.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface DataAccessObject<O extends Model<?>, I extends ID<?>> {
public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
Iterable<O> {
/**
* Load the instance represented by <tt>id</tt> from the database
*
@@ -41,6 +50,14 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> {
*/
O select(I id);
/**
* Loads an List of all {@link ID}s in the database
*
* @return the list containing all {@link ID} objects
*/
@IgnoreCaching
List<I> selectIDs();
/**
* Save the instance to the database. If a new database entry was created
* returns true.

View File

@@ -41,9 +41,10 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.Model;
import com.l2jserver.model.Model.ObjectState;
import com.l2jserver.model.id.ID;
import com.l2jserver.model.id.object.allocator.IDAllocator;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
@@ -268,6 +269,11 @@ public class MySQLDatabaseService extends AbstractService implements
final PreparedStatement st = conn.prepareStatement(query());
this.parametize(st, object);
rows += st.executeUpdate();
// update object state
if (object instanceof Model)
((Model<?>) object).setObjectState(ObjectState.STORED);
final Mapper<T> mapper = keyMapper(object);
if (mapper == null)
continue;
@@ -330,8 +336,11 @@ public class MySQLDatabaseService extends AbstractService implements
final ResultSet rs = st.getResultSet();
while (rs.next()) {
final T obj = mapper().map(rs);
if (obj != null)
list.add(obj);
if (obj == null)
continue;
if (obj instanceof Model)
((Model<?>) obj).setObjectState(ObjectState.STORED);
list.add(obj);
}
return list;
}
@@ -385,7 +394,10 @@ public class MySQLDatabaseService extends AbstractService implements
st.execute();
final ResultSet rs = st.getResultSet();
while (rs.next()) {
return mapper().map(rs);
final T object = mapper().map(rs);
if (object instanceof Model)
((Model<?>) object).setObjectState(ObjectState.STORED);
return object;
}
return null;
}
@@ -456,27 +468,30 @@ public class MySQLDatabaseService extends AbstractService implements
* @param <I>
* the id type
*/
public abstract static class CachedMapper<T extends WorldObject, I extends ObjectID<T>>
public abstract static class CachedMapper<T extends Model<?>, I extends ID<?>>
implements Mapper<T> {
/**
* The database service instance
*/
private final MySQLDatabaseService database;
private final Mapper<I> idMapper;
/**
* Creates a new instance
*
* @param database
* the database service
*/
public CachedMapper(MySQLDatabaseService database) {
public CachedMapper(MySQLDatabaseService database, Mapper<I> idMapper) {
this.database = database;
this.idMapper = idMapper;
}
@Override
@SuppressWarnings("unchecked")
public final T map(ResultSet rs) throws SQLException {
final I id = createID(rs);
final I id = idMapper.map(rs);
Preconditions.checkNotNull(id, "id");
if (database.hasCachedObject(id))
@@ -488,16 +503,6 @@ public class MySQLDatabaseService extends AbstractService implements
return object;
}
/**
* Creates an ID for an object
*
* @param rs
* the jdbc result set
* @return the id
* @throws SQLException
*/
protected abstract I createID(ResultSet rs) throws SQLException;
/**
* Maps an uncached object. Once mapping is complete, it will be added
* to the cache.

View File

@@ -31,7 +31,6 @@ import java.util.Set;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ScriptClassLoader extends URLClassLoader {
/**
* Just for compatibility with {@link URLClassLoader}
*

View File

@@ -43,7 +43,7 @@ public interface ScriptCompiler {
* @param files
* list of jar files
*/
void setLibraires(Iterable<File> files);
void setLibraries(Iterable<File> files);
/**
* Compiles single class that is represented as string
@@ -51,10 +51,10 @@ public interface ScriptCompiler {
* @param className
* class name
* @param sourceCode
* class sourse code
* class source code
* @return {@link CompilationResult}
*/
CompilationResult compile(String className, String sourceCode);
CompilationResult compile(String className, byte[] sourceCode);
/**
* Compiles classes that are represented as strings
@@ -67,7 +67,7 @@ public interface ScriptCompiler {
* @throws IllegalArgumentException
* if number of class names != number of sources
*/
CompilationResult compile(String[] className, String[] sourceCode)
CompilationResult compile(String[] className, byte[][] sourceCode)
throws IllegalArgumentException;
/**
@@ -80,7 +80,7 @@ public interface ScriptCompiler {
CompilationResult compile(Iterable<File> compilationUnits);
/**
* Returns array of supported file types. This files will be threated as
* Returns array of supported file types. This files will be treated as
* source files.
*
* @return array of supported file types.

View File

@@ -48,13 +48,13 @@ import com.l2jserver.util.factory.CollectionFactory;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Depends(LoggingService.class)
public class PreCompiledScriptingService extends AbstractService implements
public class ScriptingServiceImpl extends AbstractService implements
ScriptingService {
/**
* Logger for script context
*/
private static final Logger log = LoggerFactory
.getLogger(PreCompiledScriptingService.class);
.getLogger(ScriptingServiceImpl.class);
private final Injector injector;
@@ -64,7 +64,7 @@ public class PreCompiledScriptingService extends AbstractService implements
private final Set<ScriptContext> contexts = CollectionFactory.newSet();
@Inject
public PreCompiledScriptingService(Injector injector) {
public ScriptingServiceImpl(Injector injector) {
this.injector = injector;
}

View File

@@ -14,7 +14,7 @@
* 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.scripting.impl.javacc;
package com.l2jserver.service.game.scripting.impl;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -58,10 +58,25 @@ public class BinaryClass implements JavaFileObject {
* @param name
* class name
*/
protected BinaryClass(String name) {
public BinaryClass(String name) {
this.name = name;
}
/**
* Constructor that accepts class name as parameter
*
* @param name
* class name
*/
public BinaryClass(String name, byte[] data) {
this.name = name;
try {
this.baos.write(data);
} catch (IOException e) {
throw new RuntimeException("Cannor write class data", e);
}
}
/**
* Throws {@link UnsupportedOperationException}
*

View File

@@ -14,7 +14,7 @@
* 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.scripting.impl.javacc;
package com.l2jserver.service.game.scripting.impl;
import java.util.Locale;
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class is simple compiler error listener that forwards errors to log4j
* This class is simple compiler error listener that forwards errors to slf4j
* logger
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -40,7 +40,7 @@ public class ErrorListener implements DiagnosticListener<JavaFileObject> {
.getLogger(ErrorListener.class);
/**
* Reports compilation errors to log4j
* Reports compilation errors to slf4j
*
* @param diagnostic
* compiler errors

View File

@@ -14,7 +14,7 @@
* 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.scripting.impl.javacc;
package com.l2jserver.service.game.scripting.impl;
import java.net.URI;
@@ -26,11 +26,11 @@ import javax.tools.SimpleJavaFileObject;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JavaSourceFromString extends SimpleJavaFileObject {
public class JavaSourceFromByteArray extends SimpleJavaFileObject {
/**
* Source code of the class
*/
private final String code;
private final byte[] code;
/**
* Creates new object that contains sources of java class
@@ -40,13 +40,28 @@ public class JavaSourceFromString extends SimpleJavaFileObject {
* @param code
* source code of class
*/
public JavaSourceFromString(String className, String code) {
public JavaSourceFromByteArray(String className, byte[] code) {
super(URI.create("string:///" + className.replace('.', '/')
+ JavaFileObject.Kind.SOURCE.extension),
JavaFileObject.Kind.SOURCE);
this.code = code;
}
/**
* Creates new object that contains sources of java class
*
* @param className
* class name of class
* @param code
* source code of class
*/
public JavaSourceFromByteArray(String className, byte[] code,
JavaFileObject.Kind kind) {
super(URI.create("string:///" + className.replace('.', '/')
+ JavaFileObject.Kind.SOURCE.extension), kind);
this.code = code;
}
/**
* Returns class source code
*
@@ -56,6 +71,6 @@ public class JavaSourceFromString extends SimpleJavaFileObject {
*/
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return code;
return new String(code);
}
}

View File

@@ -14,7 +14,7 @@
* 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.scripting.impl.javacc;
package com.l2jserver.service.game.scripting.impl;
import java.io.File;
import java.io.IOException;
@@ -30,7 +30,6 @@ import org.apache.commons.io.FileUtils;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class JavaSourceFromFile extends SimpleJavaFileObject {
/**
* Construct a JavaFileObject of the given kind and with the given File.
*

View File

@@ -143,7 +143,7 @@ public class ScriptContextImpl implements ScriptContext {
.getCompilationResult().getClassLoader());
}
scriptCompiler.setLibraires(libraries);
scriptCompiler.setLibraries(libraries);
compilationResult = scriptCompiler.compile(files);
getClassListener().postLoad(compilationResult.getCompiledClasses());

View File

@@ -0,0 +1,137 @@
/*
* 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.scripting.impl.compiled;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.util.factory.CollectionFactory;
/**
* This classloader is used to load script classes. <br>
* <br>
* Due to JavaCompiler limitations we have to keep list of available classes
* here.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PrecompiledScriptClassLoader extends ScriptClassLoader {
/**
* Map of all loaded classes
*/
private final Map<String, Class<?>> classes = CollectionFactory.newMap();
/**
* Creates new ScriptClassLoader with given ClassFileManger
*/
PrecompiledScriptClassLoader(final File root) {
super(new URL[] {});
}
/**
* Creates new ScriptClassLoader with given ClassFileManger and another
* classLoader as parent
*
* @param parent
* parent classLoader
*/
PrecompiledScriptClassLoader(ClassLoader parent) {
super(new URL[] {}, parent);
}
/**
* AddsLibrary jar
*
* @param file
* jar file to add
* @throws IOException
*/
@Override
public void addLibrary(File file) throws IOException {
}
/**
* Loads class from library, parent or compiled
*
* @param name
* class to load
* @param file
* the class file
* @return loaded class
* @throws ClassNotFoundException
* if class not found
* @throws IOException
*/
public Class<?> loadClass(File file) throws ClassNotFoundException,
IOException {
byte[] b = FileUtils.readFileToByteArray(file);
Class<?> c = super.defineClass(null, b, 0, b.length);
classes.put(c.getName(), c);
return c;
}
@Override
public synchronized Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
final File file = new File("target/templates");
final File classFile = new File(file, name.replaceAll("\\.", "/")
+ ".class");
System.out.println(name + " -> " + classFile);
if (!classFile.exists()) {
System.out.println("super");
return super.loadClass(name, resolve);
} else if (classes.containsKey(name)) {
return classes.get(name);
} else {
try {
byte[] b = FileUtils.readFileToByteArray(classFile);
System.out.println("Defining...");
Class<?> c = super.defineClass(null, b, 0, b.length);
classes.put(c.getName(), c);
System.out.println(c.getName());
return c;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getLibraryClasses() {
return Collections.emptySet();
}
/**
* {@inheritDoc}
*/
@Override
public Set<String> getCompiledClasses() {
return Collections.unmodifiableSet(classes.keySet());
}
}

View File

@@ -0,0 +1,93 @@
/*
* 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.scripting.impl.compiled;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.l2jserver.service.game.scripting.CompilationResult;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.service.game.scripting.ScriptCompiler;
import com.l2jserver.util.factory.CollectionFactory;
/**
* Wrapper for JavaCompiler api
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PrecompiledScriptCompiler implements ScriptCompiler {
/**
* Parent classloader that has to be used for this compiler
*/
protected ScriptClassLoader parentClassLoader;
public PrecompiledScriptCompiler() {
}
@Override
public void setParentClassLoader(ScriptClassLoader classLoader) {
parentClassLoader = classLoader;
}
@Override
public void setLibraries(Iterable<File> files) {
// do nothing
}
@Override
public CompilationResult compile(String className, byte[] sourceCode) {
throw new UnsupportedOperationException(
"This compiler cannot compile from source");
}
@Override
public CompilationResult compile(String[] className, byte[][] sourceCode)
throws IllegalArgumentException {
throw new UnsupportedOperationException(
"This compiler cannot compile from source");
}
@Override
public CompilationResult compile(Iterable<File> compilationUnits) {
final PrecompiledScriptClassLoader cl = new PrecompiledScriptClassLoader(
this.getClass().getClassLoader());
final List<Class<?>> classes = CollectionFactory.newList();
for (final File file : compilationUnits) {
try {
classes.add(cl.loadClass(file));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return new CompilationResult(classes.toArray(new Class<?>[classes
.size()]), cl);
}
/**
* Only class files are supported by this compiler
*
* @return "class";
*/
@Override
public String[] getSupportedFileTypes() {
return new String[] { "class" };
}
}

View File

@@ -34,6 +34,7 @@ import javax.tools.JavaFileObject.Kind;
import javax.tools.StandardLocation;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.service.game.scripting.impl.BinaryClass;
import com.l2jserver.util.factory.CollectionFactory;
/**

View File

@@ -35,6 +35,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.service.game.scripting.impl.BinaryClass;
import com.l2jserver.util.ClassUtils;
import com.l2jserver.util.factory.CollectionFactory;

View File

@@ -33,6 +33,9 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.service.game.scripting.CompilationResult;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.service.game.scripting.ScriptCompiler;
import com.l2jserver.service.game.scripting.impl.ErrorListener;
import com.l2jserver.service.game.scripting.impl.JavaSourceFromByteArray;
import com.l2jserver.service.game.scripting.impl.JavaSourceFromFile;
import com.l2jserver.util.factory.CollectionFactory;
/**
@@ -41,7 +44,6 @@ import com.l2jserver.util.factory.CollectionFactory;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ScriptCompilerImpl implements ScriptCompiler {
/**
* Logger for this class
*/
@@ -99,7 +101,7 @@ public class ScriptCompilerImpl implements ScriptCompiler {
* list of jar files
*/
@Override
public void setLibraires(Iterable<File> files) {
public void setLibraries(Iterable<File> files) {
libraries = files;
}
@@ -115,8 +117,8 @@ public class ScriptCompilerImpl implements ScriptCompiler {
* if compilation failed with errros
*/
@Override
public CompilationResult compile(String className, String sourceCode) {
return compile(new String[] { className }, new String[] { sourceCode });
public CompilationResult compile(String className, byte[] sourceCode) {
return compile(new String[] { className }, new byte[][] { sourceCode });
}
/**
@@ -134,7 +136,7 @@ public class ScriptCompilerImpl implements ScriptCompiler {
* if compilation failed with errros
*/
@Override
public CompilationResult compile(String[] classNames, String[] sourceCode)
public CompilationResult compile(String[] classNames, byte[][] sourceCode)
throws IllegalArgumentException {
if (classNames.length != sourceCode.length) {
@@ -145,7 +147,7 @@ public class ScriptCompilerImpl implements ScriptCompiler {
List<JavaFileObject> compilationUnits = CollectionFactory.newList();
for (int i = 0; i < classNames.length; i++) {
JavaFileObject compilationUnit = new JavaSourceFromString(
JavaFileObject compilationUnit = new JavaSourceFromByteArray(
classNames[i], sourceCode[i]);
compilationUnits.add(compilationUnit);
}
@@ -212,7 +214,7 @@ public class ScriptCompilerImpl implements ScriptCompiler {
}
/**
* Reolves list of classes by their names
* Resolves list of classes by their names
*
* @param classNames
* names of the classes

View File

@@ -22,6 +22,8 @@ import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import com.l2jserver.service.game.scripting.impl.BinaryClass;
/**
* This class represents URL Connection that is used to "connect" to scripts
* binary data that was loaded by specified {@link ScriptCompilerImpl}.<br>

View File

@@ -82,7 +82,8 @@ public class CachedWorldIDService extends AbstractService implements
@Inject
public CachedWorldIDService(CacheService cacheService,
IDAllocator allocator, CharacterDAO characterDao, ItemDAO itemDao, NPCDAO npcDao) {
IDAllocator allocator, CharacterDAO characterDao, ItemDAO itemDao,
NPCDAO npcDao) {
this.cacheService = cacheService;
this.allocator = allocator;
this.characterDao = characterDao;
@@ -103,9 +104,9 @@ public class CachedWorldIDService extends AbstractService implements
@Override
public void load() {
load(characterDao.listIDs());
load(itemDao.listIDs());
//load(npcDao.listIDs());
load(characterDao.selectIDs());
load(itemDao.selectIDs());
load(npcDao.selectIDs());
loaded = true;
}

View File

@@ -0,0 +1,36 @@
/*
* 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.calculator;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public abstract class AbstractFunction<T extends CalculatorContext> implements
Function<T> {
private final int order;
public AbstractFunction(int order) {
this.order = order;
}
@Override
public int order() {
return order;
}
}

View File

@@ -16,8 +16,8 @@
*/
package com.l2jserver.util.calculator;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.l2jserver.util.factory.CollectionFactory;
@@ -28,18 +28,19 @@ import com.l2jserver.util.factory.CollectionFactory;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Calculator implements Function<Double> {
public class Calculator<T extends CalculatorContext> extends
AbstractFunction<T> {
/**
* List of operations in this calculator
*/
private final List<FunctionContainer> functions = CollectionFactory
.newList();
private final List<Function<T>> functions = CollectionFactory.newList();
/**
* Creates a new empty calculator. Functions can be add using
* {@link #add(int, Function)}.
*/
public Calculator() {
super(0x00);
}
/**
@@ -49,9 +50,10 @@ public class Calculator implements Function<Double> {
* @param functions
* the calculator functions
*/
public Calculator(Function<Double>... functions) {
for (int i = 0; i < functions.length; i++) {
this.functions.add(new FunctionContainer(i, functions[i]));
public Calculator(Function<T>... functions) {
super(0x00);
for (final Function<T> func : functions) {
this.functions.add(func);
}
}
@@ -66,14 +68,14 @@ public class Calculator implements Function<Double> {
* @param function
* the operation
*/
public void add(int order, Function<Double> function) {
functions.add(new FunctionContainer(order, function));
Collections.sort(functions);
public void add(Function<T> function) {
functions.add(function);
Collections.sort(functions, FunctionOrderComparator.SHARED_INSTANCE);
}
/**
* Imports all functions in the given <tt>calculator</tt>. This is useful to
* preserve right calculation ordering but changes to original
* Imports all functions from the given <tt>calculator</tt>. This is useful
* to preserve right calculation ordering but changes to original
* <tt>calculator</tt> will no reflect in this one.
* <p>
* This method will heuristically search for nested calculators.
@@ -81,101 +83,48 @@ public class Calculator implements Function<Double> {
* @param calculator
* the calculator
*/
public void importFunctions(Calculator calculator) {
for (final FunctionContainer container : calculator.functions) {
if (container.function instanceof Calculator) {
importFunctions((Calculator) container.function);
public void importFunctions(Calculator<T> calculator) {
for (final Function<T> function : calculator.functions) {
if (function instanceof Calculator) {
importFunctions((Calculator<T>) function);
} else {
functions.add(container);
functions.add(function);
}
}
}
/**
* Computes the result and output it. Input value is 0.
* Removes all imported functions from the given <tt>calculator</tt>.
* <p>
* This method will heuristically search for nested calculators.
*
* @return the computed value
* @see #calculate(Double)
* @param calculator
* the calculator
*/
public double calculate() {
return calculate(0.00);
public void removeFunctions(Calculator<T> calculator) {
for (final Function<T> function : calculator.functions) {
if (function instanceof Calculator) {
removeFunctions((Calculator<T>) function);
} else {
functions.remove(function);
}
}
}
@Override
public Double calculate(Double input) {
double result = input;
for (final FunctionContainer container : functions) {
result = container.function.calculate(result);
public void calculate(T ctx) {
for (final Function<T> function : functions) {
function.calculate(ctx);
}
return result;
}
/**
* <h1>-- Internal use only --</h1> Container used to sort calculator
* functions. This class implements {@link Comparable} and can be used to
* sort lists using {@link Collections#sort(List)} or
* {@link Arrays#sort(Object[])}.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
private static class FunctionContainer implements
Comparable<FunctionContainer> {
/**
* The execution order
*/
protected final int order;
/**
* The function object
*/
protected final Function<Double> function;
/**
* Creates a new instance
*
* @param order
* the execution order
* @param function
* the function
*/
public FunctionContainer(int order, Function<Double> function) {
this.order = order;
this.function = function;
}
public static class FunctionOrderComparator implements
Comparator<Function<?>> {
public static final FunctionOrderComparator SHARED_INSTANCE = new FunctionOrderComparator();
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((function == null) ? 0 : function.hashCode());
result = prime * result + order;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FunctionContainer other = (FunctionContainer) obj;
if (function == null) {
if (other.function != null)
return false;
} else if (!function.equals(other.function))
return false;
if (order != other.order)
return false;
return true;
}
@Override
public int compareTo(FunctionContainer o) {
if (this.equals(o))
return 0;
return this.order - o.order;
public int compare(Function<?> func1, Function<?> func2) {
return (func1.order() - func2.order());
}
}
}

View File

@@ -0,0 +1,25 @@
/*
* 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.calculator;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class CalculatorContext {
public double result;
}

View File

@@ -22,18 +22,19 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class DivisionFunction implements Function<Double> {
public class DivisionFunction extends AbstractFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public DivisionFunction(double value) {
public DivisionFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public Double calculate(Double value) {
return value / this.value;
public void calculate(CalculatorContext ctx) {
ctx.result /= this.value;
}
}

View File

@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Function<T extends Number> {
public interface Function<T extends CalculatorContext> {
/**
* Performs the operation in the calculation process.
* <p>
@@ -33,5 +33,10 @@ public interface Function<T extends Number> {
* the input value
* @return the output value
*/
T calculate(T value);
void calculate(T ctx);
/**
* @return the order this function will be executed
*/
int order();
}

View File

@@ -22,11 +22,14 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ModulusFunction implements Function<Double> {
public class ModulusFunction extends AbstractFunction<CalculatorContext> {
public ModulusFunction(int order) {
super(order);
}
@Override
public Double calculate(Double value) {
if (value < 0)
return value * -1;
return value;
public void calculate(CalculatorContext ctx) {
if (ctx.result < 0)
ctx.result *= -1;
}
}

View File

@@ -22,18 +22,19 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MultiplicationFunction implements Function<Double> {
public class MultiplicationFunction extends AbstractFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public MultiplicationFunction(double value) {
public MultiplicationFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public Double calculate(Double value) {
return value * this.value;
public void calculate(CalculatorContext ctx) {
ctx.result *= this.value;
}
}

View File

@@ -22,9 +22,13 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NegateFunction implements Function<Double> {
public class NegateFunction extends AbstractFunction<CalculatorContext> {
public NegateFunction(int order) {
super(order);
}
@Override
public Double calculate(Double value) {
return -value;
public void calculate(CalculatorContext ctx) {
ctx.result = -ctx.result;
}
}

View File

@@ -26,7 +26,7 @@ public class PercentFunction extends MultiplicationFunction {
/**
* The value
*/
public PercentFunction(double value) {
super(value / 100);
public PercentFunction(int order, double value) {
super(order, value / 100);
}
}

View File

@@ -21,9 +21,13 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class RoundFunction implements Function<Double> {
public class RoundFunction extends AbstractFunction<CalculatorContext> {
public RoundFunction(int order) {
super(order);
}
@Override
public Double calculate(Double value) {
return (double) Math.round(value);
public void calculate(CalculatorContext ctx) {
ctx.result = Math.round(ctx.result);
}
}

View File

@@ -17,23 +17,23 @@
package com.l2jserver.util.calculator;
/**
* This function performs an set. It ignores the input value and return its
* own.
* This function performs an set. It ignores the input value and return its own.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SetFunction implements Function<Double> {
public class SetFunction extends AbstractFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public SetFunction(double value) {
public SetFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public Double calculate(Double value) {
return this.value;
public void calculate(CalculatorContext ctx) {
ctx.result = value;
}
}

View File

@@ -22,18 +22,19 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SubtractFunction implements Function<Double> {
public class SubtractFunction extends AbstractFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public SubtractFunction(double value) {
public SubtractFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public Double calculate(Double value) {
return value - this.value;
public void calculate(CalculatorContext ctx) {
ctx.result -= value;
}
}

View File

@@ -22,18 +22,19 @@ package com.l2jserver.util.calculator;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SumFunction implements Function<Double> {
public class SumFunction extends AbstractFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public SumFunction(double value) {
public SumFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public Double calculate(Double value) {
return value + this.value;
public void calculate(CalculatorContext ctx) {
ctx.result += value;
}
}