mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +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:
@@ -1,23 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- <template:item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" -->
|
||||
<!-- xsi:schemaLocation="http://schemas.l2jserver2.com/item ../item.xsd" -->
|
||||
<!-- xmlns:template="http://schemas.l2jserver2.com/item" id="1" icon="icon.etc_adena_i00"> -->
|
||||
<!-- <name>Short Sword</name> -->
|
||||
<!-- <material>STEEL</material> -->
|
||||
<!-- <effect type="IMMEDIATE" /> -->
|
||||
<!-- <price>1</price> -->
|
||||
<!-- <stats> -->
|
||||
<!-- <physicalDamage> -->
|
||||
<!-- <set order="128">510</set> -->
|
||||
<!-- </physicalDamage> -->
|
||||
<!-- <magicalDamage> -->
|
||||
<!-- <set order="128">508</set> -->
|
||||
<!-- </magicalDamage> -->
|
||||
<!-- <criticalChance> -->
|
||||
<!-- <set order="128">8</set> -->
|
||||
<!-- </criticalChance> -->
|
||||
<!-- <physicalAttackSpeed> -->
|
||||
<!-- <set order="128">379</set> -->
|
||||
<!-- </physicalAttackSpeed> -->
|
||||
<!-- </stats> -->
|
||||
<!-- </template:item> -->
|
||||
<template:item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://schemas.l2jserver2.com/item ../item.xsd"
|
||||
xmlns:template="http://schemas.l2jserver2.com/item" id="1" icon="icon.etc_adena_i00">
|
||||
<name>Short Sword</name>
|
||||
<material>STEEL</material>
|
||||
<effect type="IMMEDIATE" />
|
||||
xmlns:template="http://schemas.l2jserver2.com/item" id="1" name="Short sword">
|
||||
<weight>1</weight>
|
||||
<price>1</price>
|
||||
<stats>
|
||||
<physicalDamage>
|
||||
<set order="128">510</set>
|
||||
</physicalDamage>
|
||||
<magicalDamage>
|
||||
<set order="128">508</set>
|
||||
</magicalDamage>
|
||||
<criticalChance>
|
||||
<set order="128">8</set>
|
||||
</criticalChance>
|
||||
<physicalAttackSpeed>
|
||||
<set order="128">379</set>
|
||||
</physicalAttackSpeed>
|
||||
</stats>
|
||||
<icon>icon.etc_adena_i00</icon>
|
||||
<material>GOLD</material>
|
||||
<!-- <effect type="IMMEDIATE" /> -->
|
||||
</template:item>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item id="2" icon="icon.etc_adena_i00">
|
||||
<name>Adena</name>
|
||||
<material>GOLD</material>
|
||||
<effect type="IMMEDIATE" />
|
||||
<template:item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://schemas.l2jserver2.com/item ../item.xsd"
|
||||
xmlns:template="http://schemas.l2jserver2.com/item" id="2" name="Long Sword">
|
||||
<weight>1</weight>
|
||||
<price>1</price>
|
||||
</item>
|
||||
<icon>icon.etc_adena_i00</icon>
|
||||
<material>GOLD</material>
|
||||
<!-- <effect type="IMMEDIATE" /> -->
|
||||
</template:item>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item id="57" icon="icon.etc_adena_i00">
|
||||
<name>Adena</name>
|
||||
<material>GOLD</material>
|
||||
<effect type="IMMEDIATE" />
|
||||
<template:item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://schemas.l2jserver2.com/item ../item.xsd"
|
||||
xmlns:template="http://schemas.l2jserver2.com/item" id="57" name="Adena">
|
||||
<weight>1</weight>
|
||||
<price>1</price>
|
||||
</item>
|
||||
<icon>icon.etc_adena_i00</icon>
|
||||
<material>GOLD</material>
|
||||
<!-- <effect type="IMMEDIATE" /> -->
|
||||
</template:item>
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user