1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00

Implements item drop mode configuration

This commit is contained in:
2011-12-29 01:16:50 -02:00
parent 394a2853e2
commit c5911ea884
8 changed files with 144 additions and 22 deletions

View File

@@ -96,7 +96,13 @@
<service interface="com.l2jserver.service.game.npc.NPCService"
implementation="com.l2jserver.service.game.npc.NPCServiceImpl" />
<service interface="com.l2jserver.service.game.item.ItemService"
implementation="com.l2jserver.service.game.item.ItemServiceImpl" />
implementation="com.l2jserver.service.game.item.ItemServiceImpl">
<!-- Whether drops are persisted in the database. Valid modes are: -->
<!-- ALL - All types of drops are stored into the database -->
<!-- CHARACTER_ONLY - Only items dropped by characters are stored in the database -->
<!-- NONE - None of the dropped items are saved into the database -->
<drop persistent="ALL" />
</service>
<service interface="com.l2jserver.service.game.world.WorldService"
implementation="com.l2jserver.service.game.world.WorldServiceImpl" />
<service interface="com.l2jserver.service.game.world.event.WorldEventDispatcher"

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- This file should be renamed as "services.xml" and configured according
<!-- This file should be copied as "services.xml" and configured according
to your needs. Since "services.xml" has been added to ".gitignore", this
means that your password won't be sent to the repository when you make a
commit. -->
@@ -58,17 +58,22 @@
you normally don't need to change anything here nor in the firewall. -->
<server listen="0.0.0.0:7777" />
</service>
<!-- Logging service -->
<service interface="com.l2jserver.service.core.LoggingService"
implementation="com.l2jserver.service.core.Log4JLoggingService">
<logger name="" level="ERROR" />
<logger name="com.l2jserver" level="INFO" />
<logger name="com.l2jserver.service.game.template.XMLTemplateService" level="INFO" />
<logger name="com.l2jserver.service.game.template.XMLTemplateService"
level="INFO" />
<logger name="com.l2jserver.service.cache" level="INFO" />
<logger name="com.l2jserver.service.database.sql.AbstractSQLDatabaseService" level="INFO" />
<logger name="com.l2jserver.service.game.world.CachedWorldIDService" level="INFO" />
<logger name="com.l2jserver.model.id.object.allocator.BitSetIDAllocator" level="INFO" />
<logger
name="com.l2jserver.service.database.sql.AbstractSQLDatabaseService"
level="INFO" />
<logger name="com.l2jserver.service.game.world.CachedWorldIDService"
level="INFO" />
<logger name="com.l2jserver.model.id.object.allocator.BitSetIDAllocator"
level="INFO" />
</service>
<!-- ###################################################################### -->
@@ -112,7 +117,14 @@
<service interface="com.l2jserver.service.game.npc.NPCService"
implementation="com.l2jserver.service.game.npc.NPCServiceImpl" />
<service interface="com.l2jserver.service.game.item.ItemService"
implementation="com.l2jserver.service.game.item.ItemServiceImpl" />
implementation="com.l2jserver.service.game.item.ItemServiceImpl">
<!-- Whether drops are persisted in the database. Valid modes are: -->
<!-- ALL - All types of drops are stored into the database -->
<!-- CHARACTER_ONLY - Only items dropped by characters are stored in the
database -->
<!-- NONE - None of the dropped items are saved into the database -->
<drop persistent="ALL" />
</service>
<service interface="com.l2jserver.service.game.world.WorldService"
implementation="com.l2jserver.service.game.world.WorldServiceImpl" />
<service interface="com.l2jserver.service.game.world.event.WorldEventDispatcher"

View File

