diff --git a/src/main/java/com/l2jserver/game/net/packet/server/SM_NPC_INFO.java b/src/main/java/com/l2jserver/game/net/packet/server/SM_NPC_INFO.java index 5cf636e65..d6288f967 100644 --- a/src/main/java/com/l2jserver/game/net/packet/server/SM_NPC_INFO.java +++ b/src/main/java/com/l2jserver/game/net/packet/server/SM_NPC_INFO.java @@ -58,16 +58,16 @@ public class SM_NPC_INFO extends AbstractServerPacket { buffer.writeInt(npc.getPoint().getZ()); buffer.writeInt((int) npc.getPoint().getAngle()); buffer.writeInt(0x00); // unk - buffer.writeInt((int) template.getMagicalAttackSpeed()); - buffer.writeInt((int) template.getPhysicalAttackSpeed()); - buffer.writeInt((int) template.getRunSpeed()); - buffer.writeInt((int) template.getWalkSpeed()); - buffer.writeInt((int) template.getRunSpeed()); // swim run speed - buffer.writeInt((int) template.getWalkSpeed()); // swim walk speed - buffer.writeInt((int) template.getRunSpeed()); // swim run speed - buffer.writeInt((int) template.getWalkSpeed()); // swim walk speed - buffer.writeInt((int) template.getRunSpeed()); // fly run speed - buffer.writeInt((int) template.getWalkSpeed()); // fly run speed + buffer.writeInt(npc.getStats().getMagicalAttackSpeed()); + buffer.writeInt(npc.getStats().getPhysicalAttackSpeed()); + buffer.writeInt(npc.getStats().getRunSpeed()); + buffer.writeInt(npc.getStats().getWalkSpeed()); + buffer.writeInt(npc.getStats().getRunSpeed()); // swim run speed + buffer.writeInt(npc.getStats().getWalkSpeed()); // swim walk speed + buffer.writeInt(npc.getStats().getRunSpeed()); // swim run speed + buffer.writeInt(npc.getStats().getWalkSpeed()); // swim walk speed + buffer.writeInt(npc.getStats().getRunSpeed()); // fly run speed + buffer.writeInt(npc.getStats().getWalkSpeed()); // fly run speed buffer.writeDouble(0x01); // TODO buffer.writeDouble(0x01);// TODO buffer.writeDouble(template.getCollisionRadius()); @@ -79,7 +79,7 @@ public class SM_NPC_INFO extends AbstractServerPacket { .getLeftHand().getID() : 0x00)); buffer.writeByte(1); // name above char 1=true ... ?? buffer.writeByte(0x00); // is running - buffer.writeByte(0x00); // is in combat + buffer.writeByte((npc.isAttacking() ? 0x01 : 0x00)); // is in combat buffer.writeByte(0x00); // is like dead (faking) buffer.writeByte(0x00); // 0=teleported 1=default 2=summoned BufferUtils.writeString(buffer, template.getName()); @@ -102,8 +102,11 @@ public class SM_NPC_INFO extends AbstractServerPacket { buffer.writeInt(0x00); // C6 -- is flying buffer.writeInt(0x00); // unk buffer.writeInt(0x00);// CT1.5 Pet form and skills, Color effect - buffer.writeByte((template.getDisplayName() ? 0x01 : 0x00)); // hide name - buffer.writeByte((template.getDisplayName() ? 0x01 : 0x00)); // hide name, again + buffer.writeByte((template.getDisplayName() ? 0x01 : 0x00)); // hide + // name + buffer.writeByte((template.getDisplayName() ? 0x01 : 0x00)); // hide + // name, + // again buffer.writeInt(0x00); // special effects buffer.writeInt(0x00); // display effect diff --git a/src/main/java/com/l2jserver/model/world/Actor.java b/src/main/java/com/l2jserver/model/world/Actor.java index 1c6bb1c37..ae658b38a 100644 --- a/src/main/java/com/l2jserver/model/world/Actor.java +++ b/src/main/java/com/l2jserver/model/world/Actor.java @@ -21,6 +21,7 @@ import com.l2jserver.model.id.template.ActorTemplateID; import com.l2jserver.model.template.ActorTemplate; import com.l2jserver.model.world.actor.ActorEffects; import com.l2jserver.model.world.actor.ActorSkillContainer; +import com.l2jserver.model.world.actor.stat.ActorStats; /** * Abstract {@link Actor} class. @@ -132,6 +133,8 @@ public abstract class Actor extends PositionableObject { protected Actor(ActorTemplateID templateID) { this.templateID = templateID; } + + public abstract ActorStats getStats(); /** * @return the race diff --git a/src/main/java/com/l2jserver/model/world/NPC.java b/src/main/java/com/l2jserver/model/world/NPC.java index 227056964..dbac0fff2 100644 --- a/src/main/java/com/l2jserver/model/world/NPC.java +++ b/src/main/java/com/l2jserver/model/world/NPC.java @@ -20,6 +20,7 @@ import com.l2jserver.model.id.TemplateID; import com.l2jserver.model.id.object.NPCID; import com.l2jserver.model.id.template.NPCTemplateID; import com.l2jserver.model.template.NPCTemplate; +import com.l2jserver.model.world.npc.NPCStats; import com.l2jserver.service.game.ai.AIScript; /** @@ -29,6 +30,8 @@ import com.l2jserver.service.game.ai.AIScript; * @author Rogiel */ public class NPC extends Actor { + private NPCStats stats; + private NPCState state; public enum NPCState { @@ -45,6 +48,13 @@ public class NPC extends Actor { super(templateID); } + /** + * @return the stats + */ + public NPCStats getStats() { + return stats; + } + /** * @return the state */ diff --git a/src/main/java/com/l2jserver/model/world/Pet.java b/src/main/java/com/l2jserver/model/world/Pet.java index 396f80f96..f5168a807 100644 --- a/src/main/java/com/l2jserver/model/world/Pet.java +++ b/src/main/java/com/l2jserver/model/world/Pet.java @@ -19,6 +19,7 @@ package com.l2jserver.model.world; import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.id.object.ItemID; import com.l2jserver.model.id.template.ActorTemplateID; +import com.l2jserver.model.world.actor.stat.ActorStats; /** * This class represents an Pet in the Lineage II World @@ -82,4 +83,13 @@ public class Pet extends Player { public void setItemID(ItemID itemID) { this.itemID = itemID; } + + /* (non-Javadoc) + * @see com.l2jserver.model.world.Actor#getStats() + */ + @Override + public ActorStats getStats() { + // TODO Auto-generated method stub + return null; + } } diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculator.java index c924831cb..6739803c7 100644 --- a/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculator.java @@ -16,20 +16,13 @@ */ package com.l2jserver.model.world.actor.calculator; -import com.l2jserver.model.world.Actor; +import com.l2jserver.util.calculator.Calculator; /** * @author Rogiel */ -public class ActorCalculator { - @SuppressWarnings("unused") - private final Actor actor; - - public ActorCalculator(Actor actor) { - this.actor = actor; - } - - public double calculateMaxHP() { - return 0; +public class ActorCalculator extends Calculator { + public ActorCalculator(ActorCalculatorFunction... functions) { + super(functions); } } diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculatorFunction.java b/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculatorFunction.java new file mode 100644 index 000000000..7a09419fa --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/ActorCalculatorFunction.java @@ -0,0 +1,41 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.actor.calculator; + +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; +import com.l2jserver.util.calculator.AbstractFunction; + +/** + * An calculator for character formulas. + * + * @author Rogiel + */ +public abstract class ActorCalculatorFunction extends + AbstractFunction { + public ActorCalculatorFunction(int order) { + super(order); + } + + @Override + public final double calculate(ActorCalculatorContext ctx, double value) { + return calculate(ctx.actor, ctx.actor.getTemplate(), value); + } + + protected abstract double calculate(Actor a, + ActorTemplate t, double value); +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseAttackAccuracyCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/AttackAccuracyBonusCalculator.java similarity index 57% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseAttackAccuracyCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/AttackAccuracyBonusCalculator.java index fc5b97204..85151913c 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseAttackAccuracyCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/AttackAccuracyBonusCalculator.java @@ -14,13 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; import org.apache.commons.math.util.FastMath; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; /** * Calculates the character base accuracy. @@ -37,25 +36,20 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseAttackAccuracyCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseAttackAccuracyCalculator() { - super(new AbstractFunction(0x000) { +public class AttackAccuracyBonusCalculator extends ActorCalculator { + public AttackAccuracyBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseAccuracy(); - } - }, new AbstractFunction(0x100) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final int level = c.getLevel(); + protected double calculate(Actor a, ActorTemplate t, double value) { + final int level = a.getLevel(); - ctx.result += FastMath.sqrt(c.getStats().getDexterity()) * 6; - ctx.result += level; + value += FastMath.sqrt(a.getStats().getDexterity()) * 6; + value += level; if (level > 77) - ctx.result += (level - 77) + 1; + value += (level - 77) + 1; if (level > 69) - ctx.result += (level - 69); + value += (level - 69); + return value; } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseAttackEvasionCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/AttackEvasionBonusCalculator.java similarity index 57% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseAttackEvasionCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/AttackEvasionBonusCalculator.java index e6304b2ab..cd4ec0948 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseAttackEvasionCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/AttackEvasionBonusCalculator.java @@ -14,13 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; import org.apache.commons.math.util.FastMath; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; /** * Calculates the character evasion @@ -37,25 +36,20 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseAttackEvasionCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseAttackEvasionCalculator() { - super(new AbstractFunction(0x000) { +public class AttackEvasionBonusCalculator extends ActorCalculator { + public AttackEvasionBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseEvasion(); - } - }, new AbstractFunction(0x100) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final int level = c.getLevel(); + protected double calculate(Actor a, ActorTemplate t, double value) { + final int level = a.getLevel(); - ctx.result += FastMath.sqrt(c.getStats().getDexterity()) * 6; - ctx.result += level; + value += FastMath.sqrt(a.getStats().getDexterity()) * 6; + value += level; if (level > 77) - ctx.result += (level - 77) + 1; + value += (level - 77) + 1; if (level > 69) - ctx.result += (level - 69); + value += (level - 69); + return value; } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalAttackCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalAttackBonusCalculator.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalAttackCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/MagicalAttackBonusCalculator.java index 0839b80c4..eddb2680c 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalAttackCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalAttackBonusCalculator.java @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; -import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; /** * Calculates the character base magical attack @@ -31,20 +30,14 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseMagicalAttackCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseMagicalAttackCalculator() { - super(new AbstractFunction(0x000) { +public class MagicalAttackBonusCalculator extends ActorCalculator { + public MagicalAttackBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseMagicalAttack(); - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= Math - .pow(((100.0 - 11 + c.getLevel()) / 100.0), 2) - * Math.pow(BaseStats.INT.calculateBonus(c.getStats() + 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); } }); diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalAttackSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalAttackSpeedBonusCalculator.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalAttackSpeedCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/MagicalAttackSpeedBonusCalculator.java index 4d587a56a..2588a5dab 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalAttackSpeedCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalAttackSpeedBonusCalculator.java @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; -import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; /** * Calculates the base magical attack speed @@ -31,19 +30,14 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseMagicalAttackSpeedCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseMagicalAttackSpeedCalculator() { - super(new AbstractFunction(0x000) { +public class MagicalAttackSpeedBonusCalculator extends ActorCalculator { + public MagicalAttackSpeedBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseMagicalAttackSpeed(); - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.WIT.calculateBonus(c.getStats() - .getWitness()); + protected double calculate(Actor a, ActorTemplate t, double value) { + return value + * BaseStats.WIT.calculateBonus(a.getStats() + .getWitness()); } }); } diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalCriticalRateBonusCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalCriticalRateBonusCalculator.java new file mode 100644 index 000000000..7dbef0f6f --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalCriticalRateBonusCalculator.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jse rver . + * + * 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 . + */ +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; + +/** + * Calculates the base magical attack critical rate + * + *
+ * ctx.result = c.getTemplate().getBaseCritical(); // must be checked
+ * ctx.result *= BaseStats.WIT.calculateBonus(c.getStats().getWitness());
+ * 
+ * + * @author Rogiel + */ +public class MagicalCriticalRateBonusCalculator extends ActorCalculator { + 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()); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalDefenseBonusCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalDefenseBonusCalculator.java new file mode 100644 index 000000000..e149e2149 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/MagicalDefenseBonusCalculator.java @@ -0,0 +1,68 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base magical 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;
+ * ctx.result *= BaseStats.MEN.calculateBonus(c.getStats().getMentality())
+ * 		* ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class MagicalDefenseBonusCalculator extends ActorCalculator { + public MagicalDefenseBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { + @Override + protected double calculate(Actor a, ActorTemplate t, double value) { + // final CharacterInventory inv = c.getInventory(); + + // if (inv.has(LEFT_FINGER)) + // ctx.result -= 5; + // if (inv.has(RIGHT_FINGER)) + // ctx.result -= 5; + // if (inv.has(LEFT_EAR)) + // ctx.result -= 9; + // if (inv.has(RIGHT_EAR)) + // ctx.result -= 9; + // if (inv.has(NECK)) + // ctx.result -= 13; + + return value + * BaseStats.MEN.calculateBonus(a.getStats() + .getMentality()) + * ((100.0 - 11 + a.getLevel()) / 100.0); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/MaximumHPBonusCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/MaximumHPBonusCalculator.java new file mode 100644 index 000000000..91c33c9bc --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/MaximumHPBonusCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the actor maximum HP bonus + * + *
+ * return value * BaseStats.CON.calculateBonus(c.getStats().getConcentration());
+ * 
+ * + * @author Rogiel + */ +public class MaximumHPBonusCalculator extends ActorCalculator { + public MaximumHPBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { + @Override + protected double calculate(Actor a, ActorTemplate t, double value) { + return value + * BaseStats.CON.calculateBonus(a.getStats() + .getConcentration()); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/MaximumMPBonusCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/MaximumMPBonusCalculator.java new file mode 100644 index 000000000..a5b2e3925 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/MaximumMPBonusCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the actor maximum HP bonus + * + *
+ * return value * BaseStats.CON.calculateBonus(c.getStats().getConcentration());
+ * 
+ * + * @author Rogiel + */ +public class MaximumMPBonusCalculator extends ActorCalculator { + public MaximumMPBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { + @Override + protected double calculate(Actor a, ActorTemplate t, double value) { + return value + * BaseStats.MEN.calculateBonus(a.getStats() + .getMentality()); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalAttackCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalAttackBonusCalculator.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalAttackCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalAttackBonusCalculator.java index a2933e402..6902f6088 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalAttackCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalAttackBonusCalculator.java @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; -import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; /** * Calculates the character base physical attack @@ -32,19 +31,15 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BasePhysicalAttackCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BasePhysicalAttackCalculator() { - super(new AbstractFunction(0x000) { +public class PhysicalAttackBonusCalculator extends ActorCalculator { + public PhysicalAttackBonusCalculator() { + super(new ActorCalculatorFunction(0x100) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBasePhysicalAttack(); - } - }, new AbstractFunction(0x100) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.STR.calculateBonus(c.getStats() - .getStrength()) * ((100.0 - 11 + c.getLevel()) / 100.0); + protected double calculate(Actor a, ActorTemplate t, double value) { + return value + * BaseStats.STR.calculateBonus(a.getStats() + .getStrength()) + * ((100.0 - 11 + a.getLevel()) / 100.0); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalAttackSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalAttackSpeedBonusCalculator.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalAttackSpeedCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalAttackSpeedBonusCalculator.java index a565a060e..4cb3b2a72 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalAttackSpeedCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalAttackSpeedBonusCalculator.java @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; -import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; /** * Calculates the character base physical attack speed @@ -31,19 +30,14 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BasePhysicalAttackSpeedCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BasePhysicalAttackSpeedCalculator() { - super(new AbstractFunction(0x000) { +public class PhysicalAttackSpeedBonusCalculator extends ActorCalculator { + public PhysicalAttackSpeedBonusCalculator() { + super(new ActorCalculatorFunction(0x200) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBasePhysicalAttackSpeed(); - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.DEX.calculateBonus(c.getStats() - .getDexterity()); + protected double calculate(Actor a, ActorTemplate t, double value) { + return value + * BaseStats.DEX.calculateBonus(a.getStats() + .getDexterity()); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalCriticalRateCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalCriticalRateBonusCalculator.java similarity index 59% rename from src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalCriticalRateCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalCriticalRateBonusCalculator.java index 923955265..bfdd6d40e 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalCriticalRateCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalCriticalRateBonusCalculator.java @@ -14,12 +14,11 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; -import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; /** * Calculates the character base critical rate @@ -32,21 +31,14 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BasePhysicalCriticalRateCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BasePhysicalCriticalRateCalculator() { - super(new AbstractFunction(0x000) { +public class PhysicalCriticalRateBonusCalculator extends ActorCalculator { + public PhysicalCriticalRateBonusCalculator() { + super(new ActorCalculatorFunction(0x090) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseCritical(); - } - }, new AbstractFunction(0x090) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.DEX.calculateBonus(c.getStats() - .getDexterity()); - ctx.result *= 10; - + 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 } }); diff --git a/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalDefenseBonusCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalDefenseBonusCalculator.java new file mode 100644 index 000000000..6f1e2cd81 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/PhysicalDefenseBonusCalculator.java @@ -0,0 +1,72 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.actor.calculator; + +import com.l2jserver.model.template.ActorTemplate; +import com.l2jserver.model.world.Actor; + +/** + * Calculates the character base physical defense + * + *
+ * ctx.result = c.getTemplate().getBasePhysicalDefense();
+ * 
+ * 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))
+ * 	ctx.result -= hasMagePDef ? 8 : 18;
+ * if (inv.has(GLOVES))
+ * 	ctx.result -= 8;
+ * if (inv.has(FEET))
+ * 	ctx.result -= 7;
+ * ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class PhysicalDefenseBonusCalculator extends ActorCalculator { + 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); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseRunSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/RunSpeedBonusCalculator.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseRunSpeedCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/RunSpeedBonusCalculator.java index aacd974cd..07813bc9b 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseRunSpeedCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/RunSpeedBonusCalculator.java @@ -14,36 +14,32 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; +import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the character base run speed * *
- * ctx.result = c.getTemplate().getBaseRunSpeed();
  * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
  * 
* * @author Rogiel */ -public class BaseRunSpeedCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseRunSpeedCalculator() { - super(new AbstractFunction(0x000) { +public class RunSpeedBonusCalculator extends CharacterCalculator { + public RunSpeedBonusCalculator() { + super(new CharacterCalculatorFunction(0x300) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseRunSpeed(); - } - }, new AbstractFunction(0x300) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.DEX.calculateBonus(c.getStats() - .getDexterity()); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return value + * BaseStats.DEX.calculateBonus(c.getStats() + .getDexterity()); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseWalkSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/actor/calculator/WalkSpeedBonusCalculator.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseWalkSpeedCalculator.java rename to src/main/java/com/l2jserver/model/world/actor/calculator/WalkSpeedBonusCalculator.java index 0dfbef68c..b4d25d8fe 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseWalkSpeedCalculator.java +++ b/src/main/java/com/l2jserver/model/world/actor/calculator/WalkSpeedBonusCalculator.java @@ -14,36 +14,32 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.actor.calculator; +import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the character base walk speed * *
- * ctx.result = c.getTemplate().getBaseWalkSpeed();
  * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
  * 
* * @author Rogiel */ -public class BaseWalkSpeedCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseWalkSpeedCalculator() { - super(new AbstractFunction(0x000) { +public class WalkSpeedBonusCalculator extends CharacterCalculator { + public WalkSpeedBonusCalculator() { + super(new CharacterCalculatorFunction(0x300) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseWalkSpeed(); - } - }, new AbstractFunction(0x300) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.DEX.calculateBonus(c.getStats() - .getDexterity()); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return value + * BaseStats.DEX.calculateBonus(c.getStats() + .getDexterity()); } }); } diff --git a/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java b/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java index cce3ab7ed..0373bbb19 100644 --- a/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java +++ b/src/main/java/com/l2jserver/model/world/actor/stat/ActorStats.java @@ -16,10 +16,339 @@ */ 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.AttackAccuracyBonusCalculator; +import com.l2jserver.model.world.actor.calculator.AttackEvasionBonusCalculator; +import com.l2jserver.model.world.actor.calculator.MagicalAttackBonusCalculator; +import com.l2jserver.model.world.actor.calculator.MagicalAttackSpeedBonusCalculator; +import com.l2jserver.model.world.actor.calculator.MagicalCriticalRateBonusCalculator; +import com.l2jserver.model.world.actor.calculator.MagicalDefenseBonusCalculator; +import com.l2jserver.model.world.actor.calculator.MaximumHPBonusCalculator; +import com.l2jserver.model.world.actor.calculator.MaximumMPBonusCalculator; +import com.l2jserver.model.world.actor.calculator.PhysicalAttackBonusCalculator; +import com.l2jserver.model.world.actor.calculator.PhysicalAttackSpeedBonusCalculator; +import com.l2jserver.model.world.actor.calculator.PhysicalCriticalRateBonusCalculator; +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.Calculator; + /** * @author Rogiel - * + * */ -public class ActorStats { +public abstract class ActorStats { + // bonuses + /** + * The calculator for base maximum HP + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator HP_BONUS_CALCULATOR = new MaximumHPBonusCalculator(); + /** + * The calculator for base maximum HP + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator MP_BONUS_CALCULATOR = new MaximumMPBonusCalculator(); + /** + * The calculator for run speed bonus + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator RUN_SPEED_BONUS_CALCULATOR = new RunSpeedBonusCalculator(); + /** + * The calculator for walk speed bonus + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator WALK_SPEED_BONUS_CALCULATOR = new WalkSpeedBonusCalculator(); + /** + * The calculator base physical attack + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator PHYSICAL_ATTACK_BONUS_CALCULATOR = new PhysicalAttackBonusCalculator(); + /** + * The calculator base physical attack speed + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator PHYSICAL_ATTACK_SPEED_BONUS_CALCULATOR = new PhysicalAttackSpeedBonusCalculator(); + /** + * The calculator base physical attack critical rate + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator PHYSICAL_CRITICAL_RATE_BONUS_CALCULATOR = new PhysicalCriticalRateBonusCalculator(); + /** + * The calculator base physical defense + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator PHYSICAL_DEFENSE_BONUS_CALCULATOR = new PhysicalDefenseBonusCalculator(); + + /** + * The calculator base magical attack + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator MAGICAL_ATTACK_BONUS_CALCULATOR = new MagicalAttackBonusCalculator(); + /** + * The calculator base magical attack speed + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator MAGICAL_ATTACK_SPEED_BONUS_CALCULATOR = new MagicalAttackSpeedBonusCalculator(); + /** + * The calculator base magical attack critical rate + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator MAGICAL_CRITICAL_RATE_BONUS_CALCULATOR = new MagicalCriticalRateBonusCalculator(); + /** + * The calculator base magical defense + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator MAGICAL_DEFENSE_BONUS_CALCULATOR = new MagicalDefenseBonusCalculator(); + + /** + * The calculator base attack accuracy + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator ATTACK_ACCURACY_BONUS_CALCULATOR = new AttackAccuracyBonusCalculator(); + /** + * The calculator base evasion + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final ActorCalculator ATTACK_EVASION_BONUS_CALCULATOR = new AttackEvasionBonusCalculator(); + + /** + * The list of calculators for this character + *

+ * 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 Calculator[] calculators = new Calculator[StatType + .values().length]; + + public ActorStats() { + for (int i = 0; i < calculators.length; i++) { + calculators[i] = new Calculator(); + } + + // 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); + } + + /** + * @return the calculated maximum HP + */ + public int getMaxHP() { + return (int) calc(StatType.MAX_HP); + } + + /** + * @return the calculated maximum MP + */ + public int getMaxMP() { + return (int) calc(StatType.MAX_MP); + } + + /** + * @return the calculated intelligence + */ + public int getIntelligence() { + return (int) calc(StatType.STAT_INT); + } + + /** + * @return the calculated strength + */ + public int getStrength() { + return (int) calc(StatType.STAT_STR); + } + + /** + * @return the calculated concentration + */ + public int getConcentration() { + return (int) calc(StatType.STAT_CON); + } + + /** + * @return the calculated mentality + */ + public int getMentality() { + return (int) calc(StatType.STAT_MEN); + } + + /** + * @return the calculated dexterity + */ + public int getDexterity() { + return (int) calc(StatType.STAT_DEX); + } + + /** + * @return the calculated witness + */ + public int getWitness() { + return (int) calc(StatType.STAT_WIT); + } + + /** + * @return the calculated run speed + */ + public int getRunSpeed() { + return (int) calc(StatType.RUN_SPEED); + } + + /** + * @return the calculated walk speed + */ + public int getWalkSpeed() { + return (int) calc(StatType.WALK_SPEED); + } + + /** + * @return the calculated physical attack + */ + public int getPhysicalAttack() { + return (int) calc(StatType.POWER_ATTACK); + } + + /** + * @return the calculated physical attack speed + */ + public int getPhysicalAttackSpeed() { + return (int) calc(StatType.POWER_ATTACK_SPEED); + } + + /** + * @return the calculated physical attack critical rate + */ + public int getPhysicalCriticalRate() { + return (int) calc(StatType.CRITICAL_RATE); + } + + /** + * @return the calculated physical defense + */ + public int getPhysicalDefense() { + return (int) calc(StatType.POWER_DEFENSE); + } + + /** + * @return the calculated magical attack + */ + public int getMagicalAttack() { + return (int) calc(StatType.MAGIC_ATTACK); + } + + /** + * @return the calculated magical attack speed + */ + public int getMagicalAttackSpeed() { + return (int) calc(StatType.MAGIC_ATTACK_SPEED); + } + + /** + * @return the calculated magical attack critical rate + */ + public int getMagicalCriticalRate() { + return (int) calc(StatType.MCRITICAL_RATE); + } + + /** + * @return the calculated magical defense + */ + public int getMagicalDefense() { + return (int) calc(StatType.MAGIC_DEFENSE); + } + + /** + * @return the calculated accuracy + */ + public int getAccuracy() { + return (int) calc(StatType.ACCURACY_COMBAT); + } + + /** + * @return the calculated evasion rate + */ + public int getEvasionRate() { + 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 type + */ + protected Calculator getCalculator(StatType type) { + return calculators[type.ordinal()]; + } + + /** + * Does the calculation of an given {@link StatType} + * + * @param type + * the type + * @return the value calculated + */ + protected double calc(StatType type) { + final T ctx = createContext(); + return getCalculator(type).calculate(ctx); + } + + protected abstract T createContext(); } diff --git a/src/main/java/com/l2jserver/model/world/actor/stat/StatType.java b/src/main/java/com/l2jserver/model/world/actor/stat/StatType.java new file mode 100644 index 000000000..9d63cde72 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/stat/StatType.java @@ -0,0 +1,118 @@ +package com.l2jserver.model.world.actor.stat; + +/** + * Attribute types for weapons + * + * @author Rogiel + */ +public enum StatType { + MAX_HP, MAX_MP, MAX_CP, REGENERATE_HP_RATE, REGENERATE_CP_RATE, REGENERATE_MP_RATE, RECHARGE_MP_RATE, HEAL_EFFECTIVNESS, HEAL_PROFICIENCY, HEAL_STATIC_BONUS, + + // Atk & Def + POWER_DEFENSE, MAGIC_DEFENSE, POWER_ATTACK, MAGIC_ATTACK, PHYSICAL_SKILL_POWER, POWER_ATTACK_SPEED, MAGIC_ATTACK_SPEED, // how + // fast + // a + // spell + // is + // casted + MAGIC_REUSE_RATE, // how fast spells becomes ready to reuse + SHIELD_DEFENCE, CRITICAL_DAMAGE, CRITICAL_DAMAGE_ADD, // this is another + // type for + // special + // critical + // damage mods - + // vicious + // stance, crit + // power and + // crit damage + // SA + // it was totally bad since now... + MAGIC_CRIT_DMG, + + PVP_PHYSICAL_DMG, PVP_MAGICAL_DMG, PVP_PHYS_SKILL_DMG, + + PVP_PHYSICAL_DEF, PVP_MAGICAL_DEF, PVP_PHYS_SKILL_DEF, + + PVE_PHYSICAL_DMG, PVE_PHYS_SKILL_DMG, PVE_BOW_DMG, PVE_BOW_SKILL_DMG, PVE_MAGICAL_DMG, + + // Atk & Def rates + EVASION_RATE, P_SKILL_EVASION, CRIT_DAMAGE_EVASION, SHIELD_RATE, CRITICAL_RATE, BLOW_RATE, LETHAL_RATE, MCRITICAL_RATE, EXPSP_RATE, ATTACK_CANCEL, + + // Accuracy and range + ACCURACY_COMBAT, POWER_ATTACK_RANGE, MAGIC_ATTACK_RANGE, POWER_ATTACK_ANGLE, ATTACK_COUNT_MAX, + // Run speed, + // walk & escape speed are calculated proportionally, + // magic speed is a buff + RUN_SPEED, WALK_SPEED, + + // + // Player-only stats + // + STAT_STR, STAT_CON, STAT_DEX, STAT_INT, STAT_WIT, STAT_MEN, + + // + // Special stats, share one slot in Calculator + // + + // stats of various abilities + BREATH, FALL, LIMIT_HP, // non-displayed hp limit + // + AGGRESSION, // locks a mob on tank caster + BLEED, // by daggers, like poison + POISON, // by magic, hp dmg over time + STUN, // disable move/ATTACK for a period of time + ROOT, // disable movement, but not ATTACK + MOVEMENT, // slowdown movement, debuff + CONFUSION, // mob changes target, opposite to aggression/hate + SLEEP, // sleep until attacked + VALAKAS, VALAKAS_RES, + // + AGGRESSION_VULN, BLEED_VULN, POISON_VULN, STUN_VULN, PARALYZE_VULN, ROOT_VULN, SLEEP_VULN, CONFUSION_VULN, MOVEMENT_VULN, FIRE_RES, WIND_RES, WATER_RES, EARTH_RES, HOLY_RES, DARK_RES, + // Skills Power + FIRE_POWER, WATER_POWER, WIND_POWER, EARTH_POWER, HOLY_POWER, DARK_POWER, CANCEL_VULN, // Resistance + // for + // cancel + // type + // skills + DERANGEMENT_VULN, DEBUFF_VULN, BUFF_VULN, CRIT_VULN, // Resistence to + // Crit DMG in + // percent. + CRIT_ADD_VULN, // Resistence to Crit DMG in value . + MAGIC_DAMAGE_VULN, MAGIC_SUCCESS_RES, MAGIC_FAILURE_RATE, + + AGGRESSION_PROF, BLEED_PROF, POISON_PROF, STUN_PROF, PARALYZE_PROF, ROOT_PROF, SLEEP_PROF, CONFUSION_PROF, PROF, CANCEL_PROF, DERANGEMENT_PROF, DEBUFF_PROF, CRIT_PROF, + + NONE_WPN_VULN, // Shields!!! + SWORD_WPN_VULN, BLUNT_WPN_VULN, DAGGER_WPN_VULN, BOW_WPN_VULN, CROSSBOW_WPN_VULN, POLE_WPN_VULN, ETC_WPN_VULN, FIST_WPN_VULN, DUAL_WPN_VULN, DUALFIST_WPN_VULN, BIGSWORD_WPN_VULN, BIGBLUNT_WPN_VULN, DUALDAGGER_WPN_VULN, RAPIER_WPN_VULN, ANCIENT_WPN_VULN, PET_WPN_VULN, + + REFLECT_DAMAGE_PERCENT, REFLECT_SKILL_MAGIC, REFLECT_SKILL_PHYSIC, VENGEANCE_SKILL_MAGIC_DAMAGE, VENGEANCE_SKILL_PHYSICAL_DAMAGE, ABSORB_DAMAGE_PERCENT, TRANSFER_DAMAGE_PERCENT, ABSORB_MANA_DAMAGE_PERCENT, + + MAX_LOAD, WEIGHT_LIMIT, + + PATK_PLANTS, PATK_INSECTS, PATK_ANIMALS, PATK_MONSTERS, PATK_DRAGONS, PATK_GIANTS, PATK_MCREATURES, + + PDEF_PLANTS, PDEF_INSECTS, PDEF_ANIMALS, PDEF_MONSTERS, PDEF_DRAGONS, PDEF_GIANTS, PDEF_MCREATURES, + + ATK_REUSE, P_REUSE, + + // ExSkill :) + INV_LIM, WH_LIM, FREIGHT_LIM, P_SELL_LIM, P_BUY_LIM, REC_D_LIM, REC_C_LIM, + + // C4 Stats + PHYSICAL_MP_CONSUME_RATE, MAGICAL_MP_CONSUME_RATE, DANCE_MP_CONSUME_RATE, BOW_MP_CONSUME_RATE, HP_CONSUME_RATE, MP_CONSUME, SOULSHOT_COUNT, + + // T1 stats + transformId, TALISMAN_SLOTS, CLOAK_SLOT, + + // Shield Stats + SHIELD_DEFENCE_ANGLE, + + // Skill mastery + SKILL_MASTERY, + + // vitality + VITALITY_CONSUME_RATE; + + // PHYSICAL_ATTACK, MAGICAL_ATTACK, CRITICAL_RATE, + // PHYSICAL_ATTACK_SPEED; +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/model/world/actor/stat/Stats.java b/src/main/java/com/l2jserver/model/world/actor/stat/Stats.java deleted file mode 100644 index 3ff0b4560..000000000 --- a/src/main/java/com/l2jserver/model/world/actor/stat/Stats.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.l2jserver.model.world.actor.stat; - -import java.util.List; -import java.util.Map; - -import com.l2jserver.model.world.Actor; -import com.l2jserver.util.calculator.Calculator; -import com.l2jserver.util.calculator.DivisionFunction; -import com.l2jserver.util.calculator.Function; -import com.l2jserver.util.calculator.MultiplicationFunction; -import com.l2jserver.util.calculator.SetFunction; -import com.l2jserver.util.calculator.SubtractFunction; -import com.l2jserver.util.calculator.SumFunction; -import com.l2jserver.util.factory.CollectionFactory; - -/** - * This class handles the stats an can add operations to the calculator - * - * @author Rogiel - */ -public class Stats { - /** - * Attribute types for weapons - * - * @author Rogiel - */ - public enum StatType { - MAX_HP, MAX_MP, MAX_CP, REGENERATE_HP_RATE, REGENERATE_CP_RATE, REGENERATE_MP_RATE, RECHARGE_MP_RATE, HEAL_EFFECTIVNESS, HEAL_PROFICIENCY, HEAL_STATIC_BONUS, - - // Atk & Def - POWER_DEFENSE, MAGIC_DEFENSE, POWER_ATTACK, MAGIC_ATTACK, PHYSICAL_SKILL_POWER, POWER_ATTACK_SPEED, MAGIC_ATTACK_SPEED, // how - // fast - // a - // spell - // is - // casted - MAGIC_REUSE_RATE, // how fast spells becomes ready to reuse - SHIELD_DEFENCE, CRITICAL_DAMAGE, CRITICAL_DAMAGE_ADD, // this is another - // type for - // special - // critical - // damage mods - - // vicious - // stance, crit - // power and - // crit damage - // SA - // it was totally bad since now... - MAGIC_CRIT_DMG, - - PVP_PHYSICAL_DMG, PVP_MAGICAL_DMG, PVP_PHYS_SKILL_DMG, - - PVP_PHYSICAL_DEF, PVP_MAGICAL_DEF, PVP_PHYS_SKILL_DEF, - - PVE_PHYSICAL_DMG, PVE_PHYS_SKILL_DMG, PVE_BOW_DMG, PVE_BOW_SKILL_DMG, PVE_MAGICAL_DMG, - - // Atk & Def rates - EVASION_RATE, P_SKILL_EVASION, CRIT_DAMAGE_EVASION, SHIELD_RATE, CRITICAL_RATE, BLOW_RATE, LETHAL_RATE, MCRITICAL_RATE, EXPSP_RATE, ATTACK_CANCEL, - - // Accuracy and range - ACCURACY_COMBAT, POWER_ATTACK_RANGE, MAGIC_ATTACK_RANGE, POWER_ATTACK_ANGLE, ATTACK_COUNT_MAX, - // Run speed, - // walk & escape speed are calculated proportionally, - // magic speed is a buff - RUN_SPEED, WALK_SPEED, - - // - // Player-only stats - // - STAT_STR, STAT_CON, STAT_DEX, STAT_INT, STAT_WIT, STAT_MEN, - - // - // Special stats, share one slot in Calculator - // - - // stats of various abilities - BREATH, FALL, LIMIT_HP, // non-displayed hp limit - // - AGGRESSION, // locks a mob on tank caster - BLEED, // by daggers, like poison - POISON, // by magic, hp dmg over time - STUN, // disable move/ATTACK for a period of time - ROOT, // disable movement, but not ATTACK - MOVEMENT, // slowdown movement, debuff - CONFUSION, // mob changes target, opposite to aggression/hate - SLEEP, // sleep until attacked - VALAKAS, VALAKAS_RES, - // - AGGRESSION_VULN, BLEED_VULN, POISON_VULN, STUN_VULN, PARALYZE_VULN, ROOT_VULN, SLEEP_VULN, CONFUSION_VULN, MOVEMENT_VULN, FIRE_RES, WIND_RES, WATER_RES, EARTH_RES, HOLY_RES, DARK_RES, - // Skills Power - FIRE_POWER, WATER_POWER, WIND_POWER, EARTH_POWER, HOLY_POWER, DARK_POWER, CANCEL_VULN, // Resistance - // for - // cancel - // type - // skills - DERANGEMENT_VULN, DEBUFF_VULN, BUFF_VULN, CRIT_VULN, // Resistence to - // Crit DMG in - // percent. - CRIT_ADD_VULN, // Resistence to Crit DMG in value . - MAGIC_DAMAGE_VULN, MAGIC_SUCCESS_RES, MAGIC_FAILURE_RATE, - - AGGRESSION_PROF, BLEED_PROF, POISON_PROF, STUN_PROF, PARALYZE_PROF, ROOT_PROF, SLEEP_PROF, CONFUSION_PROF, PROF, CANCEL_PROF, DERANGEMENT_PROF, DEBUFF_PROF, CRIT_PROF, - - NONE_WPN_VULN, // Shields!!! - SWORD_WPN_VULN, BLUNT_WPN_VULN, DAGGER_WPN_VULN, BOW_WPN_VULN, CROSSBOW_WPN_VULN, POLE_WPN_VULN, ETC_WPN_VULN, FIST_WPN_VULN, DUAL_WPN_VULN, DUALFIST_WPN_VULN, BIGSWORD_WPN_VULN, BIGBLUNT_WPN_VULN, DUALDAGGER_WPN_VULN, RAPIER_WPN_VULN, ANCIENT_WPN_VULN, PET_WPN_VULN, - - REFLECT_DAMAGE_PERCENT, REFLECT_SKILL_MAGIC, REFLECT_SKILL_PHYSIC, VENGEANCE_SKILL_MAGIC_DAMAGE, VENGEANCE_SKILL_PHYSICAL_DAMAGE, ABSORB_DAMAGE_PERCENT, TRANSFER_DAMAGE_PERCENT, ABSORB_MANA_DAMAGE_PERCENT, - - MAX_LOAD, WEIGHT_LIMIT, - - PATK_PLANTS, PATK_INSECTS, PATK_ANIMALS, PATK_MONSTERS, PATK_DRAGONS, PATK_GIANTS, PATK_MCREATURES, - - PDEF_PLANTS, PDEF_INSECTS, PDEF_ANIMALS, PDEF_MONSTERS, PDEF_DRAGONS, PDEF_GIANTS, PDEF_MCREATURES, - - ATK_REUSE, P_REUSE, - - // ExSkill :) - INV_LIM, WH_LIM, FREIGHT_LIM, P_SELL_LIM, P_BUY_LIM, REC_D_LIM, REC_C_LIM, - - // C4 Stats - PHYSICAL_MP_CONSUME_RATE, MAGICAL_MP_CONSUME_RATE, DANCE_MP_CONSUME_RATE, BOW_MP_CONSUME_RATE, HP_CONSUME_RATE, MP_CONSUME, SOULSHOT_COUNT, - - // T1 stats - transformId, TALISMAN_SLOTS, CLOAK_SLOT, - - // Shield Stats - SHIELD_DEFENCE_ANGLE, - - // Skill mastery - SKILL_MASTERY, - - // vitality - VITALITY_CONSUME_RATE; - - // PHYSICAL_ATTACK, MAGICAL_ATTACK, CRITICAL_RATE, - // PHYSICAL_ATTACK_SPEED; - } - - private final Map>> operations = CollectionFactory - .newMap(); - - /** - * Sets the result of an calculator - * - * @param type - * the attribute type - * @param order - * the calculation order - * @param value - * the value to set - */ - public void set(Stats.StatType type, int order, double value) { - func(type, new SetFunction(order, value)); - } - - /** - * Adds value to the result of an calculator - * - * @param type - * the attribute type - * @param order - * the calculation order - * @param value - * the value to be summed - */ - public void add(Stats.StatType type, int order, double value) { - func(type, new SumFunction(order, value)); - } - - /** - * Subtracts value from the result of an calculator - * - * @param type - * the attribute type - * @param order - * the calculation order - * @param value - * the value to be subtracted - */ - public void sub(Stats.StatType type, int order, double value) { - func(type, new SubtractFunction(order, value)); - } - - /** - * Multiply value the result of an calculator - * - * @param type - * the attribute type - * @param order - * the calculation order - * @param value - * the value to be multiplied - */ - public void mult(Stats.StatType type, int order, double value) { - func(type, new MultiplicationFunction(order, value)); - } - - /** - * Divides by value the result of an calculator - * - * @param type - * the attribute type - * @param order - * the calculation order - * @param value - * the value to be divided by - */ - public void div(Stats.StatType type, int order, double value) { - func(type, new DivisionFunction(order, value)); - } - - /** - * Performs an enchant operation. Note that this is not implemented yet! - * - * @param type - * the attribute type - * @param order - * the calculation order - * @param value - * TODO - */ - public void enchant(Stats.StatType type, int order, double value) { - // TODO enchant operation for weapon - } - - public void func(StatType type, Function function) { - getMap(type).add(function); - } - - /** - * Returns the Order-Operation map for type - * - * @param type - * the type - * @return the order-operation map - */ - private List> getMap(Stats.StatType type) { - List> list = operations.get(type); - if (list == null) { - list = CollectionFactory.newList(); - operations.put(type, list); - } - return list; - } - - /** - * Creates the calculator object for this weapon - * - * @param type - * the type - * @param calculator - * the calculator - */ - public void calculator(Stats.StatType type, Calculator calculator) { - final List> operations = this.operations.get(type); - if (operations == null || operations.size() == 0) - return; - for (final Function func : operations) { - calculator.add(func); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/model/world/character/CharacterStats.java b/src/main/java/com/l2jserver/model/world/character/CharacterStats.java index 9b1e8c18d..c5b64a6ef 100644 --- a/src/main/java/com/l2jserver/model/world/character/CharacterStats.java +++ b/src/main/java/com/l2jserver/model/world/character/CharacterStats.java @@ -18,30 +18,34 @@ package com.l2jserver.model.world.character; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.actor.stat.ActorStats; -import com.l2jserver.model.world.actor.stat.Stats.StatType; -import com.l2jserver.model.world.character.calculator.BaseAttackAccuracyCalculator; -import com.l2jserver.model.world.character.calculator.BaseAttackEvasionCalculator; -import com.l2jserver.model.world.character.calculator.BaseCPCalculator; -import com.l2jserver.model.world.character.calculator.BaseConcentrationCalculator; -import com.l2jserver.model.world.character.calculator.BaseDexterityCalculator; -import com.l2jserver.model.world.character.calculator.BaseHPCalculator; -import com.l2jserver.model.world.character.calculator.BaseIntelligenceCalculator; -import com.l2jserver.model.world.character.calculator.BaseMPCalculator; -import com.l2jserver.model.world.character.calculator.BaseMagicalAttackCalculator; -import com.l2jserver.model.world.character.calculator.BaseMagicalAttackSpeedCalculator; -import com.l2jserver.model.world.character.calculator.BaseMagicalCriticalRateCalculator; -import com.l2jserver.model.world.character.calculator.BaseMagicalDefenseCalculator; -import com.l2jserver.model.world.character.calculator.BaseMentalityCalculator; -import com.l2jserver.model.world.character.calculator.BasePhysicalAttackCalculator; -import com.l2jserver.model.world.character.calculator.BasePhysicalAttackSpeedCalculator; -import com.l2jserver.model.world.character.calculator.BasePhysicalCriticalRateCalculator; -import com.l2jserver.model.world.character.calculator.BasePhysicalDefenseCalculator; -import com.l2jserver.model.world.character.calculator.BaseRunSpeedCalculator; -import com.l2jserver.model.world.character.calculator.BaseStrengthCalculator; -import com.l2jserver.model.world.character.calculator.BaseWalkSpeedCalculator; -import com.l2jserver.model.world.character.calculator.BaseWitnessCalculator; +import com.l2jserver.model.world.actor.stat.StatType; import com.l2jserver.model.world.character.calculator.CharacterCalculator; import com.l2jserver.model.world.character.calculator.CharacterCalculatorContext; +import com.l2jserver.model.world.character.calculator.MaximumCPAddCalculator; +import com.l2jserver.model.world.character.calculator.MaximumCPBonusCalculator; +import com.l2jserver.model.world.character.calculator.MaximumHPAddCalculator; +import com.l2jserver.model.world.character.calculator.MaximumMPAddCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseAttackAccuracyCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseAttackEvasionCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseCPCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseConcentrationCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseDexterityCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseHPCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseIntelligenceCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseMPCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseMagicalAttackCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseMagicalAttackSpeedCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseMagicalCriticalRateCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseMagicalDefenseCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseMentalityCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBasePhysicalAttackCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBasePhysicalAttackSpeedCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBasePhysicalCriticalRateCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBasePhysicalDefenseCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseRunSpeedCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseStrengthCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseWalkSpeedCalculator; +import com.l2jserver.model.world.character.calculator.base.CharacterBaseWitnessCalculator; import com.l2jserver.util.calculator.Calculator; /** @@ -61,28 +65,29 @@ import com.l2jserver.util.calculator.Calculator; * * @author Rogiel */ -public class CharacterStats extends ActorStats { - /** - * The calculator for base maximum HP - *

- * This calculator does not store any state and thus is safe to be - * shared. - */ - private static final CharacterCalculator BASE_HP_CALCULATOR = new BaseHPCalculator(); +public class CharacterStats extends ActorStats { + // base calculators /** * The calculator for base maximum MP *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_MP_CALCULATOR = new BaseMPCalculator(); + private static final CharacterCalculator BASE_HP_CALCULATOR = new CharacterBaseHPCalculator(); + /** + * The calculator for base maximum MP + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final CharacterCalculator BASE_MP_CALCULATOR = new CharacterBaseMPCalculator(); /** * The calculator for base maximum CP *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_CP_CALCULATOR = new BaseCPCalculator(); + private static final CharacterCalculator BASE_CP_CALCULATOR = new CharacterBaseCPCalculator(); /** * The calculator for base intelligence @@ -90,42 +95,42 @@ public class CharacterStats extends ActorStats { * This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_INT_CALCULATOR = new BaseIntelligenceCalculator(); + private static final CharacterCalculator BASE_INT_CALCULATOR = new CharacterBaseIntelligenceCalculator(); /** * The calculator for base strength *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_STR_CALCULATOR = new BaseStrengthCalculator(); + private static final CharacterCalculator BASE_STR_CALCULATOR = new CharacterBaseStrengthCalculator(); /** * The calculator for base concentration *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_CON_CALCULATOR = new BaseConcentrationCalculator(); + private static final CharacterCalculator BASE_CON_CALCULATOR = new CharacterBaseConcentrationCalculator(); /** * The calculator for base mentality *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_MEN_CALCULATOR = new BaseMentalityCalculator(); + private static final CharacterCalculator BASE_MEN_CALCULATOR = new CharacterBaseMentalityCalculator(); /** * The calculator for base dexterity *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_DEX_CALCULATOR = new BaseDexterityCalculator(); + private static final CharacterCalculator BASE_DEX_CALCULATOR = new CharacterBaseDexterityCalculator(); /** * The calculator for base witness *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_WIT_CALCULATOR = new BaseWitnessCalculator(); + private static final CharacterCalculator BASE_WIT_CALCULATOR = new CharacterBaseWitnessCalculator(); /** * The calculator for base run speed @@ -133,14 +138,14 @@ public class CharacterStats extends ActorStats { * This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_RUN_SPEED_CALCULATOR = new BaseRunSpeedCalculator(); + private static final CharacterCalculator BASE_RUN_SPEED_CALCULATOR = new CharacterBaseRunSpeedCalculator(); /** * The calculator for base walk speed *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_WALK_SPEED_CALCULATOR = new BaseWalkSpeedCalculator(); + private static final CharacterCalculator BASE_WALK_SPEED_CALCULATOR = new CharacterBaseWalkSpeedCalculator(); /** * The calculator base physical attack @@ -148,28 +153,28 @@ public class CharacterStats extends ActorStats { * This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_PHYSICAL_ATTACK_CALCULATOR = new BasePhysicalAttackCalculator(); + private static final CharacterCalculator BASE_PHYSICAL_ATTACK_CALCULATOR = new CharacterBasePhysicalAttackCalculator(); /** * The calculator base physical attack speed *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR = new BasePhysicalAttackSpeedCalculator(); + private static final CharacterCalculator BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR = new CharacterBasePhysicalAttackSpeedCalculator(); /** * The calculator base physical attack critical rate *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR = new BasePhysicalCriticalRateCalculator(); + private static final CharacterCalculator BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR = new CharacterBasePhysicalCriticalRateCalculator(); /** * The calculator base physical defense *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_PHYSICAL_DEFENSE_CALCULATOR = new BasePhysicalDefenseCalculator(); + private static final CharacterCalculator BASE_PHYSICAL_DEFENSE_CALCULATOR = new CharacterBasePhysicalDefenseCalculator(); /** * The calculator base magical attack @@ -177,28 +182,28 @@ public class CharacterStats extends ActorStats { * This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_MAGICAL_ATTACK_CALCULATOR = new BaseMagicalAttackCalculator(); + private static final CharacterCalculator BASE_MAGICAL_ATTACK_CALCULATOR = new CharacterBaseMagicalAttackCalculator(); /** * The calculator base magical attack speed *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_MAGICAL_ATTACK_SPEED_CALCULATOR = new BaseMagicalAttackSpeedCalculator(); + private static final CharacterCalculator BASE_MAGICAL_ATTACK_SPEED_CALCULATOR = new CharacterBaseMagicalAttackSpeedCalculator(); /** * The calculator base magical attack critical rate *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_MAGICAL_CRITICAL_RATE_CALCULATOR = new BaseMagicalCriticalRateCalculator(); + private static final CharacterCalculator BASE_MAGICAL_CRITICAL_RATE_CALCULATOR = new CharacterBaseMagicalCriticalRateCalculator(); /** * The calculator base magical defense *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new BaseMagicalDefenseCalculator(); + private static final CharacterCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new CharacterBaseMagicalDefenseCalculator(); /** * The calculator base attack accuracy @@ -206,31 +211,51 @@ public class CharacterStats extends ActorStats { * This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new BaseAttackAccuracyCalculator(); + private static final CharacterCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new CharacterBaseAttackAccuracyCalculator(); /** * The calculator base evasion *

* This calculator does not store any state and thus is safe to be * shared. */ - private static final CharacterCalculator BASE_ATTACK_EVASION_CALCULATOR = new BaseAttackEvasionCalculator(); + private static final CharacterCalculator BASE_ATTACK_EVASION_CALCULATOR = new CharacterBaseAttackEvasionCalculator(); + + // BONUS + /** + * The calculator for CP bonus + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final CharacterCalculator CP_BONUS_CALCULATOR = new MaximumCPBonusCalculator(); + + // ADD + /** + * The calculator for HP add + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final CharacterCalculator HP_ADD_CALCULATOR = new MaximumHPAddCalculator(); + /** + * The calculator for MP add + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final CharacterCalculator MP_ADD_CALCULATOR = new MaximumMPAddCalculator(); + /** + * The calculator for CP add + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final CharacterCalculator CP_ADD_CALCULATOR = new MaximumCPAddCalculator(); /** * The character */ private final L2Character character; - /** - * The list of calculators for this character - *

- * 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 Calculator[] calculators = new Calculator[StatType - .values().length]; /** * Creates a new {@link CharacterStats} and adds default calculators @@ -239,12 +264,10 @@ public class CharacterStats extends ActorStats { * the character */ public CharacterStats(L2Character character) { + super(); this.character = character; - for (int i = 0; i < calculators.length; i++) { - calculators[i] = new Calculator(); - } - // import default functions + // base add(StatType.MAX_HP, BASE_HP_CALCULATOR); add(StatType.MAX_MP, BASE_MP_CALCULATOR); add(StatType.MAX_CP, BASE_CP_CALCULATOR); @@ -272,23 +295,17 @@ public class CharacterStats extends ActorStats { 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 } - /** - * @return the calculated maximum HP - */ - public int getMaxHP() { - return (int) calc(StatType.MAX_HP); - } - - /** - * @return the calculated maximum MP - */ - public int getMaxMP() { - return (int) calc(StatType.MAX_MP); - } - /** * @return the calculated maximum CP */ @@ -296,132 +313,6 @@ public class CharacterStats extends ActorStats { return (int) calc(StatType.MAX_CP); } - /** - * @return the calculated intelligence - */ - public int getIntelligence() { - return (int) calc(StatType.STAT_INT); - } - - /** - * @return the calculated strength - */ - public int getStrength() { - return (int) calc(StatType.STAT_STR); - } - - /** - * @return the calculated concentration - */ - public int getConcentration() { - return (int) calc(StatType.STAT_CON); - } - - /** - * @return the calculated mentality - */ - public int getMentality() { - return (int) calc(StatType.STAT_MEN); - } - - /** - * @return the calculated dexterity - */ - public int getDexterity() { - return (int) calc(StatType.STAT_DEX); - } - - /** - * @return the calculated witness - */ - public int getWitness() { - return (int) calc(StatType.STAT_WIT); - } - - /** - * @return the calculated run speed - */ - public int getRunSpeed() { - return (int) calc(StatType.RUN_SPEED); - } - - /** - * @return the calculated walk speed - */ - public int getWalkSpeed() { - return (int) calc(StatType.WALK_SPEED); - } - - /** - * @return the calculated physical attack - */ - public int getPhysicalAttack() { - return (int) calc(StatType.POWER_ATTACK); - } - - /** - * @return the calculated physical attack speed - */ - public int getPhysicalAttackSpeed() { - return (int) calc(StatType.POWER_ATTACK_SPEED); - } - - /** - * @return the calculated physical attack critical rate - */ - public int getPhysicalCriticalRate() { - return (int) calc(StatType.CRITICAL_RATE); - } - - /** - * @return the calculated physical defense - */ - public int getPhysicalDefense() { - return (int) calc(StatType.POWER_DEFENSE); - } - - /** - * @return the calculated magical attack - */ - public int getMagicalAttack() { - return (int) calc(StatType.MAGIC_ATTACK); - } - - /** - * @return the calculated magical attack speed - */ - public int getMagicalAttackSpeed() { - return (int) calc(StatType.MAGIC_ATTACK_SPEED); - } - - /** - * @return the calculated magical attack critical rate - */ - public int getMagicalCriticalRate() { - return (int) calc(StatType.MCRITICAL_RATE); - } - - /** - * @return the calculated magical defense - */ - public int getMagicalDefense() { - return (int) calc(StatType.MAGIC_DEFENSE); - } - - /** - * @return the calculated accuracy - */ - public int getAccuracy() { - return (int) calc(StatType.ACCURACY_COMBAT); - } - - /** - * @return the calculated evasion rate - */ - public int getEvasionRate() { - return (int) calc(StatType.EVASION_RATE); - } - /** * @return the calculated maximum load */ @@ -429,34 +320,8 @@ public class CharacterStats extends ActorStats { return (int) calc(StatType.MAX_LOAD); } - public void add(StatType type, Calculator calculator) { - getCalculator(type).importFunctions(calculator); - } - - public void remove(StatType type, Calculator calculator) { - getCalculator(type).removeFunctions(calculator); - } - - /** - * @param the - * calculator {@link StatType} - * @return the calculator object associated with the given type - */ - protected Calculator getCalculator(StatType type) { - return calculators[type.ordinal()]; - } - - /** - * Does the calculation of an given {@link StatType} - * - * @param type - * the type - * @return the value calculated - */ - public double calc(StatType type) { - final CharacterCalculatorContext ctx = new CharacterCalculatorContext( - character); - getCalculator(type).calculate(character, ctx); - return ctx.result; + @Override + protected CharacterCalculatorContext createContext() { + return new CharacterCalculatorContext(character); } } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseCPCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/BaseCPCalculator.java deleted file mode 100644 index 8aba3fe01..000000000 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseCPCalculator.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -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.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; - -/** - * Calculates the character maximum CP - * - *

- * ctx.result = c.getTemplate().getBaseCP();
- * 
- * int lvl = c.getLevel() - template.getMinimumLevel();
- * double mod = template.getBaseCPModifier() * lvl;
- * double max = (template.getBaseCPAdd() + mod) * lvl;
- * double min = (template.getBaseCPAdd() * lvl) + mod;
- * ctx.result += (max + min) / 2;
- * 
- * ctx.result *= BaseStats.CON.calculateBonus(c.getStats().getConcentration());
- * 
- * - * @author Rogiel - */ -public class BaseCPCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseCPCalculator() { - super(new AbstractFunction(0x000) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseCP(); - } - }, new AbstractFunction(0x100) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final CharacterTemplate template = c.getTemplate(); - - int lvl = c.getLevel() - template.getMinimumLevel(); - double mod = template.getBaseCPModifier() * lvl; - double max = (template.getBaseCPAdd() + mod) * lvl; - double min = (template.getBaseCPAdd() * lvl) + mod; - - ctx.result += (max + min) / 2; - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.CON.calculateBonus(c.getStats() - .getConcentration()); - } - }); - } -} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseHPCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/BaseHPCalculator.java deleted file mode 100644 index bbe23e5f6..000000000 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseHPCalculator.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -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.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; - -/** - * Calculates the character maximum HP - * - *
- * ctx.result = c.getTemplate().getBaseHP();
- * 
- * int lvl = c.getLevel() - template.getMinimumLevel();
- * double mod = template.getBaseHP() * lvl;
- * double max = (template.getBaseHPAdd() + mod) * lvl;
- * double min = (template.getBaseHPAdd() * lvl) + mod;
- * ctx.result += (max + min) / 2;
- * 
- * ctx.result *= BaseStats.CON.calculateBonus(c.getStats().getConcentration());
- * 
- * - * @author Rogiel - */ -public class BaseHPCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseHPCalculator() { - super(new AbstractFunction(0x000) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseHP(); - } - }, new AbstractFunction(0x100) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final CharacterTemplate template = c.getTemplate(); - - int lvl = c.getLevel() - template.getMinimumLevel(); - double mod = template.getBaseHP() * lvl; - double max = (template.getBaseHPAdd() + mod) * lvl; - double min = (template.getBaseHPAdd() * lvl) + mod; - - ctx.result += (max + min) / 2; - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.CON.calculateBonus(c.getStats() - .getConcentration()); - } - }); - } -} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseHPRegenerationCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/BaseHPRegenerationCalculator.java deleted file mode 100644 index 7052d94d8..000000000 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseHPRegenerationCalculator.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -package com.l2jserver.model.world.character.calculator; - -import com.l2jserver.model.world.L2Character; -import com.l2jserver.model.world.L2Character.CharacterMoveType; -import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; - -/** - * Calculates the character base HP regeneration - * - *
- * TODO base hp regen
- * 
- * - * @author Rogiel - */ -public class BaseHPRegenerationCalculator extends CharacterCalculator { - /** - * Retail value is 100 - */ - public static final double HP_REGEN_MULTIPLIER = 100; - - @SuppressWarnings("unchecked") - public BaseHPRegenerationCalculator() { - super(new AbstractFunction(0x000) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - // TODO set base hp regen - ctx.result = 0; - - // initial value is changed here - ctx.result += (c.getLevel() > 10) ? ((c.getLevel() - 1) / 10.0) - : 0.5; - - // Add CON bonus - ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0) - * BaseStats.CON.calculateBonus(c.getStats() - .getConcentration()); - - if (ctx.result < 0) - ctx.result = 0; - - } - }, new AbstractFunction(Integer.MAX_VALUE) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - double hpRegenMultiplier = HP_REGEN_MULTIPLIER; - double hpRegenBonus = 0; - - // TODO SevenSigns Festival modifier - // if (SevenSignsFestival.getInstance().isFestivalInProgress() - // && player.isFestivalParticipant()) - // hpRegenMultiplier *= calcFestivalRegenModifier(player); - // else { - // double siegeModifier = calcSiegeRegenModifer(player); - // if (siegeModifier > 0) - // hpRegenMultiplier *= siegeModifier; - // } - - // TODO clan hall regen - // if (player.isInsideZone(L2Character.ZONE_CLANHALL) - // && player.getClan() != null - // && player.getClan().getHasHideout() > 0) { - // L2ClanHallZone zone = ZoneManager.getInstance().getZone( - // player, L2ClanHallZone.class); - // int posChIndex = zone == null ? -1 : zone.getClanHallId(); - // int clanHallIndex = player.getClan().getHasHideout(); - // if (clanHallIndex > 0 && clanHallIndex == posChIndex) { - // ClanHall clansHall = ClanHallManager.getInstance() - // .getClanHallById(clanHallIndex); - // if (clansHall != null) - // if (clansHall.getFunction(ClanHall.FUNC_RESTORE_HP) != null) - // hpRegenMultiplier *= 1 + (double) clansHall - // .getFunction(ClanHall.FUNC_RESTORE_HP) - // .getLvl() / 100; - // } - // } - - // TODO castle regen - // if (player.isInsideZone(L2Character.ZONE_CASTLE) - // && player.getClan() != null - // && player.getClan().getHasCastle() > 0) { - // L2CastleZone zone = ZoneManager.getInstance().getZone( - // player, L2CastleZone.class); - // int posCastleIndex = zone == null ? -1 : zone.getCastleId(); - // int castleIndex = player.getClan().getHasCastle(); - // if (castleIndex > 0 && castleIndex == posCastleIndex) { - // Castle castle = CastleManager.getInstance() - // .getCastleById(castleIndex); - // if (castle != null) - // if (castle.getFunction(Castle.FUNC_RESTORE_HP) != null) - // hpRegenMultiplier *= 1 + (double) castle - // .getFunction(Castle.FUNC_RESTORE_HP) - // .getLvl() / 100; - // } - // } - - // TODO fort regen - // if (player.isInsideZone(L2Character.ZONE_FORT) - // && player.getClan() != null - // && player.getClan().getHasFort() > 0) { - // L2FortZone zone = ZoneManager.getInstance().getZone(player, - // L2FortZone.class); - // int posFortIndex = zone == null ? -1 : zone.getFortId(); - // int fortIndex = player.getClan().getHasFort(); - // if (fortIndex > 0 && fortIndex == posFortIndex) { - // Fort fort = FortManager.getInstance().getFortById( - // fortIndex); - // if (fort != null) - // if (fort.getFunction(Fort.FUNC_RESTORE_HP) != null) - // hpRegenMultiplier *= 1 + (double) fort - // .getFunction(Fort.FUNC_RESTORE_HP) - // .getLvl() / 100; - // } - // } - - // TODO Mother Tree effect is calculated at last - // if (player.isInsideZone(L2Character.ZONE_MOTHERTREE)) { - // L2MotherTreeZone zone = ZoneManager.getInstance().getZone( - // player, L2MotherTreeZone.class); - // int hpBonus = zone == null ? 0 : zone.getHpRegenBonus(); - // hpRegenBonus += hpBonus; - // } - - // Calculate Movement bonus - // if (player.isSitting()) - // hpRegenMultiplier *= 1.5; // Sitting - // else - if (c.isIdle()) - hpRegenMultiplier *= 1.1; // Staying - else if (c.getMoveType() == CharacterMoveType.RUN) - hpRegenMultiplier *= 0.7; // Running - - ctx.result = ctx.result * hpRegenMultiplier + hpRegenBonus; - } - }); - } -} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMPCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/BaseMPCalculator.java deleted file mode 100644 index 61e105655..000000000 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMPCalculator.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -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.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; - -/** - * Calculates the character base MP - * - *
- * ctx.result = c.getTemplate().getBaseBaseMP();
- * 
- * int lvl = c.getLevel() - template.getMinimumLevel();
- * double mod = template.getBaseMPModifier() * lvl;
- * double max = (template.getBaseMPAdd() + mod) * lvl;
- * double min = (template.getBaseMPAdd() * lvl) + mod;
- * ctx.result += (max + min) / 2;
- * 
- * ctx.result *= BaseStats.MEN.calculateBonus(c.getStats().getMentality());
- * 
- * - * @author Rogiel - */ -public class BaseMPCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseMPCalculator() { - super(new AbstractFunction(0x000) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseBaseMP(); - } - }, new AbstractFunction(0x100) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final CharacterTemplate template = c.getTemplate(); - - int lvl = c.getLevel() - template.getMinimumLevel(); - double mod = template.getBaseMPModifier() * lvl; - double max = (template.getBaseMPAdd() + mod) * lvl; - double min = (template.getBaseMPAdd() * lvl) + mod; - - ctx.result += (max + min) / 2; - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result *= BaseStats.MEN.calculateBonus(c.getStats() - .getMentality()); - } - }); - } -} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalDefenseCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalDefenseCalculator.java deleted file mode 100644 index 5c4670efb..000000000 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalDefenseCalculator.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -package com.l2jserver.model.world.character.calculator; - -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEFT_EAR; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEFT_FINGER; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.NECK; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_EAR; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_FINGER; - -import com.l2jserver.model.world.L2Character; -import com.l2jserver.model.world.actor.stat.BaseStats; -import com.l2jserver.model.world.character.CharacterInventory; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; - -/** - * Calculates the character base magical 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;
- * ctx.result *= BaseStats.MEN.calculateBonus(c.getStats().getMentality())
- * 		* ((100.0 - 11 + c.getLevel()) / 100.0);
- * 
- * - * @author Rogiel - */ -public class BaseMagicalDefenseCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseMagicalDefenseCalculator() { - super(new AbstractFunction(0x000) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseMagicalDefense(); - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final CharacterInventory inv = c.getInventory(); - - if (inv.has(LEFT_FINGER)) - ctx.result -= 5; - if (inv.has(RIGHT_FINGER)) - ctx.result -= 5; - if (inv.has(LEFT_EAR)) - ctx.result -= 9; - if (inv.has(RIGHT_EAR)) - ctx.result -= 9; - if (inv.has(NECK)) - ctx.result -= 13; - - ctx.result *= BaseStats.MEN.calculateBonus(c.getStats() - .getMentality()) - * ((100.0 - 11 + c.getLevel()) / 100.0); - } - }); - } -} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalDefenseCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalDefenseCalculator.java deleted file mode 100644 index 246ce5ff8..000000000 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BasePhysicalDefenseCalculator.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -package com.l2jserver.model.world.character.calculator; - -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.CHEST; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.FEET; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.GLOVES; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.HEAD; -import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEGS; - -import com.l2jserver.model.world.Item; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.model.world.character.CharacterClass; -import com.l2jserver.model.world.character.CharacterClass.ClassType; -import com.l2jserver.model.world.character.CharacterInventory; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; - -/** - * Calculates the character base physical defense - * - *
- * ctx.result = c.getTemplate().getBasePhysicalDefense();
- * 
- * 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))
- * 	ctx.result -= hasMagePDef ? 8 : 18;
- * if (inv.has(GLOVES))
- * 	ctx.result -= 8;
- * if (inv.has(FEET))
- * 	ctx.result -= 7;
- * ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0);
- * 
- * - * @author Rogiel - */ -public class BasePhysicalDefenseCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BasePhysicalDefenseCalculator() { - super(new AbstractFunction(0x000) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBasePhysicalDefense(); - } - }, new AbstractFunction(0x200) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - final CharacterInventory inv = c.getInventory(); - - // orc mystics are a special case - boolean hasMagePDef = (c.getCharacterClass().type == ClassType.MYSTIC || c - .getCharacterClass() == CharacterClass.ORC_MYSTIC); - - if (inv.has(HEAD)) - ctx.result -= 12; - final Item chest = inv.getItem(CHEST); - if (chest != null) - ctx.result -= hasMagePDef ? 15 : 31; - if (inv.has(LEGS)) - // FIXME full armor also applies here - ctx.result -= hasMagePDef ? 8 : 18; - if (inv.has(GLOVES)) - ctx.result -= 8; - if (inv.has(FEET)) - ctx.result -= 7; - ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0); - } - }); - } -} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculator.java index 8d6220a5f..d08839dff 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculator.java +++ b/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculator.java @@ -16,17 +16,15 @@ */ package com.l2jserver.model.world.character.calculator; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.Calculator; -import com.l2jserver.util.calculator.Function; +import com.l2jserver.model.world.actor.calculator.ActorCalculator; /** * An calculator for character formulas. * * @author Rogiel */ -public class CharacterCalculator extends Calculator { - public CharacterCalculator(Function... functions) { +public class CharacterCalculator extends ActorCalculator { + public CharacterCalculator(CharacterCalculatorFunction... functions) { super(functions); } } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculatorFunction.java b/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculatorFunction.java new file mode 100644 index 000000000..60d16132a --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/CharacterCalculatorFunction.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.character.calculator; + +import com.l2jserver.model.template.ActorTemplate; +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; + +/** + * An calculator for character formulas. + * + * @author Rogiel + */ +public abstract class CharacterCalculatorFunction extends + ActorCalculatorFunction { + public CharacterCalculatorFunction(int order) { + super(order); + } + + @Override + protected final double calculate(Actor a, ActorTemplate actorTemplate, + double value) { + return calculate((L2Character) a, (CharacterTemplate) actorTemplate, + value); + } + + protected abstract double calculate(L2Character c, CharacterTemplate t, + double value); +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/MaximumCPAddCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumCPAddCalculator.java new file mode 100644 index 000000000..96f8b4603 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumCPAddCalculator.java @@ -0,0 +1,50 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.character.calculator; + +import com.l2jserver.model.template.CharacterTemplate; +import com.l2jserver.model.world.L2Character; + +/** + * Calculates the character base CP + * + *
+ * int lvl = c.getLevel() - template.getMinimumLevel();
+ * double mod = template.getBaseCPModifier() * lvl;
+ * double max = (template.getBaseCPAdd() + mod) * lvl;
+ * double min = (template.getBaseCPAdd() * lvl) + mod;
+ * ctx.result += (max + min) / 2;
+ * 
+ * + * @author Rogiel + */ +public class MaximumCPAddCalculator extends CharacterCalculator { + 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; + + return value + (max + min) / 2; + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/MaximumCPBonusCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumCPBonusCalculator.java new file mode 100644 index 000000000..ccb7a02dc --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumCPBonusCalculator.java @@ -0,0 +1,48 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base CP + * + *
+ * int lvl = c.getLevel() - template.getMinimumLevel();
+ * double mod = template.getBaseCPModifier() * lvl;
+ * double max = (template.getBaseCPAdd() + mod) * lvl;
+ * double min = (template.getBaseCPAdd() * lvl) + mod;
+ * ctx.result += (max + min) / 2;
+ * 
+ * + * @author Rogiel + */ +public class MaximumCPBonusCalculator extends CharacterCalculator { + public MaximumCPBonusCalculator() { + super(new CharacterCalculatorFunction(0x100) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return value + * BaseStats.CON.calculateBonus(c.getStats() + .getConcentration()); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/MaximumHPAddCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumHPAddCalculator.java new file mode 100644 index 000000000..5822bc35f --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumHPAddCalculator.java @@ -0,0 +1,50 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.character.calculator; + +import com.l2jserver.model.template.CharacterTemplate; +import com.l2jserver.model.world.L2Character; + +/** + * Calculates the character maximum HP + * + *
+ * int lvl = c.getLevel() - template.getMinimumLevel();
+ * double mod = template.getBaseHPModifier() * lvl;
+ * double max = (template.getBaseHPAdd() + mod) * lvl;
+ * double min = (template.getBaseHPAdd() * lvl) + mod;
+ * ctx.result += (max + min) / 2;
+ * 
+ * + * @author Rogiel + */ +public class MaximumHPAddCalculator extends CharacterCalculator { + 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; + + return value + (max + min) / 2; + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/MaximumMPAddCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumMPAddCalculator.java new file mode 100644 index 000000000..fc1b15f98 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/MaximumMPAddCalculator.java @@ -0,0 +1,50 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.character.calculator; + +import com.l2jserver.model.template.CharacterTemplate; +import com.l2jserver.model.world.L2Character; + +/** + * Calculates the character base MP + * + *
+ * int lvl = c.getLevel() - template.getMinimumLevel();
+ * double mod = template.getBaseMPModifier() * lvl;
+ * double max = (template.getBaseMPAdd() + mod) * lvl;
+ * double min = (template.getBaseMPAdd() * lvl) + mod;
+ * ctx.result += (max + min) / 2;
+ * 
+ * + * @author Rogiel + */ +public class MaximumMPAddCalculator extends CharacterCalculator { + 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; + + return value + (max + min) / 2; + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseAttackAccuracyCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseAttackAccuracyCalculator.java new file mode 100644 index 000000000..4a6cffe5c --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseAttackAccuracyCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base accuracy. + * + *
+ * ctx.result = c.getTemplate().getBaseAccuracy();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseAttackAccuracyCalculator extends CharacterCalculator { + public CharacterBaseAttackAccuracyCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseAccuracy(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseAttackEvasionCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseAttackEvasionCalculator.java new file mode 100644 index 000000000..f9b3eacb1 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseAttackEvasionCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character evasion + * + *
+ * ctx.result = c.getTemplate().getBaseEvasion();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseAttackEvasionCalculator extends CharacterCalculator { + public CharacterBaseAttackEvasionCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseEvasion(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseCPCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseCPCalculator.java new file mode 100644 index 000000000..8ba505a29 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseCPCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character maximum CP + * + *
+ * return c.getTemplate().getBaseCP();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseCPCalculator extends CharacterCalculator { + public CharacterBaseCPCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + public double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseCP(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseConcentrationCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseConcentrationCalculator.java similarity index 62% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseConcentrationCalculator.java rename to src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseConcentrationCalculator.java index cd95006c8..62da08952 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseConcentrationCalculator.java +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseConcentrationCalculator.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.character.calculator.base; +import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the character concentration @@ -29,13 +30,13 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseConcentrationCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseConcentrationCalculator() { - super(new AbstractFunction(0x000) { +public class CharacterBaseConcentrationCalculator extends CharacterCalculator { + public CharacterBaseConcentrationCalculator() { + super(new CharacterCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseConcentration(); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseConcentration(); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseDexterityCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseDexterityCalculator.java similarity index 62% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseDexterityCalculator.java rename to src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseDexterityCalculator.java index ae1c35e94..c1a1bf1fd 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseDexterityCalculator.java +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseDexterityCalculator.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.character.calculator.base; +import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the character base dexterity @@ -29,13 +30,13 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseDexterityCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseDexterityCalculator() { - super(new AbstractFunction(0x000) { +public class CharacterBaseDexterityCalculator extends CharacterCalculator { + public CharacterBaseDexterityCalculator() { + super(new CharacterCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseDexterity(); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseDexterity(); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseHPCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseHPCalculator.java new file mode 100644 index 000000000..73407c647 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseHPCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character maximum HP + * + *
+ * return c.getTemplate().getBaseHP();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseHPCalculator extends CharacterCalculator { + public CharacterBaseHPCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + public double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseHP(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseIntelligenceCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseIntelligenceCalculator.java similarity index 62% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseIntelligenceCalculator.java rename to src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseIntelligenceCalculator.java index b900f1b45..be58cbb32 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseIntelligenceCalculator.java +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseIntelligenceCalculator.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.character.calculator.base; +import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the character base intelligence @@ -29,13 +30,13 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseIntelligenceCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseIntelligenceCalculator() { - super(new AbstractFunction(0x000) { +public class CharacterBaseIntelligenceCalculator extends CharacterCalculator { + public CharacterBaseIntelligenceCalculator() { + super(new CharacterCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseIntelligence(); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseIntelligence(); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMPCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMPCalculator.java new file mode 100644 index 000000000..c68544d26 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMPCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character maximum HP + * + *
+ * return c.getTemplate().getBaseMP();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseMPCalculator extends CharacterCalculator { + public CharacterBaseMPCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + public double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseBaseMP(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalAttackCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalAttackCalculator.java new file mode 100644 index 000000000..a7ac57808 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalAttackCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base magical attack + * + *
+ * ctx.result *= (((100.0 - 11 + c.getLevel()) / 100.0) ˆ 2)
+ * 		* (BaseStats.INT.calculateBonus(c.getStats().getIntelligence()) ˆ 2);
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseMagicalAttackCalculator extends CharacterCalculator { + public CharacterBaseMagicalAttackCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseMagicalAttack(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalAttackSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalAttackSpeedCalculator.java new file mode 100644 index 000000000..1bc10bf72 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalAttackSpeedCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the base magical attack speed + * + *
+ * ctx.result = c.getTemplate().getBaseMagicalAttackSpeed();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseMagicalAttackSpeedCalculator extends CharacterCalculator { + public CharacterBaseMagicalAttackSpeedCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseMagicalAttackSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalCriticalRateCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalCriticalRateCalculator.java similarity index 55% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalCriticalRateCalculator.java rename to src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalCriticalRateCalculator.java index 2d418507e..9bdeaa203 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMagicalCriticalRateCalculator.java +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalCriticalRateCalculator.java @@ -14,12 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +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.actor.stat.BaseStats; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the base magical attack critical rate @@ -31,21 +31,14 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseMagicalCriticalRateCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseMagicalCriticalRateCalculator() { - super(new AbstractFunction(0x000) { +public class CharacterBaseMagicalCriticalRateCalculator extends + CharacterCalculator { + public CharacterBaseMagicalCriticalRateCalculator() { + super(new CharacterCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - // XXX is the same as physical???? - ctx.result = c.getTemplate().getBaseCritical(); - } - }, new AbstractFunction(0x300) { - @Override - public void calculate(L2Character c, CalculatorContext ctx) { - // TODO only apply if using a weapon - ctx.result *= BaseStats.WIT.calculateBonus(c.getStats() - .getWitness()); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseCritical(); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalDefenseCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalDefenseCalculator.java new file mode 100644 index 000000000..2b94ac8d5 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMagicalDefenseCalculator.java @@ -0,0 +1,54 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base magical 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;
+ * ctx.result *= BaseStats.MEN.calculateBonus(c.getStats().getMentality())
+ * 		* ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseMagicalDefenseCalculator extends CharacterCalculator { + public CharacterBaseMagicalDefenseCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseMagicalDefense(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMentalityCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMentalityCalculator.java similarity index 62% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseMentalityCalculator.java rename to src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMentalityCalculator.java index 2179ba8e0..1e04bd18b 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseMentalityCalculator.java +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseMentalityCalculator.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.character.calculator.base; +import com.l2jserver.model.template.CharacterTemplate; import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +import com.l2jserver.model.world.character.calculator.CharacterCalculator; +import com.l2jserver.model.world.character.calculator.CharacterCalculatorFunction; /** * Calculates the character base mentality @@ -29,13 +30,13 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseMentalityCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseMentalityCalculator() { - super(new AbstractFunction(0x000) { +public class CharacterBaseMentalityCalculator extends CharacterCalculator { + public CharacterBaseMentalityCalculator() { + super(new CharacterCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseMentality(); + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseMentality(); } }); } diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalAttackCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalAttackCalculator.java new file mode 100644 index 000000000..759b667e6 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalAttackCalculator.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base physical attack + * + *
+ * ctx.result = c.getTemplate().getBasePhysicalAttack();
+ * ctx.result *= BaseStats.STR.calculateBonus(c.getStats().getStrength())
+ * 		* ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class CharacterBasePhysicalAttackCalculator extends CharacterCalculator { + public CharacterBasePhysicalAttackCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBasePhysicalAttack(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalAttackSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalAttackSpeedCalculator.java new file mode 100644 index 000000000..1fc6b9eec --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalAttackSpeedCalculator.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base physical attack speed + * + *
+ * ctx.result = c.getTemplate().getBasePhysicalAttackSpeed();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * 
+ * + * @author Rogiel + */ +public class CharacterBasePhysicalAttackSpeedCalculator extends + CharacterCalculator { + public CharacterBasePhysicalAttackSpeedCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBasePhysicalAttackSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalCriticalRateCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalCriticalRateCalculator.java new file mode 100644 index 000000000..f7188dc23 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalCriticalRateCalculator.java @@ -0,0 +1,46 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base critical rate + * + *
+ * ctx.result = c.getTemplate().getBaseCritical();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * ctx.result *= 10;
+ * 
+ * + * @author Rogiel + */ +public class CharacterBasePhysicalCriticalRateCalculator extends + CharacterCalculator { + public CharacterBasePhysicalCriticalRateCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseCritical(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalDefenseCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalDefenseCalculator.java new file mode 100644 index 000000000..d5b58b3fe --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBasePhysicalDefenseCalculator.java @@ -0,0 +1,56 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base physical defense + * + *
+ * ctx.result = c.getTemplate().getBasePhysicalDefense();
+ * 
+ * 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))
+ * 	ctx.result -= hasMagePDef ? 8 : 18;
+ * if (inv.has(GLOVES))
+ * 	ctx.result -= 8;
+ * if (inv.has(FEET))
+ * 	ctx.result -= 7;
+ * ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class CharacterBasePhysicalDefenseCalculator extends CharacterCalculator { + public CharacterBasePhysicalDefenseCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBasePhysicalDefense(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseRunSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseRunSpeedCalculator.java new file mode 100644 index 000000000..ab0305276 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseRunSpeedCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base run speed + * + *
+ * ctx.result = c.getTemplate().getBaseRunSpeed();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseRunSpeedCalculator extends CharacterCalculator { + public CharacterBaseRunSpeedCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseRunSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseStrengthCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseStrengthCalculator.java new file mode 100644 index 000000000..c349b965a --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseStrengthCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base strength + * + *
+ * ctx.result = c.getTemplate().getBaseStrength();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseStrengthCalculator extends CharacterCalculator { + public CharacterBaseStrengthCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseStrength(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseWalkSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseWalkSpeedCalculator.java new file mode 100644 index 000000000..52efdf32d --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseWalkSpeedCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base walk speed + * + *
+ * ctx.result = c.getTemplate().getBaseWalkSpeed();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseWalkSpeedCalculator extends CharacterCalculator { + public CharacterBaseWalkSpeedCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseWalkSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseWitnessCalculator.java b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseWitnessCalculator.java new file mode 100644 index 000000000..509f81655 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/character/calculator/base/CharacterBaseWitnessCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base witness + * + *
+ * ctx.result = c.getTemplate().getBaseWitness();
+ * 
+ * + * @author Rogiel + */ +public class CharacterBaseWitnessCalculator extends CharacterCalculator { + public CharacterBaseWitnessCalculator() { + super(new CharacterCalculatorFunction(0x000) { + @Override + protected double calculate(L2Character c, CharacterTemplate t, + double value) { + return t.getBaseWitness(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/NPCStats.java b/src/main/java/com/l2jserver/model/world/npc/NPCStats.java new file mode 100644 index 000000000..5c08d2e28 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/NPCStats.java @@ -0,0 +1,256 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.npc; + +import com.l2jserver.model.world.NPC; +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.base.NPCBaseAttackAccuracyCalculator; +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; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseHPCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseIntelligenceCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseMPCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseMagicalAttackCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseMagicalAttackSpeedCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseMagicalCriticalRateCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseMagicalDefenseCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseMentalityCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBasePhysicalAttackCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBasePhysicalAttackSpeedCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBasePhysicalCriticalRateCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBasePhysicalDefenseCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseRunSpeedCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseStrengthCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseWalkSpeedCalculator; +import com.l2jserver.model.world.npc.calculator.base.NPCBaseWitnessCalculator; +import com.l2jserver.util.calculator.Calculator; + +/** + * 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 Calculator#importFunctions(Calculator) 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 Calculator#removeFunctions(Calculator) removed} and the calculator + * return to its original state. + *

+ * Another important note is that calculators should perform calculations as + * fast as possible. + *

+ * IMPORTANT: NEVER TOUCH THE STATIC CALCULATORS! + * + * @author Rogiel + */ +public class NPCStats extends ActorStats { + /** + * The calculator for base maximum MP + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_HP_CALCULATOR = new NPCBaseHPCalculator(); + /** + * The calculator for base maximum MP + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_MP_CALCULATOR = new NPCBaseMPCalculator(); + + /** + * The calculator for base intelligence + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_INT_CALCULATOR = new NPCBaseIntelligenceCalculator(); + /** + * The calculator for base strength + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_STR_CALCULATOR = new NPCBaseStrengthCalculator(); + /** + * The calculator for base concentration + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_CON_CALCULATOR = new NPCBaseConcentrationCalculator(); + /** + * The calculator for base mentality + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_MEN_CALCULATOR = new NPCBaseMentalityCalculator(); + /** + * The calculator for base dexterity + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_DEX_CALCULATOR = new NPCBaseDexterityCalculator(); + /** + * The calculator for base witness + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_WIT_CALCULATOR = new NPCBaseWitnessCalculator(); + + /** + * The calculator for base run speed + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_RUN_SPEED_CALCULATOR = new NPCBaseRunSpeedCalculator(); + /** + * The calculator for base walk speed + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_WALK_SPEED_CALCULATOR = new NPCBaseWalkSpeedCalculator(); + + /** + * The calculator base physical attack + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_PHYSICAL_ATTACK_CALCULATOR = new NPCBasePhysicalAttackCalculator(); + /** + * The calculator base physical attack speed + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_PHYSICAL_ATTACK_SPEED_CALCULATOR = new NPCBasePhysicalAttackSpeedCalculator(); + /** + * The calculator base physical attack critical rate + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_PHYSICAL_CRITICAL_RATE_CALCULATOR = new NPCBasePhysicalCriticalRateCalculator(); + /** + * The calculator base physical defense + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_PHYSICAL_DEFENSE_CALCULATOR = new NPCBasePhysicalDefenseCalculator(); + + /** + * The calculator base magical attack + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_MAGICAL_ATTACK_CALCULATOR = new NPCBaseMagicalAttackCalculator(); + /** + * The calculator base magical attack speed + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_MAGICAL_ATTACK_SPEED_CALCULATOR = new NPCBaseMagicalAttackSpeedCalculator(); + /** + * The calculator base magical attack critical rate + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_MAGICAL_CRITICAL_RATE_CALCULATOR = new NPCBaseMagicalCriticalRateCalculator(); + /** + * The calculator base magical defense + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_MAGICAL_DEFENSE_CALCULATOR = new NPCBaseMagicalDefenseCalculator(); + + /** + * The calculator base attack accuracy + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_ATTACK_ACCURACY_CALCULATOR = new NPCBaseAttackAccuracyCalculator(); + /** + * The calculator base evasion + *

+ * This calculator does not store any state and thus is safe to be + * shared. + */ + private static final NPCCalculator BASE_ATTACK_EVASION_CALCULATOR = new NPCBaseAttackEvasionCalculator(); + + /** + * The NPC + */ + private final NPC npc; + + /** + * Creates a new {@link NPCStats} and adds default calculators + * + * @param npc + * the npc + */ + public NPCStats(NPC npc) { + super(); + this.npc = npc; + + add(StatType.MAX_HP, BASE_HP_CALCULATOR); + add(StatType.MAX_MP, BASE_MP_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); + } + + @Override + protected NPCCalculatorContext createContext() { + return new NPCCalculatorContext(npc); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculator.java index b38d1e4f8..af3465205 100644 --- a/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculator.java +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculator.java @@ -16,17 +16,14 @@ */ package com.l2jserver.model.world.npc.calculator; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.Calculator; -import com.l2jserver.util.calculator.Function; +import com.l2jserver.model.world.actor.calculator.ActorCalculator; /** * @author Rogiel * */ -public class NPCCalculator extends Calculator { - public NPCCalculator( - Function... functions) { +public class NPCCalculator extends ActorCalculator { + public NPCCalculator(NPCCalculatorFunction... functions) { super(functions); } } diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculatorContext.java b/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculatorContext.java new file mode 100644 index 000000000..28dc14603 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculatorContext.java @@ -0,0 +1,37 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.npc.calculator; + +import com.l2jserver.model.world.NPC; +import com.l2jserver.model.world.actor.calculator.ActorCalculatorContext; + +/** + * Calculator context for {@link NPC} formulas + * + * @author Rogiel + */ +public class NPCCalculatorContext extends ActorCalculatorContext { + /** + * The npc instance + */ + public final NPC npc; + + public NPCCalculatorContext(NPC npc) { + super(npc); + this.npc = npc; + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculatorFunction.java b/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculatorFunction.java new file mode 100644 index 000000000..5bbd591bb --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/NPCCalculatorFunction.java @@ -0,0 +1,42 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +package com.l2jserver.model.world.npc.calculator; + +import com.l2jserver.model.template.ActorTemplate; +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; + +/** + * An function for {@link NPC} formulas. + * + * @author Rogiel + */ +public abstract class NPCCalculatorFunction extends ActorCalculatorFunction { + public NPCCalculatorFunction(int order) { + super(order); + } + + @Override + protected final double calculate(Actor a, ActorTemplate actorTemplate, + double value) { + return calculate((NPC) a, (NPCTemplate) actorTemplate, value); + } + + protected abstract double calculate(NPC c, NPCTemplate t, double value); +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseAttackAccuracyCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseAttackAccuracyCalculator.java new file mode 100644 index 000000000..d38d70ad4 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseAttackAccuracyCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base accuracy. + * + *

+ * ctx.result = c.getTemplate().getBaseAccuracy();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseAttackAccuracyCalculator extends NPCCalculator { + public NPCBaseAttackAccuracyCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, double value) { + // return t.getEvasion() + // TODO + return value; + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseAttackEvasionCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseAttackEvasionCalculator.java new file mode 100644 index 000000000..e5e52b62f --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseAttackEvasionCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character evasion + * + *
+ * ctx.result = c.getTemplate().getEvasion();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseAttackEvasionCalculator extends NPCCalculator { + public NPCBaseAttackEvasionCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getEvasion(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseConcentrationCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseConcentrationCalculator.java new file mode 100644 index 000000000..6ba33918b --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseConcentrationCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character concentration + * + *
+ * ctx.result = c.getTemplate().getConcentration();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseConcentrationCalculator extends NPCCalculator { + public NPCBaseConcentrationCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getConcentration(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseDexterityCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseDexterityCalculator.java new file mode 100644 index 000000000..e906033d9 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseDexterityCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base dexterity + * + *
+ * ctx.result = c.getTemplate().getDexterity();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseDexterityCalculator extends NPCCalculator { + public NPCBaseDexterityCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getDexterity(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseHPCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseHPCalculator.java new file mode 100644 index 000000000..72cd6260b --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseHPCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character maximum HP + * + *
+ * return c.getTemplate().getHP();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseHPCalculator extends NPCCalculator { + public NPCBaseHPCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + public double calculate(NPC c, NPCTemplate t, + double value) { + return t.getMaximumHP(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseIntelligenceCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseIntelligenceCalculator.java new file mode 100644 index 000000000..8f2555bca --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseIntelligenceCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base intelligence + * + *
+ * ctx.result = c.getTemplate().getIntelligence();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseIntelligenceCalculator extends NPCCalculator { + public NPCBaseIntelligenceCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getIntelligence(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMPCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMPCalculator.java new file mode 100644 index 000000000..28d6be92a --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMPCalculator.java @@ -0,0 +1,42 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character maximum HP + * + *
+ * return c.getTemplate().getMP();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseMPCalculator extends NPCCalculator { + public NPCBaseMPCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + public double calculate(NPC c, NPCTemplate t, double value) { + return t.getMaximumMP(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalAttackCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalAttackCalculator.java new file mode 100644 index 000000000..d8b470b23 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalAttackCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base magical attack + * + *
+ * ctx.result *= (((100.0 - 11 + c.getLevel()) / 100.0) ˆ 2)
+ * 		* (BaseStats.INT.calculateBonus(c.getStats().getIntelligence()) ˆ 2);
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseMagicalAttackCalculator extends NPCCalculator { + public NPCBaseMagicalAttackCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getMagicalAttack(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalAttackSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalAttackSpeedCalculator.java new file mode 100644 index 000000000..a879e38db --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalAttackSpeedCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the base magical attack speed + * + *
+ * ctx.result = c.getTemplate().getMagicalAttackSpeed();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseMagicalAttackSpeedCalculator extends NPCCalculator { + public NPCBaseMagicalAttackSpeedCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getMagicalAttackSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalCriticalRateCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalCriticalRateCalculator.java new file mode 100644 index 000000000..e980a90ad --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalCriticalRateCalculator.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the base magical attack critical rate + * + *
+ * ctx.result = c.getTemplate().getCritical(); // must be checked
+ * ctx.result *= BaseStats.WIT.calculateBonus(c.getStats().getWitness());
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseMagicalCriticalRateCalculator extends + NPCCalculator { + public NPCBaseMagicalCriticalRateCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getCritical(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalDefenseCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalDefenseCalculator.java new file mode 100644 index 000000000..21d239988 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMagicalDefenseCalculator.java @@ -0,0 +1,54 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base magical 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;
+ * ctx.result *= BaseStats.MEN.calculateBonus(c.getStats().getMentality())
+ * 		* ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseMagicalDefenseCalculator extends NPCCalculator { + public NPCBaseMagicalDefenseCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getMagicalDefense(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMentalityCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMentalityCalculator.java new file mode 100644 index 000000000..e6ec893a2 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseMentalityCalculator.java @@ -0,0 +1,43 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base mentality + * + *
+ * ctx.result = c.getTemplate().getMentality();
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseMentalityCalculator extends NPCCalculator { + public NPCBaseMentalityCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getMentality(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalAttackCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalAttackCalculator.java new file mode 100644 index 000000000..de57d8159 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalAttackCalculator.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base physical attack + * + *
+ * ctx.result = c.getTemplate().getPhysicalAttack();
+ * ctx.result *= BaseStats.STR.calculateBonus(c.getStats().getStrength())
+ * 		* ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class NPCBasePhysicalAttackCalculator extends NPCCalculator { + public NPCBasePhysicalAttackCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getPhysicalAttack(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalAttackSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalAttackSpeedCalculator.java new file mode 100644 index 000000000..47e7ea283 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalAttackSpeedCalculator.java @@ -0,0 +1,45 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base physical attack speed + * + *
+ * ctx.result = c.getTemplate().getPhysicalAttackSpeed();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * 
+ * + * @author Rogiel + */ +public class NPCBasePhysicalAttackSpeedCalculator extends + NPCCalculator { + public NPCBasePhysicalAttackSpeedCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getPhysicalAttackSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalCriticalRateCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalCriticalRateCalculator.java new file mode 100644 index 000000000..e72d0e29e --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalCriticalRateCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base critical rate + * + *
+ * ctx.result = c.getTemplate().getBaseCritical();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * ctx.result *= 10;
+ * 
+ * + * @author Rogiel + */ +public class NPCBasePhysicalCriticalRateCalculator extends NPCCalculator { + public NPCBasePhysicalCriticalRateCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, double value) { + return t.getCritical(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalDefenseCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalDefenseCalculator.java new file mode 100644 index 000000000..aa02790e8 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBasePhysicalDefenseCalculator.java @@ -0,0 +1,55 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base physical defense + * + *
+ * ctx.result = c.getTemplate().getBasePhysicalDefense();
+ * 
+ * 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))
+ * 	ctx.result -= hasMagePDef ? 8 : 18;
+ * if (inv.has(GLOVES))
+ * 	ctx.result -= 8;
+ * if (inv.has(FEET))
+ * 	ctx.result -= 7;
+ * ctx.result *= ((100.0 - 11 + c.getLevel()) / 100.0);
+ * 
+ * + * @author Rogiel + */ +public class NPCBasePhysicalDefenseCalculator extends NPCCalculator { + public NPCBasePhysicalDefenseCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, double value) { + return t.getPhysicalDefense(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseRunSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseRunSpeedCalculator.java new file mode 100644 index 000000000..a86d171ef --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseRunSpeedCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base run speed + * + *
+ * ctx.result = c.getTemplate().getBaseRunSpeed();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseRunSpeedCalculator extends NPCCalculator { + public NPCBaseRunSpeedCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getRunSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseStrengthCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseStrengthCalculator.java similarity index 63% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseStrengthCalculator.java rename to src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseStrengthCalculator.java index a9098c8f9..396d332cb 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseStrengthCalculator.java +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseStrengthCalculator.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.npc.calculator.base; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +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; /** * Calculates the character base strength @@ -29,13 +30,13 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseStrengthCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseStrengthCalculator() { - super(new AbstractFunction(0x000) { +public class NPCBaseStrengthCalculator extends NPCCalculator { + public NPCBaseStrengthCalculator() { + super(new NPCCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseStrength(); + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getStrength(); } }); } diff --git a/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseWalkSpeedCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseWalkSpeedCalculator.java new file mode 100644 index 000000000..b1ffb54f1 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseWalkSpeedCalculator.java @@ -0,0 +1,44 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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; + +/** + * Calculates the character base walk speed + * + *
+ * ctx.result = c.getTemplate().getBaseWalkSpeed();
+ * ctx.result *= BaseStats.DEX.calculateBonus(c.getStats().getDexterity());
+ * 
+ * + * @author Rogiel + */ +public class NPCBaseWalkSpeedCalculator extends NPCCalculator { + public NPCBaseWalkSpeedCalculator() { + super(new NPCCalculatorFunction(0x000) { + @Override + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getWalkSpeed(); + } + }); + } +} diff --git a/src/main/java/com/l2jserver/model/world/character/calculator/BaseWitnessCalculator.java b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseWitnessCalculator.java similarity index 63% rename from src/main/java/com/l2jserver/model/world/character/calculator/BaseWitnessCalculator.java rename to src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseWitnessCalculator.java index 084ef0042..37cc99a03 100644 --- a/src/main/java/com/l2jserver/model/world/character/calculator/BaseWitnessCalculator.java +++ b/src/main/java/com/l2jserver/model/world/npc/calculator/base/NPCBaseWitnessCalculator.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.model.world.character.calculator; +package com.l2jserver.model.world.npc.calculator.base; -import com.l2jserver.model.world.L2Character; -import com.l2jserver.util.calculator.AbstractFunction; -import com.l2jserver.util.calculator.CalculatorContext; +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; /** * Calculates the character base witness @@ -29,13 +30,13 @@ import com.l2jserver.util.calculator.CalculatorContext; * * @author Rogiel */ -public class BaseWitnessCalculator extends CharacterCalculator { - @SuppressWarnings("unchecked") - public BaseWitnessCalculator() { - super(new AbstractFunction(0x000) { +public class NPCBaseWitnessCalculator extends NPCCalculator { + public NPCBaseWitnessCalculator() { + super(new NPCCalculatorFunction(0x000) { @Override - public void calculate(L2Character c, CalculatorContext ctx) { - ctx.result = c.getTemplate().getBaseWitness(); + protected double calculate(NPC c, NPCTemplate t, + double value) { + return t.getWitness(); } }); } diff --git a/src/main/java/com/l2jserver/util/calculator/AbstractFunction.java b/src/main/java/com/l2jserver/util/calculator/AbstractFunction.java index a292033cf..72d66dcfa 100644 --- a/src/main/java/com/l2jserver/util/calculator/AbstractFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/AbstractFunction.java @@ -16,13 +16,12 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * @author Rogiel * */ -public abstract class AbstractFunction implements Function { +public abstract class AbstractFunction implements + Function { private final int order; public AbstractFunction(int order) { diff --git a/src/main/java/com/l2jserver/util/calculator/Calculator.java b/src/main/java/com/l2jserver/util/calculator/Calculator.java index 1c6250789..7c9021c46 100644 --- a/src/main/java/com/l2jserver/util/calculator/Calculator.java +++ b/src/main/java/com/l2jserver/util/calculator/Calculator.java @@ -20,7 +20,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import com.l2jserver.model.world.Actor; import com.l2jserver.util.factory.CollectionFactory; /** @@ -29,11 +28,13 @@ import com.l2jserver.util.factory.CollectionFactory; * * @author Rogiel */ -public class Calculator extends AbstractFunction { +public class Calculator extends + AbstractFunction { /** * List of operations in this calculator */ - private final List> functions = CollectionFactory.newList(); + private final List> functions = CollectionFactory + .newList(); /** * Creates a new empty calculator. Functions can be add using @@ -50,9 +51,9 @@ public class Calculator extends AbstractFunction { * @param functions * the calculator functions */ - public Calculator(Function... functions) { + public Calculator(Function... functions) { super(0x00); - for (final Function func : functions) { + for (final Function func : functions) { this.functions.add(func); } } @@ -68,7 +69,7 @@ public class Calculator extends AbstractFunction { * @param function * the operation */ - public void add(Function function) { + public void add(Function function) { functions.add(function); Collections.sort(functions, FunctionOrderComparator.SHARED_INSTANCE); } @@ -83,10 +84,10 @@ public class Calculator extends AbstractFunction { * @param calculator * the calculator */ - public void importFunctions(Calculator calculator) { - for (final Function function : calculator.functions) { + public void importFunctions(Calculator calculator) { + for (final Function function : calculator.functions) { if (function instanceof Calculator) { - importFunctions((Calculator) function); + importFunctions((Calculator) function); } else { functions.add(function); } @@ -101,10 +102,10 @@ public class Calculator extends AbstractFunction { * @param calculator * the calculator */ - public void removeFunctions(Calculator calculator) { - for (final Function function : calculator.functions) { + public void removeFunctions(Calculator calculator) { + for (final Function function : calculator.functions) { if (function instanceof Calculator) { - removeFunctions((Calculator) function); + removeFunctions((Calculator) function); } else { functions.remove(function); } @@ -112,10 +113,15 @@ public class Calculator extends AbstractFunction { } @Override - public void calculate(O object, CalculatorContext ctx) { - for (final Function function : functions) { - function.calculate(object, ctx); + public double calculate(T ctx, double value) { + for (final Function function : functions) { + value = function.calculate(ctx, value); } + return value; + } + + public double calculate(T ctx) { + return calculate(ctx, 0); } public static class FunctionOrderComparator implements diff --git a/src/main/java/com/l2jserver/util/calculator/CalculatorContext.java b/src/main/java/com/l2jserver/util/calculator/CalculatorContext.java index 47b11ce1f..321f789e8 100644 --- a/src/main/java/com/l2jserver/util/calculator/CalculatorContext.java +++ b/src/main/java/com/l2jserver/util/calculator/CalculatorContext.java @@ -18,8 +18,7 @@ package com.l2jserver.util.calculator; /** * @author Rogiel - * + * */ public class CalculatorContext { - public double result; } diff --git a/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java b/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java index 3ab43f11e..3ab1598fe 100644 --- a/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/DivisionFunction.java @@ -16,15 +16,13 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs a division:
chain value / * value
* * @author Rogiel */ -public class DivisionFunction extends AbstractFunction { +public class DivisionFunction extends AbstractFunction { /** * The value */ @@ -36,7 +34,7 @@ public class DivisionFunction extends AbstractFunction { } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result /= this.value; + public double calculate(CalculatorContext ctx, double value) { + return value / this.value; } } diff --git a/src/main/java/com/l2jserver/util/calculator/Function.java b/src/main/java/com/l2jserver/util/calculator/Function.java index 0fb77cf05..d0cb337c6 100644 --- a/src/main/java/com/l2jserver/util/calculator/Function.java +++ b/src/main/java/com/l2jserver/util/calculator/Function.java @@ -16,14 +16,12 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * An function is nothing more than a mathematical operation. * * @author Rogiel */ -public interface Function { +public interface Function { /** * Performs the operation in the calculation process. *

@@ -35,7 +33,7 @@ public interface Function { * the input value * @return the output value */ - void calculate(O actor, CalculatorContext ctx); + double calculate(T ctx, double value); /** * @return the order this function will be executed diff --git a/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java b/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java index b1d2cfbea..8f1a06f8e 100644 --- a/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/ModulusFunction.java @@ -16,22 +16,19 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs an modulus:

|chain value| *
* * @author Rogiel */ -public class ModulusFunction extends AbstractFunction { +public class ModulusFunction extends AbstractFunction { public ModulusFunction(int order) { super(order); } @Override - public void calculate(O actor, CalculatorContext ctx) { - if (ctx.result < 0) - ctx.result *= -1; + public double calculate(CalculatorContext ctx, double value) { + return Math.abs(value); } } diff --git a/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java b/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java index 72531e35a..b946fc96c 100644 --- a/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/MultiplicationFunction.java @@ -16,16 +16,13 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs an multiplication:
chain value * * value
* * @author Rogiel */ -public class MultiplicationFunction extends - AbstractFunction { +public class MultiplicationFunction extends AbstractFunction { /** * The value */ @@ -37,7 +34,7 @@ public class MultiplicationFunction extends } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result *= this.value; + public double calculate(CalculatorContext ctx, double value) { + return value * this.value; } } diff --git a/src/main/java/com/l2jserver/util/calculator/NegateFunction.java b/src/main/java/com/l2jserver/util/calculator/NegateFunction.java index 41de59e7f..9981b598f 100644 --- a/src/main/java/com/l2jserver/util/calculator/NegateFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/NegateFunction.java @@ -16,21 +16,19 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs an negate:
-chain value *
* * @author Rogiel */ -public class NegateFunction extends AbstractFunction { +public class NegateFunction extends AbstractFunction { public NegateFunction(int order) { super(order); } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result = -ctx.result; + public double calculate(CalculatorContext ctx, double value) { + return -value; } } diff --git a/src/main/java/com/l2jserver/util/calculator/PercentFunction.java b/src/main/java/com/l2jserver/util/calculator/PercentFunction.java index 0a6979d71..68dd000a5 100644 --- a/src/main/java/com/l2jserver/util/calculator/PercentFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/PercentFunction.java @@ -16,15 +16,13 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs a multiplication:
chain value * * (value / 100)
* * @author Rogiel */ -public class PercentFunction extends MultiplicationFunction { +public class PercentFunction extends MultiplicationFunction { /** * The value */ diff --git a/src/main/java/com/l2jserver/util/calculator/RoundFunction.java b/src/main/java/com/l2jserver/util/calculator/RoundFunction.java index 3aadbbeeb..fc1bfb8a0 100644 --- a/src/main/java/com/l2jserver/util/calculator/RoundFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/RoundFunction.java @@ -16,20 +16,18 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs an rounding in the number. * * @author Rogiel */ -public class RoundFunction extends AbstractFunction { +public class RoundFunction extends AbstractFunction { public RoundFunction(int order) { super(order); } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result = Math.round(ctx.result); + public double calculate(CalculatorContext ctx, double value) { + return Math.round(value); } } diff --git a/src/main/java/com/l2jserver/util/calculator/SetFunction.java b/src/main/java/com/l2jserver/util/calculator/SetFunction.java index 134b7d900..d29620a54 100644 --- a/src/main/java/com/l2jserver/util/calculator/SetFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/SetFunction.java @@ -16,14 +16,12 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs an set. It ignores the input value and return its own. * * @author Rogiel */ -public class SetFunction extends AbstractFunction { +public class SetFunction extends AbstractFunction { /** * The value */ @@ -35,7 +33,7 @@ public class SetFunction extends AbstractFunction { } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result = value; + public double calculate(CalculatorContext ctx, double value) { + return this.value; } } diff --git a/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java b/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java index 31a6d8077..dc20a7c0d 100644 --- a/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/SubtractFunction.java @@ -16,15 +16,13 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs an subtraction:
chain value - * value
* * @author Rogiel */ -public class SubtractFunction extends AbstractFunction { +public class SubtractFunction extends AbstractFunction { /** * The value */ @@ -36,7 +34,7 @@ public class SubtractFunction extends AbstractFunction { } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result -= value; + public double calculate(CalculatorContext ctx, double value) { + return value - this.value; } } diff --git a/src/main/java/com/l2jserver/util/calculator/SumFunction.java b/src/main/java/com/l2jserver/util/calculator/SumFunction.java index 710a5c26b..c1d00089f 100644 --- a/src/main/java/com/l2jserver/util/calculator/SumFunction.java +++ b/src/main/java/com/l2jserver/util/calculator/SumFunction.java @@ -16,15 +16,13 @@ */ package com.l2jserver.util.calculator; -import com.l2jserver.model.world.Actor; - /** * This function performs a sum:
chain value + * value
* * @author Rogiel */ -public class SumFunction extends AbstractFunction { +public class SumFunction extends AbstractFunction { /** * The value */ @@ -36,7 +34,7 @@ public class SumFunction extends AbstractFunction { } @Override - public void calculate(O actor, CalculatorContext ctx) { - ctx.result += value; + public double calculate(CalculatorContext ctx, double value) { + return value + this.value; } } diff --git a/src/main/java/com/l2jserver/util/geometry/Point.java b/src/main/java/com/l2jserver/util/geometry/Point.java index 5a4f11821..74c7a7dab 100644 --- a/src/main/java/com/l2jserver/util/geometry/Point.java +++ b/src/main/java/com/l2jserver/util/geometry/Point.java @@ -44,6 +44,29 @@ public class Point { this.y = y; } + /** + * @return the x + */ + public int getX() { + return x; + } + + /** + * @return the y + */ + public int getY() { + return y; + } + + /** + * Creates a new point from X and Y axis + * + * @param x + * the x axis + * @param y + * the y axis + * @return the new created Point + */ public static final Point fromXY(int x, int y) { return new Point(x, y); } diff --git a/src/main/java/com/l2jserver/util/geometry/Point3D.java b/src/main/java/com/l2jserver/util/geometry/Point3D.java index 63f402f53..e6ccf9719 100644 --- a/src/main/java/com/l2jserver/util/geometry/Point3D.java +++ b/src/main/java/com/l2jserver/util/geometry/Point3D.java @@ -22,7 +22,7 @@ package com.l2jserver.util.geometry; * * @author Rogiel */ -public class Point3D { +public class Point3D extends Point { /** * The point coordinate */ @@ -41,6 +41,7 @@ public class Point3D { * the angle */ public Point3D(Coordinate coordinate, double angle) { + super(coordinate.getX(), coordinate.getY()); this.coordinate = coordinate; this.angle = angle; } @@ -63,6 +64,7 @@ public class Point3D { * @return the x * @see com.l2jserver.util.geometry.Coordinate#getX() */ + @Override public int getX() { return coordinate.getX(); } @@ -71,6 +73,7 @@ public class Point3D { * @return the y * @see com.l2jserver.util.geometry.Coordinate#getY() */ + @Override public int getY() { return coordinate.getY(); } @@ -130,7 +133,7 @@ public class Point3D { * the angle * @return the new {@link Point3D} object created */ - public static Point3D fromXYZA(int x, int y, int z, double angle) { + public static final Point3D fromXYZA(int x, int y, int z, double angle) { return new Point3D(Coordinate.fromXYZ(x, y, z), angle); } @@ -145,7 +148,7 @@ public class Point3D { * the z point * @return the new {@link Point3D} object created */ - public static Point3D fromXYZ(int x, int y, int z) { + public static final Point3D fromXYZ(int x, int y, int z) { return fromXYZA(x, y, z, 0); } } diff --git a/src/main/java/com/l2jserver/util/geometry/PolygonArea.java b/src/main/java/com/l2jserver/util/geometry/PolygonArea.java index ec92e9064..083ce70bc 100644 --- a/src/main/java/com/l2jserver/util/geometry/PolygonArea.java +++ b/src/main/java/com/l2jserver/util/geometry/PolygonArea.java @@ -118,7 +118,6 @@ public class PolygonArea extends AbstractArea { @Override public Point getClosestPoint(int x, int y) { - Point closestPoint = null; double closestDistance = 0; diff --git a/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java b/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java index c3e19bff5..62894ed3c 100644 --- a/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java +++ b/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java @@ -20,8 +20,6 @@ import junit.framework.Assert; import org.junit.Test; -import com.l2jserver.model.world.L2Character; - /** * @author Rogiel * @@ -29,137 +27,127 @@ import com.l2jserver.model.world.L2Character; public class CalculatorTest { @Test public void testSimple() { - final Calculator calc = new Calculator(); + final Calculator calc = new Calculator(); - calc.add(new SetFunction(0, 10)); - calc.add(new MultiplicationFunction(1, 2)); - calc.add(new SetFunction(2, 30)); + calc.add(new SetFunction(0, 10)); + calc.add(new MultiplicationFunction(1, 2)); + calc.add(new SetFunction(2, 30)); final CalculatorContext ctx = new CalculatorContext(); - calc.calculate(null, ctx); - Assert.assertEquals(30.0, ctx.result); + Assert.assertEquals(30.0, calc.calculate(ctx)); } @Test public void testPercent() { - final Calculator calc = new Calculator(); + final Calculator calc = new Calculator(); - calc.add(new SetFunction(0, 10)); - calc.add(new MultiplicationFunction(1, 2)); - calc.add(new PercentFunction(2, 75)); + calc.add(new SetFunction(0, 10)); + calc.add(new MultiplicationFunction(1, 2)); + calc.add(new PercentFunction(2, 75)); final CalculatorContext ctx = new CalculatorContext(); - calc.calculate(null, ctx); - Assert.assertEquals(15.0, ctx.result); + Assert.assertEquals(15.0, calc.calculate(ctx)); } @Test public void testComplex() { - final Calculator calc = new Calculator(); + final Calculator calc = new Calculator(); - 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)); + 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(); - calc.calculate(null, ctx); - Assert.assertEquals(5.0, ctx.result); + Assert.assertEquals(5.0, calc.calculate(ctx)); } @Test public void testNesting() { - final Calculator calc1 = new Calculator(); + final Calculator calc1 = new Calculator(); 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)); + 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)); - calc1.calculate(null, ctx1); - Assert.assertEquals(5.0, ctx1.result); + Assert.assertEquals(5.0, calc1.calculate(ctx1)); - final Calculator calc2 = new Calculator(); + final Calculator calc2 = new Calculator(); 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)); + 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)); - calc2.calculate(null, ctx2); - Assert.assertEquals(-2.5, ctx2.result); + Assert.assertEquals(-2.5, calc2.calculate(ctx2)); - final Calculator calc3 = new Calculator(); + final Calculator calc3 = new Calculator(); final CalculatorContext ctx3 = new CalculatorContext(); calc3.add(calc1); calc3.add(calc2); // this should be executed - calc2.add(new SumFunction(10, 1)); + calc2.add(new SumFunction(10, 1)); - calc3.calculate(null, ctx3); - Assert.assertEquals(2.25, ctx3.result); + Assert.assertEquals(2.25, calc3.calculate(ctx3)); } @Test public void testImporting() { - final Calculator calc1 = new Calculator(); + final Calculator calc1 = new Calculator(); 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)); + 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)); - calc1.calculate(null, ctx1); - Assert.assertEquals(5.0, ctx1.result); + Assert.assertEquals(5.0, calc1.calculate(ctx1)); - final Calculator calc2 = new Calculator(); + final Calculator calc2 = new Calculator(); 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)); + 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)); - calc2.calculate(null, ctx2); - Assert.assertEquals(-2.5, ctx2.result); + Assert.assertEquals(-2.5, calc2.calculate(ctx2)); - final Calculator calc3 = new Calculator(); + final Calculator calc3 = new Calculator(); final CalculatorContext ctx3 = new CalculatorContext(); calc3.importFunctions(calc1); calc3.importFunctions(calc2); // this should not be executed - calc2.add(new SumFunction(11, 50)); + calc2.add(new SumFunction(11, 50)); - calc3.calculate(null, ctx3); - Assert.assertEquals(1.25, ctx3.result); + Assert.assertEquals(1.25, calc3.calculate(ctx3)); } @Test public void testRounding() { - final Calculator calc = new Calculator(); + final Calculator calc = new Calculator(); - 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)); + 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(); - calc.calculate(null, ctx); - Assert.assertEquals(-3.0, ctx.result); + Assert.assertEquals(-3.0, calc.calculate(ctx)); } }