1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-05 23:22:47 +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

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