@@ -0,0 +1,66 @@
/*
* 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.ServiceConfiguration;
import com.l2jserver.service.configuration.XMLConfigurationService.ConfigurationXPath;
/**
* Defines configurations for {@link ItemService} implementations
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ItemServiceConfiguration extends ServiceConfiguration {
/**
* Gets the item drop mode
*
* @return the drop mode
*/
@ConfigurationPropertyGetter(defaultValue = "ALL")
@ConfigurationXPath("drop/@persistent")
ItemServiceDropMode getItemDropMode();
/**
* Sets the item drop mode
*
* @param mode
* the drop mode
*/
@ConfigurationPropertySetter
@ConfigurationXPath("drop/@persistent")
void setItemDropMode(ItemServiceDropMode mode);
/**
* The drop modes available
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum ItemServiceDropMode {
/**
* All types of drops are stored into the database.
*/
ALL,
/**
* Only items dropped by characters are stored in the database.
*/
CHARACTER_ONLY,
/**
* None of the dropped items are saved into the database.
*/
NONE;
}
}

View File

@@ -33,7 +33,7 @@ import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.character.CharacterInventory.ItemLocation;
import com.l2jserver.model.world.item.ItemDropEvent;
import com.l2jserver.model.world.item.ItemPickEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractConfigurableService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
@@ -52,7 +52,9 @@ import com.l2jserver.util.geometry.Point3D;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
@Depends({ SpawnService.class, DatabaseService.class })
public class ItemServiceImpl extends AbstractService implements ItemService {
public class ItemServiceImpl extends
AbstractConfigurableService<ItemServiceConfiguration> implements
ItemService {
/**
* The item DAO
*/
@@ -88,6 +90,7 @@ public class ItemServiceImpl extends AbstractService implements ItemService {
@Inject
private ItemServiceImpl(ItemDAO itemDao, SpawnService spawnService,
WorldEventDispatcher eventDispatcher, ItemIDProvider itemIdProvider) {
super(ItemServiceConfiguration.class);
this.itemDao = itemDao;
this.spawnService = spawnService;
this.eventDispatcher = eventDispatcher;
@@ -96,6 +99,7 @@ public class ItemServiceImpl extends AbstractService implements ItemService {
@Override
protected void doStart() throws ServiceStartException {
logger.info("ItemService drop mode is {}", config.getItemDropMode());
items = itemDao.selectDroppedItems();
try {
for (final Item item : items) {
@@ -204,8 +208,8 @@ public class ItemServiceImpl extends AbstractService implements ItemService {
stackItems[items.length] = item;
try {
item = stack(stackItems);
Item[] deleteItems = ArrayUtils.copyArrayExcept(
Item[].class, stackItems, item);
Item[] deleteItems = ArrayUtils.copyArrayExcept(stackItems,
item);
destroy(deleteItems);
character.getInventory().add(item);
} catch (NonStackableItemsServiceException e) {
@@ -218,6 +222,11 @@ public class ItemServiceImpl extends AbstractService implements ItemService {
character.getInventory().add(item);
this.items.remove(item);
// removes transient state
if (item.equals(originalItem)
&& item.getObjectDesire() == ObjectDesire.TRANSIENT)
item.setObjectDesire(ObjectDesire.UPDATE);
itemDao.saveObjectsAsync(item);
if (!item.equals(originalItem)) {
itemDao.saveObjectsAsync(originalItem);
@@ -254,9 +263,29 @@ public class ItemServiceImpl extends AbstractService implements ItemService {
}
}
itemDao.saveObjectsAsync(item);
if (!item.equals(sourceItem)) {
itemDao.saveObjectsAsync(sourceItem);
boolean persist = true;
switch (config.getItemDropMode()) {
case ALL:
persist = true;
break;
case CHARACTER_ONLY:
persist = (actor instanceof L2Character);
break;
case NONE:
persist = false;
break;
}
if (persist) {
itemDao.saveObjectsAsync(item);
if (!item.equals(sourceItem)) {
itemDao.saveObjectsAsync(sourceItem);
}
} else {
if (item.equals(sourceItem)) {
itemDao.delete(item);
item.setObjectDesire(ObjectDesire.TRANSIENT);
}
}
items.add(item);