diff --git a/l2jserver2-gameserver/data/template/item/1-ShortSword.xml b/l2jserver2-gameserver/data/template/item/1-ShortSword.xml index cd83fecbd..4f5f20638 100644 --- a/l2jserver2-gameserver/data/template/item/1-ShortSword.xml +++ b/l2jserver2-gameserver/data/template/item/1-ShortSword.xml @@ -1,23 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + - Short Sword - STEEL - + xmlns:template="http://schemas.l2jserver2.com/item" id="1" name="Short sword"> + 1 1 - - - 510 - - - 508 - - - 8 - - - 379 - - + icon.etc_adena_i00 + GOLD + diff --git a/l2jserver2-gameserver/data/template/item/2-LongSword.xml b/l2jserver2-gameserver/data/template/item/2-LongSword.xml index c4862cdfc..e4fd4e3cc 100644 --- a/l2jserver2-gameserver/data/template/item/2-LongSword.xml +++ b/l2jserver2-gameserver/data/template/item/2-LongSword.xml @@ -1,7 +1,10 @@ - - Adena - GOLD - + + 1 1 - + icon.etc_adena_i00 + GOLD + + diff --git a/l2jserver2-gameserver/data/template/item/57-Adena.xml b/l2jserver2-gameserver/data/template/item/57-Adena.xml index 3a50f4b66..e0de16cf4 100644 --- a/l2jserver2-gameserver/data/template/item/57-Adena.xml +++ b/l2jserver2-gameserver/data/template/item/57-Adena.xml @@ -1,7 +1,10 @@ - - Adena - GOLD - + + 1 1 - + icon.etc_adena_i00 + GOLD + + diff --git a/l2jserver2-gameserver/distribution/sql/sql/item.sql b/l2jserver2-gameserver/distribution/sql/sql/item.sql index 48d6b3f34..069ba3078 100644 --- a/l2jserver2-gameserver/distribution/sql/sql/item.sql +++ b/l2jserver2-gameserver/distribution/sql/sql/item.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `item_id` int(12) NOT NULL, `template_id` int(10) NOT NULL, `character_id` int(12) DEFAULT NULL, - `location` enum('PAPERDOLL','INVENTORY','WAREHOUSE') DEFAULT NULL, + `location` enum('GROUND','PAPERDOLL','INVENTORY','WAREHOUSE') DEFAULT NULL, `paperdoll` enum('UNDERWEAR','HEAD','HAIR1','HAIR2','NECK','RIGHT_HAND','CHEST','LEFT_HAND','RIGHT_EAR','LEFT_EAR','GLOVES','LEGS','FEET','RIGHT_FINGER','LEFT_FINGER','LEFT_BRACELET','RIGHT_BRACELET','DECORATION_1','DECORATION_2','DECORATION_3','DECORATION_4','DECORATION_5','DECORATION_6','CLOAK,BELT') DEFAULT NULL, `count` int(10) NOT NULL, `coord_x` int(10) DEFAULT NULL, @@ -19,5 +19,5 @@ CREATE TABLE IF NOT EXISTS `item` ( INSERT INTO `item` (`item_id`, `template_id`, `character_id`, `location`, `paperdoll`, `count`, `coord_x`, `coord_y`, `coord_z`) VALUES (268635457, 57, 268437456, 'INVENTORY', NULL, 200000000, NULL, NULL, NULL), -(268635459, 1, 268437456, 'PAPERDOLL', 'RIGHT_HAND', 1, NULL, NULL, NULL), -(268635460, 1, 268437456, 'INVENTORY', NULL, 1, NULL, NULL, NULL); +(268635459, 57, NULL, 'GROUND', NULL, 100, 147459, 24434, -1992), +(268635460, 1, 268437456, 'INVENTORY', NULL, 1, NULL, NULL, NULL); \ No newline at end of file diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java index 6ef003d2b..4b13f743f 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -22,6 +22,7 @@ import com.l2jserver.service.configuration.ConfigurationService; import com.l2jserver.service.database.DatabaseService; import com.l2jserver.service.game.character.CharacterService; import com.l2jserver.service.game.chat.ChatService; +import com.l2jserver.service.game.item.ItemService; import com.l2jserver.service.game.map.pathing.PathingService; import com.l2jserver.service.game.npc.NPCService; import com.l2jserver.service.game.scripting.ScriptingService; @@ -58,6 +59,7 @@ public class L2JGameServerMain { serviceManager.start(ChatService.class); serviceManager.start(NPCService.class); + serviceManager.start(ItemService.class); serviceManager.start(CharacterService.class); serviceManager.start(PathingService.class); diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_ITEM_GROUND.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_ITEM_GROUND.java index 532059a51..1a5d6491e 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_ITEM_GROUND.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_ITEM_GROUND.java @@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import com.l2jserver.game.net.Lineage2Client; import com.l2jserver.game.net.packet.AbstractServerPacket; +import com.l2jserver.model.world.Item; /** * This packet sends an item that is dropped on the ground @@ -32,22 +33,25 @@ public class SM_ITEM_GROUND extends AbstractServerPacket { */ public static final int OPCODE = 0x16; - public SM_ITEM_GROUND() { + private final Item item; + + public SM_ITEM_GROUND(Item item) { super(OPCODE); + this.item = item; } @Override public void write(Lineage2Client conn, ChannelBuffer buffer) { - buffer.writeInt(268437456); // char who dropped - buffer.writeInt(268635461); // item obj id - buffer.writeInt(57); // item template id + buffer.writeInt((item.getOwnerID() != null ? item.getOwnerID().getID() : 0)); // char who dropped + buffer.writeInt(item.getID().getID()); // item obj id + buffer.writeInt(item.getTemplateID().getID()); // item template id - buffer.writeInt(-84341); // x - buffer.writeInt(244623); // y - buffer.writeInt(-3728); // z + buffer.writeInt(item.getPoint().getX()); // x + buffer.writeInt(item.getPoint().getY()); // y + buffer.writeInt(item.getPoint().getZ()); // z // only show item count if it is a stackable item buffer.writeInt(0x01); // show count - buffer.writeLong(4001); // count + buffer.writeLong(item.getCount()); // count buffer.writeInt(1); // unknown } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java index 478329d93..c366458c0 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java @@ -16,6 +16,8 @@ */ package com.l2jserver.model.dao; +import java.util.List; + import com.l2jserver.model.id.object.ItemID; import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; @@ -37,4 +39,6 @@ public interface ItemDAO extends DataAccessObject, Cacheable { * @return amount of items loaded */ int loadInventory(L2Character character); + + List loadDroppedItems(); } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java index 2dc3d4a00..b7dd8fd21 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java @@ -106,6 +106,10 @@ public class CharacterInventory implements Iterable { * @author Rogiel */ public enum InventoryLocation { + /** + * The item is dropped on the ground + */ + GROUND, /** * The item is equipped */ diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java index 938588661..6b503e431 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/ServiceModule.java @@ -41,6 +41,8 @@ import com.l2jserver.service.game.chat.ChatLoggingService; import com.l2jserver.service.game.chat.ChatService; import com.l2jserver.service.game.chat.DatabaseChatLoggingService; import com.l2jserver.service.game.chat.SimpleChatService; +import com.l2jserver.service.game.item.ItemService; +import com.l2jserver.service.game.item.ItemServiceImpl; import com.l2jserver.service.game.map.pathing.MapperPathingService; import com.l2jserver.service.game.map.pathing.PathingService; import com.l2jserver.service.game.npc.NPCService; @@ -80,8 +82,8 @@ public class ServiceModule extends AbstractModule { bind(VFSService.class).to(Java7VFSService.class).in(Scopes.SINGLETON); bind(ThreadService.class).to(ThreadServiceImpl.class).in( Scopes.SINGLETON); - bind(ConfigurationService.class).to(XMLConfigurationService.class) - .in(Scopes.SINGLETON); + bind(ConfigurationService.class).to(XMLConfigurationService.class).in( + Scopes.SINGLETON); bind(CacheService.class).to(SoftCacheService.class) .in(Scopes.SINGLETON); @@ -119,6 +121,7 @@ public class ServiceModule extends AbstractModule { bind(AttackService.class).to(AttackServiceImpl.class).in( Scopes.SINGLETON); bind(NPCService.class).to(NPCServiceImpl.class).in(Scopes.SINGLETON); + bind(ItemService.class).to(ItemServiceImpl.class).in(Scopes.SINGLETON); bind(WorldService.class).to(WorldServiceImpl.class) .in(Scopes.SINGLETON); diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java index 3eb3f3784..c0b1c8173 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java @@ -21,6 +21,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.inject.Inject; import com.l2jserver.model.dao.ItemDAO; import com.l2jserver.model.id.object.CharacterID; @@ -50,6 +53,11 @@ import com.l2jserver.util.geometry.Coordinate; */ public abstract class JDBCItemDAO extends AbstractJDBCDAO implements ItemDAO { + /** + * The logger + */ + private final Logger log = LoggerFactory.getLogger(this.getClass()); + /** * The {@link ItemID} factory */ @@ -120,6 +128,10 @@ public abstract class JDBCItemDAO extends AbstractJDBCDAO final ItemTemplateID templateId = templateIdFactory.resolveID(rs .getInt(TEMPLATE_ID)); final ItemTemplate template = templateId.getTemplate(); + if (template == null) { + log.warn("No template found for {} while loading {}", templateId, id); + return null; + } final Item item = template.create(); item.setID(id); @@ -188,6 +200,27 @@ public abstract class JDBCItemDAO extends AbstractJDBCDAO return items.size(); } + @Override + public List loadDroppedItems() { + return database.query(new SelectListQuery() { + @Override + protected String query() { + return "SELECT * FROM `" + TABLE + "` WHERE `" + LOCATION + + "` = ?"; + } + + @Override + protected void parametize(PreparedStatement st) throws SQLException { + st.setString(1, InventoryLocation.GROUND.name()); + } + + @Override + protected Mapper mapper() { + return mapper; + } + }); + } + @Override public List selectIDs() { return database.query(new SelectListQuery() { diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java index 14d2681e4..07e3bf2b9 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/character/CharacterServiceImpl.java @@ -27,7 +27,6 @@ import com.l2jserver.game.net.packet.server.SM_CHAR_INFO; import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_EXTRA; import com.l2jserver.game.net.packet.server.SM_CHAR_INVENTORY; import com.l2jserver.game.net.packet.server.SM_CHAT; -import com.l2jserver.game.net.packet.server.SM_ITEM_GROUND; import com.l2jserver.game.net.packet.server.SM_MOVE; import com.l2jserver.game.net.packet.server.SM_MOVE_TYPE; import com.l2jserver.game.net.packet.server.SM_TARGET; @@ -336,8 +335,6 @@ public class CharacterServiceImpl extends AbstractService implements // start broadcasting -- will broadcast all nearby objects broadcastService.broadcast(conn); - conn.write(new SM_ITEM_GROUND()); - // characters start in run mode try { run(character); diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemService.java new file mode 100644 index 000000000..e5eada574 --- /dev/null +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemService.java @@ -0,0 +1,28 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 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. + * + * l2jserver2 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 l2jserver2. If not, see . + */ +package com.l2jserver.service.game.item; + +import com.l2jserver.service.Service; + +/** + * This service handles item management. Drop and pick up, create and destroy. + * + * @author Rogiel + */ +public interface ItemService extends Service { + +} diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java new file mode 100644 index 000000000..49a30855d --- /dev/null +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java @@ -0,0 +1,82 @@ +/* + * This file is part of l2jserver2 . + * + * l2jserver2 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. + * + * l2jserver2 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 l2jserver2. If not, see . + */ +package com.l2jserver.service.game.item; + +import java.util.List; + +import com.google.inject.Inject; +import com.l2jserver.model.dao.ItemDAO; +import com.l2jserver.model.world.Item; +import com.l2jserver.service.AbstractService; +import com.l2jserver.service.AbstractService.Depends; +import com.l2jserver.service.ServiceStartException; +import com.l2jserver.service.ServiceStopException; +import com.l2jserver.service.database.DatabaseService; +import com.l2jserver.service.game.spawn.AlreadySpawnedServiceException; +import com.l2jserver.service.game.spawn.SpawnPointNotFoundServiceException; +import com.l2jserver.service.game.spawn.SpawnService; + +/** + * @author Rogiel + */ +@Depends({ SpawnService.class, DatabaseService.class }) +public class ItemServiceImpl extends AbstractService implements ItemService { + /** + * The item DAO + */ + private final ItemDAO itemDao; + /** + * The Spawn Service + */ + private final SpawnService spawnService; + + /** + * All items on the ground persisted to the database + */ + private List items; + + /** + * @param itemDao + * the item DAO + * @param spawnService + * the spawn service + */ + @Inject + private ItemServiceImpl(ItemDAO itemDao, SpawnService spawnService) { + this.itemDao = itemDao; + this.spawnService = spawnService; + } + + @Override + protected void doStart() throws ServiceStartException { + items = itemDao.loadDroppedItems(); + try { + for (final Item item : items) { + spawnService.spawn(item, null); + } + } catch (SpawnPointNotFoundServiceException e) { + throw new ServiceStartException(e); + } catch (AlreadySpawnedServiceException e) { + throw new ServiceStartException(e); + } + } + + @Override + protected void doStop() throws ServiceStopException { + super.doStop(); + } +} diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java index 9691668f1..85c8d1e3b 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/template/XMLTemplateService.java @@ -237,9 +237,6 @@ public class XMLTemplateService extends AbstractService implements BasicFileAttributes attrs) throws IOException { if (!file.toString().endsWith(".xml")) return FileVisitResult.CONTINUE; - // FIXME remove hard coded skip of item template loading - if (file.toString().contains("/item/")) - return FileVisitResult.CONTINUE; // FIXME remove hard coded skip of zone template loading if (file.toString().contains("zones.xml")) return FileVisitResult.CONTINUE; diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java index 642d7be45..b8ce280e8 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListUpdateFilter.java @@ -29,11 +29,6 @@ import com.l2jserver.util.geometry.Point3D; * @author Rogiel */ public class KnownListUpdateFilter extends AndFilter { - /** - * Constant declaring the range in which knownlist will be scanned - */ - public static final int KNOWNLIST_RANGE = 2000; - /** * Creates a new instance. * @@ -48,6 +43,6 @@ public class KnownListUpdateFilter extends AndFilter { */ public KnownListUpdateFilter(PositionableObject object, Point3D old) { super(new KnownListFilter(object), new NotFilter( - new RangePointFilter(old, KNOWNLIST_RANGE))); + new RangePointFilter(old, KnownListFilter.KNOWNLIST_RANGE))); } } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java index 69d284485..70a320be3 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java @@ -26,11 +26,13 @@ import com.l2jserver.game.net.SystemMessage; import com.l2jserver.game.net.packet.server.SM_ATTACK; import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_BROADCAST; import com.l2jserver.game.net.packet.server.SM_DIE; +import com.l2jserver.game.net.packet.server.SM_ITEM_GROUND; import com.l2jserver.game.net.packet.server.SM_MOVE; import com.l2jserver.game.net.packet.server.SM_MOVE_TYPE; import com.l2jserver.game.net.packet.server.SM_NPC_INFO; import com.l2jserver.game.net.packet.server.SM_OBJECT_REMOVE; import com.l2jserver.model.id.object.CharacterID; +import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.PositionableObject; @@ -218,6 +220,8 @@ public class BroadcastServiceImpl extends AbstractService implements conn.write(new SM_NPC_INFO((NPC) o)); } else if (o instanceof L2Character) { conn.write(new SM_CHAR_INFO_BROADCAST((L2Character) o)); + } else if (o instanceof Item) { + conn.write(new SM_ITEM_GROUND((Item) o)); } } }
@@ -48,6 +43,6 @@ public class KnownListUpdateFilter extends AndFilter { */ public KnownListUpdateFilter(PositionableObject object, Point3D old) { super(new KnownListFilter(object), new NotFilter( - new RangePointFilter(old, KNOWNLIST_RANGE))); + new RangePointFilter(old, KnownListFilter.KNOWNLIST_RANGE))); } } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java index 69d284485..70a320be3 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/broadcast/BroadcastServiceImpl.java @@ -26,11 +26,13 @@ import com.l2jserver.game.net.SystemMessage; import com.l2jserver.game.net.packet.server.SM_ATTACK; import com.l2jserver.game.net.packet.server.SM_CHAR_INFO_BROADCAST; import com.l2jserver.game.net.packet.server.SM_DIE; +import com.l2jserver.game.net.packet.server.SM_ITEM_GROUND; import com.l2jserver.game.net.packet.server.SM_MOVE; import com.l2jserver.game.net.packet.server.SM_MOVE_TYPE; import com.l2jserver.game.net.packet.server.SM_NPC_INFO; import com.l2jserver.game.net.packet.server.SM_OBJECT_REMOVE; import com.l2jserver.model.id.object.CharacterID; +import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; import com.l2jserver.model.world.NPC; import com.l2jserver.model.world.PositionableObject; @@ -218,6 +220,8 @@ public class BroadcastServiceImpl extends AbstractService implements conn.write(new SM_NPC_INFO((NPC) o)); } else if (o instanceof L2Character) { conn.write(new SM_CHAR_INFO_BROADCAST((L2Character) o)); + } else if (o instanceof Item) { + conn.write(new SM_ITEM_GROUND((Item) o)); } } }