mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 23:42:55 +00:00
@@ -16,13 +16,19 @@
|
||||
*/
|
||||
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>
|
||||
*/
|
||||
public class AttackCalculator extends SimpleCalculator<AttackCalculatorContext> {
|
||||
public class AttackCalculator extends
|
||||
ComplexCalculator<AttackCalculatorContext, AttackCalculatorType> {
|
||||
public AttackCalculator(AttackCalculatorFunction... functions) {
|
||||
super(functions);
|
||||
super(AttackCalculatorType.class, functions);
|
||||
}
|
||||
|
||||
public enum AttackCalculatorType {
|
||||
DAMAGE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.model.server.attack;
|
||||
|
||||
import com.l2jserver.model.server.attack.AttackCalculator.AttackCalculatorType;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
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>
|
||||
*/
|
||||
public abstract class AttackCalculatorFunction extends
|
||||
AbstractDoubleFunction<AttackCalculatorContext> {
|
||||
public AttackCalculatorFunction(int order) {
|
||||
super(order);
|
||||
AbstractDoubleFunction<AttackCalculatorContext, AttackCalculatorType> {
|
||||
public AttackCalculatorFunction(int order, AttackCalculatorType type) {
|
||||
super(order, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.l2jserver.model.world.Actor;
|
||||
*/
|
||||
public class PhysicalAttackCalculator extends AttackCalculator {
|
||||
public PhysicalAttackCalculator() {
|
||||
super(new AttackCalculatorFunction(0x000) {
|
||||
super(new AttackCalculatorFunction(0x000, AttackCalculatorType.DAMAGE) {
|
||||
@Override
|
||||
public double calculate(Actor attacker, Actor target, double value) {
|
||||
// TODO this is certainly not right!!!
|
||||
@@ -33,7 +33,8 @@ public class PhysicalAttackCalculator extends AttackCalculator {
|
||||
return attacker.getStats().getPhysicalAttack()
|
||||
- target.getStats().getPhysicalDefense();
|
||||
}
|
||||
}, new AttackCalculatorFunction(Integer.MAX_VALUE) {
|
||||
}, new AttackCalculatorFunction(Integer.MAX_VALUE,
|
||||
AttackCalculatorType.DAMAGE) {
|
||||
@Override
|
||||
public double calculate(Actor attacker, Actor target, double value) {
|
||||
if (value <= 0)
|
||||
|
||||
@@ -22,14 +22,16 @@ import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.XmlValue;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
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.actor.stat.StatType;
|
||||
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
|
||||
|
||||
/**
|
||||
@@ -74,6 +76,10 @@ public class ItemTemplate extends AbstractTemplate<Item> {
|
||||
protected StatAttribute physicalDamage;
|
||||
@XmlElement(name = "magicalDamage")
|
||||
protected StatAttribute magicalDamage;
|
||||
@XmlElement(name = "criticalChance")
|
||||
protected StatAttribute criticalChance;
|
||||
@XmlElement(name = "physicalAttackSpeed")
|
||||
protected StatAttribute physicalAttackSpeed;
|
||||
}
|
||||
|
||||
@XmlElement(name = "stats")
|
||||
@@ -95,7 +101,9 @@ public class ItemTemplate extends AbstractTemplate<Item> {
|
||||
protected StatSet set;
|
||||
|
||||
public static class StatSet {
|
||||
@XmlAttribute(name = "order")
|
||||
protected int order;
|
||||
@XmlValue
|
||||
protected double value;
|
||||
|
||||
/**
|
||||
@@ -172,33 +180,41 @@ public class ItemTemplate extends AbstractTemplate<Item> {
|
||||
/**
|
||||
* @return the physical damage
|
||||
*/
|
||||
public ItemPhysicalDamageActorCalculator getPhysicalDamage() {
|
||||
public ItemSetActorCalculator getPhysicalDamage() {
|
||||
if (stats == 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
|
||||
*/
|
||||
public StatAttribute getMagicalDamage() {
|
||||
public ItemSetActorCalculator getMagicalDamage() {
|
||||
if (stats == null)
|
||||
return null;
|
||||
return stats.magicalDamage;
|
||||
if (stats.magicalDamage == null)
|
||||
return null;
|
||||
return new ItemSetActorCalculator(stats.magicalDamage.set,
|
||||
StatType.MAGIC_ATTACK);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.l2jserver.model.template.AbstractTemplate#getID()
|
||||
/**
|
||||
* @return the magical damage
|
||||
*/
|
||||
public ItemSetActorCalculator getCriticalChance() {
|
||||
if (stats == null)
|
||||
return null;
|
||||
if (stats.criticalChance == null)
|
||||
return null;
|
||||
return new ItemSetActorCalculator(stats.criticalChance.set,
|
||||
StatType.CRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemTemplateID getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ItemTemplateID getID() {
|
||||
// return (ItemTemplateID) super.getID();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -19,20 +19,23 @@ package com.l2jserver.model.template.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.template.ItemTemplate.StatAttribute.StatSet;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.calculator.ActorCalculator;
|
||||
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.calculator.ActorFormula;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ItemPhysicalDamageActorCalculator extends ActorCalculator {
|
||||
public ItemPhysicalDamageActorCalculator(final StatSet set) {
|
||||
super(new ActorCalculatorFunction(set.getOrder()) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return set.getValue();
|
||||
}
|
||||
});
|
||||
public class ItemSetActorCalculator extends ActorFormula {
|
||||
private final StatSet set;
|
||||
|
||||
public ItemSetActorCalculator(StatSet set, StatType type) {
|
||||
super(set.getOrder(), type);
|
||||
this.set = set;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return set.getValue();
|
||||
}
|
||||
}
|
||||
@@ -35,9 +35,9 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll
|
||||
* <li><b>Equipped by the {@link L2Character character}</b>: <tt>location</tt>
|
||||
* is {@link InventoryLocation#PAPERDOLL}, <tt>paperdoll</tt> is not null and
|
||||
* <tt>coordinate</tt> is null.</li>
|
||||
* <li><b>Dropped on the ground</b>: <tt>location</tt></li> and <tt>paperdoll</tt>
|
||||
* are null, <tt>coordinate</tt> is not null and represents the dropping
|
||||
* location.
|
||||
* <li><b>Dropped on the ground</b>: <tt>location</tt></li> and
|
||||
* <tt>paperdoll</tt> are null, <tt>coordinate</tt> is not null and represents
|
||||
* the dropping location.
|
||||
* </ul>
|
||||
* <p>
|
||||
* Please note that {@link PositionableObject} values are only set if the object
|
||||
@@ -127,6 +127,13 @@ public class Item extends PositionableObject {
|
||||
return templateID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the templateID
|
||||
*/
|
||||
public ItemTemplate getTemplate() {
|
||||
return templateID.getTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ownerID
|
||||
*/
|
||||
|
||||
@@ -16,13 +16,17 @@
|
||||
*/
|
||||
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>
|
||||
*/
|
||||
public class ActorCalculator extends SimpleCalculator<ActorCalculatorContext> {
|
||||
public ActorCalculator(ActorCalculatorFunction... functions) {
|
||||
super(functions);
|
||||
public class ActorCalculator extends
|
||||
ComplexCalculator<ActorCalculatorContext, StatType> {
|
||||
public ActorCalculator(Class<StatType> type,
|
||||
Calculator<ActorCalculatorContext, StatType>... calculators) {
|
||||
super(type, calculators);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
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>
|
||||
*/
|
||||
public abstract class ActorCalculatorFunction extends
|
||||
AbstractDoubleFunction<ActorCalculatorContext> {
|
||||
public ActorCalculatorFunction(int order) {
|
||||
super(order);
|
||||
AbstractDoubleFunction<ActorCalculatorContext, StatType> {
|
||||
public ActorCalculatorFunction(int order, StatType type) {
|
||||
super(order, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,6 +37,6 @@ public abstract class ActorCalculatorFunction extends
|
||||
return calculate(ctx.actor, ctx.actor.getTemplate(), value);
|
||||
}
|
||||
|
||||
protected abstract double calculate(Actor a,
|
||||
ActorTemplate<?> t, double value);
|
||||
protected abstract double calculate(Actor a, ActorTemplate<?> t,
|
||||
double value);
|
||||
}
|
||||
|
||||
@@ -14,21 +14,15 @@
|
||||
* 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;
|
||||
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>
|
||||
*/
|
||||
public class ModulusFunction extends AbstractDoubleFunction<CalculatorContext> {
|
||||
public ModulusFunction(int order) {
|
||||
super(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(CalculatorContext ctx, double value) {
|
||||
return Math.abs(value);
|
||||
public abstract class ActorFormula extends ActorCalculatorFunction {
|
||||
public ActorFormula(int order, StatType type) {
|
||||
super(order, type);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import org.apache.commons.math.util.FastMath;
|
||||
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* Calculates the character base accuracy.
|
||||
@@ -36,21 +37,21 @@ import com.l2jserver.model.world.Actor;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AttackAccuracyBonusCalculator extends ActorCalculator {
|
||||
public class AttackAccuracyBonusCalculator extends ActorFormula {
|
||||
public AttackAccuracyBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
final int level = a.getLevel();
|
||||
super(0x200, StatType.ACCURACY_COMBAT);
|
||||
}
|
||||
|
||||
value += FastMath.sqrt(a.getStats().getDexterity()) * 6;
|
||||
value += level;
|
||||
if (level > 77)
|
||||
value += (level - 77) + 1;
|
||||
if (level > 69)
|
||||
value += (level - 69);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
final int level = a.getLevel();
|
||||
|
||||
value += FastMath.sqrt(a.getStats().getDexterity()) * 6;
|
||||
value += level;
|
||||
if (level > 77)
|
||||
value += (level - 77) + 1;
|
||||
if (level > 69)
|
||||
value += (level - 69);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.apache.commons.math.util.FastMath;
|
||||
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* Calculates the character evasion
|
||||
@@ -36,21 +37,21 @@ import com.l2jserver.model.world.Actor;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AttackEvasionBonusCalculator extends ActorCalculator {
|
||||
public class AttackEvasionBonusCalculator extends ActorFormula {
|
||||
public AttackEvasionBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
final int level = a.getLevel();
|
||||
super(0x200, StatType.EVASION_RATE);
|
||||
}
|
||||
|
||||
value += FastMath.sqrt(a.getStats().getDexterity()) * 6;
|
||||
value += level;
|
||||
if (level > 77)
|
||||
value += (level - 77) + 1;
|
||||
if (level > 69)
|
||||
value += (level - 69);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
final int level = a.getLevel();
|
||||
|
||||
value += FastMath.sqrt(a.getStats().getDexterity()) * 6;
|
||||
value += level;
|
||||
if (level > 77)
|
||||
value += (level - 77) + 1;
|
||||
if (level > 69)
|
||||
value += (level - 69);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MagicalAttackBonusCalculator extends ActorCalculator {
|
||||
public class MagicalAttackBonusCalculator extends ActorFormula {
|
||||
public MagicalAttackBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* Math.pow(((100.0 - 11 + a.getLevel()) / 100.0), 2)
|
||||
* Math.pow(BaseStats.INT.calculateBonus(a.getStats()
|
||||
.getIntelligence()), 2);
|
||||
}
|
||||
});
|
||||
super(0x200, StatType.MAGIC_ATTACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* Math.pow(((100.0 - 11 + a.getLevel()) / 100.0), 2)
|
||||
* Math.pow(BaseStats.INT.calculateBonus(a.getStats()
|
||||
.getIntelligence()), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MagicalAttackSpeedBonusCalculator extends ActorCalculator {
|
||||
public class MagicalAttackSpeedBonusCalculator extends ActorFormula {
|
||||
public MagicalAttackSpeedBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.WIT.calculateBonus(a.getStats()
|
||||
.getWitness());
|
||||
}
|
||||
});
|
||||
super(0x200, StatType.MAGIC_ATTACK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value * BaseStats.WIT.calculateBonus(a.getStats().getWitness());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MagicalCriticalRateBonusCalculator extends ActorCalculator {
|
||||
public class MagicalCriticalRateBonusCalculator extends ActorFormula {
|
||||
public MagicalCriticalRateBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x300) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
// TODO only apply if using a weapon
|
||||
return value
|
||||
* BaseStats.WIT.calculateBonus(a.getStats()
|
||||
.getWitness());
|
||||
}
|
||||
});
|
||||
super(0x300, StatType.MCRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
// TODO only apply if using a weapon
|
||||
return value * BaseStats.WIT.calculateBonus(a.getStats().getWitness());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MagicalDefenseBonusCalculator extends ActorCalculator {
|
||||
public class MagicalDefenseBonusCalculator extends ActorFormula {
|
||||
public MagicalDefenseBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
// final CharacterInventory inv = c.getInventory();
|
||||
super(0x200, StatType.MAGIC_DEFENSE);
|
||||
}
|
||||
|
||||
// if (inv.has(LEFT_FINGER))
|
||||
// ctx.result -= 5;
|
||||
// if (inv.has(RIGHT_FINGER))
|
||||
// ctx.result -= 5;
|
||||
// if (inv.has(LEFT_EAR))
|
||||
// ctx.result -= 9;
|
||||
// if (inv.has(RIGHT_EAR))
|
||||
// ctx.result -= 9;
|
||||
// if (inv.has(NECK))
|
||||
// ctx.result -= 13;
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
// final CharacterInventory inv = c.getInventory();
|
||||
|
||||
return value
|
||||
* BaseStats.MEN.calculateBonus(a.getStats()
|
||||
.getMentality())
|
||||
* ((100.0 - 11 + a.getLevel()) / 100.0);
|
||||
}
|
||||
});
|
||||
// if (inv.has(LEFT_FINGER))
|
||||
// ctx.result -= 5;
|
||||
// if (inv.has(RIGHT_FINGER))
|
||||
// ctx.result -= 5;
|
||||
// if (inv.has(LEFT_EAR))
|
||||
// ctx.result -= 9;
|
||||
// if (inv.has(RIGHT_EAR))
|
||||
// ctx.result -= 9;
|
||||
// if (inv.has(NECK))
|
||||
// ctx.result -= 13;
|
||||
|
||||
return value
|
||||
* BaseStats.MEN.calculateBonus(a.getStats().getMentality())
|
||||
* ((100.0 - 11 + a.getLevel()) / 100.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MaximumHPBonusCalculator extends ActorCalculator {
|
||||
public class MaximumHPBonusCalculator extends ActorFormula {
|
||||
public MaximumHPBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.CON.calculateBonus(a.getStats()
|
||||
.getConcentration());
|
||||
}
|
||||
});
|
||||
super(0x200, StatType.MAX_HP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.CON.calculateBonus(a.getStats().getConcentration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MaximumMPBonusCalculator extends ActorCalculator {
|
||||
public class MaximumMPBonusCalculator extends ActorFormula {
|
||||
public MaximumMPBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.MEN.calculateBonus(a.getStats()
|
||||
.getMentality());
|
||||
}
|
||||
});
|
||||
super(0x200, StatType.MAX_MP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.MEN.calculateBonus(a.getStats().getMentality());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class PhysicalAttackBonusCalculator extends ActorCalculator {
|
||||
public class PhysicalAttackBonusCalculator extends ActorFormula {
|
||||
public PhysicalAttackBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x100) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.STR.calculateBonus(a.getStats()
|
||||
.getStrength())
|
||||
* ((100.0 - 11 + a.getLevel()) / 100.0);
|
||||
}
|
||||
});
|
||||
super(0x100, StatType.POWER_ATTACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value * BaseStats.STR.calculateBonus(a.getStats().getStrength())
|
||||
* ((100.0 - 11 + a.getLevel()) / 100.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class PhysicalAttackSpeedBonusCalculator extends ActorCalculator {
|
||||
public class PhysicalAttackSpeedBonusCalculator extends ActorFormula {
|
||||
public PhysicalAttackSpeedBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(a.getStats()
|
||||
.getDexterity());
|
||||
}
|
||||
});
|
||||
super(0x200, StatType.POWER_ATTACK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(a.getStats().getDexterity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class PhysicalCriticalRateBonusCalculator extends ActorCalculator {
|
||||
public class PhysicalCriticalRateBonusCalculator extends ActorFormula {
|
||||
public PhysicalCriticalRateBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x090) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(a.getStats()
|
||||
.getDexterity()) * 10;
|
||||
// TODO l2j uses another variable here, must check why
|
||||
}
|
||||
});
|
||||
super(0x090, StatType.CRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(a.getStats().getDexterity())
|
||||
* 10;
|
||||
// TODO l2j uses another variable here, must check why
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class PhysicalDefenseBonusCalculator extends ActorCalculator {
|
||||
public class PhysicalDefenseBonusCalculator extends ActorFormula {
|
||||
public PhysicalDefenseBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x200) {
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
// final CharacterInventory inv = c.getInventory();
|
||||
//
|
||||
// // orc mystics are a special case
|
||||
// boolean hasMagePDef = (c.getCharacterClass().type ==
|
||||
// ClassType.MYSTIC || c
|
||||
// .getCharacterClass() == CharacterClass.ORC_MYSTIC);
|
||||
//
|
||||
// if (inv.has(HEAD))
|
||||
// ctx.result -= 12;
|
||||
// final Item chest = inv.getItem(CHEST);
|
||||
// if (chest != null)
|
||||
// ctx.result -= hasMagePDef ? 15 : 31;
|
||||
// if (inv.has(LEGS))
|
||||
// // FIXME full armor also applies here
|
||||
// ctx.result -= hasMagePDef ? 8 : 18;
|
||||
// if (inv.has(GLOVES))
|
||||
// ctx.result -= 8;
|
||||
// if (inv.has(FEET))
|
||||
// ctx.result -= 7;
|
||||
return value * ((100.0 - 11 + a.getLevel()) / 100.0);
|
||||
}
|
||||
});
|
||||
super(0x200, StatType.POWER_DEFENSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor a, ActorTemplate<?> t, double value) {
|
||||
// final CharacterInventory inv = c.getInventory();
|
||||
//
|
||||
// // orc mystics are a special case
|
||||
// boolean hasMagePDef = (c.getCharacterClass().type ==
|
||||
// ClassType.MYSTIC || c
|
||||
// .getCharacterClass() == CharacterClass.ORC_MYSTIC);
|
||||
//
|
||||
// if (inv.has(HEAD))
|
||||
// ctx.result -= 12;
|
||||
// final Item chest = inv.getItem(CHEST);
|
||||
// if (chest != null)
|
||||
// ctx.result -= hasMagePDef ? 15 : 31;
|
||||
// if (inv.has(LEGS))
|
||||
// // FIXME full armor also applies here
|
||||
// ctx.result -= hasMagePDef ? 8 : 18;
|
||||
// if (inv.has(GLOVES))
|
||||
// ctx.result -= 8;
|
||||
// if (inv.has(FEET))
|
||||
// ctx.result -= 7;
|
||||
return value * ((100.0 - 11 + a.getLevel()) / 100.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class RunSpeedBonusCalculator extends ActorCalculator {
|
||||
public class RunSpeedBonusCalculator extends ActorFormula {
|
||||
public RunSpeedBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x300) {
|
||||
@Override
|
||||
protected double calculate(Actor c, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(c.getStats()
|
||||
.getDexterity());
|
||||
}
|
||||
});
|
||||
super(0x300, StatType.RUN_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor c, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.actor.calculator;
|
||||
import com.l2jserver.model.template.ActorTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class WalkSpeedBonusCalculator extends ActorCalculator {
|
||||
public class WalkSpeedBonusCalculator extends ActorFormula {
|
||||
public WalkSpeedBonusCalculator() {
|
||||
super(new ActorCalculatorFunction(0x300) {
|
||||
@Override
|
||||
protected double calculate(Actor c, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(c.getStats()
|
||||
.getDexterity());
|
||||
}
|
||||
});
|
||||
super(0x300, StatType.WALK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(Actor c, ActorTemplate<?> t, double value) {
|
||||
return value
|
||||
* BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.ActorCalculatorContext;
|
||||
import com.l2jserver.model.world.actor.calculator.ActorFormula;
|
||||
import com.l2jserver.model.world.actor.calculator.AttackAccuracyBonusCalculator;
|
||||
import com.l2jserver.model.world.actor.calculator.AttackEvasionBonusCalculator;
|
||||
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.RunSpeedBonusCalculator;
|
||||
import com.l2jserver.model.world.actor.calculator.WalkSpeedBonusCalculator;
|
||||
import com.l2jserver.util.calculator.SimpleCalculator;
|
||||
|
||||
/**
|
||||
* @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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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")
|
||||
private final SimpleCalculator<T>[] calculators = new SimpleCalculator[StatType
|
||||
.values().length];
|
||||
|
||||
public ActorStats() {
|
||||
for (int i = 0; i < calculators.length; i++) {
|
||||
calculators[i] = new SimpleCalculator<T>();
|
||||
}
|
||||
|
||||
// bonuses
|
||||
add(StatType.MAX_HP, HP_BONUS_CALCULATOR);
|
||||
add(StatType.MAX_MP, MP_BONUS_CALCULATOR);
|
||||
|
||||
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);
|
||||
protected void addTo(ActorCalculator calculator) {
|
||||
calculator.addNoSort(HP_BONUS_FORMULA, MP_BONUS_FORMULA,
|
||||
RUN_SPEED_BONUS_FORMULA, WALK_SPEED_BONUS_FORMULA,
|
||||
PHYSICAL_ATTACK_BONUS_FORMULA,
|
||||
PHYSICAL_ATTACK_SPEED_BONUS_FORMULA,
|
||||
PHYSICAL_CRITICAL_RATE_BONUS_FORMULA,
|
||||
PHYSICAL_DEFENSE_BONUS_FORMULA, MAGICAL_ATTACK_BONUS_FORMULA,
|
||||
MAGICAL_ATTACK_SPEED_BONUS_FORMULA,
|
||||
MAGICAL_CRITICAL_RATE_BONUS_FORMULA,
|
||||
MAGICAL_DEFENSE_BONUS_FORMULA, ATTACK_ACCURACY_BONUS_FORMULA,
|
||||
ATTACK_EVASION_BONUS_FORMULA);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,22 +296,15 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
|
||||
return (int) calc(StatType.EVASION_RATE);
|
||||
}
|
||||
|
||||
public void add(StatType type, ActorCalculator calculator) {
|
||||
getCalculator(type).importFunctions(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()];
|
||||
}
|
||||
// public void add(StatType type, ActorCalculator calculator) {
|
||||
// if (calculator == null)
|
||||
// return;
|
||||
// getCalculator(type).importFunctions(calculator);
|
||||
// }
|
||||
//
|
||||
// public void remove(StatType type, ActorCalculator calculator) {
|
||||
// getCalculator(type).removeFunctions(calculator);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Does the calculation of an given {@link StatType}
|
||||
@@ -347,12 +315,10 @@ public abstract class ActorStats<T extends ActorCalculatorContext> {
|
||||
*/
|
||||
protected double calc(StatType type) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
package com.l2jserver.model.world.character;
|
||||
|
||||
import com.l2jserver.model.template.ItemTemplate;
|
||||
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.StatType;
|
||||
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
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.MaximumCPBonusCalculator;
|
||||
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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -96,42 +99,42 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -139,14 +142,14 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -154,28 +157,28 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -183,28 +186,28 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -212,14 +215,14 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* shared.</u>
|
||||
*/
|
||||
private static final CharacterCalculator BASE_ATTACK_EVASION_CALCULATOR = new CharacterBaseAttackEvasionCalculator();
|
||||
private static final CharacterFormula BASE_ATTACK_EVASION_FORMULA = new CharacterBaseAttackEvasionCalculator();
|
||||
|
||||
// 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
|
||||
* shared.</u>
|
||||
*/
|
||||
private static final CharacterCalculator CP_BONUS_CALCULATOR = new MaximumCPBonusCalculator();
|
||||
private static final CharacterFormula CP_BONUS_FORMULA = new MaximumCPBonusCalculator();
|
||||
|
||||
// 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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* shared.</u>
|
||||
*/
|
||||
private static final CharacterCalculator CP_ADD_CALCULATOR = new MaximumCPAddCalculator();
|
||||
private static final CharacterFormula CP_ADD_FORMULA = new MaximumCPAddCalculator();
|
||||
|
||||
/**
|
||||
* The character
|
||||
*/
|
||||
private final L2Character character;
|
||||
|
||||
private static final CharacterCalculator calculator = new CharacterCalculator(
|
||||
StatType.class);
|
||||
|
||||
/**
|
||||
* Creates a new {@link CharacterStats} and adds default calculators
|
||||
*
|
||||
@@ -267,44 +273,12 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
public CharacterStats(L2Character character) {
|
||||
super();
|
||||
this.character = character;
|
||||
setup();
|
||||
}
|
||||
|
||||
// base
|
||||
add(StatType.MAX_HP, BASE_HP_CALCULATOR);
|
||||
add(StatType.MAX_MP, BASE_MP_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
|
||||
@Override
|
||||
protected ActorCalculator getCalculator() {
|
||||
return calculator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,15 +295,53 @@ public class CharacterStats extends ActorStats<CharacterCalculatorContext> {
|
||||
return (int) calc(StatType.MAX_LOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCalculators() {
|
||||
super.updateCalculators();
|
||||
if (character.getInventory().has(InventoryPaperdoll.RIGHT_HAND)) {
|
||||
add(StatType.POWER_ATTACK,
|
||||
character.getInventory()
|
||||
.getItem(InventoryPaperdoll.RIGHT_HAND)
|
||||
.getTemplateID().getTemplate().getPhysicalDamage());
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private void setup() {
|
||||
calculator.addNoSort(BASE_HP_FORMULA, BASE_MP_FORMULA,
|
||||
BASE_CP_FORMULA);
|
||||
|
||||
calculator.addNoSort(BASE_INT_FORMULA, BASE_STR_FORMULA,
|
||||
BASE_CON_FORMULA, BASE_MEN_FORMULA, BASE_DEX_FORMULA,
|
||||
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
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
package com.l2jserver.model.world.character.calculator;
|
||||
|
||||
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.
|
||||
@@ -24,7 +27,8 @@ import com.l2jserver.model.world.actor.calculator.ActorCalculator;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterCalculator extends ActorCalculator {
|
||||
public CharacterCalculator(CharacterCalculatorFunction... functions) {
|
||||
super(functions);
|
||||
public CharacterCalculator(Class<StatType> type,
|
||||
Calculator<ActorCalculatorContext, StatType>... calculators) {
|
||||
super(type, calculators);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* An calculator for character formulas.
|
||||
@@ -29,8 +30,8 @@ import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
|
||||
*/
|
||||
public abstract class CharacterCalculatorFunction extends
|
||||
ActorCalculatorFunction {
|
||||
public CharacterCalculatorFunction(int order) {
|
||||
super(order);
|
||||
public CharacterCalculatorFunction(int order, StatType type) {
|
||||
super(order, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,20 +14,17 @@
|
||||
* 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;
|
||||
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>
|
||||
*/
|
||||
public class RoundFunction extends AbstractDoubleFunction<CalculatorContext> {
|
||||
public RoundFunction(int order) {
|
||||
super(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(CalculatorContext ctx, double value) {
|
||||
return Math.round(value);
|
||||
public abstract class CharacterFormula extends CharacterCalculatorFunction {
|
||||
public CharacterFormula(int order, StatType type) {
|
||||
super(order, type);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package com.l2jserver.model.world.character.calculator;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* Calculates the character base CP
|
||||
@@ -32,19 +33,17 @@ import com.l2jserver.model.world.L2Character;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MaximumCPAddCalculator extends CharacterCalculator {
|
||||
public class MaximumCPAddCalculator extends CharacterFormula {
|
||||
public MaximumCPAddCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x100) {
|
||||
@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;
|
||||
super(0x100, StatType.MAX_CP);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.model.world.character.calculator;
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.actor.stat.BaseStats;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class MaximumCPBonusCalculator extends CharacterCalculator {
|
||||
public class MaximumCPBonusCalculator extends CharacterFormula {
|
||||
public MaximumCPBonusCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x100) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return value
|
||||
* BaseStats.CON.calculateBonus(c.getStats()
|
||||
.getConcentration());
|
||||
}
|
||||
});
|
||||
super(0x100, StatType.MAX_CP);
|
||||
}
|
||||
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return value
|
||||
* BaseStats.CON.calculateBonus(c.getStats().getConcentration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.l2jserver.model.world.character.calculator;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* Calculates the character maximum HP
|
||||
@@ -32,19 +33,17 @@ import com.l2jserver.model.world.L2Character;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MaximumHPAddCalculator extends CharacterCalculator {
|
||||
public class MaximumHPAddCalculator extends CharacterFormula {
|
||||
public MaximumHPAddCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x100) {
|
||||
@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;
|
||||
super(0x100, StatType.MAX_HP);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.l2jserver.model.world.character.calculator;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* Calculates the character base MP
|
||||
@@ -32,19 +33,18 @@ import com.l2jserver.model.world.L2Character;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class MaximumMPAddCalculator extends CharacterCalculator {
|
||||
public class MaximumMPAddCalculator extends CharacterFormula {
|
||||
public MaximumMPAddCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x100) {
|
||||
@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;
|
||||
super(0x100, StatType.MAX_MP);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseAttackAccuracyCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseAttackAccuracyCalculator extends CharacterFormula {
|
||||
public CharacterBaseAttackAccuracyCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseAccuracy();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.ACCURACY_COMBAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseAccuracy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseAttackEvasionCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseAttackEvasionCalculator extends CharacterFormula {
|
||||
public CharacterBaseAttackEvasionCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseEvasion();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.EVASION_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseEvasion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseCPCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseCPCalculator extends CharacterFormula {
|
||||
public CharacterBaseCPCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
public double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseCP();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAX_CP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseCP();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseConcentrationCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseConcentrationCalculator extends CharacterFormula {
|
||||
public CharacterBaseConcentrationCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseConcentration();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_CON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseConcentration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseDexterityCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseDexterityCalculator extends CharacterFormula {
|
||||
public CharacterBaseDexterityCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseDexterity();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_DEX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseDexterity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseHPCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseHPCalculator extends CharacterFormula {
|
||||
public CharacterBaseHPCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
public double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseHP();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAX_HP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseHP();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseIntelligenceCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseIntelligenceCalculator extends CharacterFormula {
|
||||
public CharacterBaseIntelligenceCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseIntelligence();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_INT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseIntelligence();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* Calculates the character maximum HP
|
||||
* Calculates the character maximum MP
|
||||
*
|
||||
* <pre>
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseMPCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseMPCalculator extends CharacterFormula {
|
||||
public CharacterBaseMPCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
public double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseBaseMP();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAX_MP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseBaseMP();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseMagicalAttackCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseMagicalAttackCalculator extends CharacterFormula {
|
||||
public CharacterBaseMagicalAttackCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseMagicalAttack();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAGIC_ATTACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseMagicalAttack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseMagicalAttackSpeedCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseMagicalAttackSpeedCalculator extends CharacterFormula {
|
||||
public CharacterBaseMagicalAttackSpeedCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseMagicalAttackSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAGIC_ATTACK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseMagicalAttackSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseMagicalCriticalRateCalculator extends
|
||||
CharacterCalculator {
|
||||
CharacterFormula {
|
||||
public CharacterBaseMagicalCriticalRateCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseCritical();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MCRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseCritical();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseMagicalDefenseCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseMagicalDefenseCalculator extends CharacterFormula {
|
||||
public CharacterBaseMagicalDefenseCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseMagicalDefense();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAGIC_DEFENSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseMagicalDefense();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseMentalityCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseMentalityCalculator extends CharacterFormula {
|
||||
public CharacterBaseMentalityCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseMentality();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_MEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseMentality();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBasePhysicalAttackCalculator extends CharacterCalculator {
|
||||
public class CharacterBasePhysicalAttackCalculator extends CharacterFormula {
|
||||
public CharacterBasePhysicalAttackCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBasePhysicalAttack();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.POWER_ATTACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBasePhysicalAttack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBasePhysicalAttackSpeedCalculator extends
|
||||
CharacterCalculator {
|
||||
CharacterFormula {
|
||||
public CharacterBasePhysicalAttackSpeedCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBasePhysicalAttackSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.POWER_ATTACK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBasePhysicalAttackSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBasePhysicalCriticalRateCalculator extends
|
||||
CharacterCalculator {
|
||||
CharacterFormula {
|
||||
public CharacterBasePhysicalCriticalRateCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseCritical();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.CRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseCritical();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBasePhysicalDefenseCalculator extends CharacterCalculator {
|
||||
public class CharacterBasePhysicalDefenseCalculator extends CharacterFormula {
|
||||
public CharacterBasePhysicalDefenseCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBasePhysicalDefense();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.POWER_DEFENSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBasePhysicalDefense();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseRunSpeedCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseRunSpeedCalculator extends CharacterFormula {
|
||||
public CharacterBaseRunSpeedCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseRunSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.RUN_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseRunSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseStrengthCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseStrengthCalculator extends CharacterFormula {
|
||||
public CharacterBaseStrengthCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseStrength();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_STR);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseStrength();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseWalkSpeedCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseWalkSpeedCalculator extends CharacterFormula {
|
||||
public CharacterBaseWalkSpeedCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseWalkSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.WALK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseWalkSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.character.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.CharacterTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculator;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.character.calculator.CharacterFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class CharacterBaseWitnessCalculator extends CharacterCalculator {
|
||||
public class CharacterBaseWitnessCalculator extends CharacterFormula {
|
||||
public CharacterBaseWitnessCalculator() {
|
||||
super(new CharacterCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t,
|
||||
double value) {
|
||||
return t.getBaseWitness();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_WIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(L2Character c, CharacterTemplate t, double value) {
|
||||
return t.getBaseWitness();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package 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.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
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.NPCBaseConcentrationCalculator;
|
||||
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
|
||||
* 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
|
||||
* {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and their functions
|
||||
* are added to this class calculator. Once the skill effect has past away, all
|
||||
* the functions that were imported are now
|
||||
* {@link SimpleCalculator#removeFunctions(SimpleCalculator) removed} and the calculator
|
||||
* return to its original state.
|
||||
* {@link SimpleCalculator#importFunctions(SimpleCalculator) imported} and their
|
||||
* functions are added to this class calculator. Once the skill effect has past
|
||||
* away, all the functions that were imported are now
|
||||
* {@link SimpleCalculator#removeFunctions(SimpleCalculator) removed} and the
|
||||
* calculator return to its original state.
|
||||
* <p>
|
||||
* Another important note is that calculators should perform calculations as
|
||||
* 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
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -81,42 +83,42 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -124,14 +126,14 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -139,28 +141,28 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -168,28 +170,28 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
* <p>
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* 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
|
||||
@@ -197,51 +199,56 @@ public class NPCStats extends ActorStats<NPCCalculatorContext> {
|
||||
* <u>This calculator does not store any state and thus is safe to be
|
||||
* shared.</u>
|
||||
*/
|
||||
private static final NPCCalculator BASE_ATTACK_EVASION_CALCULATOR = new NPCBaseAttackEvasionCalculator();
|
||||
private static final NPCFormula BASE_ATTACK_EVASION_FORMULA = new NPCBaseAttackEvasionCalculator();
|
||||
|
||||
/**
|
||||
* The NPC
|
||||
*/
|
||||
private final NPC npc;
|
||||
|
||||
private static final NPCCalculator calculator = new NPCCalculator(
|
||||
StatType.class);
|
||||
|
||||
/**
|
||||
* Creates a new {@link NPCStats} and adds default calculators
|
||||
*
|
||||
* @param npc
|
||||
* the npc
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public NPCStats(NPC npc) {
|
||||
super();
|
||||
this.npc = npc;
|
||||
|
||||
add(StatType.MAX_HP, BASE_HP_CALCULATOR);
|
||||
add(StatType.MAX_MP, BASE_MP_CALCULATOR);
|
||||
calculator.addNoSort(BASE_HP_FORMULA, BASE_MP_FORMULA);
|
||||
|
||||
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);
|
||||
calculator.addNoSort(BASE_INT_FORMULA, BASE_STR_FORMULA,
|
||||
BASE_CON_FORMULA, BASE_MEN_FORMULA, BASE_DEX_FORMULA,
|
||||
BASE_WIT_FORMULA);
|
||||
|
||||
add(StatType.RUN_SPEED, BASE_RUN_SPEED_CALCULATOR);
|
||||
add(StatType.WALK_SPEED, BASE_WALK_SPEED_CALCULATOR);
|
||||
calculator.addNoSort(BASE_RUN_SPEED_FORMULA,
|
||||
BASE_WALK_SPEED_FORMULA);
|
||||
|
||||
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);
|
||||
calculator.addNoSort(BASE_PHYSICAL_ATTACK_FORMULA,
|
||||
BASE_PHYSICAL_ATTACK_SPEED_FORMULA,
|
||||
BASE_PHYSICAL_CRITICAL_RATE_FORMULA,
|
||||
BASE_PHYSICAL_DEFENSE_FORMULA);
|
||||
|
||||
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);
|
||||
calculator.addNoSort(BASE_MAGICAL_ATTACK_FORMULA,
|
||||
BASE_MAGICAL_ATTACK_SPEED_FORMULA,
|
||||
BASE_MAGICAL_CRITICAL_RATE_FORMULA,
|
||||
BASE_MAGICAL_DEFENSE_FORMULA);
|
||||
|
||||
add(StatType.EVASION_RATE, BASE_ATTACK_EVASION_CALCULATOR);
|
||||
calculator.addNoSort(BASE_ATTACK_EVASION_FORMULA);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NPCCalculatorContext createContext() {
|
||||
return new NPCCalculatorContext(npc);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActorCalculator getCalculator() {
|
||||
return calculator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
package com.l2jserver.model.world.npc.calculator;
|
||||
|
||||
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>
|
||||
*
|
||||
*/
|
||||
public class NPCCalculator extends ActorCalculator {
|
||||
public NPCCalculator(NPCCalculatorFunction... functions) {
|
||||
super(functions);
|
||||
public NPCCalculator(Class<StatType> type, NPCCalculator... calculators) {
|
||||
super(type, calculators);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.actor.calculator.ActorCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public abstract class NPCCalculatorFunction extends ActorCalculatorFunction {
|
||||
public NPCCalculatorFunction(int order) {
|
||||
super(order);
|
||||
public NPCCalculatorFunction(int order, StatType type) {
|
||||
super(order, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,21 +14,16 @@
|
||||
* 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;
|
||||
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>
|
||||
*
|
||||
*/
|
||||
public class NegateFunction extends AbstractDoubleFunction<CalculatorContext> {
|
||||
public NegateFunction(int order) {
|
||||
super(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(CalculatorContext ctx, double value) {
|
||||
return -value;
|
||||
public abstract class NPCFormula extends NPCCalculatorFunction {
|
||||
public NPCFormula(int order, StatType type) {
|
||||
super(order, type);
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseAttackEvasionCalculator extends NPCCalculator {
|
||||
public class NPCBaseAttackEvasionCalculator extends NPCFormula {
|
||||
public NPCBaseAttackEvasionCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getEvasion();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.EVASION_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getEvasion();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseConcentrationCalculator extends NPCCalculator {
|
||||
public class NPCBaseConcentrationCalculator extends NPCFormula {
|
||||
public NPCBaseConcentrationCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getConcentration();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_CON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getConcentration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseDexterityCalculator extends NPCCalculator {
|
||||
public class NPCBaseDexterityCalculator extends NPCFormula {
|
||||
public NPCBaseDexterityCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getDexterity();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_DEX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getDexterity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseHPCalculator extends NPCCalculator {
|
||||
public class NPCBaseHPCalculator extends NPCFormula {
|
||||
public NPCBaseHPCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
public double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getMaximumHP();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAX_HP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMaximumHP();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseIntelligenceCalculator extends NPCCalculator {
|
||||
public class NPCBaseIntelligenceCalculator extends NPCFormula {
|
||||
public NPCBaseIntelligenceCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getIntelligence();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_INT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getIntelligence();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseMPCalculator extends NPCCalculator {
|
||||
public class NPCBaseMPCalculator extends NPCFormula {
|
||||
public NPCBaseMPCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
public double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMaximumMP();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAX_MP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMaximumMP();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseMagicalAttackCalculator extends NPCCalculator {
|
||||
public class NPCBaseMagicalAttackCalculator extends NPCFormula {
|
||||
public NPCBaseMagicalAttackCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getMagicalAttack();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAGIC_ATTACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMagicalAttack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseMagicalAttackSpeedCalculator extends NPCCalculator {
|
||||
public class NPCBaseMagicalAttackSpeedCalculator extends NPCFormula {
|
||||
public NPCBaseMagicalAttackSpeedCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getMagicalAttackSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAGIC_ATTACK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMagicalAttackSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseMagicalCriticalRateCalculator extends
|
||||
NPCCalculator {
|
||||
public class NPCBaseMagicalCriticalRateCalculator extends NPCFormula {
|
||||
public NPCBaseMagicalCriticalRateCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getCritical();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MCRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getCritical();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseMagicalDefenseCalculator extends NPCCalculator {
|
||||
public class NPCBaseMagicalDefenseCalculator extends NPCFormula {
|
||||
public NPCBaseMagicalDefenseCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getMagicalDefense();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.MAGIC_DEFENSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMagicalDefense();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseMentalityCalculator extends NPCCalculator {
|
||||
public class NPCBaseMentalityCalculator extends NPCFormula {
|
||||
public NPCBaseMentalityCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getMentality();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_MEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getMentality();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBasePhysicalAttackCalculator extends NPCCalculator {
|
||||
public class NPCBasePhysicalAttackCalculator extends NPCFormula {
|
||||
public NPCBasePhysicalAttackCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getPhysicalAttack();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.POWER_ATTACK);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getPhysicalAttack();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBasePhysicalAttackSpeedCalculator extends
|
||||
NPCCalculator {
|
||||
public class NPCBasePhysicalAttackSpeedCalculator extends NPCFormula {
|
||||
public NPCBasePhysicalAttackSpeedCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getPhysicalAttackSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.POWER_ATTACK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getPhysicalAttackSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBasePhysicalCriticalRateCalculator extends NPCCalculator {
|
||||
public class NPCBasePhysicalCriticalRateCalculator extends NPCFormula {
|
||||
public NPCBasePhysicalCriticalRateCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getCritical();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.CRITICAL_RATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getCritical();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBasePhysicalDefenseCalculator extends NPCCalculator {
|
||||
public class NPCBasePhysicalDefenseCalculator extends NPCFormula {
|
||||
public NPCBasePhysicalDefenseCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getPhysicalDefense();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.POWER_DEFENSE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getPhysicalDefense();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseRunSpeedCalculator extends NPCCalculator {
|
||||
public class NPCBaseRunSpeedCalculator extends NPCFormula {
|
||||
public NPCBaseRunSpeedCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getRunSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.RUN_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getRunSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseStrengthCalculator extends NPCCalculator {
|
||||
public class NPCBaseStrengthCalculator extends NPCFormula {
|
||||
public NPCBaseStrengthCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getStrength();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_STR);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getStrength();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseWalkSpeedCalculator extends NPCCalculator {
|
||||
public class NPCBaseWalkSpeedCalculator extends NPCFormula {
|
||||
public NPCBaseWalkSpeedCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getWalkSpeed();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.WALK_SPEED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getWalkSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package com.l2jserver.model.world.npc.calculator.base;
|
||||
|
||||
import com.l2jserver.model.template.NPCTemplate;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculator;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCCalculatorFunction;
|
||||
import com.l2jserver.model.world.actor.stat.StatType;
|
||||
import com.l2jserver.model.world.npc.calculator.NPCFormula;
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public class NPCBaseWitnessCalculator extends NPCCalculator {
|
||||
public class NPCBaseWitnessCalculator extends NPCFormula {
|
||||
public NPCBaseWitnessCalculator() {
|
||||
super(new NPCCalculatorFunction(0x000) {
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t,
|
||||
double value) {
|
||||
return t.getWitness();
|
||||
}
|
||||
});
|
||||
super(0x000, StatType.STAT_WIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected double calculate(NPC c, NPCTemplate t, double value) {
|
||||
return t.getWitness();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ public class Log4JLoggingService extends AbstractService implements
|
||||
LoggingService {
|
||||
private Logger rootLogger;
|
||||
private Logger l2jLogger;
|
||||
private Logger scriptLogger;
|
||||
private Logger nettyLogger;
|
||||
|
||||
@Override
|
||||
@@ -47,7 +46,6 @@ public class Log4JLoggingService extends AbstractService implements
|
||||
BasicConfigurator.configure();
|
||||
rootLogger = Logger.getRootLogger();
|
||||
l2jLogger = Logger.getLogger("com.l2jserver");
|
||||
scriptLogger = Logger.getLogger("script");
|
||||
nettyLogger = Logger.getLogger("org.jboss.netty");
|
||||
|
||||
rootLogger.removeAllAppenders();
|
||||
@@ -55,7 +53,6 @@ public class Log4JLoggingService extends AbstractService implements
|
||||
rootLogger.addAppender(new ConsoleAppender(layout, "System.err"));
|
||||
|
||||
l2jLogger.setLevel(Level.INFO);
|
||||
scriptLogger.setLevel(Level.INFO);
|
||||
nettyLogger.setLevel(Level.DEBUG);
|
||||
Logger.getLogger("com.l2jserver.model.id.object.allocator").setLevel(Level.WARN);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.server.AttackHit;
|
||||
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.PhysicalAttackCalculator;
|
||||
import com.l2jserver.model.world.Actor;
|
||||
@@ -90,8 +91,9 @@ public class AttackServiceImpl extends AbstractService implements AttackService
|
||||
|
||||
@Override
|
||||
public AttackHit call() throws Exception {
|
||||
final double damage = PHYSICAL_ATTACK_CALCULATOR
|
||||
.calculate(new AttackCalculatorContext(attacker, target));
|
||||
final double damage = PHYSICAL_ATTACK_CALCULATOR.calculate(
|
||||
AttackCalculatorType.DAMAGE, new AttackCalculatorContext(
|
||||
attacker, target));
|
||||
// TODO calculate miss
|
||||
// TODO calculate critical
|
||||
// TODO calculate soulshot
|
||||
|
||||
@@ -92,7 +92,7 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
* The {@link WorldService}
|
||||
*/
|
||||
private final WorldService worldService;
|
||||
/**
|
||||
/*
|
||||
* The {@link WorldService} event dispatcher
|
||||
*/
|
||||
private final WorldEventDispatcher eventDispatcher;
|
||||
@@ -156,7 +156,7 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
character.setOnline(true);
|
||||
|
||||
// inventory interfere on calculators
|
||||
character.getStats().updateCalculators();
|
||||
character.getStats().updateCalculator();
|
||||
|
||||
// chat listener
|
||||
final ChatChannelListener globalChatListener = new ChatChannelListener() {
|
||||
|
||||
@@ -18,14 +18,15 @@ package com.l2jserver.util.calculator;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractDoubleFunction<T extends CalculatorContext> implements
|
||||
Function<T> {
|
||||
public abstract class AbstractDoubleFunction<T extends CalculatorContext, V extends Enum<V>>
|
||||
implements Function<T, V> {
|
||||
private final int order;
|
||||
private final V type;
|
||||
|
||||
public AbstractDoubleFunction(int order) {
|
||||
public AbstractDoubleFunction(int order, V type) {
|
||||
this.order = order;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,4 +34,8 @@ public abstract class AbstractDoubleFunction<T extends CalculatorContext> implem
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,12 @@
|
||||
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>
|
||||
*
|
||||
*/
|
||||
public class PercentFunction extends MultiplicationFunction {
|
||||
/**
|
||||
* The value
|
||||
*/
|
||||
public PercentFunction(int order, double value) {
|
||||
super(order, value / 100);
|
||||
}
|
||||
public interface Calculator<T extends CalculatorContext, V extends Enum<V>>
|
||||
extends Function<T, V> {
|
||||
double calculate(V v, T ctx, double value);
|
||||
|
||||
double calculate(V v, T ctx);
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ package com.l2jserver.util.calculator;
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
@@ -39,4 +39,6 @@ public interface Function<C extends CalculatorContext> {
|
||||
* @return the order this function will be executed
|
||||
*/
|
||||
int order();
|
||||
|
||||
V type();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -25,22 +25,13 @@ import java.util.Comparator;
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class SimpleCalculator<T extends CalculatorContext> extends
|
||||
AbstractDoubleFunction<T> {
|
||||
public class SimpleCalculator<T extends CalculatorContext, V extends Enum<V>>
|
||||
extends AbstractDoubleFunction<T, V> implements Calculator<T, V> {
|
||||
protected final V value;
|
||||
/**
|
||||
* List of operations in this calculator
|
||||
*/
|
||||
private Function<? super T>[] 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];
|
||||
}
|
||||
protected final Function<T, V>[] functions;
|
||||
|
||||
/**
|
||||
* Creates a new calculator with <tt>functions</tt> in the declaration
|
||||
@@ -49,85 +40,37 @@ public class SimpleCalculator<T extends CalculatorContext> extends
|
||||
* @param functions
|
||||
* the calculator functions
|
||||
*/
|
||||
public SimpleCalculator(Function<? super T>... functions) {
|
||||
super(0x00);
|
||||
public SimpleCalculator(V value, Function<T, V>... functions) {
|
||||
super(0x00, value);
|
||||
this.value = value;
|
||||
this.functions = functions;
|
||||
Arrays.sort(this.functions, 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<? 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) {
|
||||
public double calculate(V v, T ctx, double value) {
|
||||
if (v != this.value)
|
||||
return value;
|
||||
for (final Function<T, V> function : functions) {
|
||||
value = function.calculate(ctx, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public double calculate(T ctx) {
|
||||
public double calculate(V v, T ctx) {
|
||||
return calculate(ctx, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculate(T ctx, double value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class FunctionOrderComparator implements
|
||||
Comparator<Function<?>> {
|
||||
Comparator<Function<?, ?>> {
|
||||
public static final FunctionOrderComparator SHARED_INSTANCE = new FunctionOrderComparator();
|
||||
|
||||
@Override
|
||||
public int compare(Function<?> func1, Function<?> func2) {
|
||||
public int compare(Function<?, ?> func1, Function<?, ?> func2) {
|
||||
return (func1.order() - func2.order());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -16,138 +16,144 @@
|
||||
*/
|
||||
package com.l2jserver.util.calculator;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class CalculatorTest {
|
||||
@Test
|
||||
public void testSimple() {
|
||||
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
|
||||
|
||||
calc.add(new SetFunction(0, 10));
|
||||
calc.add(new MultiplicationFunction(1, 2));
|
||||
calc.add(new SetFunction(2, 30));
|
||||
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
Assert.assertEquals(30.0, calc.calculate(ctx));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPercent() {
|
||||
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
|
||||
|
||||
calc.add(new SetFunction(0, 10));
|
||||
calc.add(new MultiplicationFunction(1, 2));
|
||||
calc.add(new PercentFunction(2, 75));
|
||||
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
Assert.assertEquals(15.0, calc.calculate(ctx));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplex() {
|
||||
final SimpleCalculator<CalculatorContext> calc = new SimpleCalculator<CalculatorContext>();
|
||||
|
||||
calc.add(new SetFunction(0, 10));
|
||||
calc.add(new MultiplicationFunction(1, 2));
|
||||
calc.add(new PercentFunction(2, 75));
|
||||
calc.add(new SumFunction(3, 3));
|
||||
calc.add(new SubtractFunction(4, 8));
|
||||
calc.add(new DivisionFunction(5, 2));
|
||||
|
||||
final CalculatorContext ctx = new CalculatorContext();
|
||||
Assert.assertEquals(5.0, calc.calculate(ctx));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNesting() {
|
||||
final SimpleCalculator<CalculatorContext> calc1 = new SimpleCalculator<CalculatorContext>();
|
||||
final CalculatorContext ctx1 = new CalculatorContext();
|
||||
|
||||
calc1.add(new SetFunction(0, 10));
|
||||
calc1.add(new MultiplicationFunction(1, 2));
|
||||
calc1.add(new PercentFunction(2, 75));
|
||||
calc1.add(new SumFunction(3, 3));
|
||||
calc1.add(new SubtractFunction(4, 8));
|
||||
calc1.add(new DivisionFunction(5, 2));
|
||||
|
||||
Assert.assertEquals(5.0, calc1.calculate(ctx1));
|
||||
|
||||
final SimpleCalculator<CalculatorContext> calc2 = new SimpleCalculator<CalculatorContext>();
|
||||
final CalculatorContext ctx2 = new CalculatorContext();
|
||||
|
||||
calc2.add(new MultiplicationFunction(0, 2));
|
||||
calc2.add(new PercentFunction(1, 75));
|
||||
calc2.add(new SumFunction(2, 3));
|
||||
calc2.add(new SubtractFunction(3, 8));
|
||||
calc2.add(new DivisionFunction(4, 2));
|
||||
|
||||
Assert.assertEquals(-2.5, calc2.calculate(ctx2));
|
||||
|
||||
final SimpleCalculator<CalculatorContext> calc3 = new SimpleCalculator<CalculatorContext>();
|
||||
final CalculatorContext ctx3 = new CalculatorContext();
|
||||
calc3.add(calc1);
|
||||
calc3.add(calc2);
|
||||
|
||||
// this should be executed
|
||||
calc2.add(new SumFunction(10, 1));
|
||||
|
||||
Assert.assertEquals(2.25, calc3.calculate(ctx3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImporting() {
|
||||
final SimpleCalculator<CalculatorContext> calc1 = new SimpleCalculator<CalculatorContext>();
|
||||
final CalculatorContext ctx1 = new CalculatorContext();
|
||||
|
||||
calc1.add(new SetFunction(0, 10));
|
||||
calc1.add(new MultiplicationFunction(2, 2));
|
||||
calc1.add(new PercentFunction(4, 75));
|
||||
calc1.add(new SumFunction(6, 3));
|
||||
calc1.add(new SubtractFunction(8, 8));
|
||||
calc1.add(new DivisionFunction(10, 2));
|
||||
|
||||
Assert.assertEquals(5.0, calc1.calculate(ctx1));
|
||||
|
||||
final SimpleCalculator<CalculatorContext> calc2 = new SimpleCalculator<CalculatorContext>();
|
||||
final CalculatorContext ctx2 = new CalculatorContext();
|
||||
|
||||
calc2.add(new MultiplicationFunction(1, 2));
|
||||
calc2.add(new PercentFunction(3, 75));
|
||||
calc2.add(new SumFunction(5, 3));
|
||||
calc2.add(new SubtractFunction(7, 8));
|
||||
calc2.add(new DivisionFunction(9, 2));
|
||||
|
||||
Assert.assertEquals(-2.5, calc2.calculate(ctx2));
|
||||
|
||||
final SimpleCalculator<CalculatorContext> calc3 = new SimpleCalculator<CalculatorContext>();
|
||||
final CalculatorContext ctx3 = new CalculatorContext();
|
||||
calc3.importFunctions(calc1);
|
||||
calc3.importFunctions(calc2);
|
||||
|
||||
// this should not be executed
|
||||
calc2.add(new SumFunction(11, 50));
|
||||
|
||||
Assert.assertEquals(1.25, calc3.calculate(ctx3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRounding() {
|
||||
final SimpleCalculator<CalculatorContext> calc = new 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));
|
||||
}
|
||||
// @Test
|
||||
// public void testSimple() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new SetFunction(0, 10));
|
||||
// calc.add(new MultiplicationFunction(1, 2));
|
||||
// calc.add(new SetFunction(2, 30));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(30.0, calc.calculate(ctx));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testPercent() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new SetFunction(0, 10));
|
||||
// calc.add(new MultiplicationFunction(1, 2));
|
||||
// calc.add(new PercentFunction(2, 75));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(15.0, calc.calculate(ctx));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testComplex() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
//
|
||||
// calc.add(new SetFunction(0, 10));
|
||||
// calc.add(new MultiplicationFunction(1, 2));
|
||||
// calc.add(new PercentFunction(2, 75));
|
||||
// calc.add(new SumFunction(3, 3));
|
||||
// calc.add(new SubtractFunction(4, 8));
|
||||
// calc.add(new DivisionFunction(5, 2));
|
||||
//
|
||||
// final CalculatorContext ctx = new CalculatorContext();
|
||||
// Assert.assertEquals(5.0, calc.calculate(ctx));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testNesting() {
|
||||
// final SimpleCalculator<CalculatorContext> calc1 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx1 = new CalculatorContext();
|
||||
//
|
||||
// calc1.add(new SetFunction(0, 10));
|
||||
// calc1.add(new MultiplicationFunction(1, 2));
|
||||
// calc1.add(new PercentFunction(2, 75));
|
||||
// calc1.add(new SumFunction(3, 3));
|
||||
// calc1.add(new SubtractFunction(4, 8));
|
||||
// calc1.add(new DivisionFunction(5, 2));
|
||||
//
|
||||
// Assert.assertEquals(5.0, calc1.calculate(ctx1));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc2 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx2 = new CalculatorContext();
|
||||
//
|
||||
// calc2.add(new MultiplicationFunction(0, 2));
|
||||
// calc2.add(new PercentFunction(1, 75));
|
||||
// calc2.add(new SumFunction(2, 3));
|
||||
// calc2.add(new SubtractFunction(3, 8));
|
||||
// calc2.add(new DivisionFunction(4, 2));
|
||||
//
|
||||
// Assert.assertEquals(-2.5, calc2.calculate(ctx2));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc3 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx3 = new CalculatorContext();
|
||||
// calc3.add(calc1);
|
||||
// calc3.add(calc2);
|
||||
//
|
||||
// // this should be executed
|
||||
// calc2.add(new SumFunction(10, 1));
|
||||
//
|
||||
// Assert.assertEquals(2.25, calc3.calculate(ctx3));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testImporting() {
|
||||
// final SimpleCalculator<CalculatorContext> calc1 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx1 = new CalculatorContext();
|
||||
//
|
||||
// calc1.add(new SetFunction(0, 10));
|
||||
// calc1.add(new MultiplicationFunction(2, 2));
|
||||
// calc1.add(new PercentFunction(4, 75));
|
||||
// calc1.add(new SumFunction(6, 3));
|
||||
// calc1.add(new SubtractFunction(8, 8));
|
||||
// calc1.add(new DivisionFunction(10, 2));
|
||||
//
|
||||
// Assert.assertEquals(5.0, calc1.calculate(ctx1));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc2 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx2 = new CalculatorContext();
|
||||
//
|
||||
// calc2.add(new MultiplicationFunction(1, 2));
|
||||
// calc2.add(new PercentFunction(3, 75));
|
||||
// calc2.add(new SumFunction(5, 3));
|
||||
// calc2.add(new SubtractFunction(7, 8));
|
||||
// calc2.add(new DivisionFunction(9, 2));
|
||||
//
|
||||
// Assert.assertEquals(-2.5, calc2.calculate(ctx2));
|
||||
//
|
||||
// final SimpleCalculator<CalculatorContext> calc3 = new
|
||||
// SimpleCalculator<CalculatorContext>();
|
||||
// final CalculatorContext ctx3 = new CalculatorContext();
|
||||
// calc3.importFunctions(calc1);
|
||||
// calc3.importFunctions(calc2);
|
||||
//
|
||||
// // this should not be executed
|
||||
// calc2.add(new SumFunction(11, 50));
|
||||
//
|
||||
// Assert.assertEquals(1.25, calc3.calculate(ctx3));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRounding() {
|
||||
// final SimpleCalculator<CalculatorContext> calc = new
|
||||
// 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));
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user