1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-07 07:52:57 +00:00

Item template structure

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 20:11:42 -03:00
parent e886165b89
commit fe41dbdc6f
59 changed files with 1400 additions and 85 deletions

View File

@@ -23,6 +23,14 @@ import com.l2jserver.model.world.character.CharacterClass;
public class RequestCharacterTemplatesPacket extends AbstractClientPacket {
public static final int OPCODE = 0x13;
public static final CharacterClass[] TEMPLATE_CLASSES = {
CharacterClass.HUMAN_FIGHTER, CharacterClass.HUMAN_MYSTIC,
CharacterClass.ELVEN_FIGHTER, CharacterClass.ELVEN_MYSTIC,
CharacterClass.DARK_FIGHTER, CharacterClass.DARK_MYSTIC,
CharacterClass.ORC_FIGHTER, CharacterClass.ORC_MYSTIC,
CharacterClass.DWARVEN_FIGHTER, CharacterClass.MALE_SOLDIER,
CharacterClass.FEMALE_SOLDIER };
/**
* The logger
*/
@@ -43,12 +51,13 @@ public class RequestCharacterTemplatesPacket extends AbstractClientPacket {
@Override
public void process(final Lineage2Connection conn) {
log.debug("Requested character templates");
final CharacterTemplateID id = idFactory
.createID(CharacterClass.HUMAN_FIGHTER.id);
final CharacterTemplate template = id.getTemplate();
for (final CharacterClass charClass : TEMPLATE_CLASSES) {
final CharacterTemplateID id = idFactory.createID(charClass.id);
final CharacterTemplate template = id.getTemplate();
final CharacterTemplatePacket templatePacket = new CharacterTemplatePacket(
template);
final CharacterTemplatePacket templatePacket = new CharacterTemplatePacket(
template);
conn.write(templatePacket);
conn.write(templatePacket);
}
}
}

View File

@@ -4,6 +4,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.capability.Depositable;
import com.l2jserver.model.template.capability.Dropable;
import com.l2jserver.model.template.capability.Enchantable;
import com.l2jserver.model.template.capability.Sellable;
import com.l2jserver.model.template.capability.Tradable;
import com.l2jserver.model.template.capability.Usable;
import com.l2jserver.model.world.Item;
/**
@@ -18,16 +24,114 @@ public abstract class ItemTemplate extends AbstractTemplate<Item> {
private static final Logger log = LoggerFactory
.getLogger(ItemTemplate.class);
protected int weight = 0;
protected int price = 0;
protected String icon;
protected boolean immediateEffect = true;
protected ItemMaterial material;
public enum ItemMaterial {
COTTON, WOOD, PAPER, FISH, ORIHARUKON, HORN, ADAMANTAITE, CHRYSOLITE, MITHRIL, COBWEB, RUNE_XP, CLOTH, SCALE_OF_DRAGON, BONE, GOLD, LEATHER, FINE_STEEL, SILVER, DYESTUFF, CRYSTAL, RUNE_REMOVE_PENALTY, STEEL, BRONZE, RUNE_SP, LIQUID, BLOOD_STEEL, DAMASCUS;
}
public ItemTemplate(ItemTemplateID id) {
super(id);
}
public ItemTemplate(final ItemTemplateID id, String icon,
ItemMaterial material) {
super(id);
this.icon = icon;
this.material = material;
}
@Override
public Item create() {
log.debug("Creating a new Item instance with template {}", this);
return new Item(this.getID());
}
public void stack(Item... object) {
}
/**
* @return true if item is enchantable
*/
public boolean isEnchantable() {
return (this instanceof Enchantable);
}
/**
* @return the sellable
*/
public boolean isSellable() {
return (this instanceof Sellable);
}
/**
* @return the dropable
*/
public boolean isDropable() {
return (this instanceof Dropable);
}
/**
* @return the tradable
*/
public boolean isTradable() {
return (this instanceof Tradable);
}
/**
* @return the usable
*/
public boolean isUsable() {
return (this instanceof Usable);
}
/**
* @return the usable
*/
public boolean isDepositable() {
return (this instanceof Depositable);
}
/**
* @return the weight
*/
public int getWeight() {
return weight;
}
/**
* @return the price
*/
public int getPrice() {
return price;
}
/**
* @return the icon
*/
public String getIcon() {
return icon;
}
/**
* @return the immediateEffect
*/
public boolean isImmediateEffect() {
return immediateEffect;
}
/**
* @return the material
*/
public ItemMaterial getMaterial() {
return material;
}
@Override
public ItemTemplateID getID() {
return (ItemTemplateID) super.getID();

View File

@@ -1,16 +0,0 @@
package com.l2jserver.model.template;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.capability.Attackable;
import com.l2jserver.model.world.Item;
/**
* Template for Weapon {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class WeaponTemplate extends ItemTemplate implements Attackable {
public WeaponTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -14,8 +14,4 @@ import com.l2jserver.model.world.capability.Attacker;
public interface Attackable extends TemplateCapability {
void attack(Attacker source,
com.l2jserver.model.world.capability.Attackable target);
int getPhysicalDamage();
int getMagicalDamage();
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.capability;
import com.l2jserver.model.template.Template;
import com.l2jserver.model.world.capability.Attacker;
/**
* Defines an {@link Template template} {@link TemplateCapability capability}
* that can be selled.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Depositable extends TemplateCapability {
void sell(Attacker source,
com.l2jserver.model.world.capability.Attackable target);
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.capability;
import com.l2jserver.model.template.Template;
import com.l2jserver.model.world.capability.Attacker;
/**
* Defines an {@link Template template} {@link TemplateCapability capability}
* that can be selled.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Dropable extends TemplateCapability {
void sell(Attacker source,
com.l2jserver.model.world.capability.Attackable target);
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.capability;
import com.l2jserver.model.template.Template;
import com.l2jserver.model.world.capability.Attacker;
/**
* Defines an {@link Template template} {@link TemplateCapability capability}
* that can be selled.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Sellable extends TemplateCapability {
void sell(Attacker source,
com.l2jserver.model.world.capability.Attackable target);
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.capability;
import com.l2jserver.model.template.Template;
import com.l2jserver.model.world.capability.Attacker;
/**
* Defines an {@link Template template} {@link TemplateCapability capability}
* that can be selled.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Tradable extends TemplateCapability {
void sell(Attacker source,
com.l2jserver.model.world.capability.Attackable target);
}

View File

@@ -0,0 +1,13 @@
package com.l2jserver.model.template.capability;
import com.l2jserver.model.template.Template;
/**
* Defines an {@link Template template} {@link TemplateCapability capability}
* that can be used.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Usable extends TemplateCapability {
void canUse();
}

View File

@@ -1,6 +1,7 @@
package com.l2jserver.model.template;
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.template.capability.Defendable;
import com.l2jserver.model.template.capability.IncomingDamageIntercept;
import com.l2jserver.model.world.Item;

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for consumable arrow {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ArrowTemplate extends ConsumableTemplate {
public ArrowTemplate(ItemTemplateID id, String icon, ItemMaterial material) {
super(id, icon, material);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for Castle Guard {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class CastleGuardTemplate extends ItemTemplate {
public CastleGuardTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -1,6 +1,7 @@
package com.l2jserver.model.template;
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.template.capability.Consumable;
import com.l2jserver.model.world.Item;
@@ -11,7 +12,8 @@ import com.l2jserver.model.world.Item;
*/
public abstract class ConsumableTemplate extends ItemTemplate implements
Consumable {
public ConsumableTemplate(ItemTemplateID id) {
super(id);
public ConsumableTemplate(ItemTemplateID id, String icon,
ItemMaterial material) {
super(id, icon, material);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for coupom {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class CoupomTemplate extends ItemTemplate {
public CoupomTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for crop {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class CropTemplate extends ItemTemplate {
public CropTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for consumable Dye {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class DyeTemplate extends ConsumableTemplate {
public DyeTemplate(ItemTemplateID id, String icon, ItemMaterial material) {
super(id, icon, material);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for consumable elixir {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ElixirTemplate extends ConsumableTemplate {
public ElixirTemplate(ItemTemplateID id, String icon, ItemMaterial material) {
super(id, icon, material);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for consumable enchant scroll {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class EnchantScrollTemplate extends ScrollTemplate {
public EnchantScrollTemplate(ItemTemplateID id, String icon) {
super(id, icon);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for harvest {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class HarvestTemplate extends ItemTemplate {
public HarvestTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for lottery ticket {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class LotteryTicketTemplate extends TicketTemplate {
public LotteryTicketTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for lure {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class LureTemplate extends ItemTemplate {
public LureTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for material {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class MaterialTemplate extends ItemTemplate {
public MaterialTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for pet collar {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class PetCollarTemplate extends ItemTemplate {
public PetCollarTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -1,6 +1,7 @@
package com.l2jserver.model.template;
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.capability.Stackable;
import com.l2jserver.model.world.Item;
/**
@@ -8,8 +9,9 @@ import com.l2jserver.model.world.Item;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class PotionTemplate extends ConsumableTemplate {
public PotionTemplate(ItemTemplateID id) {
super(id);
public abstract class PotionTemplate extends ConsumableTemplate implements
Stackable<Item> {
public PotionTemplate(ItemTemplateID id, String icon) {
super(id, icon, ItemMaterial.LIQUID);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for Race Ticket {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class RaceTicketTemplate extends TicketTemplate {
public RaceTicketTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,18 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for recipe {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class RecipeTemplate extends ItemTemplate {
private ItemTemplateID item;
public RecipeTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for rune {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class RuneTemplate extends ItemTemplate {
public RuneTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for consumable scroll {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ScrollTemplate extends ConsumableTemplate {
public ScrollTemplate(ItemTemplateID id, String icon) {
super(id, icon, ItemMaterial.PAPER);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for seed {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class SeedTemplate extends ItemTemplate {
public SeedTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.world.Item;
/**
* Template for ticket of lord {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class TicketOfLordTemplate extends TicketTemplate {
public TicketOfLordTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,16 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Item;
/**
* Template for ticket {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class TicketTemplate extends ItemTemplate {
public TicketTemplate(ItemTemplateID id) {
super(id);
}
}

View File

@@ -0,0 +1,201 @@
package com.l2jserver.model.template.item;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.template.capability.Attackable;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
/**
* Template for Weapon {@link Item}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class WeaponTemplate extends ItemTemplate implements Attackable {
protected InventoryPaperdoll paperdoll = null;
protected WeaponType type;
public enum WeaponType {
FISHINGROD, CROSSBOW, BIG_SWORD, RAPIER, DUAL_FIST, ETC, DAGGER, BLUNT, BIG_BLUNT, DUAL_DAGGER, DUAL, FLAG, POLE, FIST, BOW, OWN_THING, SWORD, ANCIENT_SWORD;
}
protected final WeaponAttribute attribute = new WeaponAttribute();
protected int randomDamage = 0;
protected int attackRange = 0;
protected int[] damageRange = new int[] {};
protected int soulshots = 0;
protected int spiritshots = 0;
protected int crystals;
protected CrystalType crystal;
public enum CrystalType {
GRADE_A, GRADE_B, GRADE_C, GRADE_D;
}
public WeaponTemplate(ItemTemplateID id, String icon,
ItemMaterial material, InventoryPaperdoll paperdoll, WeaponType type) {
super(id, icon, material);
this.paperdoll = paperdoll;
this.type = type;
}
public enum WeaponAttributeType {
PHYSICAL_ATTACK, MAGICAL_ATTACK, R_CRITICAL, PHYSICAL_ATTACK_SPEED;
}
public class WeaponAttribute {
public void add(WeaponAttributeType type, int order, int value) {
}
public void set(WeaponAttributeType type, int order, int value) {
}
public void enchant(WeaponAttributeType type, int order, int value) {
}
}
/**
* @return the paperdoll
*/
public InventoryPaperdoll getPaperdoll() {
return paperdoll;
}
/**
* @param paperdoll
* the paperdoll to set
*/
public void setPaperdoll(InventoryPaperdoll paperdoll) {
this.paperdoll = paperdoll;
}
/**
* @return the type
*/
public WeaponType getType() {
return type;
}
/**
* @param type
* the type to set
*/
public void setType(WeaponType type) {
this.type = type;
}
/**
* @return the randomDamage
*/
public int getRandomDamage() {
return randomDamage;
}
/**
* @param randomDamage
* the randomDamage to set
*/
public void setRandomDamage(int randomDamage) {
this.randomDamage = randomDamage;
}
/**
* @return the attackRange
*/
public int getAttackRange() {
return attackRange;
}
/**
* @param attackRange
* the attackRange to set
*/
public void setAttackRange(int attackRange) {
this.attackRange = attackRange;
}
/**
* @return the damageRange
*/
public int[] getDamageRange() {
return damageRange;
}
/**
* @param damageRange
* the damageRange to set
*/
public void setDamageRange(int[] damageRange) {
this.damageRange = damageRange;
}
/**
* @return the soulshots
*/
public int getSoulshots() {
return soulshots;
}
/**
* @param soulshots
* the soulshots to set
*/
public void setSoulshots(int soulshots) {
this.soulshots = soulshots;
}
/**
* @return the spiritshots
*/
public int getSpiritshots() {
return spiritshots;
}
/**
* @param spiritshots
* the spiritshots to set
*/
public void setSpiritshots(int spiritshots) {
this.spiritshots = spiritshots;
}
/**
* @return the crystals
*/
public int getCrystals() {
return crystals;
}
/**
* @param crystals
* the crystals to set
*/
public void setCrystals(int crystals) {
this.crystals = crystals;
}
/**
* @return the crystal
*/
public CrystalType getCrystal() {
return crystal;
}
/**
* @param crystal
* the crystal to set
*/
public void setCrystal(CrystalType crystal) {
this.crystal = crystal;
}
/**
* @return the attribute
*/
public WeaponAttribute getAttribute() {
return attribute;
}
}

View File

@@ -49,6 +49,8 @@ public class Item extends AbstractObject implements Playable, Spawnable,
* Drop coordinate of this item
*/
private Coordinate coordinate;
private int count = 1;
public Item(ItemTemplateID templateID) {
this.templateID = templateID;

View File

@@ -59,6 +59,11 @@ public class ScriptTemplateService extends AbstractService implements
public void addTemplate(Class<? extends Template<?>> t) {
final Template<?> template = injector.getInstance(t);
if (templates.containsKey(template.getID()))
throw new TemplateException("Template with ID" + template.getID()
+ " is already registered for "
+ templates.get(template.getID()));
if (template.getID() != null)
templates.put(template.getID(), template);
}

View File

@@ -0,0 +1,21 @@
package com.l2jserver.service.game.template;
public class TemplateException extends RuntimeException {
private static final long serialVersionUID = 1L;
public TemplateException() {
super();
}
public TemplateException(String message, Throwable cause) {
super(message, cause);
}
public TemplateException(String message) {
super(message);
}
public TemplateException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,38 @@
package com.l2jserver.util.calculator;
import java.util.List;
import com.l2jserver.util.calculator.operation.AddOperation;
import com.l2jserver.util.calculator.operation.CalculatorOperation;
import com.l2jserver.util.calculator.operation.SetOperation;
import com.l2jserver.util.calculator.operation.SubtractOperation;
import com.l2jserver.util.factory.CollectionFactory;
public class Formula {
private List<CalculatorOperation<Integer>> operations = CollectionFactory
.newList(null);
public void addOperation(int order, CalculatorOperation<Integer> operation) {
operations.set(order, operation);
}
public void add(int order, int value) {
addOperation(order, new AddOperation(value));
}
public void subtract(int order, int value) {
addOperation(order, new SubtractOperation(value));
}
public void set(int order, int value) {
addOperation(order, new SetOperation(value));
}
public int calculate() {
int value = 0;
for (CalculatorOperation<Integer> operation : operations) {
value = operation.calculate(value);
}
return value;
}
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class AddOperation implements CalculatorOperation<Integer> {
private Integer value;
public AddOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value + this.value;
}
}

View File

@@ -0,0 +1,5 @@
package com.l2jserver.util.calculator.operation;
public interface CalculatorOperation<T extends Number> {
T calculate(T value);
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class MultiplyOperation implements CalculatorOperation<Integer> {
private Integer value;
public MultiplyOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value * this.value;
}
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class SetOperation implements CalculatorOperation<Integer> {
private Integer value;
public SetOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return this.value;
}
}

View File

@@ -0,0 +1,14 @@
package com.l2jserver.util.calculator.operation;
public class SubtractOperation implements CalculatorOperation<Integer> {
private Integer value;
public SubtractOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value - this.value;
}
}