1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2026-01-30 06:22:47 +00:00

Calculator engine improved

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-31 00:03:04 -03:00
parent ae3007559f
commit 7d4d9114e5
92 changed files with 1368 additions and 1318 deletions

47
data/database.trace.db Normal file
View File

@@ -0,0 +1,47 @@
05-30 18:40:23 jdbc[2]: exception
org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-155]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.message.DbException.get(DbException.java:133)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1363)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1338)
at org.h2.jdbc.JdbcConnection.getAutoCommit(JdbcConnection.java:395)
at org.apache.commons.dbcp.DelegatingConnection.getAutoCommit(DelegatingConnection.java:337)
at org.apache.commons.dbcp.PoolableConnectionFactory.activateObject(PoolableConnectionFactory.java:703)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1197)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
at com.l2jserver.service.database.JDBCDatabaseService.query(JDBCDatabaseService.java:170)
at com.l2jserver.db.dao.jdbc.JDBCCharacterDAO.selectByAccount(JDBCCharacterDAO.java:251)
at com.l2jserver.game.net.packet.client.CM_AUTH_LOGIN.process(CM_AUTH_LOGIN.java:88)
at com.l2jserver.game.net.handler.Lineage2PacketHandler.messageReceived(Lineage2PacketHandler.java:83)
at org.jboss.netty.channel.SimpleChannelHandler.handleUpstream(SimpleChannelHandler.java:100)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
at org.jboss.netty.handler.logging.LoggingHandler.handleUpstream(LoggingHandler.java:231)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:76)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
at org.jboss.netty.handler.codec.oneone.OneToOneDecoder.handleUpstream(OneToOneDecoder.java:74)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:317)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)
at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:540)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:349)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:280)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:200)
at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:44)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

View File

@@ -6,16 +6,16 @@
<price>1</price> <price>1</price>
<stats> <stats>
<physicalDamage> <physicalDamage>
<set order="0x80">8</set> <set order="128">8</set>
</physicalDamage> </physicalDamage>
<magicalDamage> <magicalDamage>
<set order="0x80">6</set> <set order="128">6</set>
</magicalDamage> </magicalDamage>
<criticalChance> <criticalChance>
<set order="0x80">8</set> <set order="128">8</set>
</criticalChance> </criticalChance>
<physicalAttackSpeed> <physicalAttackSpeed>
<set order="0x80">379</set> <set order="128">379</set>
</physicalAttackSpeed> </physicalAttackSpeed>
</stats> </stats>
</item> </item>

View File

@@ -16,13 +16,19 @@
*/ */
package com.l2jserver.model.server.attack; package com.l2jserver.model.server.attack;
import com.l2jserver.util.calculator.SimpleCalculator; import com.l2jserver.model.server.attack.AttackCalculator.AttackCalculatorType;
import com.l2jserver.util.calculator.ComplexCalculator;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class AttackCalculator extends SimpleCalculator<AttackCalculatorContext> { public class AttackCalculator extends
ComplexCalculator<AttackCalculatorContext, AttackCalculatorType> {
public AttackCalculator(AttackCalculatorFunction... functions) { public AttackCalculator(AttackCalculatorFunction... functions) {
super(functions); super(AttackCalculatorType.class, functions);
}
public enum AttackCalculatorType {
DAMAGE;
} }
} }

View File

