1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-05 23:22:47 +00:00

Implements dropped items on the ground

The dropped item is broadcasted to all players near by and are stored in
the database, allowing them to be restored after a server restart.
This commit is contained in:
2011-12-14 14:57:38 -02:00
parent 9688d6b351
commit 3e0fbc07fc
16 changed files with 221 additions and 53 deletions

View File

@@ -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);

View File

@@ -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
}

View File

@@ -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<Item, ItemID>, Cacheable {
* @return amount of items loaded
*/
int loadInventory(L2Character character);
List<Item> loadDroppedItems();
}

View File

@@ -106,6 +106,10 @@ public class CharacterInventory implements Iterable<Item> {
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum InventoryLocation {
/**
* The item is dropped on the ground
*/
GROUND,
/**
* The item is equipped
*/

View File

@@ -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);

View File

@@ -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<Item, ItemID>
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<Item, ItemID>
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<Item, ItemID>
return items.size();
}
@Override
public List<Item> loadDroppedItems() {
return database.query(new SelectListQuery<Item>() {
@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<Item> mapper() {
return mapper;
}
});
}
@Override
public List<ItemID> selectIDs() {
return database.query(new SelectListQuery<ItemID>() {

View File

@@ -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);

View File

@@ -0,0 +1,28 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game.item;
import com.l2jserver.service.Service;
/**
* This service handles item management. Drop and pick up, create and destroy.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ItemService extends Service {
}

View File

@@ -0,0 +1,82 @@
/*
* This file is part of l2jserver2 <l2jserver2.com>.
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <a href="http://www.rogiel.com">Rogiel</a>
*/
@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<Item> 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();
}
}

View File

@@ -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;

View File

@@ -29,11 +29,6 @@ import com.l2jserver.util.geometry.Point3D;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class KnownListUpdateFilter extends AndFilter<PositionableObject> {
/**
* Constant declaring the range in which knownlist will be scanned
*/
public static final int KNOWNLIST_RANGE = 2000;
/**
* Creates a new instance.
* <p>
@@ -48,6 +43,6 @@ public class KnownListUpdateFilter extends AndFilter<PositionableObject> {
*/
public KnownListUpdateFilter(PositionableObject object, Point3D old) {
super(new KnownListFilter(object), new NotFilter<PositionableObject>(
new RangePointFilter(old, KNOWNLIST_RANGE)));
new RangePointFilter(old, KnownListFilter.KNOWNLIST_RANGE)));
}
}

View File

@@ -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));
}
}
}