diff --git a/data/script/template/script/template/item/weapon/LongSwordTemplate.java b/data/script/template/script/template/item/weapon/LongSwordTemplate.java index ea4e7e9d5..642922d13 100644 --- a/data/script/template/script/template/item/weapon/LongSwordTemplate.java +++ b/data/script/template/script/template/item/weapon/LongSwordTemplate.java @@ -1,4 +1,3 @@ - /* * This file is part of l2jserver . * @@ -14,9 +13,14 @@ * * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . -*/ + */ package script.template.item.weapon; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.MAGICAL_ATTACK; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.PHYSICAL_ATTACK; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.PHYSICAL_ATTACK_SPEED; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.R_CRITICAL; + import com.google.inject.Inject; import com.l2jserver.model.id.template.factory.ItemTemplateIDFactory; import com.l2jserver.model.world.capability.Attackable; @@ -32,10 +36,10 @@ public class LongSwordTemplate extends AbstractNoGradeWeaponTemplate { ItemMaterial.STEEL, InventoryPaperdoll.RIGHT_HAND, WeaponType.SWORD); - attribute.set(WeaponAttributeType.PHYSICAL_ATTACK, 0x08, 24); - attribute.set(WeaponAttributeType.MAGICAL_ATTACK, 0x08, 17); - attribute.set(WeaponAttributeType.R_CRITICAL, 0x08, 8); - attribute.set(WeaponAttributeType.PHYSICAL_ATTACK_SPEED, 0x08, 379); + attribute.set(PHYSICAL_ATTACK, 0x80, 24); + attribute.set(MAGICAL_ATTACK, 0x80, 17); + attribute.set(R_CRITICAL, 0x80, 8); + attribute.set(PHYSICAL_ATTACK_SPEED, 0x80, 379); this.randomDamage = 10; this.attackRange = 40; diff --git a/data/script/template/script/template/item/weapon/ShortSwordTemplate.java b/data/script/template/script/template/item/weapon/ShortSwordTemplate.java index 0bafa69f4..7ef0fd987 100644 --- a/data/script/template/script/template/item/weapon/ShortSwordTemplate.java +++ b/data/script/template/script/template/item/weapon/ShortSwordTemplate.java @@ -1,4 +1,3 @@ - /* * This file is part of l2jserver . * @@ -14,9 +13,14 @@ * * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . -*/ + */ package script.template.item.weapon; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.MAGICAL_ATTACK; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.PHYSICAL_ATTACK; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.PHYSICAL_ATTACK_SPEED; +import static com.l2jserver.model.template.item.WeaponTemplate.WeaponAttributeType.R_CRITICAL; + import com.google.inject.Inject; import com.l2jserver.model.id.template.factory.ItemTemplateIDFactory; import com.l2jserver.model.world.capability.Attackable; @@ -32,10 +36,10 @@ public class ShortSwordTemplate extends AbstractNoGradeWeaponTemplate { ItemMaterial.STEEL, InventoryPaperdoll.RIGHT_HAND, WeaponType.SWORD); - attribute.set(WeaponAttributeType.PHYSICAL_ATTACK, 0x08, 8); - attribute.set(WeaponAttributeType.MAGICAL_ATTACK, 0x08, 6); - attribute.set(WeaponAttributeType.R_CRITICAL, 0x08, 8); - attribute.set(WeaponAttributeType.PHYSICAL_ATTACK_SPEED, 0x08, 379); + attribute.set(PHYSICAL_ATTACK, 0x08, 8); + attribute.set(MAGICAL_ATTACK, 0x08, 6); + attribute.set(R_CRITICAL, 0x08, 8); + attribute.set(PHYSICAL_ATTACK_SPEED, 0x08, 379); this.type = WeaponType.SWORD; this.paperdoll = InventoryPaperdoll.RIGHT_HAND; diff --git a/src/main/java/com/l2jserver/L2JGameServerMain.java b/src/main/java/com/l2jserver/L2JGameServerMain.java index ea0a988e4..f2f86803e 100644 --- a/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -16,8 +16,6 @@ */ package com.l2jserver; -import org.apache.log4j.BasicConfigurator; - import com.l2jserver.routines.GameServerInitializationRoutine; public class L2JGameServerMain { @@ -26,8 +24,6 @@ public class L2JGameServerMain { * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException { - BasicConfigurator.configure(); - final L2JGameServer server = new L2JGameServer(); try { server.getInjector() diff --git a/src/main/java/com/l2jserver/game/net/Lineage2CryptographyKey.java b/src/main/java/com/l2jserver/game/net/Lineage2CryptographyKey.java index 96b48f19d..7bb7eeb61 100644 --- a/src/main/java/com/l2jserver/game/net/Lineage2CryptographyKey.java +++ b/src/main/java/com/l2jserver/game/net/Lineage2CryptographyKey.java @@ -22,7 +22,7 @@ package com.l2jserver.game.net; * * @author Rogiel */ -public class Lineage2CryptographyKey implements Cloneable { +public class Lineage2CryptographyKey { /** * The raw key */ @@ -76,12 +76,7 @@ public class Lineage2CryptographyKey implements Cloneable { key[11] = (byte) (old >> 0x18 & 0xff); } - @Override - public Lineage2CryptographyKey clone() { - try { - return (Lineage2CryptographyKey) super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } + public Lineage2CryptographyKey copy() { + return new Lineage2CryptographyKey(key); } } diff --git a/src/main/java/com/l2jserver/game/net/codec/Lineage2PacketReader.java b/src/main/java/com/l2jserver/game/net/codec/Lineage2PacketReader.java index 0d7f6af75..a2e951755 100644 --- a/src/main/java/com/l2jserver/game/net/codec/Lineage2PacketReader.java +++ b/src/main/java/com/l2jserver/game/net/codec/Lineage2PacketReader.java @@ -32,10 +32,11 @@ import com.l2jserver.game.net.packet.client.CharacterCreatePacket; import com.l2jserver.game.net.packet.client.EnterWorld; import com.l2jserver.game.net.packet.client.LogoutPacket; import com.l2jserver.game.net.packet.client.ProtocolVersionPacket; +import com.l2jserver.game.net.packet.client.RequestAllFortressInfoPacket; import com.l2jserver.game.net.packet.client.RequestCharacterTemplatesPacket; -import com.l2jserver.game.net.packet.client.RequestGotoLobby; -import com.l2jserver.game.net.packet.client.RequestKeyMapping; -import com.l2jserver.game.net.packet.client.RequestManorList; +import com.l2jserver.game.net.packet.client.RequestGotoLobbyPacket; +import com.l2jserver.game.net.packet.client.RequestKeyMappingPacket; +import com.l2jserver.game.net.packet.client.RequestManorListPacket; /** * This decoder reads an frame and decodes the packet in it. Each packet has an @@ -128,12 +129,14 @@ public class Lineage2PacketReader extends OneToOneDecoder { case 0xd0: // COMPOSED final int opcode2 = buffer.readUnsignedShort(); switch (opcode2) { - case RequestGotoLobby.OPCODE2: - return RequestGotoLobby.class; - case RequestKeyMapping.OPCODE2: - return RequestKeyMapping.class; - case RequestManorList.OPCODE2: - return RequestManorList.class; + case RequestGotoLobbyPacket.OPCODE2: + return RequestGotoLobbyPacket.class; + case RequestKeyMappingPacket.OPCODE2: + return RequestKeyMappingPacket.class; + case RequestManorListPacket.OPCODE2: + return RequestManorListPacket.class; + case RequestAllFortressInfoPacket.OPCODE2: + return RequestAllFortressInfoPacket.class; default: logger.warn("Unknown opcode2 for 0xd0: 0x{}", Integer.toHexString(opcode2)); diff --git a/src/main/java/com/l2jserver/game/net/packet/client/AuthLoginPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/AuthLoginPacket.java index 20741ce24..b9c70d1f4 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/AuthLoginPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/AuthLoginPacket.java @@ -88,6 +88,7 @@ public class AuthLoginPacket extends AbstractClientPacket { final List chars = characterDao.selectByAccount(accountId); // conn.write(CharacterSelectionListPacket.fromL2Session( // conn.getSession(), chars.toArray(new L2Character[0]))); + conn.setCharacterID(chars.get(0).getID()); conn.write(new CharacterEnterWorldPacket(chars.get(0), playKey1)); } diff --git a/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java b/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java index 7ce7d1dbf..cf149c624 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/EnterWorld.java @@ -20,7 +20,8 @@ import org.jboss.netty.buffer.ChannelBuffer; import com.l2jserver.game.net.Lineage2Connection; import com.l2jserver.game.net.packet.AbstractClientPacket; -import com.l2jserver.game.net.packet.server.InventoryPacket; +import com.l2jserver.game.net.packet.server.GameGuardQueryPacket; +import com.l2jserver.game.net.packet.server.UserInformationPacket; /** * The client is requesting a logout. Currently, when this packet is received @@ -51,6 +52,8 @@ public class EnterWorld extends AbstractClientPacket { @Override public void process(final Lineage2Connection conn) { - conn.write(new InventoryPacket(conn.getCharacter().getInventory())); + conn.write(new UserInformationPacket(conn.getCharacter())); + conn.write(new GameGuardQueryPacket()); + //conn.write(new InventoryPacket(conn.getCharacter().getInventory())); } } diff --git a/src/main/java/com/l2jserver/game/net/packet/client/ProtocolVersionPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/ProtocolVersionPacket.java index 41544df90..26eedfa49 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/ProtocolVersionPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/ProtocolVersionPacket.java @@ -82,7 +82,7 @@ public class ProtocolVersionPacket extends AbstractClientPacket { keygen.generate()); conn.getDecrypter().enable(inKey); - final Lineage2CryptographyKey outKey = inKey.clone(); + final Lineage2CryptographyKey outKey = inKey.copy(); log.debug("Decrypter has been enabled"); log.debug("Client protocol version: {}", version); diff --git a/src/main/java/com/l2jserver/game/net/packet/client/RequestAllFortressInfoPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/RequestAllFortressInfoPacket.java new file mode 100644 index 000000000..34f34065f --- /dev/null +++ b/src/main/java/com/l2jserver/game/net/packet/client/RequestAllFortressInfoPacket.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.game.net.packet.client; + +import org.jboss.netty.buffer.ChannelBuffer; + +import com.l2jserver.game.net.Lineage2Connection; +import com.l2jserver.game.net.packet.AbstractClientPacket; +import com.l2jserver.game.net.packet.server.FortInfoPacket; + +/** + * The client is requesting the manor list. + * + * @author Rogiel + */ +public class RequestAllFortressInfoPacket extends AbstractClientPacket { + /** + * The packet OPCODE1 + */ + public static final int OPCODE1 = 0xd0; + /** + * The packet OPCODE2 + */ + public static final int OPCODE2 = 0x3d; + + @Override + public void read(Lineage2Connection conn, ChannelBuffer buffer) { + } + + @Override + public void process(final Lineage2Connection conn) { + conn.write(new FortInfoPacket()); + } +} diff --git a/src/main/java/com/l2jserver/game/net/packet/client/RequestGotoLobby.java b/src/main/java/com/l2jserver/game/net/packet/client/RequestGotoLobbyPacket.java similarity index 93% rename from src/main/java/com/l2jserver/game/net/packet/client/RequestGotoLobby.java rename to src/main/java/com/l2jserver/game/net/packet/client/RequestGotoLobbyPacket.java index edace873e..f480825b2 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/RequestGotoLobby.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/RequestGotoLobbyPacket.java @@ -33,7 +33,7 @@ import com.l2jserver.model.world.L2Character; * * @author Rogiel */ -public class RequestGotoLobby extends AbstractClientPacket { +public class RequestGotoLobbyPacket extends AbstractClientPacket { /** * The packet OPCODE1 */ @@ -49,7 +49,7 @@ public class RequestGotoLobby extends AbstractClientPacket { private final CharacterDAO characterDao; @Inject - public RequestGotoLobby(CharacterDAO characterDao) { + public RequestGotoLobbyPacket(CharacterDAO characterDao) { this.characterDao = characterDao; } diff --git a/src/main/java/com/l2jserver/game/net/packet/client/RequestKeyMapping.java b/src/main/java/com/l2jserver/game/net/packet/client/RequestKeyMappingPacket.java similarity index 95% rename from src/main/java/com/l2jserver/game/net/packet/client/RequestKeyMapping.java rename to src/main/java/com/l2jserver/game/net/packet/client/RequestKeyMappingPacket.java index e7ac1212e..619b1789b 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/RequestKeyMapping.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/RequestKeyMappingPacket.java @@ -26,7 +26,7 @@ import com.l2jserver.game.net.packet.AbstractClientPacket; * * @author Rogiel */ -public class RequestKeyMapping extends AbstractClientPacket { +public class RequestKeyMappingPacket extends AbstractClientPacket { /** * The packet OPCODE1 */ diff --git a/src/main/java/com/l2jserver/game/net/packet/client/RequestManorList.java b/src/main/java/com/l2jserver/game/net/packet/client/RequestManorListPacket.java similarity index 95% rename from src/main/java/com/l2jserver/game/net/packet/client/RequestManorList.java rename to src/main/java/com/l2jserver/game/net/packet/client/RequestManorListPacket.java index bfddebe53..48bb384be 100644 --- a/src/main/java/com/l2jserver/game/net/packet/client/RequestManorList.java +++ b/src/main/java/com/l2jserver/game/net/packet/client/RequestManorListPacket.java @@ -27,7 +27,7 @@ import com.l2jserver.game.net.packet.server.ManorListPacket; * * @author Rogiel */ -public class RequestManorList extends AbstractClientPacket { +public class RequestManorListPacket extends AbstractClientPacket { /** * The packet OPCODE1 */ diff --git a/src/main/java/com/l2jserver/game/net/packet/client/RequestShortcutRegistry.java b/src/main/java/com/l2jserver/game/net/packet/client/RequestShortcutRegistry.java new file mode 100644 index 000000000..f299c1733 --- /dev/null +++ b/src/main/java/com/l2jserver/game/net/packet/client/RequestShortcutRegistry.java @@ -0,0 +1,70 @@ +/* + * 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.game.net.packet.client; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.l2jserver.game.net.Lineage2Connection; +import com.l2jserver.game.net.packet.AbstractClientPacket; + +/** + * The client is requesting a logout. Currently, when this packet is received + * the connection is immediately closed. + * + * @author Rogiel + */ +public class RequestShortcutRegistry extends AbstractClientPacket { + /** + * The packet OPCODE1 + */ + public static final int OPCODE1 = 0xd0; + /** + * The packet OPCODE2 + */ + public static final int OPCODE2 = 0x3d; + + /** + * The logger + */ + private static final Logger log = LoggerFactory + .getLogger(RequestShortcutRegistry.class); + + /** + * The shortcut type + */ + private int type; + /** + * The shortcut ID + */ + private int id; + private int slot; + private int page; + private int lvl; + private int characterType; + + @Override + public void read(Lineage2Connection conn, ChannelBuffer buffer) { + } + + @Override + public void process(final Lineage2Connection conn) { + log.debug("Logging out client {}", conn); + conn.close(); + } +} diff --git a/src/main/java/com/l2jserver/game/net/packet/server/FortInfoPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/FortInfoPacket.java new file mode 100644 index 000000000..9f6b141a6 --- /dev/null +++ b/src/main/java/com/l2jserver/game/net/packet/server/FortInfoPacket.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.game.net.packet.server; + +import org.jboss.netty.buffer.ChannelBuffer; + +import com.l2jserver.game.net.Lineage2Connection; +import com.l2jserver.game.net.packet.AbstractServerPacket; +import com.l2jserver.util.BufferUtils; + +/** + * This packet send the manor list to the client + * + * @author Rogiel + */ +public class FortInfoPacket extends AbstractServerPacket { + /** + * The packet OPCODE + */ + public static final int OPCODE = 0xfe; + + public FortInfoPacket() { + super(OPCODE); + } + + @Override + public void write(Lineage2Connection conn, ChannelBuffer buffer) { + buffer.writeShort(0x15); + buffer.writeInt(21); + int i = 101; + for (; i < 122; i++) { + buffer.writeInt(i); // fort id + BufferUtils.writeString(buffer, ""); // clan name + buffer.writeInt(0x00); // is in siege + buffer.writeInt(0x00); // Time of possession + } + + // TODO implement fort service + } +} diff --git a/src/main/java/com/l2jserver/game/net/packet/server/GameGuardQueryPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/GameGuardQueryPacket.java new file mode 100644 index 000000000..c3de25e01 --- /dev/null +++ b/src/main/java/com/l2jserver/game/net/packet/server/GameGuardQueryPacket.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.game.net.packet.server; + +import org.jboss.netty.buffer.ChannelBuffer; + +import com.l2jserver.game.net.Lineage2Connection; +import com.l2jserver.game.net.packet.AbstractServerPacket; + +/** + * This packet send the GameGuard query to the client. The client will send an + * notification, but this can be ignored if GG is not supposed to be enforced. + * + * @author Rogiel + */ +public class GameGuardQueryPacket extends AbstractServerPacket { + /** + * The packet OPCODE + */ + public static final int OPCODE = 0x74; + + public GameGuardQueryPacket() { + super(OPCODE); + + } + + @Override + public void write(Lineage2Connection conn, ChannelBuffer buffer) { + buffer.writeInt(0x27533DD9); + buffer.writeInt(0x2E72A51D); + buffer.writeInt(0x2017038B); + buffer.writeInt(0xC35B1EA3); + } +} diff --git a/src/main/java/com/l2jserver/game/net/packet/server/UserInformationPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/UserInformationPacket.java index 200e10275..5f3098b7c 100644 --- a/src/main/java/com/l2jserver/game/net/packet/server/UserInformationPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/server/UserInformationPacket.java @@ -16,10 +16,40 @@ */ package com.l2jserver.game.net.packet.server; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.BELT; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.CHEST; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.CLOAK; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.DECORATION_1; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.DECORATION_2; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.DECORATION_3; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.DECORATION_4; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.DECORATION_5; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.DECORATION_6; +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.HAIR1; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.HAIR2; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.HEAD; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEFT_BRACELET; +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.LEFT_HAND; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.LEGS; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.NECK; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_BRACELET; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_EAR; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_FINGER; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.RIGHT_HAND; +import static com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll.UNDERWEAR; + import org.jboss.netty.buffer.ChannelBuffer; import com.l2jserver.game.net.Lineage2Connection; import com.l2jserver.game.net.packet.AbstractServerPacket; +import com.l2jserver.model.world.Item; +import com.l2jserver.model.world.L2Character; +import com.l2jserver.model.world.actor.ActorExperience; +import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll; import com.l2jserver.util.BufferUtils; /** @@ -31,26 +61,296 @@ public class UserInformationPacket extends AbstractServerPacket { /** * The packet OPCODE */ - public static final int OPCODE = 0xfe; + public static final int OPCODE = 0x32; /** - * TODO + * The character */ - private String[] manors; + private L2Character character; - public UserInformationPacket(String... manors) { + public UserInformationPacket(L2Character character) { super(OPCODE); - this.manors = manors; + this.character = character; } @Override public void write(Lineage2Connection conn, ChannelBuffer buffer) { - buffer.writeShort(0x22); - buffer.writeInt(manors.length); - int i = 1; - for (String manor : manors) { - buffer.writeInt(i++); - BufferUtils.writeString(buffer, manor); - } + buffer.writeInt(character.getPoint().getX()); + buffer.writeInt(character.getPoint().getY()); + buffer.writeInt(character.getPoint().getZ()); + buffer.writeInt(0); // vehicle + buffer.writeInt(character.getID().getID()); + BufferUtils.writeString(buffer, character.getName()); + buffer.writeInt(character.getRace().id); + buffer.writeInt(character.getSex().option); + + buffer.writeInt(character.getCharacterClass().id); + + buffer.writeInt(character.getLevel()); + buffer.writeLong(ActorExperience.LEVEL_1.experience); + buffer.writeInt(character.getAttributes().getStrength()); + buffer.writeInt(character.getAttributes().getDexterity()); + buffer.writeInt(character.getAttributes().getConcentration()); + buffer.writeInt(character.getAttributes().getIntelligence()); + buffer.writeInt(character.getAttributes().getWitness()); + buffer.writeInt(character.getAttributes().getMentality()); + buffer.writeInt(200); // hp + buffer.writeInt((int) 200); // cur hp + buffer.writeInt(200); // mp + buffer.writeInt((int) 200); // cur mp + buffer.writeInt(0); // sp + buffer.writeInt(0); // load + buffer.writeInt(200); // max load + + // 20 no weapon, 40 weapon equippe + buffer.writeInt(20); + + writePaperdollObjectID(buffer, character, UNDERWEAR); + writePaperdollObjectID(buffer, character, RIGHT_EAR); + writePaperdollObjectID(buffer, character, LEFT_EAR); + writePaperdollObjectID(buffer, character, NECK); + writePaperdollObjectID(buffer, character, RIGHT_FINGER); + writePaperdollObjectID(buffer, character, LEFT_FINGER); + writePaperdollObjectID(buffer, character, HEAD); + writePaperdollObjectID(buffer, character, RIGHT_HAND); + writePaperdollObjectID(buffer, character, LEFT_HAND); + writePaperdollObjectID(buffer, character, GLOVES); + writePaperdollObjectID(buffer, character, CHEST); + writePaperdollObjectID(buffer, character, LEGS); + writePaperdollObjectID(buffer, character, FEET); + writePaperdollObjectID(buffer, character, CLOAK); + writePaperdollObjectID(buffer, character, RIGHT_HAND); + writePaperdollObjectID(buffer, character, HAIR1); + writePaperdollObjectID(buffer, character, HAIR2); + writePaperdollObjectID(buffer, character, RIGHT_BRACELET); + writePaperdollObjectID(buffer, character, LEFT_BRACELET); + writePaperdollObjectID(buffer, character, DECORATION_1); + writePaperdollObjectID(buffer, character, DECORATION_2); + writePaperdollObjectID(buffer, character, DECORATION_3); + writePaperdollObjectID(buffer, character, DECORATION_4); + writePaperdollObjectID(buffer, character, DECORATION_5); + writePaperdollObjectID(buffer, character, DECORATION_6); + writePaperdollObjectID(buffer, character, BELT); + + writePaperdollItemID(buffer, character, UNDERWEAR); + writePaperdollItemID(buffer, character, RIGHT_EAR); + writePaperdollItemID(buffer, character, LEFT_EAR); + writePaperdollItemID(buffer, character, NECK); + writePaperdollItemID(buffer, character, RIGHT_FINGER); + writePaperdollItemID(buffer, character, LEFT_FINGER); + writePaperdollItemID(buffer, character, HEAD); + buffer.writeInt(246); + //writePaperdollItemID(buffer, character, RIGHT_HAND); + writePaperdollItemID(buffer, character, LEFT_HAND); + writePaperdollItemID(buffer, character, GLOVES); + writePaperdollItemID(buffer, character, CHEST); + writePaperdollItemID(buffer, character, LEGS); + writePaperdollItemID(buffer, character, FEET); + writePaperdollItemID(buffer, character, CLOAK); + ///writePaperdollItemID(buffer, character, RIGHT_HAND); + buffer.writeInt(246); + writePaperdollItemID(buffer, character, HAIR1); + writePaperdollItemID(buffer, character, HAIR2); + writePaperdollItemID(buffer, character, RIGHT_BRACELET); + writePaperdollItemID(buffer, character, LEFT_BRACELET); + writePaperdollItemID(buffer, character, DECORATION_1); + writePaperdollItemID(buffer, character, DECORATION_2); + writePaperdollItemID(buffer, character, DECORATION_3); + writePaperdollItemID(buffer, character, DECORATION_4); + writePaperdollItemID(buffer, character, DECORATION_5); + writePaperdollItemID(buffer, character, DECORATION_6); + writePaperdollItemID(buffer, character, BELT); + + writePaperdollAugumentID(buffer, character, UNDERWEAR); + writePaperdollAugumentID(buffer, character, RIGHT_EAR); + writePaperdollAugumentID(buffer, character, LEFT_EAR); + writePaperdollAugumentID(buffer, character, NECK); + writePaperdollAugumentID(buffer, character, RIGHT_FINGER); + writePaperdollAugumentID(buffer, character, LEFT_FINGER); + writePaperdollAugumentID(buffer, character, HEAD); + writePaperdollAugumentID(buffer, character, RIGHT_HAND); + writePaperdollAugumentID(buffer, character, LEFT_HAND); + writePaperdollAugumentID(buffer, character, GLOVES); + writePaperdollAugumentID(buffer, character, CHEST); + writePaperdollAugumentID(buffer, character, LEGS); + writePaperdollAugumentID(buffer, character, FEET); + writePaperdollAugumentID(buffer, character, CLOAK); + writePaperdollAugumentID(buffer, character, RIGHT_HAND); + writePaperdollAugumentID(buffer, character, HAIR1); + writePaperdollAugumentID(buffer, character, HAIR2); + writePaperdollAugumentID(buffer, character, RIGHT_BRACELET); + writePaperdollAugumentID(buffer, character, LEFT_BRACELET); + writePaperdollAugumentID(buffer, character, DECORATION_1); + writePaperdollAugumentID(buffer, character, DECORATION_2); + writePaperdollAugumentID(buffer, character, DECORATION_3); + writePaperdollAugumentID(buffer, character, DECORATION_4); + writePaperdollAugumentID(buffer, character, DECORATION_5); + writePaperdollAugumentID(buffer, character, DECORATION_6); + writePaperdollAugumentID(buffer, character, BELT); + + buffer.writeInt(0x00); // (max?) talismans count + buffer.writeInt(0x00); // cloak sratus + buffer.writeInt(character.getAttributes().getPhysicalAttack()); + buffer.writeInt(character.getAttributes().getAttackSpeed()); + buffer.writeInt(character.getAttributes().getPhysicalDefense()); + + buffer.writeInt(character.getAttributes().getEvasionChance()); // evasion + buffer.writeInt(character.getAttributes().getAccuracy()); + buffer.writeInt(character.getAttributes().getCriticalChance()); + + buffer.writeInt(character.getAttributes().getMagicalAttack()); + buffer.writeInt(character.getAttributes().getCastSpeed()); + buffer.writeInt(character.getAttributes().getAttackSpeed()); + + buffer.writeInt(character.getAttributes().getMagicalDefense()); + + buffer.writeInt(0x00); // 0-non-pvp 1-pvp = violett name + buffer.writeInt(0x00); // karma + + buffer.writeInt(0x10); // run speed + buffer.writeInt(0x20); // walk speed + buffer.writeInt(0x10); // swim run speed + buffer.writeInt(0x20); // swim walk speed + buffer.writeInt(0); // unk + buffer.writeInt(0); // unk + buffer.writeInt(0); // fly speed -only if flying + buffer.writeInt(0); // fly speed -only if flying + buffer.writeDouble(0x01); // move speed multiplier + buffer.writeDouble(0x01); // attack speed multiplier + + // L2Summon pet = _activeChar.getPet(); + // L2Transformation trans; + // if (_activeChar.getMountType() != 0 && pet != null) { + // writeF(pet.getTemplate().fCollisionRadius); + // writeF(pet.getTemplate().fCollisionHeight); + // } else if ((trans = _activeChar.getTransformation()) != null) { + // writeF(trans.getCollisionRadius()); + // writeF(trans.getCollisionHeight()); + // } else { + // writeF(_activeChar.getCollisionRadius()); + // writeF(_activeChar.getCollisionHeight()); + // } + buffer.writeDouble(9.0); // collision radius + buffer.writeDouble(23.0); // collision heigth + + buffer.writeInt(character.getAppearance().getHairStyle().option); + buffer.writeInt(character.getAppearance().getHairColor().option); + buffer.writeInt(character.getAppearance().getFace().option); + buffer.writeInt(0x00); // is gm + + String title = "Testing"; // title + BufferUtils.writeString(buffer, title); + + int clanid = 0; + if (character.getClanID() != null) + clanid = character.getClanID().getID(); + buffer.writeInt(clanid); // clanid + buffer.writeInt(0x00); // clan crest id + buffer.writeInt(0x00); // ally id + buffer.writeInt(0x00); // ally crest id + // 0x40 leader rights + // siege flags: attacker - 0x180 sword over name, defender - 0x80 + // shield, 0xC0 crown (|leader), 0x1C0 flag (|leader) + buffer.writeInt(0x40); + buffer.writeByte(0x00); // mount type + buffer.writeByte(0x00); // private store type + buffer.writeByte(0x00); // dwarven craft + buffer.writeInt(0x00); // pk kills + buffer.writeInt(0x00); // pvp kills + + buffer.writeShort(0x00); // cubics size + // short:cubicsid[cubicssize] + // buffer.writeShort(cubicid); + + buffer.writeByte(0); // is party match room + + buffer.writeInt(0x100000); // abnormal effect + buffer.writeByte(0x0); // flying mounted = 2; otherwise: 0 + + buffer.writeInt(0x00); // clan privileges + + buffer.writeShort(2); // c2 recommendations remaining + buffer.writeShort(1); // c2 recommendations received + buffer.writeInt(0); // mount npc id + buffer.writeShort(500); // inventory limit + + buffer.writeInt(character.getCharacterClass().id); + buffer.writeInt(0x00); // special effects? circles around player... + buffer.writeInt(200); // max cp + buffer.writeInt(200); // cur cp + buffer.writeByte(127); // is mount or is airshilhelp = 0; otherwise + // enchant effect (minimum 127) + + buffer.writeByte(0x01);// team, 1=blue,2 red,0 is unknown + + buffer.writeInt(0x00); // clan crest large id + // 0x01: symbol on char menu ctrl+I + buffer.writeByte(0x00); // is noble + buffer.writeByte(0x00); // 0x01: Hero Aura + + buffer.writeByte(0x00); // Fishing Mode + buffer.writeInt(0x00); // fishing x + buffer.writeInt(0x00); // fishing y + buffer.writeInt(0x00); // fishing z + buffer.writeInt(character.getAppearance().getNameColor().toInteger()); + + // new c5 + // is running + buffer.writeByte(0x00); // changes the Speed + // display on Status + // Window + + // pledge class + buffer.writeInt(0x00); // changes the text above + // CP on Status Window + buffer.writeInt(0x00); // pledge type + + buffer.writeInt(character.getAppearance().getTitleColor().toInteger()); + + // cursed weapon ID equipped + buffer.writeInt(0x00); + + // T1 Starts + buffer.writeInt(0x00); // transformation id + + buffer.writeShort(0x00); // attack element + buffer.writeShort(0x10); // attack element value + buffer.writeShort(0x10); // fire defense value + buffer.writeShort(0x10); // water def value + buffer.writeShort(0x10); // wind def value + buffer.writeShort(0x10); // earth def value + buffer.writeShort(0x10); // holy def value + buffer.writeShort(0x10); // dark def value + + buffer.writeInt(0x00); // getAgathionId + + // T2 Starts + buffer.writeInt(0x00); // Fame + buffer.writeInt(0x01); // Minimap on Hellbound + buffer.writeInt(1); // Vitality Points + buffer.writeInt(0x000001); // special effects + } + + private void writePaperdollObjectID(ChannelBuffer buffer, + L2Character character, InventoryPaperdoll paperdoll) { + final Item item = character.getInventory().getItem(paperdoll); + int id = 0; + if (item != null) + id = item.getID().getID(); + buffer.writeInt(id); + } + + private void writePaperdollItemID(ChannelBuffer buffer, + L2Character character, InventoryPaperdoll paperdoll) { + final Item item = character.getInventory().getItem(paperdoll); + int id = 0; + if (item != null) + id = item.getTemplateID().getID(); + buffer.writeInt(id); + } + + private void writePaperdollAugumentID(ChannelBuffer buffer, + L2Character character, InventoryPaperdoll paperdoll) { + buffer.writeInt(0x00); } } diff --git a/src/main/java/com/l2jserver/model/AbstractModel.java b/src/main/java/com/l2jserver/model/AbstractModel.java new file mode 100644 index 000000000..da909b0ea --- /dev/null +++ b/src/main/java/com/l2jserver/model/AbstractModel.java @@ -0,0 +1,67 @@ +/* + * 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; + +import com.l2jserver.model.id.ID; + +/** + * @author Rogiel + * + */ +public class AbstractModel> implements Model { + /** + * The object id + */ + protected T id; + + @Override + public T getID() { + return id; + } + + @Override + public void setID(T ID) { + if(this.id != null) + throw new IllegalStateException("ID is already set"); + this.id = ID; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AbstractModel other = (AbstractModel) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } +} diff --git a/src/main/java/com/l2jserver/model/Model.java b/src/main/java/com/l2jserver/model/Model.java new file mode 100644 index 000000000..2b07a1c70 --- /dev/null +++ b/src/main/java/com/l2jserver/model/Model.java @@ -0,0 +1,36 @@ +/* + * 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; + +import com.l2jserver.model.id.ID; + +/** + * @author Rogiel + * + */ +public interface Model> { + /** + * @return the object ID + */ + T getID(); + + /** + * @param ID + * the object ID to set + */ + void setID(T ID); +} diff --git a/src/main/java/com/l2jserver/model/game/Fort.java b/src/main/java/com/l2jserver/model/game/Fort.java new file mode 100644 index 000000000..7830226e6 --- /dev/null +++ b/src/main/java/com/l2jserver/model/game/Fort.java @@ -0,0 +1,214 @@ +/* + * 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.game; + +import java.util.Date; + +import com.l2jserver.model.AbstractModel; +import com.l2jserver.model.id.CastleID; +import com.l2jserver.model.id.FortID; +import com.l2jserver.model.id.object.CharacterID; + +/** + * An fort in Lineage II game world + * + * @author Rogiel + */ +public class Fort extends AbstractModel { + /** + * The {@link Castle} of which this {@link Fort} belongs to + */ + private CastleID castleID; + /** + * The owner (clan leader) of which this {@link Fort} belongs to. + */ + private CharacterID ownerID; + + /** + * The fort name + */ + private String name; + /** + * The siege date + */ + private Date siegeDate; + /** + * The last time this fort was owned by someone + */ + private Date lastOwnedTime; + /** + * The fort type. TODO values names are unknown so far! + */ + private FortType fortType; + + /** + * The {@link Fort} types + * + * @author Rogiel + */ + public enum FortType { + TYPE1, TYPE2; + } + + /** + * The {@link Fort} state + */ + private boolean state; + /** + * The {@link Fort} blood state + */ + private boolean blood; + /** + * The {@link Fort} supply level + */ + private int supplyLvL; + + /** + * @return the castleID + */ + public CastleID getCastleID() { + return castleID; + } + + /** + * @param castleID + * the castleID to set + */ + public void setCastleID(CastleID castleID) { + this.castleID = castleID; + } + + /** + * @return the ownerID + */ + public CharacterID getOwnerID() { + return ownerID; + } + + /** + * @param ownerID + * the ownerID to set + */ + public void setOwnerID(CharacterID ownerID) { + this.ownerID = ownerID; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name + * the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the siegeDate + */ + public Date getSiegeDate() { + return siegeDate; + } + + /** + * @param siegeDate + * the siegeDate to set + */ + public void setSiegeDate(Date siegeDate) { + this.siegeDate = siegeDate; + } + + /** + * @return the lastOwnedTime + */ + public Date getLastOwnedTime() { + return lastOwnedTime; + } + + /** + * @param lastOwnedTime + * the lastOwnedTime to set + */ + public void setLastOwnedTime(Date lastOwnedTime) { + this.lastOwnedTime = lastOwnedTime; + } + + /** + * @return the fortType + */ + public FortType getFortType() { + return fortType; + } + + /** + * @param fortType + * the fortType to set + */ + public void setFortType(FortType fortType) { + this.fortType = fortType; + } + + /** + * @return the state + */ + public boolean isState() { + return state; + } + + /** + * @param state + * the state to set + */ + public void setState(boolean state) { + this.state = state; + } + + /** + * @return the blood + */ + public boolean isBlood() { + return blood; + } + + /** + * @param blood + * the blood to set + */ + public void setBlood(boolean blood) { + this.blood = blood; + } + + /** + * @return the supplyLvL + */ + public int getSupplyLvL() { + return supplyLvL; + } + + /** + * @param supplyLvL + * the supplyLvL to set + */ + public void setSupplyLvL(int supplyLvL) { + this.supplyLvL = supplyLvL; + } +} diff --git a/src/main/java/com/l2jserver/model/id/AbstractModelID.java b/src/main/java/com/l2jserver/model/id/AbstractModelID.java new file mode 100644 index 000000000..d1389e897 --- /dev/null +++ b/src/main/java/com/l2jserver/model/id/AbstractModelID.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.id; + +import com.l2jserver.model.Model; + +/** + * This is an abstract ID for most model objects that do not extend + * {@link ObjectID}. + * + * @author Rogiel + */ +public abstract class AbstractModelID>> + extends ID { + /** + * @param id + * the id + */ + protected AbstractModelID(T id) { + super(id); + } + + /** + * @return the {@link Model} object associated with this + * {@link AbstractModelID}. null if {@link Model} does not + * exists. + */ + public abstract O getObject(); +} diff --git a/src/main/java/com/l2jserver/model/id/CastleID.java b/src/main/java/com/l2jserver/model/id/CastleID.java new file mode 100644 index 000000000..edf86a354 --- /dev/null +++ b/src/main/java/com/l2jserver/model/id/CastleID.java @@ -0,0 +1,38 @@ +/* + * 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.id; + +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; + +/** + * Each {@link Castle} is identified by an {@link ID}. + * + * @author Rogiel + */ +public class CastleID extends ID { + /** + * Creates a new instance + * + * @param id + * the id + */ + @Inject + public CastleID(@Assisted int id) { + super(id); + } +} diff --git a/src/main/java/com/l2jserver/model/id/FortID.java b/src/main/java/com/l2jserver/model/id/FortID.java new file mode 100644 index 000000000..766556f4b --- /dev/null +++ b/src/main/java/com/l2jserver/model/id/FortID.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.id; + +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import com.l2jserver.model.game.Fort; + +/** + * Each {@link Fort} is identified by an {@link ID}. + * + * @author Rogiel + */ +public class FortID extends AbstractModelID { + /** + * Creates a new instance + * + * @param id + * the id + */ + @Inject + public FortID(@Assisted int id) { + super(id); + } + + @Override + public Fort getObject() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/main/java/com/l2jserver/model/id/factory/CastleIDFactory.java b/src/main/java/com/l2jserver/model/id/factory/CastleIDFactory.java new file mode 100644 index 000000000..36576831b --- /dev/null +++ b/src/main/java/com/l2jserver/model/id/factory/CastleIDFactory.java @@ -0,0 +1,27 @@ +/* + * 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.id.factory; + +import com.l2jserver.model.id.CastleID; + +/** + * Creates a new {@link CastleID} + * + * @author Rogiel + */ +public interface CastleIDFactory extends IDFactory { +} diff --git a/src/main/java/com/l2jserver/model/id/factory/FortIDFactory.java b/src/main/java/com/l2jserver/model/id/factory/FortIDFactory.java new file mode 100644 index 000000000..6769a1ec0 --- /dev/null +++ b/src/main/java/com/l2jserver/model/id/factory/FortIDFactory.java @@ -0,0 +1,27 @@ +/* + * 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.id.factory; + +import com.l2jserver.model.id.FortID; + +/** + * Creates a new {@link FortID} + * + * @author Rogiel + */ +public interface FortIDFactory extends IDFactory { +} diff --git a/src/main/java/com/l2jserver/model/id/factory/IDFactoryModule.java b/src/main/java/com/l2jserver/model/id/factory/IDFactoryModule.java index 65e3ac373..4ae180b46 100644 --- a/src/main/java/com/l2jserver/model/id/factory/IDFactoryModule.java +++ b/src/main/java/com/l2jserver/model/id/factory/IDFactoryModule.java @@ -43,9 +43,6 @@ public class IDFactoryModule extends AbstractModule { bind(IDAllocator.class).to(BitSetIDAllocator.class) .in(Scopes.SINGLETON); - // ACCOUNT ID - install(new FactoryModuleBuilder().build(AccountIDFactory.class)); - // OBJECT IDS bind(CharacterIDFactory.class).in(Scopes.SINGLETON); install(new FactoryModuleBuilder().build(CharacterIDGuiceFactory.class)); @@ -59,6 +56,10 @@ public class IDFactoryModule extends AbstractModule { // bind(PetIDFactory.class).in(Scopes.SINGLETON); // install(new FactoryModuleBuilder().build(PetIDGuiceFactory.class)); + // MISC OBJECTS + install(new FactoryModuleBuilder().build(AccountIDFactory.class)); + install(new FactoryModuleBuilder().build(FortIDFactory.class)); + // TEMPLATE IDS install(new FactoryModuleBuilder().build(ItemTemplateIDFactory.class)); install(new FactoryModuleBuilder().build(SkillTemplateIDFactory.class)); diff --git a/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java b/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java index dedea3a2a..0ffc8500b 100644 --- a/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java +++ b/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java @@ -16,11 +16,22 @@ */ package com.l2jserver.model.template.item; +import java.util.Map; +import java.util.Map.Entry; + import com.l2jserver.model.id.template.ItemTemplateID; import com.l2jserver.model.template.ItemTemplate; import com.l2jserver.model.template.capability.Attackable; import com.l2jserver.model.world.Item; import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll; +import com.l2jserver.util.calculator.Calculator; +import com.l2jserver.util.calculator.DivisionOperation; +import com.l2jserver.util.calculator.MultiplicationOperation; +import com.l2jserver.util.calculator.Operation; +import com.l2jserver.util.calculator.SetOperation; +import com.l2jserver.util.calculator.SubtractOperation; +import com.l2jserver.util.calculator.SumOperation; +import com.l2jserver.util.factory.CollectionFactory; /** * Template for Weapon {@link Item} @@ -28,29 +39,83 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll * @author Rogiel */ public abstract class WeaponTemplate extends ItemTemplate implements Attackable { + /** + * The paperldoll slot used by this weapon + */ protected InventoryPaperdoll paperdoll = null; + /** + * The weapon type + */ protected WeaponType type; + /** + * The weapon type enum + * + * @author Rogiel + */ 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; } + /** + * The weapon's attributes + */ protected final WeaponAttribute attribute = new WeaponAttribute(); + /** + * This weapon random damage + */ protected int randomDamage = 0; + /** + * This weapon attack range + */ protected int attackRange = 0; + /** + * Unknown! + */ protected int[] damageRange = new int[] {}; + /** + * Number of soulshots used per attack + */ protected int soulshots = 0; + /** + * Number of spirithots used per cast + */ protected int spiritshots = 0; - protected int crystals; + /** + * The crystal count for this weapon + */ + protected int crystals = 0; + /** + * This weapon crystal type + */ protected CrystalType crystal; + /** + * Enum containing all crystal types possible + * + * @author Rogiel + */ public enum CrystalType { GRADE_A, GRADE_B, GRADE_C, GRADE_D; } + /** + * Creates a new instance. All arguments are required! + * + * @param id + * the template id + * @param icon + * the item icon + * @param material + * the item material + * @param paperdoll + * the paperdoll slot + * @param type + * the weapon type + */ public WeaponTemplate(ItemTemplateID id, String icon, ItemMaterial material, InventoryPaperdoll paperdoll, WeaponType type) { super(id, icon, material); @@ -58,18 +123,152 @@ public abstract class WeaponTemplate extends ItemTemplate implements Attackable this.type = type; } + /** + * Append all operation for this weapon + * + * @param type + * the attribute type + * @param calc + * the calculator + */ + public void calculator(WeaponAttributeType type, Calculator calc) { + attribute.calculator(type, calc); + } + + /** + * Attribute types for weapons + * + * @author Rogiel + */ public enum WeaponAttributeType { PHYSICAL_ATTACK, MAGICAL_ATTACK, R_CRITICAL, PHYSICAL_ATTACK_SPEED; } + /** + * This class handles the Weapon attributes an can add operations to the + * calculator + * + * @author Rogiel + */ public class WeaponAttribute { - public void add(WeaponAttributeType type, int order, int value) { + private final Map>> operations = CollectionFactory + .newMap(null, null); + + /** + * Sets the result of an calculator + * + * @param type + * the attribute type + * @param order + * the calculation order + * @param value + * the value to set + */ + public void set(WeaponAttributeType type, int order, double value) { + getMap(type).put(order, new SetOperation(value)); } - public void set(WeaponAttributeType type, int order, int 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(WeaponAttributeType type, int order, double value) { + getMap(type).put(order, new SumOperation(value)); } - public void enchant(WeaponAttributeType type, int order, int 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(WeaponAttributeType type, int order, double value) { + getMap(type).put(order, new SubtractOperation(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(WeaponAttributeType type, int order, double value) { + getMap(type).put(order, new MultiplicationOperation(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(WeaponAttributeType type, int order, double value) { + getMap(type).put(order, new DivisionOperation(value)); + } + + /** + * Performs an enchant operation. Note that this is not implemented yet! + * + * @param type + * the attribute type + * @param order + * the calculation order + * @param value + * TODO + */ + public void enchant(WeaponAttributeType type, int order, double value) { + // TODO enchant operation for weapon + } + + /** + * Returns the Order-Operation map for type + * + * @param type + * the type + * @return the order-operation map + */ + private Map> getMap(WeaponAttributeType type) { + Map> map = operations.get(type); + if (map == null) { + map = CollectionFactory.newMap(null, null); + operations.put(type, map); + } + return map; + } + + /** + * Creates the calculator object for this weapon + * + * @param type + * the type + * @param calculator + * the calculator + */ + private void calculator(WeaponAttributeType type, Calculator calculator) { + final Map> operations = this.operations + .get(type); + for (final Entry> entry : operations + .entrySet()) { + calculator.add(entry.getKey(), entry.getValue()); + } } } diff --git a/src/main/java/com/l2jserver/model/world/AbstractObject.java b/src/main/java/com/l2jserver/model/world/AbstractObject.java index bc8b4e045..08368349f 100644 --- a/src/main/java/com/l2jserver/model/world/AbstractObject.java +++ b/src/main/java/com/l2jserver/model/world/AbstractObject.java @@ -16,6 +16,7 @@ */ package com.l2jserver.model.world; +import com.l2jserver.model.AbstractModel; import com.l2jserver.model.id.ObjectID; /** @@ -23,46 +24,6 @@ import com.l2jserver.model.id.ObjectID; * * @author Rogiel */ -public abstract class AbstractObject implements WorldObject { - /** - * The {@link ObjectID} - */ - protected ObjectID id; - - @Override - public ObjectID getID() { - return id; - } - - @Override - public void setID(ObjectID id) { - if (this.id != null) - throw new IllegalStateException("ID is already set!"); - this.id = id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AbstractObject other = (AbstractObject) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } +public abstract class AbstractObject extends AbstractModel> + implements WorldObject { } diff --git a/src/main/java/com/l2jserver/routines/GameServerInitializationRoutine.java b/src/main/java/com/l2jserver/routines/GameServerInitializationRoutine.java index f0e24ef67..92db24eb6 100644 --- a/src/main/java/com/l2jserver/routines/GameServerInitializationRoutine.java +++ b/src/main/java/com/l2jserver/routines/GameServerInitializationRoutine.java @@ -18,6 +18,8 @@ package com.l2jserver.routines; import com.google.inject.Inject; import com.l2jserver.service.ServiceManager; +import com.l2jserver.service.blowfish.BlowfishKeygenService; +import com.l2jserver.service.cache.CacheService; import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.game.scripting.ScriptingService; @@ -48,13 +50,14 @@ public class GameServerInitializationRoutine implements Routine { @Override public Boolean call() throws Exception { - // serviceManager.start(LoggingService.class); + serviceManager.start(CacheService.class); serviceManager.start(ConfigurationService.class); serviceManager.start(DatabaseService.class); serviceManager.start(ScriptingService.class); serviceManager.start(TemplateService.class); + serviceManager.start(BlowfishKeygenService.class); serviceManager.start(NetworkService.class); return true; } diff --git a/src/main/java/com/l2jserver/service/admin/AdminService.java b/src/main/java/com/l2jserver/service/admin/AdminService.java new file mode 100644 index 000000000..cdbeb2ecd --- /dev/null +++ b/src/main/java/com/l2jserver/service/admin/AdminService.java @@ -0,0 +1,28 @@ +/* + * 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.service.admin; + +import com.l2jserver.service.Service; + +/** + * This service handles administrators in the server + * + * @author Rogiel + */ +public interface AdminService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/admin/GMService.java b/src/main/java/com/l2jserver/service/admin/GMService.java new file mode 100644 index 000000000..00673b43e --- /dev/null +++ b/src/main/java/com/l2jserver/service/admin/GMService.java @@ -0,0 +1,28 @@ +/* + * 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.service.admin; + +import com.l2jserver.service.Service; + +/** + * This service handles GM in the server + * + * @author Rogiel + */ +public interface GMService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/blowfish/SecureBlowfishKeygenService.java b/src/main/java/com/l2jserver/service/blowfish/SecureBlowfishKeygenService.java index ccf1d11ef..51557bae1 100644 --- a/src/main/java/com/l2jserver/service/blowfish/SecureBlowfishKeygenService.java +++ b/src/main/java/com/l2jserver/service/blowfish/SecureBlowfishKeygenService.java @@ -23,8 +23,18 @@ import com.l2jserver.service.AbstractService; import com.l2jserver.service.ServiceStartException; import com.l2jserver.service.ServiceStopException; +/** + * This implementation of {@link BlowfishKeygenService} generates + * cryptographically safe keys but at the cost of speed. The key generation is + * much slower than on a pseudo-random generator. + * + * @author Rogiel + */ public class SecureBlowfishKeygenService extends AbstractService implements BlowfishKeygenService { + /** + * The random number generator + */ private RandomData random; @Override diff --git a/src/main/java/com/l2jserver/service/cache/EhCacheService.java b/src/main/java/com/l2jserver/service/cache/EhCacheService.java index 7d2a00135..64fd349ca 100644 --- a/src/main/java/com/l2jserver/service/cache/EhCacheService.java +++ b/src/main/java/com/l2jserver/service/cache/EhCacheService.java @@ -84,7 +84,7 @@ public class EhCacheService extends AbstractService implements CacheService { @Override public Cache createCache(String name, int size) { Cache cache = new Cache( - new CacheConfiguration("database-service", size) + new CacheConfiguration(name, size) .memoryStoreEvictionPolicy( MemoryStoreEvictionPolicy.LRU) .overflowToDisk(true).eternal(false) diff --git a/src/main/java/com/l2jserver/service/game/DuelService.java b/src/main/java/com/l2jserver/service/game/DuelService.java new file mode 100644 index 000000000..b8b57ffd3 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/DuelService.java @@ -0,0 +1,28 @@ +/* + * 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.service.game; + +import com.l2jserver.service.Service; + +/** + * This service handles duel events. + * + * @author Rogiel + */ +public interface DuelService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/DuelServiceImpl.java b/src/main/java/com/l2jserver/service/game/DuelServiceImpl.java new file mode 100644 index 000000000..1c2b62c49 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/DuelServiceImpl.java @@ -0,0 +1,28 @@ +/* + * 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.service.game; + +import com.l2jserver.service.AbstractService; + +/** + * Default implementation for {@link DuelService} + * + * @author Rogiel + */ +public class DuelServiceImpl extends AbstractService implements DuelService { + +} diff --git a/src/main/java/com/l2jserver/service/game/GameTimeService.java b/src/main/java/com/l2jserver/service/game/GameTimeService.java new file mode 100644 index 000000000..e58cb8309 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/GameTimeService.java @@ -0,0 +1,33 @@ +/* + * 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.service.game; + +import com.l2jserver.service.Service; + +/** + * This service is responsible for managing the time in-game world. + * + * @author Rogiel + */ +public interface GameTimeService extends Service { + /** + * Returns the in-game time + * + * @return the game time + */ + int getGameTime(); +} diff --git a/src/main/java/com/l2jserver/service/game/GameTimeServiceImpl.java b/src/main/java/com/l2jserver/service/game/GameTimeServiceImpl.java new file mode 100644 index 000000000..8bd6ab0dd --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/GameTimeServiceImpl.java @@ -0,0 +1,33 @@ +/* + * 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.service.game; + +import com.l2jserver.service.AbstractService; + +/** + * Default implementation for {@link GameTimeService} + * + * @author Rogiel + */ +public class GameTimeServiceImpl extends AbstractService implements + GameTimeService { + @Override + public int getGameTime() { + //TODO implement this! + return (int) (System.currentTimeMillis() / 1000); + } +} diff --git a/src/main/java/com/l2jserver/service/game/PKService.java b/src/main/java/com/l2jserver/service/game/PKService.java new file mode 100644 index 000000000..b62cdf507 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/PKService.java @@ -0,0 +1,28 @@ +/* + * 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.service.game; + +import com.l2jserver.service.Service; + +/** + * This service handles PK events. + * + * @author Rogiel + */ +public interface PKService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/PVPService.java b/src/main/java/com/l2jserver/service/game/PVPService.java new file mode 100644 index 000000000..5dcc8e4ec --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/PVPService.java @@ -0,0 +1,28 @@ +/* + * 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.service.game; + +import com.l2jserver.service.Service; + +/** + * This service handles PVP battles. + * + * @author Rogiel + */ +public interface PVPService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/SpawnService.java b/src/main/java/com/l2jserver/service/game/SpawnService.java new file mode 100644 index 000000000..1ce0c4ec2 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/SpawnService.java @@ -0,0 +1,51 @@ +/* + * 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.service.game; + +import com.l2jserver.model.world.capability.Spawnable; +import com.l2jserver.service.Service; + +/** + * This service is responsible for spawning monsters, npcs and players. + * + * @author Rogiel + */ +public interface SpawnService extends Service { + /** + * Spawns an object in the world + * + * @param spawnable + * the spawnable object + */ + void spawn(Spawnable spawnable); + + /** + * Schedules an {@link Spawnable} object to be respawn in a certain time. + * + * @param spawnable + * the spawnable object + */ + void scheduleRespawn(Spawnable spawnable); + + /** + * Unspawns an object from the world + * + * @param spawnable + * the spawnable object + */ + void unspawn(Spawnable spawnable); +} diff --git a/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java b/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java new file mode 100644 index 000000000..e60c9b308 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.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.service.game; + +import com.l2jserver.model.world.capability.Spawnable; +import com.l2jserver.service.AbstractService; + +/** + * Default implementation for {@link SpawnService} + * + * @author Rogiel + */ +public class SpawnServiceImpl extends AbstractService implements SpawnService { + @Override + public void spawn(Spawnable spawnable) { + // TODO Auto-generated method stub + + } + + @Override + public void scheduleRespawn(Spawnable spawnable) { + // TODO Auto-generated method stub + + } + + @Override + public void unspawn(Spawnable spawnable) { + // TODO Auto-generated method stub + + } +} diff --git a/src/main/java/com/l2jserver/service/game/castle/CastleService.java b/src/main/java/com/l2jserver/service/game/castle/CastleService.java new file mode 100644 index 000000000..8ec50506a --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/castle/CastleService.java @@ -0,0 +1,28 @@ +/* + * 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.service.game.castle; + +import com.l2jserver.service.Service; + +/** + * This service is responsible for managing {@link Castle castles}. + * + * @author Rogiel + */ +public interface CastleService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/castle/SiegeService.java b/src/main/java/com/l2jserver/service/game/castle/SiegeService.java new file mode 100644 index 000000000..3a29df53d --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/castle/SiegeService.java @@ -0,0 +1,30 @@ +/* + * 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.service.game.castle; + +import com.l2jserver.service.Service; + +/** + * This service is responsible for keeping a track on siege events. Once a siege + * has begun it will perform all operations that need to be executed during a + * siege. It will also reschedule the next one. + * + * @author Rogiel + */ +public interface SiegeService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/chat/ChatService.java b/src/main/java/com/l2jserver/service/game/chat/ChatService.java new file mode 100644 index 000000000..56f32af06 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/ChatService.java @@ -0,0 +1,62 @@ +/* + * 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.service.game.chat; + +import com.l2jserver.model.id.object.CharacterID; +import com.l2jserver.model.id.object.ClanID; +import com.l2jserver.model.world.L2Character; +import com.l2jserver.service.Service; +import com.l2jserver.service.game.chat.channel.ChatChannel; +import com.l2jserver.service.game.chat.channel.PrivateChatChannel; +import com.l2jserver.service.game.chat.channel.PublicChatChannel; + +/** + * This service chatting in the server + * + * @author Rogiel + */ +public interface ChatService extends Service { + /** + * @return the global {@link ChatChannel} + */ + PublicChatChannel getGlobalChannel(); + + /** + * @param character + * the character in the region + * @return the global {@link ChatChannel} + */ + PublicChatChannel getRegionChannel(L2Character character); + + /** + * Get an private {@link ChatChannel} to {@link CharacterID} + * + * @param character + * the target character + * @return the private {@link ChatChannel} + */ + PrivateChatChannel getChannel(CharacterID character); + + /** + * @param clan + * the clan + * @return the public clan {@link ChatChannel} + */ + PublicChatChannel getChannel(ClanID clan); + + // TODO party chat +} diff --git a/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java b/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java new file mode 100644 index 000000000..2d8dbe15a --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java @@ -0,0 +1,173 @@ +/* + * 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.service.game.chat; + +import java.util.Map; +import java.util.Set; + +import com.l2jserver.model.id.object.CharacterID; +import com.l2jserver.model.id.object.ClanID; +import com.l2jserver.model.world.Clan; +import com.l2jserver.model.world.L2Character; +import com.l2jserver.service.AbstractService; +import com.l2jserver.service.ServiceStartException; +import com.l2jserver.service.game.chat.channel.ChatChannel; +import com.l2jserver.service.game.chat.channel.ChatChannelListener; +import com.l2jserver.service.game.chat.channel.PrivateChatChannel; +import com.l2jserver.service.game.chat.channel.PublicChatChannel; +import com.l2jserver.util.factory.CollectionFactory; + +/** + * Default {@link ChatService} implementation + * + * @author Rogiel + */ +public class SimpleChatService extends AbstractService implements ChatService { + /** + * The global chat channel + */ + private GlobalChatChannelImpl global; + /** + * The list of private chat channels + */ + // TODO remove private chats from disconnected characters. Maybe plugging it + // in the NetworkService? + private Map privateChannels; + /** + * The list of clan chat channels + */ + private Map clanChannels; + + @Override + public void start() throws ServiceStartException { + this.global = new GlobalChatChannelImpl(); + this.privateChannels = CollectionFactory.newMap(null, null); + this.clanChannels = CollectionFactory.newMap(null, null); + } + + @Override + public PublicChatChannel getGlobalChannel() { + return global; + } + + @Override + public PublicChatChannel getRegionChannel(L2Character character) { + // TODO Region chat channels + return null; + } + + @Override + public PrivateChatChannel getChannel(CharacterID character) { + PrivateChatChannelImpl channel = privateChannels.get(character); + if (channel == null) { + channel = new PrivateChatChannelImpl(character); + privateChannels.put(character, channel); + } + return channel; + } + + @Override + public PublicChatChannel getChannel(ClanID clan) { + ClanChatChannelImpl channel = clanChannels.get(clan); + if (channel == null) { + channel = new ClanChatChannelImpl(clan); + clanChannels.put(clan, channel); + } + return channel; + } + + /** + * {@link ChatChannel} abstract implementation + * + * @author Rogiel + */ + private abstract class ChatChannelImpl implements ChatChannel { + /** + * The list of all listeners on this channel + */ + protected final Set listeners = CollectionFactory + .newSet(null); + + @Override + public void send(CharacterID sender, String message) { + for (final ChatChannelListener listener : listeners) { + listener.onMessage(this, sender, message); + } + } + + @Override + public void addChatChannelListener(ChatChannelListener listener) { + listeners.add(listener); + } + + @Override + public void removeChatChannelListener(ChatChannelListener listener) { + listeners.remove(listener); + } + } + + /** + * {@link PrivateChatChannel} implementation + * + * @author Rogiel + */ + private class PrivateChatChannelImpl extends ChatChannelImpl implements + PrivateChatChannel { + private final CharacterID character; + + public PrivateChatChannelImpl(CharacterID character) { + this.character = character; + } + + @Override + public CharacterID getTarget() { + return character; + } + } + + /** + * Global {@link PublicChatChannel} implemenetation + * + * @author Rogiel + */ + private class GlobalChatChannelImpl extends ChatChannelImpl implements + PublicChatChannel { + } + + /** + * {@link PublicChatChannel} implemenetation for {@link Clan clans} + * + * @author Rogiel + */ + private class ClanChatChannelImpl extends ChatChannelImpl implements + PublicChatChannel { + /** + * The clan ID + */ + @SuppressWarnings("unused") + private final ClanID clanID; + + /** + * Creates a new instance + * + * @param clanID + */ + public ClanChatChannelImpl(ClanID clanID) { + this.clanID = clanID; + } + } +} diff --git a/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java b/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java new file mode 100644 index 000000000..f5ff1b742 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannel.java @@ -0,0 +1,57 @@ +/* + * 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.service.game.chat.channel; + +import com.l2jserver.model.id.object.CharacterID; + +/** + * The {@link ChatChannel} object is used to send messages to a channel. + *

+ * Note that this is a base for all types of channel. + * + * @author Rogiel + * @see PrivateChatChannel + * @see PublicChatChannel + */ +public interface ChatChannel { + /** + * Sends a message to this channel + * + * @param sender + * the character sending the message + * @param message + * the message to be sent + */ + void send(CharacterID sender, String message); + + /** + * Adds a {@link ChatChannelListener} that will be notified once a message + * has been received. + * + * @param listener + * the listener + */ + void addChatChannelListener(ChatChannelListener listener); + + /** + * Removes a {@link ChatChannelListener}. + * + * @param listener + * the listener + */ + void removeChatChannelListener(ChatChannelListener listener); +} diff --git a/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannelListener.java b/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannelListener.java new file mode 100644 index 000000000..a33cb9ca7 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/channel/ChatChannelListener.java @@ -0,0 +1,39 @@ +/* + * 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.service.game.chat.channel; + +import com.l2jserver.model.id.object.CharacterID; + +/** + * This listener is used to received notifications once a new message is sent to + * an given {@link ChatChannel}. + * + * @author Rogiel + */ +public interface ChatChannelListener { + /** + * Notification of a new message received + * + * @param channel + * the chat channel + * @param source + * the character sending this message + * @param message + * the message + */ + void onMessage(ChatChannel channel, CharacterID source, String message); +} diff --git a/src/main/java/com/l2jserver/service/game/chat/channel/PrivateChatChannel.java b/src/main/java/com/l2jserver/service/game/chat/channel/PrivateChatChannel.java new file mode 100644 index 000000000..2f62d125d --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/channel/PrivateChatChannel.java @@ -0,0 +1,34 @@ +/* + * 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.service.game.chat.channel; + +import com.l2jserver.model.id.object.CharacterID; + +/** + * An private {@link ChatChannel}. Please note that the concept of "private" + * does not mean it requires a password or something like that to join, but the + * message is only broadcasted to a single character (i.e. private messages). + * The target can be retrieved by {@link #getTarget()}. + * + * @author Rogiel + */ +public interface PrivateChatChannel extends ChatChannel { + /** + * @return the target of this private chat channel. + */ + CharacterID getTarget(); +} diff --git a/src/main/java/com/l2jserver/service/game/chat/channel/PublicChatChannel.java b/src/main/java/com/l2jserver/service/game/chat/channel/PublicChatChannel.java new file mode 100644 index 000000000..0a669951c --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/chat/channel/PublicChatChannel.java @@ -0,0 +1,27 @@ +/* + * 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.service.game.chat.channel; + +/** + * An public {@link ChatChannel}. Please note that the concept of "public" does + * not mean it is available to anyone, but there are more than 2 player chatting + * (i.e. clan, global, region, etc...) + * + * @author Rogiel + */ +public interface PublicChatChannel extends ChatChannel { +} diff --git a/src/main/java/com/l2jserver/service/game/clan/ClanService.java b/src/main/java/com/l2jserver/service/game/clan/ClanService.java new file mode 100644 index 000000000..7c7c01833 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/clan/ClanService.java @@ -0,0 +1,29 @@ +/* + * 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.service.game.clan; + +import com.l2jserver.model.world.Clan; +import com.l2jserver.service.Service; + +/** + * This service is responsible for managing {@link Clan clans}. + * + * @author Rogiel + */ +public interface ClanService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/clan/FortService.java b/src/main/java/com/l2jserver/service/game/clan/FortService.java new file mode 100644 index 000000000..553b7e639 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/clan/FortService.java @@ -0,0 +1,28 @@ +/* + * 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.service.game.clan; + +import com.l2jserver.service.Service; + +/** + * This service manages Fort instances. + * + * @author Rogiel + */ +public interface FortService extends Service { + +} diff --git a/src/main/java/com/l2jserver/service/game/region/Region.java b/src/main/java/com/l2jserver/service/game/region/Region.java new file mode 100644 index 000000000..f50931014 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/region/Region.java @@ -0,0 +1,25 @@ +/* + * 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.service.game.region; + +/** + * @author Rogiel + * + */ +public interface Region { + +} diff --git a/src/main/java/com/l2jserver/service/game/region/RegionService.java b/src/main/java/com/l2jserver/service/game/region/RegionService.java new file mode 100644 index 000000000..ecd0e0d64 --- /dev/null +++ b/src/main/java/com/l2jserver/service/game/region/RegionService.java @@ -0,0 +1,29 @@ +/* + * 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.service.game.region; + +import com.l2jserver.model.world.L2Character; +import com.l2jserver.service.Service; + +/** + * This service manages Lineage II Regions + * + * @author Rogiel + */ +public interface RegionService extends Service { + Region getRegion(L2Character character); +} diff --git a/src/main/java/com/l2jserver/util/BufferUtils.java b/src/main/java/com/l2jserver/util/BufferUtils.java index e98b33401..8c38268ed 100644 --- a/src/main/java/com/l2jserver/util/BufferUtils.java +++ b/src/main/java/com/l2jserver/util/BufferUtils.java @@ -52,7 +52,7 @@ public class BufferUtils { * the string */ public static final void writeString(ChannelBuffer buffer, String str) { - if (str != null) { + if (str != null && str.length() > 0) { final int len = str.length(); for (int i = 0; i < len; i++) { buffer.writeChar(str.charAt(i)); diff --git a/src/main/java/com/l2jserver/util/calculator/Calculator.java b/src/main/java/com/l2jserver/util/calculator/Calculator.java new file mode 100644 index 000000000..c63ee3b03 --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/Calculator.java @@ -0,0 +1,65 @@ +/* + * 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.util.calculator; + +import java.util.List; + +import com.l2jserver.util.factory.CollectionFactory; + +/** + * An calculator is used to compute data and outputs its result. Note also, that + * an calculator is also an operation, that way you can nest calculators. + * + * @author Rogiel + */ +public class Calculator implements Operation { + /** + * List of operations in this calculator + */ + private final List> operations = CollectionFactory + .newList(null); + + /** + * Adds a new operation to this calculator. Operations with the same order + * are replaced. + * + * @param order + * the operation order, starting at 0. + * @param operation + * the operation + */ + public void add(int order, Operation operation) { + operations.add(order, operation); + } + + /** + * Computes the result and output it + * + * @return the computed value + */ + public double compute() { + return perform(0.00); + } + + @Override + public Double perform(Double result) { + for (final Operation operation : operations) { + result = operation.perform(result); + } + return result; + } +} \ No newline at end of file diff --git a/src/main/java/com/l2jserver/util/calculator/DivisionOperation.java b/src/main/java/com/l2jserver/util/calculator/DivisionOperation.java new file mode 100644 index 000000000..68748374e --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/DivisionOperation.java @@ -0,0 +1,39 @@ +/* + * 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.util.calculator; + +/** + * This operation performs a division:

chain value / + * value
+ * + * @author Rogiel + */ +public class DivisionOperation implements Operation { + /** + * The value + */ + private final double value; + + public DivisionOperation(double value) { + this.value = value; + } + + @Override + public Double perform(Double value) { + return value / this.value; + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/ModulusOperation.java b/src/main/java/com/l2jserver/util/calculator/ModulusOperation.java new file mode 100644 index 000000000..2a11fbc81 --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/ModulusOperation.java @@ -0,0 +1,32 @@ +/* + * 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.util.calculator; + +/** + * This operation performs an modulus:
|chain value| + *
+ * + * @author Rogiel + */ +public class ModulusOperation implements Operation { + @Override + public Double perform(Double value) { + if (value < 0) + return value * -1; + return value; + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/MultiplicationOperation.java b/src/main/java/com/l2jserver/util/calculator/MultiplicationOperation.java new file mode 100644 index 000000000..fa747dab7 --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/MultiplicationOperation.java @@ -0,0 +1,39 @@ +/* + * 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.util.calculator; + +/** + * This operation performs an multiplication:
chain value * + * value
+ * + * @author Rogiel + */ +public class MultiplicationOperation implements Operation { + /** + * The value + */ + private final double value; + + public MultiplicationOperation(double value) { + this.value = value; + } + + @Override + public Double perform(Double value) { + return value * this.value; + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/NegateOperation.java b/src/main/java/com/l2jserver/util/calculator/NegateOperation.java new file mode 100644 index 000000000..bcfbec3ff --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/NegateOperation.java @@ -0,0 +1,30 @@ +/* + * 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.util.calculator; + +/** + * This operation performs an negate:
-chain value + *
+ * + * @author Rogiel + */ +public class NegateOperation implements Operation { + @Override + public Double perform(Double value) { + return -value; + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/Operation.java b/src/main/java/com/l2jserver/util/calculator/Operation.java new file mode 100644 index 000000000..cff949b32 --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/Operation.java @@ -0,0 +1,31 @@ +/* + * 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.util.calculator; + +/** + * @author Rogiel + */ +public interface Operation { + /** + * Performs the operation in the calculation process + * + * @param value + * the chain input value + * @return the output value + */ + T perform(T value); +} diff --git a/src/main/java/com/l2jserver/util/calculator/PercentOperation.java b/src/main/java/com/l2jserver/util/calculator/PercentOperation.java new file mode 100644 index 000000000..af1e434e0 --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/PercentOperation.java @@ -0,0 +1,32 @@ +/* + * 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.util.calculator; + +/** + * This operation performs a multiplication:
chain value * + * (value / 100)
+ * + * @author Rogiel + */ +public class PercentOperation extends MultiplicationOperation { + /** + * The value + */ + public PercentOperation(double value) { + super(value / 100); + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/RoundOperation.java b/src/main/java/com/l2jserver/util/calculator/RoundOperation.java new file mode 100644 index 000000000..bd0477dff --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/RoundOperation.java @@ -0,0 +1,29 @@ +/* + * 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.util.calculator; + +/** + * This operation performs an rounding in the number. + * + * @author Rogiel + */ +public class RoundOperation implements Operation { + @Override + public Double perform(Double value) { + return (double) Math.round(value); + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/SetOperation.java b/src/main/java/com/l2jserver/util/calculator/SetOperation.java new file mode 100644 index 000000000..2493cd8ba --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/SetOperation.java @@ -0,0 +1,39 @@ +/* + * 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.util.calculator; + +/** + * This operation performs an set. It ignores the input value and return its + * own. + * + * @author Rogiel + */ +public class SetOperation implements Operation { + /** + * The value + */ + private final double value; + + public SetOperation(double value) { + this.value = value; + } + + @Override + public Double perform(Double value) { + return this.value; + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/SubtractOperation.java b/src/main/java/com/l2jserver/util/calculator/SubtractOperation.java new file mode 100644 index 000000000..d3aa9010b --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/SubtractOperation.java @@ -0,0 +1,39 @@ +/* + * 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.util.calculator; + +/** + * This operation performs an subtraction:
chain value - + * value
+ * + * @author Rogiel + */ +public class SubtractOperation implements Operation { + /** + * The value + */ + private final double value; + + public SubtractOperation(double value) { + this.value = value; + } + + @Override + public Double perform(Double value) { + return value - this.value; + } +} diff --git a/src/main/java/com/l2jserver/util/calculator/SumOperation.java b/src/main/java/com/l2jserver/util/calculator/SumOperation.java new file mode 100644 index 000000000..768e6b1b8 --- /dev/null +++ b/src/main/java/com/l2jserver/util/calculator/SumOperation.java @@ -0,0 +1,39 @@ +/* + * 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.util.calculator; + +/** + * This operation performs a sum:
chain value + + * value
+ * + * @author Rogiel + */ +public class SumOperation implements Operation { + /** + * The value + */ + private final double value; + + public SumOperation(double value) { + this.value = value; + } + + @Override + public Double perform(Double value) { + return value + this.value; + } +} diff --git a/src/main/java/com/l2jserver/util/exception/L2Exception.java b/src/main/java/com/l2jserver/util/exception/L2Exception.java new file mode 100644 index 000000000..b841c826f --- /dev/null +++ b/src/main/java/com/l2jserver/util/exception/L2Exception.java @@ -0,0 +1,57 @@ +/* + * 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.util.exception; + +/** + * Base exception for Lineage 2 + * + * @author Rogiel + */ +public class L2Exception extends Exception { + /** + * Default Serial Version UID + */ + private static final long serialVersionUID = 1L; + + /** + * @see Exception#Exception() + */ + public L2Exception() { + super(); + } + + /** + * @see Exception#Exception(String, Throwable) + */ + public L2Exception(String message, Throwable cause) { + super(message, cause); + } + + /** + * @see Exception#Exception(String) + */ + public L2Exception(String message) { + super(message); + } + + /** + * @see Exception#Exception(Throwable) + */ + public L2Exception(Throwable cause) { + super(cause); + } +} diff --git a/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java b/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java new file mode 100644 index 000000000..c13ddfb5c --- /dev/null +++ b/src/test/java/com/l2jserver/util/calculator/CalculatorTest.java @@ -0,0 +1,104 @@ +/* + * 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.util.calculator; + +import junit.framework.Assert; + +import org.junit.Test; + +/** + * @author Rogiel + * + */ +public class CalculatorTest { + @Test + public void testSimple() { + final Calculator calc = new Calculator(); + + calc.add(0, new SetOperation(10)); + calc.add(1, new MultiplicationOperation(2)); + calc.add(2, new SetOperation(30)); + + Assert.assertEquals(30.0, calc.compute()); + } + + @Test + public void testPercent() { + final Calculator calc = new Calculator(); + + calc.add(0, new SetOperation(10)); + calc.add(1, new MultiplicationOperation(2)); + calc.add(2, new PercentOperation(75)); + + Assert.assertEquals(15.0, calc.compute()); + } + + @Test + public void testComplex() { + final Calculator calc = new Calculator(); + + calc.add(0, new SetOperation(10)); + calc.add(1, new MultiplicationOperation(2)); + calc.add(2, new PercentOperation(75)); + calc.add(3, new SumOperation(3)); + calc.add(4, new SubtractOperation(8)); + calc.add(5, new DivisionOperation(2)); + + Assert.assertEquals(5.0, calc.compute()); + } + + @Test + public void testNesting() { + final Calculator calc1 = new Calculator(); + + calc1.add(0, new SetOperation(10)); + calc1.add(1, new MultiplicationOperation(2)); + calc1.add(2, new PercentOperation(75)); + calc1.add(3, new SumOperation(3)); + calc1.add(4, new SubtractOperation(8)); + calc1.add(5, new DivisionOperation(2)); + Assert.assertEquals(5.0, calc1.compute()); + + final Calculator calc2 = new Calculator(); + + calc2.add(0, new MultiplicationOperation(2)); + calc2.add(1, new PercentOperation(75)); + calc2.add(2, new SumOperation(3)); + calc2.add(3, new SubtractOperation(8)); + calc2.add(4, new DivisionOperation(2)); + Assert.assertEquals(-2.5, calc2.compute()); + + final Calculator calc3 = new Calculator(); + calc3.add(0, calc1); + calc3.add(1, calc2); + + Assert.assertEquals(1.25, calc3.compute()); + } + + @Test + public void testRounding() { + final Calculator calc1 = new Calculator(); + + calc1.add(0, new MultiplicationOperation(2)); + calc1.add(1, new PercentOperation(75)); + calc1.add(2, new SumOperation(3)); + calc1.add(3, new SubtractOperation(8.1)); + calc1.add(4, new DivisionOperation(2)); + calc1.add(5, new RoundOperation()); + Assert.assertEquals(-3.0, calc1.compute()); + } +}