@@ -16,6 +16,7 @@
*/ */
package com.l2jserver.model.server.attack; package com.l2jserver.model.server.attack;
import com.l2jserver.model.server.attack.AttackCalculator.AttackCalculatorType;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.util.calculator.AbstractDoubleFunction; import com.l2jserver.util.calculator.AbstractDoubleFunction;
@@ -23,9 +24,9 @@ import com.l2jserver.util.calculator.AbstractDoubleFunction;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public abstract class AttackCalculatorFunction extends public abstract class AttackCalculatorFunction extends
AbstractDoubleFunction<AttackCalculatorContext> { AbstractDoubleFunction<AttackCalculatorContext, AttackCalculatorType> {
public AttackCalculatorFunction(int order) { public AttackCalculatorFunction(int order, AttackCalculatorType type) {
super(order); super(order, type);
} }
@Override @Override

View File

@@ -25,7 +25,7 @@ import com.l2jserver.model.world.Actor;
*/ */
public class PhysicalAttackCalculator extends AttackCalculator { public class PhysicalAttackCalculator extends AttackCalculator {
public PhysicalAttackCalculator() { public PhysicalAttackCalculator() {
super(new AttackCalculatorFunction(0x000) { super(new AttackCalculatorFunction(0x000, AttackCalculatorType.DAMAGE) {
@Override @Override
public double calculate(Actor attacker, Actor target, double value) { public double calculate(Actor attacker, Actor target, double value) {
// TODO this is certainly not right!!! // TODO this is certainly not right!!!
@@ -33,7 +33,8 @@ public class PhysicalAttackCalculator extends AttackCalculator {
return attacker.getStats().getPhysicalAttack() return attacker.getStats().getPhysicalAttack()
- target.getStats().getPhysicalDefense(); - target.getStats().getPhysicalDefense();
} }
}, new AttackCalculatorFunction(Integer.MAX_VALUE) { }, new AttackCalculatorFunction(Integer.MAX_VALUE,
AttackCalculatorType.DAMAGE) {
@Override @Override
public double calculate(Actor attacker, Actor target, double value) { public double calculate(Actor attacker, Actor target, double value) {
if (value <= 0) if (value <= 0)

View File

@@ -22,14 +22,16 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.calculator.ItemPhysicalDamageActorCalculator; import com.l2jserver.model.template.calculator.ItemSetActorCalculator;
import com.l2jserver.model.world.Item; import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter; import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
/** /**
@@ -74,6 +76,10 @@ public class ItemTemplate extends AbstractTemplate<Item> {
protected StatAttribute physicalDamage; protected StatAttribute physicalDamage;
@XmlElement(name = "magicalDamage") @XmlElement(name = "magicalDamage")
protected StatAttribute magicalDamage; protected StatAttribute magicalDamage;
@XmlElement(name = "criticalChance")
protected StatAttribute criticalChance;
@XmlElement(name = "physicalAttackSpeed")
protected StatAttribute physicalAttackSpeed;
} }
@XmlElement(name = "stats") @XmlElement(name = "stats")
@@ -95,7 +101,9 @@ public class ItemTemplate extends AbstractTemplate<Item> {
protected StatSet set; protected StatSet set;
public static class StatSet { public static class StatSet {
@XmlAttribute(name = "order")
protected int order; protected int order;
@XmlValue
protected double value; protected double value;
/** /**
@@ -172,33 +180,41 @@ public class ItemTemplate extends AbstractTemplate<Item> {
/** /**
* @return the physical damage * @return the physical damage
*/ */
public ItemPhysicalDamageActorCalculator getPhysicalDamage() { public ItemSetActorCalculator getPhysicalDamage() {
if (stats == null) if (stats == null)
return null; return null;
return new ItemPhysicalDamageActorCalculator(stats.physicalDamage.set); if (stats.physicalDamage == null)
return null;
return new ItemSetActorCalculator(stats.physicalDamage.set,
StatType.POWER_ATTACK);
} }
/** /**
* @return the magical damage * @return the magical damage
*/ */
public StatAttribute getMagicalDamage() { public ItemSetActorCalculator getMagicalDamage() {
if (stats == null) if (stats == null)
return null; return null;
return stats.magicalDamage; if (stats.magicalDamage == null)
return null;
return new ItemSetActorCalculator(stats.magicalDamage.set,
StatType.MAGIC_ATTACK);
} }
/* /**
* (non-Javadoc) * @return the magical damage
*
* @see com.l2jserver.model.template.AbstractTemplate#getID()
*/ */
public ItemSetActorCalculator getCriticalChance() {
if (stats == null)
return null;
if (stats.criticalChance == null)
return null;
return new ItemSetActorCalculator(stats.criticalChance.set,
StatType.CRITICAL_RATE);
}
@Override @Override
public ItemTemplateID getID() { public ItemTemplateID getID() {
return id; return id;
} }
// @Override
// public ItemTemplateID getID() {
// return (ItemTemplateID) super.getID();
// }
} }

View File

@@ -19,20 +19,23 @@ package com.l2jserver.model.template.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.template.ItemTemplate.StatAttribute.StatSet; import com.l2jserver.model.template.ItemTemplate.StatAttribute.StatSet;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.calculator.ActorCalculator; import com.l2jserver.model.world.actor.calculator.ActorFormula;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction; import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
* *
*/ */
public class ItemPhysicalDamageActorCalculator extends ActorCalculator { public class ItemSetActorCalculator extends ActorFormula {
public ItemPhysicalDamageActorCalculator(final StatSet set) { private final StatSet set;
super(new ActorCalculatorFunction(set.getOrder()) {
@Override public ItemSetActorCalculator(StatSet set, StatType type) {
protected double calculate(Actor a, ActorTemplate<?> t, double value) { super(set.getOrder(), type);
return set.getValue(); this.set = set;
} }
});
@Override
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return set.getValue();
} }
} }

View File

@@ -35,9 +35,9 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll
* <li><b>Equipped by the {@link L2Character character}</b>: <tt>location</tt> * <li><b>Equipped by the {@link L2Character character}</b>: <tt>location</tt>
* is {@link InventoryLocation#PAPERDOLL}, <tt>paperdoll</tt> is not null and * is {@link InventoryLocation#PAPERDOLL}, <tt>paperdoll</tt> is not null and
* <tt>coordinate</tt> is null.</li> * <tt>coordinate</tt> is null.</li>
* <li><b>Dropped on the ground</b>: <tt>location</tt></li> and <tt>paperdoll</tt> * <li><b>Dropped on the ground</b>: <tt>location</tt></li> and
* are null, <tt>coordinate</tt> is not null and represents the dropping * <tt>paperdoll</tt> are null, <tt>coordinate</tt> is not null and represents
* location. * the dropping location.
* </ul> * </ul>
* <p> * <p>
* Please note that {@link PositionableObject} values are only set if the object * Please note that {@link PositionableObject} values are only set if the object
@@ -127,6 +127,13 @@ public class Item extends PositionableObject {
return templateID; return templateID;
} }
/**
* @return the templateID
*/
public ItemTemplate getTemplate() {
return templateID.getTemplate();
}
/** /**
* @return the ownerID * @return the ownerID
*/ */

View File

@@ -16,13 +16,17 @@
*/ */
package com.l2jserver.model.world.actor.calculator; package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.util.calculator.SimpleCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.calculator.ComplexCalculator;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class ActorCalculator extends SimpleCalculator<ActorCalculatorContext> { public class ActorCalculator extends
public ActorCalculator(ActorCalculatorFunction... functions) { ComplexCalculator<ActorCalculatorContext, StatType> {
super(functions); public ActorCalculator(Class<StatType> type,
Calculator<ActorCalculatorContext, StatType>... calculators) {
super(type, calculators);
} }
} }

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.util.calculator.AbstractDoubleFunction; import com.l2jserver.util.calculator.AbstractDoubleFunction;
/** /**
@@ -26,9 +27,9 @@ import com.l2jserver.util.calculator.AbstractDoubleFunction;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public abstract class ActorCalculatorFunction extends public abstract class ActorCalculatorFunction extends
AbstractDoubleFunction<ActorCalculatorContext> { AbstractDoubleFunction<ActorCalculatorContext, StatType> {
public ActorCalculatorFunction(int order) { public ActorCalculatorFunction(int order, StatType type) {
super(order); super(order, type);
} }
@Override @Override
@@ -36,6 +37,6 @@ public abstract class ActorCalculatorFunction extends
return calculate(ctx.actor, ctx.actor.getTemplate(), value); return calculate(ctx.actor, ctx.actor.getTemplate(), value);
} }
protected abstract double calculate(Actor a, protected abstract double calculate(Actor a, ActorTemplate<?> t,
ActorTemplate<?> t, double value); double value);
} }

View File

@@ -14,21 +14,15 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.util.calculator; package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* This function performs an modulus: <blockquote><code>|chain value|</code>
* </blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class ModulusFunction extends AbstractDoubleFunction<CalculatorContext> { public abstract class ActorFormula extends ActorCalculatorFunction {
public ModulusFunction(int order) { public ActorFormula(int order, StatType type) {
super(order); super(order, type);
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return Math.abs(value);
} }
} }

View File

@@ -20,6 +20,7 @@ import org.apache.commons.math.util.FastMath;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base accuracy. * Calculates the character base accuracy.
@@ -36,21 +37,21 @@ import com.l2jserver.model.world.Actor;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class AttackAccuracyBonusCalculator extends ActorCalculator { public class AttackAccuracyBonusCalculator extends ActorFormula {
public AttackAccuracyBonusCalculator() { public AttackAccuracyBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.ACCURACY_COMBAT);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
final int level = a.getLevel();
value += FastMath.sqrt(a.getStats().getDexterity()) * 6; @Override
value += level; protected double calculate(Actor a, ActorTemplate<?> t, double value) {
if (level > 77) final int level = a.getLevel();
value += (level - 77) + 1;
if (level > 69) value += FastMath.sqrt(a.getStats().getDexterity()) * 6;
value += (level - 69); value += level;
return value; if (level > 77)
} value += (level - 77) + 1;
}); if (level > 69)
value += (level - 69);
return value;
} }
} }

View File

@@ -20,6 +20,7 @@ import org.apache.commons.math.util.FastMath;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character evasion * Calculates the character evasion
@@ -36,21 +37,21 @@ import com.l2jserver.model.world.Actor;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class AttackEvasionBonusCalculator extends ActorCalculator { public class AttackEvasionBonusCalculator extends ActorFormula {
public AttackEvasionBonusCalculator() { public AttackEvasionBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.EVASION_RATE);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
final int level = a.getLevel();
value += FastMath.sqrt(a.getStats().getDexterity()) * 6; @Override
value += level; protected double calculate(Actor a, ActorTemplate<?> t, double value) {
if (level > 77) final int level = a.getLevel();
value += (level - 77) + 1;
if (level > 69) value += FastMath.sqrt(a.getStats().getDexterity()) * 6;
value += (level - 69); value += level;
return value; if (level > 77)
} value += (level - 77) + 1;
}); if (level > 69)
value += (level - 69);
return value;
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base magical attack * Calculates the character base magical attack
@@ -30,16 +31,16 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MagicalAttackBonusCalculator extends ActorCalculator { public class MagicalAttackBonusCalculator extends ActorFormula {
public MagicalAttackBonusCalculator() { public MagicalAttackBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.MAGIC_ATTACK);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* Math.pow(((100.0 - 11 + a.getLevel()) / 100.0), 2) protected double calculate(Actor a, ActorTemplate<?> t, double value) {
* Math.pow(BaseStats.INT.calculateBonus(a.getStats() return value
.getIntelligence()), 2); * Math.pow(((100.0 - 11 + a.getLevel()) / 100.0), 2)
} * Math.pow(BaseStats.INT.calculateBonus(a.getStats()
}); .getIntelligence()), 2);
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the base magical attack speed * Calculates the base magical attack speed
@@ -30,15 +31,13 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MagicalAttackSpeedBonusCalculator extends ActorCalculator { public class MagicalAttackSpeedBonusCalculator extends ActorFormula {
public MagicalAttackSpeedBonusCalculator() { public MagicalAttackSpeedBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.MAGIC_ATTACK_SPEED);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.WIT.calculateBonus(a.getStats() protected double calculate(Actor a, ActorTemplate<?> t, double value) {
.getWitness()); return value * BaseStats.WIT.calculateBonus(a.getStats().getWitness());
}
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the base magical attack critical rate * Calculates the base magical attack critical rate
@@ -30,16 +31,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MagicalCriticalRateBonusCalculator extends ActorCalculator { public class MagicalCriticalRateBonusCalculator extends ActorFormula {
public MagicalCriticalRateBonusCalculator() { public MagicalCriticalRateBonusCalculator() {
super(new ActorCalculatorFunction(0x300) { super(0x300, StatType.MCRITICAL_RATE);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
// TODO only apply if using a weapon @Override
return value protected double calculate(Actor a, ActorTemplate<?> t, double value) {
* BaseStats.WIT.calculateBonus(a.getStats() // TODO only apply if using a weapon
.getWitness()); return value * BaseStats.WIT.calculateBonus(a.getStats().getWitness());
}
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base magical defense. * Calculates the character base magical defense.
@@ -40,29 +41,28 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MagicalDefenseBonusCalculator extends ActorCalculator { public class MagicalDefenseBonusCalculator extends ActorFormula {
public MagicalDefenseBonusCalculator() { public MagicalDefenseBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.MAGIC_DEFENSE);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
// final CharacterInventory inv = c.getInventory();
// if (inv.has(LEFT_FINGER)) @Override
// ctx.result -= 5; protected double calculate(Actor a, ActorTemplate<?> t, double value) {
// if (inv.has(RIGHT_FINGER)) // final CharacterInventory inv = c.getInventory();
// 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;
return value // if (inv.has(LEFT_FINGER))
* BaseStats.MEN.calculateBonus(a.getStats() // ctx.result -= 5;
.getMentality()) // if (inv.has(RIGHT_FINGER))
* ((100.0 - 11 + a.getLevel()) / 100.0); // 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;
return value
* BaseStats.MEN.calculateBonus(a.getStats().getMentality())
* ((100.0 - 11 + a.getLevel()) / 100.0);
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the actor maximum HP bonus * Calculates the actor maximum HP bonus
@@ -29,15 +30,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MaximumHPBonusCalculator extends ActorCalculator { public class MaximumHPBonusCalculator extends ActorFormula {
public MaximumHPBonusCalculator() { public MaximumHPBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.MAX_HP);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.CON.calculateBonus(a.getStats() protected double calculate(Actor a, ActorTemplate<?> t, double value) {
.getConcentration()); return value
} * BaseStats.CON.calculateBonus(a.getStats().getConcentration());
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the actor maximum HP bonus * Calculates the actor maximum HP bonus
@@ -29,15 +30,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MaximumMPBonusCalculator extends ActorCalculator { public class MaximumMPBonusCalculator extends ActorFormula {
public MaximumMPBonusCalculator() { public MaximumMPBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.MAX_MP);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.MEN.calculateBonus(a.getStats() protected double calculate(Actor a, ActorTemplate<?> t, double value) {
.getMentality()); return value
} * BaseStats.MEN.calculateBonus(a.getStats().getMentality());
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base physical attack * Calculates the character base physical attack
@@ -31,16 +32,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class PhysicalAttackBonusCalculator extends ActorCalculator { public class PhysicalAttackBonusCalculator extends ActorFormula {
public PhysicalAttackBonusCalculator() { public PhysicalAttackBonusCalculator() {
super(new ActorCalculatorFunction(0x100) { super(0x100, StatType.POWER_ATTACK);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.STR.calculateBonus(a.getStats() protected double calculate(Actor a, ActorTemplate<?> t, double value) {
.getStrength()) return value * BaseStats.STR.calculateBonus(a.getStats().getStrength())
* ((100.0 - 11 + a.getLevel()) / 100.0); * ((100.0 - 11 + a.getLevel()) / 100.0);
}
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base physical attack speed * Calculates the character base physical attack speed
@@ -30,15 +31,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class PhysicalAttackSpeedBonusCalculator extends ActorCalculator { public class PhysicalAttackSpeedBonusCalculator extends ActorFormula {
public PhysicalAttackSpeedBonusCalculator() { public PhysicalAttackSpeedBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.POWER_ATTACK_SPEED);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.DEX.calculateBonus(a.getStats() protected double calculate(Actor a, ActorTemplate<?> t, double value) {
.getDexterity()); return value
} * BaseStats.DEX.calculateBonus(a.getStats().getDexterity());
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base critical rate * Calculates the character base critical rate
@@ -31,16 +32,16 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class PhysicalCriticalRateBonusCalculator extends ActorCalculator { public class PhysicalCriticalRateBonusCalculator extends ActorFormula {
public PhysicalCriticalRateBonusCalculator() { public PhysicalCriticalRateBonusCalculator() {
super(new ActorCalculatorFunction(0x090) { super(0x090, StatType.CRITICAL_RATE);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.DEX.calculateBonus(a.getStats() protected double calculate(Actor a, ActorTemplate<?> t, double value) {
.getDexterity()) * 10; return value
// TODO l2j uses another variable here, must check why * BaseStats.DEX.calculateBonus(a.getStats().getDexterity())
} * 10;
}); // TODO l2j uses another variable here, must check why
} }
} }

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base physical defense * Calculates the character base physical defense
@@ -41,32 +42,32 @@ import com.l2jserver.model.world.Actor;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class PhysicalDefenseBonusCalculator extends ActorCalculator { public class PhysicalDefenseBonusCalculator extends ActorFormula {
public PhysicalDefenseBonusCalculator() { public PhysicalDefenseBonusCalculator() {
super(new ActorCalculatorFunction(0x200) { super(0x200, StatType.POWER_DEFENSE);
@Override }
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
// final CharacterInventory inv = c.getInventory(); @Override
// protected double calculate(Actor a, ActorTemplate<?> t, double value) {
// // orc mystics are a special case // final CharacterInventory inv = c.getInventory();
// boolean hasMagePDef = (c.getCharacterClass().type == //
// ClassType.MYSTIC || c // // orc mystics are a special case
// .getCharacterClass() == CharacterClass.ORC_MYSTIC); // boolean hasMagePDef = (c.getCharacterClass().type ==
// // ClassType.MYSTIC || c
// if (inv.has(HEAD)) // .getCharacterClass() == CharacterClass.ORC_MYSTIC);
// ctx.result -= 12; //
// final Item chest = inv.getItem(CHEST); // if (inv.has(HEAD))
// if (chest != null) // ctx.result -= 12;
// ctx.result -= hasMagePDef ? 15 : 31; // final Item chest = inv.getItem(CHEST);
// if (inv.has(LEGS)) // if (chest != null)
// // FIXME full armor also applies here // ctx.result -= hasMagePDef ? 15 : 31;
// ctx.result -= hasMagePDef ? 8 : 18; // if (inv.has(LEGS))
// if (inv.has(GLOVES)) // // FIXME full armor also applies here
// ctx.result -= 8; // ctx.result -= hasMagePDef ? 8 : 18;
// if (inv.has(FEET)) // if (inv.has(GLOVES))
// ctx.result -= 7; // ctx.result -= 8;
return value * ((100.0 - 11 + a.getLevel()) / 100.0); // if (inv.has(FEET))
} // ctx.result -= 7;
}); return value * ((100.0 - 11 + a.getLevel()) / 100.0);
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base run speed * Calculates the character base run speed
@@ -29,15 +30,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class RunSpeedBonusCalculator extends ActorCalculator { public class RunSpeedBonusCalculator extends ActorFormula {
public RunSpeedBonusCalculator() { public RunSpeedBonusCalculator() {
super(new ActorCalculatorFunction(0x300) { super(0x300, StatType.RUN_SPEED);
@Override }
protected double calculate(Actor c, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.DEX.calculateBonus(c.getStats() protected double calculate(Actor c, ActorTemplate<?> t, double value) {
.getDexterity()); return value
} * BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
});
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.template.ActorTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base walk speed * Calculates the character base walk speed
@@ -29,15 +30,14 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class WalkSpeedBonusCalculator extends ActorCalculator { public class WalkSpeedBonusCalculator extends ActorFormula {
public WalkSpeedBonusCalculator() { public WalkSpeedBonusCalculator() {
super(new ActorCalculatorFunction(0x300) { super(0x300, StatType.WALK_SPEED);
@Override }
protected double calculate(Actor c, ActorTemplate<?> t, double value) {
return value @Override
* BaseStats.DEX.calculateBonus(c.getStats() protected double calculate(Actor c, ActorTemplate<?> t, double value) {
.getDexterity()); return value
} * BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
});
} }
} }

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.world.actor.stat;
import com.l2jserver.model.world.actor.calculator.ActorCalculator; import com.l2jserver.model.world.actor.calculator.ActorCalculator;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorContext; import com.l2jserver.model.world.actor.calculator.ActorCalculatorContext;
import com.l2jserver.model.world.actor.calculator.ActorFormula;
import com.l2jserver.model.world.actor.calculator.AttackAccuracyBonusCalculator; import com.l2jserver.model.world.actor.calculator.AttackAccuracyBonusCalculator;
import com.l2jserver.model.world.actor.calculator.AttackEvasionBonusCalculator; import com.l2jserver.model.world.actor.calculator.AttackEvasionBonusCalculator;
import com.l2jserver.model.world.actor.calculator.MagicalAttackBonusCalculator; import com.l2jserver.model.world.actor.calculator.MagicalAttackBonusCalculator;
@@ -32,7 +33,6 @@ import com.l2jserver.model.world.actor.calculator.PhysicalCriticalRateBonusCalcu
import com.l2jserver.model.world.actor.calculator.PhysicalDefenseBonusCalculator; import com.l2jserver.model.world.actor.calculator.PhysicalDefenseBonusCalculator;
import com.l2jserver.model.world.actor.calculator.RunSpeedBonusCalculator; import com.l2jserver.model.world.actor.calculator.RunSpeedBonusCalculator;
import com.l2jserver.model.world.actor.calculator.WalkSpeedBonusCalculator; import com.l2jserver.model.world.actor.calculator.WalkSpeedBonusCalculator;
import com.l2jserver.util.calculator.SimpleCalculator;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -46,28 +46,28 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator HP_BONUS_CALCULATOR = new MaximumHPBonusCalculator(); private static final ActorFormula HP_BONUS_FORMULA = new MaximumHPBonusCalculator();
/** /**
* The calculator for base maximum HP * The calculator for base maximum HP
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator MP_BONUS_CALCULATOR = new MaximumMPBonusCalculator(); private static final ActorFormula MP_BONUS_FORMULA = new MaximumMPBonusCalculator();
/** /**
* The calculator for run speed bonus * The calculator for run speed bonus
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator RUN_SPEED_BONUS_CALCULATOR = new RunSpeedBonusCalculator(); private static final ActorFormula RUN_SPEED_BONUS_FORMULA = new RunSpeedBonusCalculator();
/** /**
* The calculator for walk speed bonus * The calculator for walk speed bonus
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator WALK_SPEED_BONUS_CALCULATOR = new WalkSpeedBonusCalculator(); private static final ActorFormula WALK_SPEED_BONUS_FORMULA = new WalkSpeedBonusCalculator();
/** /**
* The calculator base physical attack * The calculator base physical attack
@@ -75,28 +75,28 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator PHYSICAL_ATTACK_BONUS_CALCULATOR = new PhysicalAttackBonusCalculator(); private static final ActorFormula PHYSICAL_ATTACK_BONUS_FORMULA = new PhysicalAttackBonusCalculator();
/** /**
* The calculator base physical attack speed * The calculator base physical attack speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator PHYSICAL_ATTACK_SPEED_BONUS_CALCULATOR = new PhysicalAttackSpeedBonusCalculator(); private static final ActorFormula PHYSICAL_ATTACK_SPEED_BONUS_FORMULA = new PhysicalAttackSpeedBonusCalculator();
/** /**
* The calculator base physical attack critical rate * The calculator base physical attack critical rate
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator PHYSICAL_CRITICAL_RATE_BONUS_CALCULATOR = new PhysicalCriticalRateBonusCalculator(); private static final ActorFormula PHYSICAL_CRITICAL_RATE_BONUS_FORMULA = new PhysicalCriticalRateBonusCalculator();
/** /**
* The calculator base physical defense * The calculator base physical defense
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator PHYSICAL_DEFENSE_BONUS_CALCULATOR = new PhysicalDefenseBonusCalculator(); private static final ActorFormula PHYSICAL_DEFENSE_BONUS_FORMULA = new PhysicalDefenseBonusCalculator();
/** /**
* The calculator base magical attack * The calculator base magical attack
@@ -104,28 +104,28 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator MAGICAL_ATTACK_BONUS_CALCULATOR = new MagicalAttackBonusCalculator(); private static final ActorFormula MAGICAL_ATTACK_BONUS_FORMULA = new MagicalAttackBonusCalculator();
/** /**
* The calculator base magical attack speed * The calculator base magical attack speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator MAGICAL_ATTACK_SPEED_BONUS_CALCULATOR = new MagicalAttackSpeedBonusCalculator(); private static final ActorFormula MAGICAL_ATTACK_SPEED_BONUS_FORMULA = new MagicalAttackSpeedBonusCalculator();
/** /**
* The calculator base magical attack critical rate * The calculator base magical attack critical rate
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator MAGICAL_CRITICAL_RATE_BONUS_CALCULATOR = new MagicalCriticalRateBonusCalculator(); private static final ActorFormula MAGICAL_CRITICAL_RATE_BONUS_FORMULA = new MagicalCriticalRateBonusCalculator();
/** /**
* The calculator base magical defense * The calculator base magical defense
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator MAGICAL_DEFENSE_BONUS_CALCULATOR = new MagicalDefenseBonusCalculator(); private static final ActorFormula MAGICAL_DEFENSE_BONUS_FORMULA = new MagicalDefenseBonusCalculator();
/** /**
* The calculator base attack accuracy * The calculator base attack accuracy
@@ -133,52 +133,27 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator ATTACK_ACCURACY_BONUS_CALCULATOR = new AttackAccuracyBonusCalculator(); private static final ActorFormula ATTACK_ACCURACY_BONUS_FORMULA = new AttackAccuracyBonusCalculator();
/** /**
* The calculator base evasion * The calculator base evasion
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final ActorCalculator ATTACK_EVASION_BONUS_CALCULATOR = new AttackEvasionBonusCalculator(); private static final ActorFormula ATTACK_EVASION_BONUS_FORMULA = new AttackEvasionBonusCalculator();
/**
* The list of calculators for this character
* <p>
* It is safe to use an array since this number cannot be changed in
* runtime, it would be required to be able to change the {@link StatType}
* enum. Also, an full-sized array is created because this way we don't need
* to change the array size very often. A bit of memory is "lost", but the
* speed gain is much higher.
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private final SimpleCalculator<T>[] calculators = new SimpleCalculator[StatType protected void addTo(ActorCalculator calculator) {
.values().length]; calculator.addNoSort(HP_BONUS_FORMULA, MP_BONUS_FORMULA,
RUN_SPEED_BONUS_FORMULA, WALK_SPEED_BONUS_FORMULA,
public ActorStats() { PHYSICAL_ATTACK_BONUS_FORMULA,
for (int i = 0; i < calculators.length; i++) { PHYSICAL_ATTACK_SPEED_BONUS_FORMULA,
calculators[i] = new SimpleCalculator<T>(); PHYSICAL_CRITICAL_RATE_BONUS_FORMULA,
} PHYSICAL_DEFENSE_BONUS_FORMULA, MAGICAL_ATTACK_BONUS_FORMULA,
MAGICAL_ATTACK_SPEED_BONUS_FORMULA,
// bonuses MAGICAL_CRITICAL_RATE_BONUS_FORMULA,
add(StatType.MAX_HP, HP_BONUS_CALCULATOR); MAGICAL_DEFENSE_BONUS_FORMULA, ATTACK_ACCURACY_BONUS_FORMULA,
add(StatType.MAX_MP, MP_BONUS_CALCULATOR); ATTACK_EVASION_BONUS_FORMULA);
add(StatType.RUN_SPEED, RUN_SPEED_BONUS_CALCULATOR);
add(StatType.WALK_SPEED, WALK_SPEED_BONUS_CALCULATOR);
add(StatType.POWER_ATTACK, PHYSICAL_ATTACK_BONUS_CALCULATOR);
add(StatType.POWER_ATTACK_SPEED, PHYSICAL_ATTACK_SPEED_BONUS_CALCULATOR);
add(StatType.CRITICAL_RATE, PHYSICAL_CRITICAL_RATE_BONUS_CALCULATOR);
add(StatType.POWER_DEFENSE, PHYSICAL_DEFENSE_BONUS_CALCULATOR);
add(StatType.MAGIC_ATTACK, MAGICAL_ATTACK_BONUS_CALCULATOR);
add(StatType.MAGIC_ATTACK_SPEED, MAGICAL_ATTACK_SPEED_BONUS_CALCULATOR);
add(StatType.MCRITICAL_RATE, MAGICAL_CRITICAL_RATE_BONUS_CALCULATOR);
add(StatType.MAGIC_DEFENSE, MAGICAL_DEFENSE_BONUS_CALCULATOR);
add(StatType.ACCURACY_COMBAT, ATTACK_ACCURACY_BONUS_CALCULATOR);
add(StatType.EVASION_RATE, ATTACK_EVASION_BONUS_CALCULATOR);
} }
/** /**
@@ -321,22 +296,15 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
return (int) calc(StatType.EVASION_RATE); return (int) calc(StatType.EVASION_RATE);
} }
public void add(StatType type, ActorCalculator calculator) { // public void add(StatType type, ActorCalculator calculator) {
getCalculator(type).importFunctions(calculator); // if (calculator == null)
} // return;
// getCalculator(type).importFunctions(calculator);
public void remove(StatType type, ActorCalculator calculator) { // }
getCalculator(type).removeFunctions(calculator); //
} // public void remove(StatType type, ActorCalculator calculator) {
// getCalculator(type).removeFunctions(calculator);
/** // }
* @param the
* calculator {@link StatType}
* @return the calculator object associated with the given <tt>type</tt>
*/
protected SimpleCalculator<T> getCalculator(StatType type) {
return calculators[type.ordinal()];
}
/** /**
* Does the calculation of an given {@link StatType} * Does the calculation of an given {@link StatType}
@@ -347,12 +315,10 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
*/ */
protected double calc(StatType type) { protected double calc(StatType type) {
final T ctx = createContext(); final T ctx = createContext();
return getCalculator(type).calculate(ctx); return getCalculator().calculate(type, ctx);
} }
public void updateCalculators() { protected abstract ActorCalculator getCalculator();
}
protected abstract T createContext(); protected abstract T createContext();
} }

View File

@@ -16,12 +16,15 @@
*/ */
package com.l2jserver.model.world.character; package com.l2jserver.model.world.character;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.calculator.ActorCalculator;
import com.l2jserver.model.world.actor.stat.ActorStats; import com.l2jserver.model.world.actor.stat.ActorStats;
import com.l2jserver.model.world.actor.stat.StatType; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll; import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.character.calculator.CharacterCalculator;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext; import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext;
import com.l2jserver.model.world.character.calculator.CharacterFormula;
import com.l2jserver.model.world.character.calculator.MaximumCPAddCalculator; import com.l2jserver.model.world.character.calculator.MaximumCPAddCalculator;
import com.l2jserver.model.world.character.calculator.MaximumCPBonusCalculator; import com.l2jserver.model.world.character.calculator.MaximumCPBonusCalculator;
import com.l2jserver.model.world.character.calculator.MaximumHPAddCalculator; import com.l2jserver.model.world.character.calculator.MaximumHPAddCalculator;
@@ -74,21 +77,21 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_HP_CALCULATOR = new CharacterBaseHPCalculator(); private static final CharacterFormula BASE_HP_FORMULA = new CharacterBaseHPCalculator();
/** /**
* The calculator for base maximum MP * The calculator for base maximum MP
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_MP_CALCULATOR = new CharacterBaseMPCalculator(); private static final CharacterFormula BASE_MP_FORMULA = new CharacterBaseMPCalculator();
/** /**
* The calculator for base maximum CP * The calculator for base maximum CP
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_CP_CALCULATOR = new CharacterBaseCPCalculator(); private static final CharacterFormula BASE_CP_FORMULA = new CharacterBaseCPCalculator();
/** /**
* The calculator for base intelligence * The calculator for base intelligence
@@ -96,42 +99,42 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_INT_CALCULATOR = new CharacterBaseIntelligenceCalculator(); private static final CharacterFormula BASE_INT_FORMULA = new CharacterBaseIntelligenceCalculator();
/** /**
* The calculator for base strength * The calculator for base strength
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_STR_CALCULATOR = new CharacterBaseStrengthCalculator(); private static final CharacterFormula BASE_STR_FORMULA = new CharacterBaseStrengthCalculator();
/** /**
* The calculator for base concentration * The calculator for base concentration
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_CON_CALCULATOR = new CharacterBaseConcentrationCalculator(); private static final CharacterFormula BASE_CON_FORMULA = new CharacterBaseConcentrationCalculator();
/** /**
* The calculator for base mentality * The calculator for base mentality
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_MEN_CALCULATOR = new CharacterBaseMentalityCalculator(); private static final CharacterFormula BASE_MEN_FORMULA = new CharacterBaseMentalityCalculator();
/** /**
* The calculator for base dexterity * The calculator for base dexterity
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_DEX_CALCULATOR = new CharacterBaseDexterityCalculator(); private static final CharacterFormula BASE_DEX_FORMULA = new CharacterBaseDexterityCalculator();
/** /**
* The calculator for base witness * The calculator for base witness
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_WIT_CALCULATOR = new CharacterBaseWitnessCalculator(); private static final CharacterFormula BASE_WIT_FORMULA = new CharacterBaseWitnessCalculator();
/** /**
* The calculator for base run speed * The calculator for base run speed
@@ -139,14 +142,14 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_RUN_SPEED_CALCULATOR = new CharacterBaseRunSpeedCalculator(); private static final CharacterFormula BASE_RUN_SPEED_FORMULA = new CharacterBaseRunSpeedCalculator();
/** /**
* The calculator for base walk speed * The calculator for base walk speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_WALK_SPEED_CALCULATOR = new CharacterBaseWalkSpeedCalculator(); private static final CharacterFormula BASE_WALK_SPEED_FORMULA = new CharacterBaseWalkSpeedCalculator();
/** /**
* The calculator base physical attack * The calculator base physical attack
@@ -154,28 +157,28 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_PHYSICAL_ATTACK_CALCULATOR = new CharacterBasePhysicalAttackCalculator(); private static final CharacterFormula BASE_PHYSICAL_ATTACK_FORMULA = new CharacterBasePhysicalAttackCalculator();
/** /**
* The calculator base physical attack speed * The calculator base physical attack speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR = new CharacterBasePhysicalAttackSpeedCalculator(); private static final CharacterFormula BASE_PHYSICAL_ATTACK_SPEED_FORMULA = new CharacterBasePhysicalAttackSpeedCalculator();
/** /**
* The calculator base physical attack critical rate * The calculator base physical attack critical rate
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR = new CharacterBasePhysicalCriticalRateCalculator(); private static final CharacterFormula BASE_PHYSICAL_CRITICAL_RATE_FORMULA = new CharacterBasePhysicalCriticalRateCalculator();
/** /**
* The calculator base physical defense * The calculator base physical defense
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_PHYSICAL_DEFENSE_CALCULATOR = new CharacterBasePhysicalDefenseCalculator(); private static final CharacterFormula BASE_PHYSICAL_DEFENSE_FORMULA = new CharacterBasePhysicalDefenseCalculator();
/** /**
* The calculator base magical attack * The calculator base magical attack
@@ -183,28 +186,28 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_MAGICAL_ATTACK_CALCULATOR = new CharacterBaseMagicalAttackCalculator(); private static final CharacterFormula BASE_MAGICAL_ATTACK_FORMULA = new CharacterBaseMagicalAttackCalculator();
/** /**
* The calculator base magical attack speed * The calculator base magical attack speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_MAGICAL_ATTACK_SPEED_CALCULATOR = new CharacterBaseMagicalAttackSpeedCalculator(); private static final CharacterFormula BASE_MAGICAL_ATTACK_SPEED_FORMULA = new CharacterBaseMagicalAttackSpeedCalculator();
/** /**
* The calculator base magical attack critical rate * The calculator base magical attack critical rate
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_MAGICAL_CRITICAL_RATE_CALCULATOR = new CharacterBaseMagicalCriticalRateCalculator(); private static final CharacterFormula BASE_MAGICAL_CRITICAL_RATE_FORMULA = new CharacterBaseMagicalCriticalRateCalculator();
/** /**
* The calculator base magical defense * The calculator base magical defense
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new CharacterBaseMagicalDefenseCalculator(); private static final CharacterFormula BASE_MAGICAL_DEFENSE_FORMULA = new CharacterBaseMagicalDefenseCalculator();
/** /**
* The calculator base attack accuracy * The calculator base attack accuracy
@@ -212,14 +215,14 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new CharacterBaseAttackAccuracyCalculator(); private static final CharacterFormula BASE_ATTACK_ACCURACY_FORMULA = new CharacterBaseAttackAccuracyCalculator();
/** /**
* The calculator base evasion * The calculator base evasion
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator BASE_ATTACK_EVASION_CALCULATOR = new CharacterBaseAttackEvasionCalculator(); private static final CharacterFormula BASE_ATTACK_EVASION_FORMULA = new CharacterBaseAttackEvasionCalculator();
// BONUS // BONUS
/** /**
@@ -228,7 +231,7 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator CP_BONUS_CALCULATOR = new MaximumCPBonusCalculator(); private static final CharacterFormula CP_BONUS_FORMULA = new MaximumCPBonusCalculator();
// ADD // ADD
/** /**
@@ -237,27 +240,30 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator HP_ADD_CALCULATOR = new MaximumHPAddCalculator(); private static final CharacterFormula HP_ADD_FORMULA = new MaximumHPAddCalculator();
/** /**
* The calculator for MP add * The calculator for MP add
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator MP_ADD_CALCULATOR = new MaximumMPAddCalculator(); private static final CharacterFormula MP_ADD_FORMULA = new MaximumMPAddCalculator();
/** /**
* The calculator for CP add * The calculator for CP add
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final CharacterCalculator CP_ADD_CALCULATOR = new MaximumCPAddCalculator(); private static final CharacterFormula CP_ADD_FORMULA = new MaximumCPAddCalculator();
/** /**
* The character * The character
*/ */
private final L2Character character; private final L2Character character;
private static final CharacterCalculator calculator = new CharacterCalculator(
StatType.class);
/** /**
* Creates a new {@link CharacterStats} and adds default calculators * Creates a new {@link CharacterStats} and adds default calculators
* *
@@ -267,44 +273,12 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
public CharacterStats(L2Character character) { public CharacterStats(L2Character character) {
super(); super();
this.character = character; this.character = character;
setup();
}
// base @Override
add(StatType.MAX_HP, BASE_HP_CALCULATOR); protected ActorCalculator getCalculator() {
add(StatType.MAX_MP, BASE_MP_CALCULATOR); return calculator;
add(StatType.MAX_CP, BASE_CP_CALCULATOR);
add(StatType.STAT_INT, BASE_INT_CALCULATOR);
add(StatType.STAT_STR, BASE_STR_CALCULATOR);
add(StatType.STAT_CON, BASE_CON_CALCULATOR);
add(StatType.STAT_MEN, BASE_MEN_CALCULATOR);
add(StatType.STAT_DEX, BASE_DEX_CALCULATOR);
add(StatType.STAT_WIT, BASE_WIT_CALCULATOR);
add(StatType.RUN_SPEED, BASE_RUN_SPEED_CALCULATOR);
add(StatType.WALK_SPEED, BASE_WALK_SPEED_CALCULATOR);
add(StatType.POWER_ATTACK, BASE_PHYSICAL_ATTACK_CALCULATOR);
add(StatType.POWER_ATTACK_SPEED, BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR);
add(StatType.CRITICAL_RATE, BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR);
add(StatType.POWER_DEFENSE, BASE_PHYSICAL_DEFENSE_CALCULATOR);
add(StatType.MAGIC_ATTACK, BASE_MAGICAL_ATTACK_CALCULATOR);
add(StatType.MAGIC_ATTACK_SPEED, BASE_MAGICAL_ATTACK_SPEED_CALCULATOR);
add(StatType.MCRITICAL_RATE, BASE_MAGICAL_CRITICAL_RATE_CALCULATOR);
add(StatType.MAGIC_DEFENSE, BASE_MAGICAL_DEFENSE_CALCULATOR);
add(StatType.ACCURACY_COMBAT, BASE_ATTACK_ACCURACY_CALCULATOR);
add(StatType.EVASION_RATE, BASE_ATTACK_EVASION_CALCULATOR);
// add hp/mp/cp add functions
add(StatType.MAX_HP, HP_ADD_CALCULATOR);
add(StatType.MAX_MP, MP_ADD_CALCULATOR);
add(StatType.MAX_CP, CP_ADD_CALCULATOR);
// bonus
add(StatType.MAX_CP, CP_BONUS_CALCULATOR);
// TODO henna stats calculators
} }
/** /**
@@ -321,15 +295,53 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
return (int) calc(StatType.MAX_LOAD); return (int) calc(StatType.MAX_LOAD);
} }
@Override @SuppressWarnings("unchecked")
public void updateCalculators() { private void setup() {
super.updateCalculators(); calculator.addNoSort(BASE_HP_FORMULA, BASE_MP_FORMULA,
if (character.getInventory().has(InventoryPaperdoll.RIGHT_HAND)) { BASE_CP_FORMULA);
add(StatType.POWER_ATTACK,
character.getInventory() calculator.addNoSort(BASE_INT_FORMULA, BASE_STR_FORMULA,
.getItem(InventoryPaperdoll.RIGHT_HAND) BASE_CON_FORMULA, BASE_MEN_FORMULA, BASE_DEX_FORMULA,
.getTemplateID().getTemplate().getPhysicalDamage()); BASE_WIT_FORMULA);
}
calculator.addNoSort(BASE_RUN_SPEED_FORMULA, BASE_WALK_SPEED_FORMULA);
calculator.addNoSort(BASE_PHYSICAL_ATTACK_FORMULA,
BASE_PHYSICAL_ATTACK_SPEED_FORMULA,
BASE_PHYSICAL_CRITICAL_RATE_FORMULA,
BASE_PHYSICAL_DEFENSE_FORMULA);
calculator.addNoSort(BASE_MAGICAL_ATTACK_FORMULA,
BASE_MAGICAL_ATTACK_SPEED_FORMULA,
BASE_MAGICAL_CRITICAL_RATE_FORMULA,
BASE_MAGICAL_DEFENSE_FORMULA);
calculator.addNoSort(BASE_ATTACK_ACCURACY_FORMULA,
BASE_ATTACK_EVASION_FORMULA);
// add hp/mp/cp add functions
calculator.addNoSort(HP_ADD_FORMULA, MP_ADD_FORMULA, CP_ADD_FORMULA);
// bonus
calculator.addNoSort(CP_BONUS_FORMULA);
addTo(calculator);
calculator.sort();
}
public void updateCalculator() {
calculator.clear();
setup();
addItem(InventoryPaperdoll.RIGHT_HAND);
}
private void addItem(InventoryPaperdoll paperdoll) {
if (!character.getInventory().has(paperdoll))
return;
final ItemTemplate item = character.getInventory().getItem(paperdoll)
.getTemplate();
calculator.add(item.getPhysicalDamage());
calculator.add(item.getMagicalDamage());
} }
@Override @Override

View File

@@ -17,6 +17,9 @@
package com.l2jserver.model.world.character.calculator; package com.l2jserver.model.world.character.calculator;
import com.l2jserver.model.world.actor.calculator.ActorCalculator; import com.l2jserver.model.world.actor.calculator.ActorCalculator;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorContext;
import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.util.calculator.Calculator;
/** /**
* An calculator for character formulas. * An calculator for character formulas.
@@ -24,7 +27,8 @@ import com.l2jserver.model.world.actor.calculator.ActorCalculator;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterCalculator extends ActorCalculator { public class CharacterCalculator extends ActorCalculator {
public CharacterCalculator(CharacterCalculatorFunction... functions) { public CharacterCalculator(Class<StatType> type,
super(functions); Calculator<ActorCalculatorContext, StatType>... calculators) {
super(type, calculators);
} }
} }

View File

@@ -21,6 +21,7 @@ import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction; import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* An calculator for character formulas. * An calculator for character formulas.
@@ -29,8 +30,8 @@ import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
*/ */
public abstract class CharacterCalculatorFunction extends public abstract class CharacterCalculatorFunction extends
ActorCalculatorFunction { ActorCalculatorFunction {
public CharacterCalculatorFunction(int order) { public CharacterCalculatorFunction(int order, StatType type) {
super(order); super(order, type);
} }
@Override @Override

View File

@@ -14,20 +14,17 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.util.calculator; package com.l2jserver.model.world.character.calculator;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* This function performs an rounding in the number. * An calculator for character formulas.
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class RoundFunction extends AbstractDoubleFunction<CalculatorContext> { public abstract class CharacterFormula extends CharacterCalculatorFunction {
public RoundFunction(int order) { public CharacterFormula(int order, StatType type) {
super(order); super(order, type);
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return Math.round(value);
} }
} }

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base CP * Calculates the character base CP
@@ -32,19 +33,17 @@ import com.l2jserver.model.world.L2Character;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MaximumCPAddCalculator extends CharacterCalculator { public class MaximumCPAddCalculator extends CharacterFormula {
public MaximumCPAddCalculator() { public MaximumCPAddCalculator() {
super(new CharacterCalculatorFunction(0x100) { super(0x100, StatType.MAX_CP);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) {
int lvl = c.getLevel() - t.getMinimumLevel();
double mod = t.getBaseCPModifier() * lvl;
double max = (t.getBaseCPAdd() + mod) * lvl;
double min = (t.getBaseCPAdd() * lvl) + mod;
return value + (max + min) / 2; protected double calculate(L2Character c, CharacterTemplate t, double value) {
} int lvl = c.getLevel() - t.getMinimumLevel();
}); double mod = t.getBaseCPModifier() * lvl;
double max = (t.getBaseCPAdd() + mod) * lvl;
double min = (t.getBaseCPAdd() * lvl) + mod;
return value + (max + min) / 2;
} }
} }

View File

@@ -19,6 +19,7 @@ package com.l2jserver.model.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.BaseStats; import com.l2jserver.model.world.actor.stat.BaseStats;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base CP * Calculates the character base CP
@@ -33,16 +34,13 @@ import com.l2jserver.model.world.actor.stat.BaseStats;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MaximumCPBonusCalculator extends CharacterCalculator { public class MaximumCPBonusCalculator extends CharacterFormula {
public MaximumCPBonusCalculator() { public MaximumCPBonusCalculator() {
super(new CharacterCalculatorFunction(0x100) { super(0x100, StatType.MAX_CP);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { protected double calculate(L2Character c, CharacterTemplate t, double value) {
return value return value
* BaseStats.CON.calculateBonus(c.getStats() * BaseStats.CON.calculateBonus(c.getStats().getConcentration());
.getConcentration());
}
});
} }
} }

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character maximum HP * Calculates the character maximum HP
@@ -32,19 +33,17 @@ import com.l2jserver.model.world.L2Character;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MaximumHPAddCalculator extends CharacterCalculator { public class MaximumHPAddCalculator extends CharacterFormula {
public MaximumHPAddCalculator() { public MaximumHPAddCalculator() {
super(new CharacterCalculatorFunction(0x100) { super(0x100, StatType.MAX_HP);
@Override }
public double calculate(L2Character c, CharacterTemplate t,
double value) {
int lvl = c.getLevel() - t.getMinimumLevel();
double mod = t.getBaseHPModifier() * lvl;
double max = (t.getBaseHPAdd() + mod) * lvl;
double min = (t.getBaseHPAdd() * lvl) + mod;
return value + (max + min) / 2; public double calculate(L2Character c, CharacterTemplate t, double value) {
} int lvl = c.getLevel() - t.getMinimumLevel();
}); double mod = t.getBaseHPModifier() * lvl;
double max = (t.getBaseHPAdd() + mod) * lvl;
double min = (t.getBaseHPAdd() * lvl) + mod;
return value + (max + min) / 2;
} }
} }

View File

@@ -18,6 +18,7 @@ package com.l2jserver.model.world.character.calculator;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* Calculates the character base MP * Calculates the character base MP
@@ -32,19 +33,18 @@ import com.l2jserver.model.world.L2Character;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class MaximumMPAddCalculator extends CharacterCalculator { public class MaximumMPAddCalculator extends CharacterFormula {
public MaximumMPAddCalculator() { public MaximumMPAddCalculator() {
super(new CharacterCalculatorFunction(0x100) { super(0x100, StatType.MAX_MP);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) {
int lvl = c.getLevel() - t.getMinimumLevel();
double mod = t.getBaseMPModifier() * lvl;
double max = (t.getBaseMPAdd() + mod) * lvl;
double min = (t.getBaseMPAdd() * lvl) + mod;
return value + (max + min) / 2; @Override
} protected double calculate(L2Character c, CharacterTemplate t, double value) {
}); int lvl = c.getLevel() - t.getMinimumLevel();
double mod = t.getBaseMPModifier() * lvl;
double max = (t.getBaseMPAdd() + mod) * lvl;
double min = (t.getBaseMPAdd() * lvl) + mod;
return value + (max + min) / 2;
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base accuracy. * Calculates the character base accuracy.
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseAttackAccuracyCalculator extends CharacterCalculator { public class CharacterBaseAttackAccuracyCalculator extends CharacterFormula {
public CharacterBaseAttackAccuracyCalculator() { public CharacterBaseAttackAccuracyCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.ACCURACY_COMBAT);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseAccuracy(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseAccuracy();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character evasion * Calculates the character evasion
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseAttackEvasionCalculator extends CharacterCalculator { public class CharacterBaseAttackEvasionCalculator extends CharacterFormula {
public CharacterBaseAttackEvasionCalculator() { public CharacterBaseAttackEvasionCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.EVASION_RATE);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseEvasion(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseEvasion();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character maximum CP * Calculates the character maximum CP
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseCPCalculator extends CharacterCalculator { public class CharacterBaseCPCalculator extends CharacterFormula {
public CharacterBaseCPCalculator() { public CharacterBaseCPCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MAX_CP);
@Override }
public double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseCP(); public double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseCP();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character concentration * Calculates the character concentration
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseConcentrationCalculator extends CharacterCalculator { public class CharacterBaseConcentrationCalculator extends CharacterFormula {
public CharacterBaseConcentrationCalculator() { public CharacterBaseConcentrationCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.STAT_CON);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseConcentration(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseConcentration();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base dexterity * Calculates the character base dexterity
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseDexterityCalculator extends CharacterCalculator { public class CharacterBaseDexterityCalculator extends CharacterFormula {
public CharacterBaseDexterityCalculator() { public CharacterBaseDexterityCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.STAT_DEX);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseDexterity(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseDexterity();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character maximum HP * Calculates the character maximum HP
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseHPCalculator extends CharacterCalculator { public class CharacterBaseHPCalculator extends CharacterFormula {
public CharacterBaseHPCalculator() { public CharacterBaseHPCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MAX_HP);
@Override }
public double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseHP(); public double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseHP();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base intelligence * Calculates the character base intelligence
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseIntelligenceCalculator extends CharacterCalculator { public class CharacterBaseIntelligenceCalculator extends CharacterFormula {
public CharacterBaseIntelligenceCalculator() { public CharacterBaseIntelligenceCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.STAT_INT);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseIntelligence(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseIntelligence();
});
} }
} }

View File

@@ -18,11 +18,11 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character maximum HP * Calculates the character maximum MP
* *
* <pre> * <pre>
* return c.getTemplate().getBaseMP(); * return c.getTemplate().getBaseMP();
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseMPCalculator extends CharacterCalculator { public class CharacterBaseMPCalculator extends CharacterFormula {
public CharacterBaseMPCalculator() { public CharacterBaseMPCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MAX_MP);
@Override }
public double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseBaseMP(); public double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseBaseMP();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base magical attack * Calculates the character base magical attack
@@ -31,14 +31,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseMagicalAttackCalculator extends CharacterCalculator { public class CharacterBaseMagicalAttackCalculator extends CharacterFormula {
public CharacterBaseMagicalAttackCalculator() { public CharacterBaseMagicalAttackCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MAGIC_ATTACK);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseMagicalAttack(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseMagicalAttack();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the base magical attack speed * Calculates the base magical attack speed
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseMagicalAttackSpeedCalculator extends CharacterCalculator { public class CharacterBaseMagicalAttackSpeedCalculator extends CharacterFormula {
public CharacterBaseMagicalAttackSpeedCalculator() { public CharacterBaseMagicalAttackSpeedCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MAGIC_ATTACK_SPEED);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseMagicalAttackSpeed(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseMagicalAttackSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the base magical attack critical rate * Calculates the base magical attack critical rate
@@ -32,14 +32,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseMagicalCriticalRateCalculator extends public class CharacterBaseMagicalCriticalRateCalculator extends
CharacterCalculator { CharacterFormula {
public CharacterBaseMagicalCriticalRateCalculator() { public CharacterBaseMagicalCriticalRateCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MCRITICAL_RATE);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseCritical(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseCritical();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base magical defense. * Calculates the character base magical defense.
@@ -41,14 +41,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseMagicalDefenseCalculator extends CharacterCalculator { public class CharacterBaseMagicalDefenseCalculator extends CharacterFormula {
public CharacterBaseMagicalDefenseCalculator() { public CharacterBaseMagicalDefenseCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.MAGIC_DEFENSE);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseMagicalDefense(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseMagicalDefense();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base mentality * Calculates the character base mentality
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseMentalityCalculator extends CharacterCalculator { public class CharacterBaseMentalityCalculator extends CharacterFormula {
public CharacterBaseMentalityCalculator() { public CharacterBaseMentalityCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.STAT_MEN);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseMentality(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseMentality();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base physical attack * Calculates the character base physical attack
@@ -32,14 +32,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBasePhysicalAttackCalculator extends CharacterCalculator { public class CharacterBasePhysicalAttackCalculator extends CharacterFormula {
public CharacterBasePhysicalAttackCalculator() { public CharacterBasePhysicalAttackCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.POWER_ATTACK);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBasePhysicalAttack(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBasePhysicalAttack();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base physical attack speed * Calculates the character base physical attack speed
@@ -32,14 +32,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBasePhysicalAttackSpeedCalculator extends public class CharacterBasePhysicalAttackSpeedCalculator extends
CharacterCalculator { CharacterFormula {
public CharacterBasePhysicalAttackSpeedCalculator() { public CharacterBasePhysicalAttackSpeedCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.POWER_ATTACK_SPEED);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBasePhysicalAttackSpeed(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBasePhysicalAttackSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base critical rate * Calculates the character base critical rate
@@ -33,14 +33,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBasePhysicalCriticalRateCalculator extends public class CharacterBasePhysicalCriticalRateCalculator extends
CharacterCalculator { CharacterFormula {
public CharacterBasePhysicalCriticalRateCalculator() { public CharacterBasePhysicalCriticalRateCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.CRITICAL_RATE);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseCritical(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseCritical();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base physical defense * Calculates the character base physical defense
@@ -43,14 +43,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBasePhysicalDefenseCalculator extends CharacterCalculator { public class CharacterBasePhysicalDefenseCalculator extends CharacterFormula {
public CharacterBasePhysicalDefenseCalculator() { public CharacterBasePhysicalDefenseCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.POWER_DEFENSE);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBasePhysicalDefense(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBasePhysicalDefense();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base run speed * Calculates the character base run speed
@@ -31,14 +31,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseRunSpeedCalculator extends CharacterCalculator { public class CharacterBaseRunSpeedCalculator extends CharacterFormula {
public CharacterBaseRunSpeedCalculator() { public CharacterBaseRunSpeedCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.RUN_SPEED);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseRunSpeed(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseRunSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base strength * Calculates the character base strength
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseStrengthCalculator extends CharacterCalculator { public class CharacterBaseStrengthCalculator extends CharacterFormula {
public CharacterBaseStrengthCalculator() { public CharacterBaseStrengthCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.STAT_STR);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseStrength(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseStrength();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base walk speed * Calculates the character base walk speed
@@ -31,14 +31,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseWalkSpeedCalculator extends CharacterCalculator { public class CharacterBaseWalkSpeedCalculator extends CharacterFormula {
public CharacterBaseWalkSpeedCalculator() { public CharacterBaseWalkSpeedCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.WALK_SPEED);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseWalkSpeed(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseWalkSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; import com.l2jserver.model.world.character.calculator.CharacterFormula;
/** /**
* Calculates the character base witness * Calculates the character base witness
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunctio
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class CharacterBaseWitnessCalculator extends CharacterCalculator { public class CharacterBaseWitnessCalculator extends CharacterFormula {
public CharacterBaseWitnessCalculator() { public CharacterBaseWitnessCalculator() {
super(new CharacterCalculatorFunction(0x000) { super(0x000, StatType.STAT_WIT);
@Override }
protected double calculate(L2Character c, CharacterTemplate t,
double value) { @Override
return t.getBaseWitness(); protected double calculate(L2Character c, CharacterTemplate t, double value) {
} return t.getBaseWitness();
});
} }
} }

View File

@@ -17,10 +17,12 @@
package com.l2jserver.model.world.npc; package com.l2jserver.model.world.npc;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.actor.calculator.ActorCalculator;
import com.l2jserver.model.world.actor.stat.ActorStats; import com.l2jserver.model.world.actor.stat.ActorStats;
import com.l2jserver.model.world.actor.stat.StatType; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.npc.calculator.NPCCalculator;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorContext; import com.l2jserver.model.world.npc.calculator.NPCCalculatorContext;
import com.l2jserver.model.world.npc.calculator.NPCFormula;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseAttackEvasionCalculator; import com.l2jserver.model.world.npc.calculator.base.NPCBaseAttackEvasionCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseConcentrationCalculator; import com.l2jserver.model.world.npc.calculator.base.NPCBaseConcentrationCalculator;
import com.l2jserver.model.world.npc.calculator.base.NPCBaseDexterityCalculator; import com.l2jserver.model.world.npc.calculator.base.NPCBaseDexterityCalculator;
@@ -46,11 +48,11 @@ import com.l2jserver.util.calculator.SimpleCalculator;
* This class is responsible for calculating the real NPC stats. The real stats * This class is responsible for calculating the real NPC stats. The real stats
* vary from the values from the templates, also, skills and items equipped can * vary from the values from the templates, also, skills and items equipped can
* change those values. Once an buff is applied, a new calculator is * change those values. Once an buff is applied, a new calculator is
* {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and their functions * {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and their
* are added to this class calculator. Once the skill effect has past away, all * functions are added to this class calculator. Once the skill effect has past
* the functions that were imported are now * away, all the functions that were imported are now
* {@link SimpleCalculator#removeFunctions(SimpleCalculator) removed} and the calculator * {@link SimpleCalculator#removeFunctions(SimpleCalculator) removed} and the
* return to its original state. * calculator return to its original state.
* <p> * <p>
* Another important note is that calculators should perform calculations as * Another important note is that calculators should perform calculations as
* fast as possible. * fast as possible.
@@ -66,14 +68,14 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_HP_CALCULATOR = new NPCBaseHPCalculator(); private static final NPCFormula BASE_HP_FORMULA = new NPCBaseHPCalculator();
/** /**
* The calculator for base maximum MP * The calculator for base maximum MP
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_MP_CALCULATOR = new NPCBaseMPCalculator(); private static final NPCFormula BASE_MP_FORMULA = new NPCBaseMPCalculator();
/** /**
* The calculator for base intelligence * The calculator for base intelligence
@@ -81,42 +83,42 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_INT_CALCULATOR = new NPCBaseIntelligenceCalculator(); private static final NPCFormula BASE_INT_FORMULA = new NPCBaseIntelligenceCalculator();
/** /**
* The calculator for base strength * The calculator for base strength
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_STR_CALCULATOR = new NPCBaseStrengthCalculator(); private static final NPCFormula BASE_STR_FORMULA = new NPCBaseStrengthCalculator();
/** /**
* The calculator for base concentration * The calculator for base concentration
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_CON_CALCULATOR = new NPCBaseConcentrationCalculator(); private static final NPCFormula BASE_CON_FORMULA = new NPCBaseConcentrationCalculator();
/** /**
* The calculator for base mentality * The calculator for base mentality
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_MEN_CALCULATOR = new NPCBaseMentalityCalculator(); private static final NPCFormula BASE_MEN_FORMULA = new NPCBaseMentalityCalculator();
/** /**
* The calculator for base dexterity * The calculator for base dexterity
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_DEX_CALCULATOR = new NPCBaseDexterityCalculator(); private static final NPCFormula BASE_DEX_FORMULA = new NPCBaseDexterityCalculator();
/** /**
* The calculator for base witness * The calculator for base witness
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_WIT_CALCULATOR = new NPCBaseWitnessCalculator(); private static final NPCFormula BASE_WIT_FORMULA = new NPCBaseWitnessCalculator();
/** /**
* The calculator for base run speed * The calculator for base run speed
@@ -124,14 +126,14 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_RUN_SPEED_CALCULATOR = new NPCBaseRunSpeedCalculator(); private static final NPCFormula BASE_RUN_SPEED_FORMULA = new NPCBaseRunSpeedCalculator();
/** /**
* The calculator for base walk speed * The calculator for base walk speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_WALK_SPEED_CALCULATOR = new NPCBaseWalkSpeedCalculator(); private static final NPCFormula BASE_WALK_SPEED_FORMULA = new NPCBaseWalkSpeedCalculator();
/** /**
* The calculator base physical attack * The calculator base physical attack
@@ -139,28 +141,28 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_PHYSICAL_ATTACK_CALCULATOR = new NPCBasePhysicalAttackCalculator(); private static final NPCFormula BASE_PHYSICAL_ATTACK_FORMULA = new NPCBasePhysicalAttackCalculator();
/** /**
* The calculator base physical attack speed * The calculator base physical attack speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR = new NPCBasePhysicalAttackSpeedCalculator(); private static final NPCFormula BASE_PHYSICAL_ATTACK_SPEED_FORMULA = new NPCBasePhysicalAttackSpeedCalculator();
/** /**
* The calculator base physical attack critical rate * The calculator base physical attack critical rate
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR = new NPCBasePhysicalCriticalRateCalculator(); private static final NPCFormula BASE_PHYSICAL_CRITICAL_RATE_FORMULA = new NPCBasePhysicalCriticalRateCalculator();
/** /**
* The calculator base physical defense * The calculator base physical defense
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_PHYSICAL_DEFENSE_CALCULATOR = new NPCBasePhysicalDefenseCalculator(); private static final NPCFormula BASE_PHYSICAL_DEFENSE_FORMULA = new NPCBasePhysicalDefenseCalculator();
/** /**
* The calculator base magical attack * The calculator base magical attack
@@ -168,28 +170,28 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_MAGICAL_ATTACK_CALCULATOR = new NPCBaseMagicalAttackCalculator(); private static final NPCFormula BASE_MAGICAL_ATTACK_FORMULA = new NPCBaseMagicalAttackCalculator();
/** /**
* The calculator base magical attack speed * The calculator base magical attack speed
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_MAGICAL_ATTACK_SPEED_CALCULATOR = new NPCBaseMagicalAttackSpeedCalculator(); private static final NPCFormula BASE_MAGICAL_ATTACK_SPEED_FORMULA = new NPCBaseMagicalAttackSpeedCalculator();
/** /**
* The calculator base magical attack critical rate * The calculator base magical attack critical rate
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_MAGICAL_CRITICAL_RATE_CALCULATOR = new NPCBaseMagicalCriticalRateCalculator(); private static final NPCFormula BASE_MAGICAL_CRITICAL_RATE_FORMULA = new NPCBaseMagicalCriticalRateCalculator();
/** /**
* The calculator base magical defense * The calculator base magical defense
* <p> * <p>
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new NPCBaseMagicalDefenseCalculator(); private static final NPCFormula BASE_MAGICAL_DEFENSE_FORMULA = new NPCBaseMagicalDefenseCalculator();
/** /**
* The calculator base evasion * The calculator base evasion
@@ -197,51 +199,56 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
* <u>This calculator does not store any state and thus is safe to be * <u>This calculator does not store any state and thus is safe to be
* shared.</u> * shared.</u>
*/ */
private static final NPCCalculator BASE_ATTACK_EVASION_CALCULATOR = new NPCBaseAttackEvasionCalculator(); private static final NPCFormula BASE_ATTACK_EVASION_FORMULA = new NPCBaseAttackEvasionCalculator();
/** /**
* The NPC * The NPC
*/ */
private final NPC npc; private final NPC npc;
private static final NPCCalculator calculator = new NPCCalculator(
StatType.class);
/** /**
* Creates a new {@link NPCStats} and adds default calculators * Creates a new {@link NPCStats} and adds default calculators
* *
* @param npc * @param npc
* the npc * the npc
*/ */
@SuppressWarnings("unchecked")
public NPCStats(NPC npc) { public NPCStats(NPC npc) {
super(); super();
this.npc = npc; this.npc = npc;
add(StatType.MAX_HP, BASE_HP_CALCULATOR); calculator.addNoSort(BASE_HP_FORMULA, BASE_MP_FORMULA);
add(StatType.MAX_MP, BASE_MP_CALCULATOR);
add(StatType.STAT_INT, BASE_INT_CALCULATOR); calculator.addNoSort(BASE_INT_FORMULA, BASE_STR_FORMULA,
add(StatType.STAT_STR, BASE_STR_CALCULATOR); BASE_CON_FORMULA, BASE_MEN_FORMULA, BASE_DEX_FORMULA,
add(StatType.STAT_CON, BASE_CON_CALCULATOR); BASE_WIT_FORMULA);
add(StatType.STAT_MEN, BASE_MEN_CALCULATOR);
add(StatType.STAT_DEX, BASE_DEX_CALCULATOR);
add(StatType.STAT_WIT, BASE_WIT_CALCULATOR);
add(StatType.RUN_SPEED, BASE_RUN_SPEED_CALCULATOR); calculator.addNoSort(BASE_RUN_SPEED_FORMULA,
add(StatType.WALK_SPEED, BASE_WALK_SPEED_CALCULATOR); BASE_WALK_SPEED_FORMULA);
add(StatType.POWER_ATTACK, BASE_PHYSICAL_ATTACK_CALCULATOR); calculator.addNoSort(BASE_PHYSICAL_ATTACK_FORMULA,
add(StatType.POWER_ATTACK_SPEED, BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR); BASE_PHYSICAL_ATTACK_SPEED_FORMULA,
add(StatType.CRITICAL_RATE, BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR); BASE_PHYSICAL_CRITICAL_RATE_FORMULA,
add(StatType.POWER_DEFENSE, BASE_PHYSICAL_DEFENSE_CALCULATOR); BASE_PHYSICAL_DEFENSE_FORMULA);
add(StatType.MAGIC_ATTACK, BASE_MAGICAL_ATTACK_CALCULATOR); calculator.addNoSort(BASE_MAGICAL_ATTACK_FORMULA,
add(StatType.MAGIC_ATTACK_SPEED, BASE_MAGICAL_ATTACK_SPEED_CALCULATOR); BASE_MAGICAL_ATTACK_SPEED_FORMULA,
add(StatType.MCRITICAL_RATE, BASE_MAGICAL_CRITICAL_RATE_CALCULATOR); BASE_MAGICAL_CRITICAL_RATE_FORMULA,
add(StatType.MAGIC_DEFENSE, BASE_MAGICAL_DEFENSE_CALCULATOR); BASE_MAGICAL_DEFENSE_FORMULA);
add(StatType.EVASION_RATE, BASE_ATTACK_EVASION_CALCULATOR); calculator.addNoSort(BASE_ATTACK_EVASION_FORMULA);
} }
@Override @Override
protected NPCCalculatorContext createContext() { protected NPCCalculatorContext createContext() {
return new NPCCalculatorContext(npc); return new NPCCalculatorContext(npc);
} }
@Override
protected ActorCalculator getCalculator() {
return calculator;
}
} }

View File

@@ -17,13 +17,14 @@
package com.l2jserver.model.world.npc.calculator; package com.l2jserver.model.world.npc.calculator;
import com.l2jserver.model.world.actor.calculator.ActorCalculator; import com.l2jserver.model.world.actor.calculator.ActorCalculator;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
* *
*/ */
public class NPCCalculator extends ActorCalculator { public class NPCCalculator extends ActorCalculator {
public NPCCalculator(NPCCalculatorFunction... functions) { public NPCCalculator(Class<StatType> type, NPCCalculator... calculators) {
super(functions); super(type, calculators);
} }
} }

View File

@@ -21,6 +21,7 @@ import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction; import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* An function for {@link NPC} formulas. * An function for {@link NPC} formulas.
@@ -28,8 +29,8 @@ import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public abstract class NPCCalculatorFunction extends ActorCalculatorFunction { public abstract class NPCCalculatorFunction extends ActorCalculatorFunction {
public NPCCalculatorFunction(int order) { public NPCCalculatorFunction(int order, StatType type) {
super(order); super(order, type);
} }
@Override @Override

View File

@@ -14,21 +14,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>. * along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.l2jserver.util.calculator; package com.l2jserver.model.world.npc.calculator;
import com.l2jserver.model.world.actor.stat.StatType;
/** /**
* This function performs an negate: <blockquote><code>-chain value</code>
* </blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/ */
public class NegateFunction extends AbstractDoubleFunction<CalculatorContext> { public abstract class NPCFormula extends NPCCalculatorFunction {
public NegateFunction(int order) { public NPCFormula(int order, StatType type) {
super(order); super(order, type);
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return -value;
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character evasion * Calculates the character evasion
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseAttackEvasionCalculator extends NPCCalculator { public class NPCBaseAttackEvasionCalculator extends NPCFormula {
public NPCBaseAttackEvasionCalculator() { public NPCBaseAttackEvasionCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.EVASION_RATE);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getEvasion(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getEvasion();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character concentration * Calculates the character concentration
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseConcentrationCalculator extends NPCCalculator { public class NPCBaseConcentrationCalculator extends NPCFormula {
public NPCBaseConcentrationCalculator() { public NPCBaseConcentrationCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.STAT_CON);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getConcentration(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getConcentration();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base dexterity * Calculates the character base dexterity
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseDexterityCalculator extends NPCCalculator { public class NPCBaseDexterityCalculator extends NPCFormula {
public NPCBaseDexterityCalculator() { public NPCBaseDexterityCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.STAT_DEX);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getDexterity(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getDexterity();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character maximum HP * Calculates the character maximum HP
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseHPCalculator extends NPCCalculator { public class NPCBaseHPCalculator extends NPCFormula {
public NPCBaseHPCalculator() { public NPCBaseHPCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.MAX_HP);
@Override }
public double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getMaximumHP(); public double calculate(NPC c, NPCTemplate t, double value) {
} return t.getMaximumHP();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base intelligence * Calculates the character base intelligence
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseIntelligenceCalculator extends NPCCalculator { public class NPCBaseIntelligenceCalculator extends NPCFormula {
public NPCBaseIntelligenceCalculator() { public NPCBaseIntelligenceCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.STAT_INT);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getIntelligence(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getIntelligence();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character maximum HP * Calculates the character maximum HP
@@ -30,13 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseMPCalculator extends NPCCalculator { public class NPCBaseMPCalculator extends NPCFormula {
public NPCBaseMPCalculator() { public NPCBaseMPCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.MAX_MP);
@Override }
public double calculate(NPC c, NPCTemplate t, double value) {
return t.getMaximumMP(); @Override
} public double calculate(NPC c, NPCTemplate t, double value) {
}); return t.getMaximumMP();
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base magical attack * Calculates the character base magical attack
@@ -31,14 +31,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseMagicalAttackCalculator extends NPCCalculator { public class NPCBaseMagicalAttackCalculator extends NPCFormula {
public NPCBaseMagicalAttackCalculator() { public NPCBaseMagicalAttackCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.MAGIC_ATTACK);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getMagicalAttack(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getMagicalAttack();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the base magical attack speed * Calculates the base magical attack speed
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseMagicalAttackSpeedCalculator extends NPCCalculator { public class NPCBaseMagicalAttackSpeedCalculator extends NPCFormula {
public NPCBaseMagicalAttackSpeedCalculator() { public NPCBaseMagicalAttackSpeedCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.MAGIC_ATTACK_SPEED);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getMagicalAttackSpeed(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getMagicalAttackSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the base magical attack critical rate * Calculates the base magical attack critical rate
@@ -31,15 +31,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseMagicalCriticalRateCalculator extends public class NPCBaseMagicalCriticalRateCalculator extends NPCFormula {
NPCCalculator {
public NPCBaseMagicalCriticalRateCalculator() { public NPCBaseMagicalCriticalRateCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.MCRITICAL_RATE);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getCritical(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getCritical();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base magical defense. * Calculates the character base magical defense.
@@ -41,14 +41,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseMagicalDefenseCalculator extends NPCCalculator { public class NPCBaseMagicalDefenseCalculator extends NPCFormula {
public NPCBaseMagicalDefenseCalculator() { public NPCBaseMagicalDefenseCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.MAGIC_DEFENSE);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getMagicalDefense(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getMagicalDefense();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base mentality * Calculates the character base mentality
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseMentalityCalculator extends NPCCalculator { public class NPCBaseMentalityCalculator extends NPCFormula {
public NPCBaseMentalityCalculator() { public NPCBaseMentalityCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.STAT_MEN);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getMentality(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getMentality();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base physical attack * Calculates the character base physical attack
@@ -32,14 +32,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBasePhysicalAttackCalculator extends NPCCalculator { public class NPCBasePhysicalAttackCalculator extends NPCFormula {
public NPCBasePhysicalAttackCalculator() { public NPCBasePhysicalAttackCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.POWER_ATTACK);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getPhysicalAttack(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getPhysicalAttack();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base physical attack speed * Calculates the character base physical attack speed
@@ -31,15 +31,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBasePhysicalAttackSpeedCalculator extends public class NPCBasePhysicalAttackSpeedCalculator extends NPCFormula {
NPCCalculator {
public NPCBasePhysicalAttackSpeedCalculator() { public NPCBasePhysicalAttackSpeedCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.POWER_ATTACK_SPEED);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getPhysicalAttackSpeed(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getPhysicalAttackSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base critical rate * Calculates the character base critical rate
@@ -32,13 +32,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBasePhysicalCriticalRateCalculator extends NPCCalculator { public class NPCBasePhysicalCriticalRateCalculator extends NPCFormula {
public NPCBasePhysicalCriticalRateCalculator() { public NPCBasePhysicalCriticalRateCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.CRITICAL_RATE);
@Override }
protected double calculate(NPC c, NPCTemplate t, double value) {
return t.getCritical(); @Override
} protected double calculate(NPC c, NPCTemplate t, double value) {
}); return t.getCritical();
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base physical defense * Calculates the character base physical defense
@@ -43,13 +43,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBasePhysicalDefenseCalculator extends NPCCalculator { public class NPCBasePhysicalDefenseCalculator extends NPCFormula {
public NPCBasePhysicalDefenseCalculator() { public NPCBasePhysicalDefenseCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.POWER_DEFENSE);
@Override }
protected double calculate(NPC c, NPCTemplate t, double value) {
return t.getPhysicalDefense(); @Override
} protected double calculate(NPC c, NPCTemplate t, double value) {
}); return t.getPhysicalDefense();
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base run speed * Calculates the character base run speed
@@ -31,14 +31,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseRunSpeedCalculator extends NPCCalculator { public class NPCBaseRunSpeedCalculator extends NPCFormula {
public NPCBaseRunSpeedCalculator() { public NPCBaseRunSpeedCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.RUN_SPEED);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getRunSpeed(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getRunSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base strength * Calculates the character base strength
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseStrengthCalculator extends NPCCalculator { public class NPCBaseStrengthCalculator extends NPCFormula {
public NPCBaseStrengthCalculator() { public NPCBaseStrengthCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.STAT_STR);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getStrength(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getStrength();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base walk speed * Calculates the character base walk speed
@@ -31,14 +31,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseWalkSpeedCalculator extends NPCCalculator { public class NPCBaseWalkSpeedCalculator extends NPCFormula {
public NPCBaseWalkSpeedCalculator() { public NPCBaseWalkSpeedCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.WALK_SPEED);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getWalkSpeed(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getWalkSpeed();
});
} }
} }

View File

@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
import com.l2jserver.model.template.NPCTemplate; import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.npc.calculator.NPCCalculator; import com.l2jserver.model.world.actor.stat.StatType;
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction; import com.l2jserver.model.world.npc.calculator.NPCFormula;
/** /**
* Calculates the character base witness * Calculates the character base witness
@@ -30,14 +30,13 @@ import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class NPCBaseWitnessCalculator extends NPCCalculator { public class NPCBaseWitnessCalculator extends NPCFormula {
public NPCBaseWitnessCalculator() { public NPCBaseWitnessCalculator() {
super(new NPCCalculatorFunction(0x000) { super(0x000, StatType.STAT_WIT);
@Override }
protected double calculate(NPC c, NPCTemplate t,
double value) { @Override
return t.getWitness(); protected double calculate(NPC c, NPCTemplate t, double value) {
} return t.getWitness();
});
} }
} }

View File

@@ -36,7 +36,6 @@ public class Log4JLoggingService extends AbstractService implements
LoggingService { LoggingService {
private Logger rootLogger; private Logger rootLogger;
private Logger l2jLogger; private Logger l2jLogger;
private Logger scriptLogger;
private Logger nettyLogger; private Logger nettyLogger;
@Override @Override
@@ -47,7 +46,6 @@ public class Log4JLoggingService extends AbstractService implements
BasicConfigurator.configure(); BasicConfigurator.configure();
rootLogger = Logger.getRootLogger(); rootLogger = Logger.getRootLogger();
l2jLogger = Logger.getLogger("com.l2jserver"); l2jLogger = Logger.getLogger("com.l2jserver");
scriptLogger = Logger.getLogger("script");
nettyLogger = Logger.getLogger("org.jboss.netty"); nettyLogger = Logger.getLogger("org.jboss.netty");
rootLogger.removeAllAppenders(); rootLogger.removeAllAppenders();
@@ -55,7 +53,6 @@ public class Log4JLoggingService extends AbstractService implements
rootLogger.addAppender(new ConsoleAppender(layout, "System.err")); rootLogger.addAppender(new ConsoleAppender(layout, "System.err"));
l2jLogger.setLevel(Level.INFO); l2jLogger.setLevel(Level.INFO);
scriptLogger.setLevel(Level.INFO);
nettyLogger.setLevel(Level.DEBUG); nettyLogger.setLevel(Level.DEBUG);
Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(Level.WARN); Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(Level.WARN);
} }

View File

@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.l2jserver.model.server.AttackHit; import com.l2jserver.model.server.AttackHit;
import com.l2jserver.model.server.attack.AttackCalculator; import com.l2jserver.model.server.attack.AttackCalculator;
import com.l2jserver.model.server.attack.AttackCalculator.AttackCalculatorType;
import com.l2jserver.model.server.attack.AttackCalculatorContext; import com.l2jserver.model.server.attack.AttackCalculatorContext;
import com.l2jserver.model.server.attack.PhysicalAttackCalculator; import com.l2jserver.model.server.attack.PhysicalAttackCalculator;
import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.Actor;
@@ -90,8 +91,9 @@ public class AttackServiceImpl extends AbstractService implements AttackService
@Override @Override
public AttackHit call() throws Exception { public AttackHit call() throws Exception {
final double damage = PHYSICAL_ATTACK_CALCULATOR final double damage = PHYSICAL_ATTACK_CALCULATOR.calculate(
.calculate(new AttackCalculatorContext(attacker, target)); AttackCalculatorType.DAMAGE, new AttackCalculatorContext(
attacker, target));
// TODO calculate miss // TODO calculate miss
// TODO calculate critical // TODO calculate critical
// TODO calculate soulshot // TODO calculate soulshot

View File

@@ -92,7 +92,7 @@ public class CharacterServiceImpl extends AbstractService implements
* The {@link WorldService} * The {@link WorldService}
*/ */
private final WorldService worldService; private final WorldService worldService;
/** /*
* The {@link WorldService} event dispatcher * The {@link WorldService} event dispatcher
*/ */
private final WorldEventDispatcher eventDispatcher; private final WorldEventDispatcher eventDispatcher;
@@ -156,7 +156,7 @@ public class CharacterServiceImpl extends AbstractService implements
character.setOnline(true); character.setOnline(true);
// inventory interfere on calculators // inventory interfere on calculators
character.getStats().updateCalculators(); character.getStats().updateCalculator();
// chat listener // chat listener
final ChatChannelListener globalChatListener = new ChatChannelListener() { final ChatChannelListener globalChatListener = new ChatChannelListener() {

View File

@@ -18,14 +18,15 @@ package com.l2jserver.util.calculator;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/ */
public abstract class AbstractDoubleFunction<T extends CalculatorContext> implements public abstract class AbstractDoubleFunction<T extends CalculatorContext, V extends Enum<V>>
Function<T> { implements Function<T, V> {
private final int order; private final int order;
private final V type;
public AbstractDoubleFunction(int order) { public AbstractDoubleFunction(int order, V type) {
this.order = order; this.order = order;
this.type = type;
} }
@Override @Override
@@ -33,4 +34,8 @@ public abstract class AbstractDoubleFunction<T extends CalculatorContext> implem
return order; return order;
} }
@Override
public V type() {
return type;
}
} }

View File

@@ -17,16 +17,12 @@
package com.l2jserver.util.calculator; package com.l2jserver.util.calculator;
/** /**
* This function performs a multiplication: <blockquote><code>chain value *
* (value / 100)</code></blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/ */
public class PercentFunction extends MultiplicationFunction { public interface Calculator<T extends CalculatorContext, V extends Enum<V>>
/** extends Function<T, V> {
* The value double calculate(V v, T ctx, double value);
*/
public PercentFunction(int order, double value) { double calculate(V v, T ctx);
super(order, value / 100);
}
} }

View File

@@ -0,0 +1,275 @@
/*
* 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;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
import java.util.Map.Entry;
import com.l2jserver.util.factory.CollectionFactory;
/**
* An calculator is used to compute data and outputs its result. Note also, that
* an calculator is also an function, that way you can nest calculators.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ComplexCalculator<T extends CalculatorContext, V extends Enum<V>>
extends AbstractDoubleFunction<T, V> implements Calculator<T, V> {
/**
* List of operations in this calculator
*/
private EnumMap<V, List<Function<T, V>>> functions;
/**
* Creates a new empty calculator. Functions can be add using
* {@link #add(V, Function)}.
*/
public ComplexCalculator(Class<V> type) {
super(0x00, null);
functions = new EnumMap<V, List<Function<T, V>>>(type);
}
/**
* Creates a new calculator with <tt>functions</tt> in the declaration
* order.
*
* @param functions
* the calculator functions
*/
@SuppressWarnings("unchecked")
public ComplexCalculator(Class<V> type, Calculator<T, V>... calculators) {
this(type);
for (final Calculator<T, V> calculator : calculators) {
importFunctions(calculator);
}
}
/**
* Creates a new calculator with <tt>functions</tt> in the declaration
* order.
*
* @param functions
* the calculator functions
*/
public ComplexCalculator(V value, Function<T, V>... functions) {
super(0x00, value);
this.functions = new EnumMap<V, List<Function<T, V>>>(
value.getDeclaringClass());
add(functions);
}
/**
* Creates a new calculator with <tt>functions</tt> in the declaration
* order.
*
* @param functions
* the calculator functions
*/
public ComplexCalculator(Class<V> type, Function<T, V>... functions) {
this(type);
add(functions);
for (final Function<T, V> func : functions) {
getList(func.type()).add(func);
}
for (final List<Function<T, V>> funcs : this.functions.values()) {
Collections.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE);
}
}
/**
* Adds a new function to this calculator. Executing order for functions
* with the same order is undefined.
* <p>
* Once a new function is added, sorting will be performed automatically.
*
* @param order
* the operation order, starting at 0.
* @param function
* the operation
*/
public void add(Function<T, V> function) {
getList(function.type()).add(function);
for (final List<Function<T, V>> funcs : functions.values()) {
Collections.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE);
}
}
/**
* Adds a new function to this calculator. Executing order for functions
* with the same order is undefined.
* <p>
* Once a new function is added, sorting will be performed automatically.
*
* @param order
* the operation order, starting at 0.
* @param function
* the operation
*/
public void add(Function<T, V>... functions) {
for (final Function<T, V> func : functions) {
getList(func.type()).add(func);
}
sort();
}
/**
* Adds a new function to this calculator. Executing order for functions
* with the same order is undefined.
* <p>
* Once a new function is added, sorting will be performed automatically.
*
* @param order
* the operation order, starting at 0.
* @param function
* the operation
*/
public void addNoSort(Function<T, V>... functions) {
for (final Function<T, V> func : functions) {
getList(func.type()).add(func);
}
}
/**
* Removes an fuction from this calculator.
*
* @param order
* the operation order, starting at 0.
* @param function
* the operation
*/
public void remove(Function<T, V> function) {
getList(function.type()).remove(function);
}
/**
* 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.
*
* @param calculator
* the calculator
*/
@SuppressWarnings("unchecked")
public void importFunctions(Calculator<T, V>... calculators) {
for (final Calculator<T, V> calculator : calculators) {
if (calculator instanceof SimpleCalculator) {
for (final Function<T, V> function : ((SimpleCalculator<T, V>) calculator).functions) {
if (function instanceof Calculator) {
importFunctions((Calculator<T, V>) function);
} else {
add(function);
}
}
} else if (calculator instanceof ComplexCalculator) {
for (final Entry<V, List<Function<T, V>>> e : ((ComplexCalculator<T, V>) calculator).functions
.entrySet()) {
for (final Function<T, V> function : e.getValue()) {
if (function instanceof Calculator) {
importFunctions((Calculator<T, V>) function);
} else {
add(function);
}
}
}
}
}
}
/**
* Removes all imported functions from the given <tt>calculator</tt>.
* <p>
* This method will heuristically search for nested calculators.
*
* @param calculator
* the calculator
*/
@SuppressWarnings("unchecked")
public void removeFunctions(Calculator<T, V>... calculators) {
for (final Calculator<T, V> calculator : calculators) {
if (calculator instanceof SimpleCalculator) {
for (final Function<T, V> function : ((SimpleCalculator<T, V>) calculator).functions) {
if (function instanceof Calculator) {
removeFunctions((Calculator<T, V>) function);
} else {
remove(function);
}
}
} else if (calculator instanceof ComplexCalculator) {
for (final Entry<V, List<Function<T, V>>> e : ((ComplexCalculator<T, V>) calculator).functions
.entrySet()) {
for (final Function<T, V> function : e.getValue()) {
if (function instanceof Calculator) {
removeFunctions((Calculator<T, V>) function);
} else {
remove(function);
}
}
}
}
}
}
public void sort() {
for (final List<Function<T, V>> funcs : functions.values()) {
Collections.sort(funcs, FunctionOrderComparator.SHARED_INSTANCE);
}
}
public void clear() {
functions.clear();
}
public double calculate(V v, T ctx, double value) {
for (final Function<T, V> function : getList(v)) {
value = function.calculate(ctx, value);
}
return value;
}
@Override
public double calculate(T ctx, double value) {
return 0;
}
public double calculate(V v, T ctx) {
return calculate(v, ctx, 0);
}
private List<Function<T, V>> getList(V value) {
List<Function<T, V>> list = functions.get(value);
if (list == null) {
list = CollectionFactory.newList();
functions.put(value, list);
}
return list;
}
public static class FunctionOrderComparator implements
Comparator<Function<?, ?>> {
public static final FunctionOrderComparator SHARED_INSTANCE = new FunctionOrderComparator();
@Override
public int compare(Function<?, ?> func1, Function<?, ?> func2) {
return (func1.order() - func2.order());
}
}
}

View File

@@ -1,40 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.calculator;
/**
* This function performs a division: <blockquote><code>chain value /
* value</code></blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class DivisionFunction extends AbstractDoubleFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public DivisionFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return value / this.value;
}
}

View File

@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public interface Function<C extends CalculatorContext> { public interface Function<C extends CalculatorContext, V extends Enum<V>> {
/** /**
* Performs the operation in the calculation process. * Performs the operation in the calculation process.
* <p> * <p>
@@ -39,4 +39,6 @@ public interface Function<C extends CalculatorContext> {
* @return the order this function will be executed * @return the order this function will be executed
*/ */
int order(); int order();
V type();
} }

View File

@@ -1,40 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.calculator;
/**
* This function performs an multiplication: <blockquote><code>chain value *
* value</code></blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class MultiplicationFunction extends AbstractDoubleFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public MultiplicationFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return value * this.value;
}
}

View File

@@ -1,39 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.calculator;
/**
* 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 extends AbstractDoubleFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public SetFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return this.value;
}
}

View File

@@ -25,22 +25,13 @@ import java.util.Comparator;
* *
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class SimpleCalculator<T extends CalculatorContext> extends public class SimpleCalculator<T extends CalculatorContext, V extends Enum<V>>
AbstractDoubleFunction<T> { extends AbstractDoubleFunction<T, V> implements Calculator<T, V> {
protected final V value;
/** /**
* List of operations in this calculator * List of operations in this calculator
*/ */
private Function<? super T>[] functions; protected final Function<T, V>[] functions;
/**
* Creates a new empty calculator. Functions can be add using
* {@link #add(int, Function)}.
*/
@SuppressWarnings("unchecked")
public SimpleCalculator() {
super(0x00);
functions = new Function[0];
}
/** /**
* Creates a new calculator with <tt>functions</tt> in the declaration * Creates a new calculator with <tt>functions</tt> in the declaration
@@ -49,85 +40,37 @@ public class SimpleCalculator<T extends CalculatorContext> extends
* @param functions * @param functions
* the calculator functions * the calculator functions
*/ */
public SimpleCalculator(Function<? super T>... functions) { public SimpleCalculator(V value, Function<T, V>... functions) {
super(0x00); super(0x00, value);
this.value = value;
this.functions = functions; this.functions = functions;
Arrays.sort(this.functions, FunctionOrderComparator.SHARED_INSTANCE);
} }
/** public double calculate(V v, T ctx, double value) {
* Adds a new function to this calculator. Executing order for functions if (v != this.value)
* with the same order is undefined. return value;
* <p> for (final Function<T, V> function : functions) {
* Once a new function is added, sorting will be performed automatically.
*
* @param order
* the operation order, starting at 0.
* @param function
* the operation
*/
public void add(Function<? super T> function) {
functions = Arrays.copyOf(functions, functions.length + 1);
functions[functions.length - 1] = function;
Arrays.sort(functions, FunctionOrderComparator.SHARED_INSTANCE);
}
/**
* 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.
*
* @param calculator
* the calculator
*/
public void importFunctions(SimpleCalculator<? super T> calculator) {
for (final Function<? super T> function : calculator.functions) {
if (function instanceof SimpleCalculator) {
importFunctions((SimpleCalculator<? super T>) function);
} else {
add(function);
}
}
}
/**
* Removes all imported functions from the given <tt>calculator</tt>.
* <p>
* This method will heuristically search for nested calculators.
*
* @param calculator
* the calculator
*/
public void removeFunctions(SimpleCalculator<? super T> calculator) {
for (final Function<? super T> function : calculator.functions) {
if (function instanceof SimpleCalculator) {
removeFunctions((SimpleCalculator<? super T>) function);
} else {
// TODO
// remove(function);
}
}
}
@Override
public double calculate(T ctx, double value) {
for (final Function<? super T> function : functions) {
value = function.calculate(ctx, value); value = function.calculate(ctx, value);
} }
return value; return value;
} }
public double calculate(T ctx) { public double calculate(V v, T ctx) {
return calculate(ctx, 0); return calculate(ctx, 0);
} }
@Override
public double calculate(T ctx, double value) {
return 0;
}
public static class FunctionOrderComparator implements public static class FunctionOrderComparator implements
Comparator<Function<?>> { Comparator<Function<?, ?>> {
public static final FunctionOrderComparator SHARED_INSTANCE = new FunctionOrderComparator(); public static final FunctionOrderComparator SHARED_INSTANCE = new FunctionOrderComparator();
@Override @Override
public int compare(Function<?> func1, Function<?> func2) { public int compare(Function<?, ?> func1, Function<?, ?> func2) {
return (func1.order() - func2.order()); return (func1.order() - func2.order());
} }
} }

View File

@@ -1,40 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.calculator;
/**
* This function performs an subtraction: <blockquote><code>chain value -
* value</code></blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SubtractFunction extends AbstractDoubleFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public SubtractFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return value - this.value;
}
}

View File

@@ -1,40 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.calculator;
/**
* This function performs a sum: <blockquote><code>chain value +
* value</code></blockquote>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SumFunction extends AbstractDoubleFunction<CalculatorContext> {
/**
* The value
*/
private final double value;
public SumFunction(int order, double value) {
super(order);
this.value = value;
}
@Override
public double calculate(CalculatorContext ctx, double value) {
return value + this.value;
}
}

View File

@@ -16,138 +16,144 @@
*/ */
package com.l2jserver.util.calculator; package com.l2jserver.util.calculator;
import junit.framework.Assert;
import org.junit.Test;
/** /**
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
* *
*/ */
public class CalculatorTest { public class CalculatorTest {
@Test // @Test
public void testSimple() { // public void testSimple() {
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>(); // final SimpleCalculator<CalculatorContext> calc = new
// SimpleCalculator<CalculatorContext>();
calc.add(new SetFunction(0, 10)); //
calc.add(new MultiplicationFunction(1, 2)); // calc.add(new SetFunction(0, 10));
calc.add(new SetFunction(2, 30)); // calc.add(new MultiplicationFunction(1, 2));
// calc.add(new SetFunction(2, 30));
final CalculatorContext ctx = new CalculatorContext(); //
Assert.assertEquals(30.0, calc.calculate(ctx)); // final CalculatorContext ctx = new CalculatorContext();
} // Assert.assertEquals(30.0, calc.calculate(ctx));
// }
@Test //
public void testPercent() { // @Test
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>(); // public void testPercent() {
// final SimpleCalculator<CalculatorContext> calc = new
calc.add(new SetFunction(0, 10)); // SimpleCalculator<CalculatorContext>();
calc.add(new MultiplicationFunction(1, 2)); //
calc.add(new PercentFunction(2, 75)); // calc.add(new SetFunction(0, 10));
// calc.add(new MultiplicationFunction(1, 2));
final CalculatorContext ctx = new CalculatorContext(); // calc.add(new PercentFunction(2, 75));
Assert.assertEquals(15.0, calc.calculate(ctx)); //
} // final CalculatorContext ctx = new CalculatorContext();
// Assert.assertEquals(15.0, calc.calculate(ctx));
@Test // }
public void testComplex() { //
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>(); // @Test
// public void testComplex() {
calc.add(new SetFunction(0, 10)); // final SimpleCalculator<CalculatorContext> calc = new
calc.add(new MultiplicationFunction(1, 2)); // SimpleCalculator<CalculatorContext>();
calc.add(new PercentFunction(2, 75)); //
calc.add(new SumFunction(3, 3)); // calc.add(new SetFunction(0, 10));
calc.add(new SubtractFunction(4, 8)); // calc.add(new MultiplicationFunction(1, 2));
calc.add(new DivisionFunction(5, 2)); // calc.add(new PercentFunction(2, 75));
// calc.add(new SumFunction(3, 3));
final CalculatorContext ctx = new CalculatorContext(); // calc.add(new SubtractFunction(4, 8));
Assert.assertEquals(5.0, calc.calculate(ctx)); // calc.add(new DivisionFunction(5, 2));
} //
// final CalculatorContext ctx = new CalculatorContext();
@Test // Assert.assertEquals(5.0, calc.calculate(ctx));
public void testNesting() { // }
final SimpleCalculator<CalculatorContext> calc1 = new SimpleCalculator<CalculatorContext>(); //
final CalculatorContext ctx1 = new CalculatorContext(); // @Test
// public void testNesting() {
calc1.add(new SetFunction(0, 10)); // final SimpleCalculator<CalculatorContext> calc1 = new
calc1.add(new MultiplicationFunction(1, 2)); // SimpleCalculator<CalculatorContext>();
calc1.add(new PercentFunction(2, 75)); // final CalculatorContext ctx1 = new CalculatorContext();
calc1.add(new SumFunction(3, 3)); //
calc1.add(new SubtractFunction(4, 8)); // calc1.add(new SetFunction(0, 10));
calc1.add(new DivisionFunction(5, 2)); // calc1.add(new MultiplicationFunction(1, 2));
// calc1.add(new PercentFunction(2, 75));
Assert.assertEquals(5.0, calc1.calculate(ctx1)); // calc1.add(new SumFunction(3, 3));
// calc1.add(new SubtractFunction(4, 8));
final SimpleCalculator<CalculatorContext> calc2 = new SimpleCalculator<CalculatorContext>(); // calc1.add(new DivisionFunction(5, 2));
final CalculatorContext ctx2 = new CalculatorContext(); //
// Assert.assertEquals(5.0, calc1.calculate(ctx1));
calc2.add(new MultiplicationFunction(0, 2)); //
calc2.add(new PercentFunction(1, 75)); // final SimpleCalculator<CalculatorContext> calc2 = new
calc2.add(new SumFunction(2, 3)); // SimpleCalculator<CalculatorContext>();
calc2.add(new SubtractFunction(3, 8)); // final CalculatorContext ctx2 = new CalculatorContext();
calc2.add(new DivisionFunction(4, 2)); //
// calc2.add(new MultiplicationFunction(0, 2));
Assert.assertEquals(-2.5, calc2.calculate(ctx2)); // calc2.add(new PercentFunction(1, 75));
// calc2.add(new SumFunction(2, 3));
final SimpleCalculator<CalculatorContext> calc3 = new SimpleCalculator<CalculatorContext>(); // calc2.add(new SubtractFunction(3, 8));
final CalculatorContext ctx3 = new CalculatorContext(); // calc2.add(new DivisionFunction(4, 2));
calc3.add(calc1); //
calc3.add(calc2); // Assert.assertEquals(-2.5, calc2.calculate(ctx2));
//
// this should be executed // final SimpleCalculator<CalculatorContext> calc3 = new
calc2.add(new SumFunction(10, 1)); // SimpleCalculator<CalculatorContext>();
// final CalculatorContext ctx3 = new CalculatorContext();
Assert.assertEquals(2.25, calc3.calculate(ctx3)); // calc3.add(calc1);
} // calc3.add(calc2);
//
@Test // // this should be executed
public void testImporting() { // calc2.add(new SumFunction(10, 1));
final SimpleCalculator<CalculatorContext> calc1 = new SimpleCalculator<CalculatorContext>(); //
final CalculatorContext ctx1 = new CalculatorContext(); // Assert.assertEquals(2.25, calc3.calculate(ctx3));
// }
calc1.add(new SetFunction(0, 10)); //
calc1.add(new MultiplicationFunction(2, 2)); // @Test
calc1.add(new PercentFunction(4, 75)); // public void testImporting() {
calc1.add(new SumFunction(6, 3)); // final SimpleCalculator<CalculatorContext> calc1 = new
calc1.add(new SubtractFunction(8, 8)); // SimpleCalculator<CalculatorContext>();
calc1.add(new DivisionFunction(10, 2)); // final CalculatorContext ctx1 = new CalculatorContext();
//
Assert.assertEquals(5.0, calc1.calculate(ctx1)); // calc1.add(new SetFunction(0, 10));
// calc1.add(new MultiplicationFunction(2, 2));
final SimpleCalculator<CalculatorContext> calc2 = new SimpleCalculator<CalculatorContext>(); // calc1.add(new PercentFunction(4, 75));
final CalculatorContext ctx2 = new CalculatorContext(); // calc1.add(new SumFunction(6, 3));
// calc1.add(new SubtractFunction(8, 8));
calc2.add(new MultiplicationFunction(1, 2)); // calc1.add(new DivisionFunction(10, 2));
calc2.add(new PercentFunction(3, 75)); //
calc2.add(new SumFunction(5, 3)); // Assert.assertEquals(5.0, calc1.calculate(ctx1));
calc2.add(new SubtractFunction(7, 8)); //
calc2.add(new DivisionFunction(9, 2)); // final SimpleCalculator<CalculatorContext> calc2 = new
// SimpleCalculator<CalculatorContext>();
Assert.assertEquals(-2.5, calc2.calculate(ctx2)); // final CalculatorContext ctx2 = new CalculatorContext();
//
final SimpleCalculator<CalculatorContext> calc3 = new SimpleCalculator<CalculatorContext>(); // calc2.add(new MultiplicationFunction(1, 2));
final CalculatorContext ctx3 = new CalculatorContext(); // calc2.add(new PercentFunction(3, 75));
calc3.importFunctions(calc1); // calc2.add(new SumFunction(5, 3));
calc3.importFunctions(calc2); // calc2.add(new SubtractFunction(7, 8));
// calc2.add(new DivisionFunction(9, 2));
// this should not be executed //
calc2.add(new SumFunction(11, 50)); // Assert.assertEquals(-2.5, calc2.calculate(ctx2));
//
Assert.assertEquals(1.25, calc3.calculate(ctx3)); // final SimpleCalculator<CalculatorContext> calc3 = new
} // SimpleCalculator<CalculatorContext>();
// final CalculatorContext ctx3 = new CalculatorContext();
@Test // calc3.importFunctions(calc1);
public void testRounding() { // calc3.importFunctions(calc2);
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>(); //
// // this should not be executed
calc.add(new MultiplicationFunction(0, 2)); // calc2.add(new SumFunction(11, 50));
calc.add(new PercentFunction(1, 75)); //
calc.add(new SumFunction(2, 3)); // Assert.assertEquals(1.25, calc3.calculate(ctx3));
calc.add(new SubtractFunction(3, 8.1)); // }
calc.add(new DivisionFunction(4, 2)); //
calc.add(new RoundFunction(5)); // @Test
// public void testRounding() {
final CalculatorContext ctx = new CalculatorContext(); // final SimpleCalculator<CalculatorContext> calc = new
Assert.assertEquals(-3.0, calc.calculate(ctx)); // SimpleCalculator<CalculatorContext>();
} //
// calc.add(new MultiplicationFunction(0, 2));
// calc.add(new PercentFunction(1, 75));
// calc.add(new SumFunction(2, 3));
// calc.add(new SubtractFunction(3, 8.1));
// calc.add(new DivisionFunction(4, 2));
// calc.add(new RoundFunction(5));
//
// final CalculatorContext ctx = new CalculatorContext();
// Assert.assertEquals(-3.0, calc.calculate(ctx));
// }
} }