Project update.
This commit is contained in:
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.L2Clan;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.events.EventDispatcher;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.player.clanwh.OnPlayerClanWHItemAdd;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.player.clanwh.OnPlayerClanWHItemDestroy;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.player.clanwh.OnPlayerClanWHItemTransfer;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
|
||||
public final class ClanWarehouse extends Warehouse
|
||||
{
|
||||
private final L2Clan _clan;
|
||||
|
||||
public ClanWarehouse(L2Clan clan)
|
||||
{
|
||||
_clan = clan;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "ClanWarehouse";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwnerId()
|
||||
{
|
||||
return _clan.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2PcInstance getOwner()
|
||||
{
|
||||
return _clan.getLeader().getPlayerInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLocation getBaseLocation()
|
||||
{
|
||||
return ItemLocation.CLANWH;
|
||||
}
|
||||
|
||||
public String getLocationId()
|
||||
{
|
||||
return "0";
|
||||
}
|
||||
|
||||
public int getLocationId(boolean dummy)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setLocationId(L2PcInstance dummy)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateCapacity(long slots)
|
||||
{
|
||||
return ((_items.size() + slots) <= Config.WAREHOUSE_SLOTS_CLAN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2ItemInstance addItem(String process, int itemId, long count, L2PcInstance actor, Object reference)
|
||||
{
|
||||
final L2ItemInstance item = super.addItem(process, itemId, count, actor, reference);
|
||||
|
||||
// Notify to scripts
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerClanWHItemAdd(process, actor, item, this), item.getItem());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
|
||||
{
|
||||
// Notify to scripts
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerClanWHItemAdd(process, actor, item, this), item.getItem());
|
||||
return super.addItem(process, item, actor, reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2ItemInstance destroyItem(String process, L2ItemInstance item, long count, L2PcInstance actor, Object reference)
|
||||
{
|
||||
// Notify to scripts
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerClanWHItemDestroy(process, actor, item, count, this), item.getItem());
|
||||
return super.destroyItem(process, item, count, actor, reference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2ItemInstance transferItem(String process, int objectId, long count, ItemContainer target, L2PcInstance actor, Object reference)
|
||||
{
|
||||
final L2ItemInstance item = getItemByObjectId(objectId);
|
||||
|
||||
// Notify to scripts
|
||||
EventDispatcher.getInstance().notifyEventAsync(new OnPlayerClanWHItemTransfer(process, actor, item, count, target), item.getItem());
|
||||
return super.transferItem(process, objectId, count, target, actor, reference);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,779 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
|
||||
import com.l2jmobius.gameserver.GameTimeController;
|
||||
import com.l2jmobius.gameserver.datatables.ItemTable;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.items.L2Item;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
|
||||
/**
|
||||
* @author Advi
|
||||
*/
|
||||
public abstract class ItemContainer
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(ItemContainer.class.getName());
|
||||
|
||||
protected final List<L2ItemInstance> _items = new CopyOnWriteArrayList<>();
|
||||
|
||||
protected ItemContainer()
|
||||
{
|
||||
}
|
||||
|
||||
protected abstract L2Character getOwner();
|
||||
|
||||
protected abstract ItemLocation getBaseLocation();
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return "ItemContainer";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int the owner object Id
|
||||
*/
|
||||
public int getOwnerId()
|
||||
{
|
||||
return getOwner() == null ? 0 : getOwner().getObjectId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the quantity of items in the inventory
|
||||
*/
|
||||
public int getSize()
|
||||
{
|
||||
return _items.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the items in inventory
|
||||
*/
|
||||
public L2ItemInstance[] getItems()
|
||||
{
|
||||
return _items.toArray(new L2ItemInstance[_items.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId the item Id
|
||||
* @return the item from inventory by itemId
|
||||
*/
|
||||
public L2ItemInstance getItemByItemId(int itemId)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getId() == itemId))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if player got item for self resurrection
|
||||
*/
|
||||
public final boolean haveItemForSelfResurrection()
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getItem().isAllowSelfResurrection()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId the item Id
|
||||
* @return the items list from inventory by using its itemId
|
||||
*/
|
||||
public List<L2ItemInstance> getItemsByItemId(int itemId)
|
||||
{
|
||||
final List<L2ItemInstance> returnList = new LinkedList<>();
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getId() == itemId))
|
||||
{
|
||||
returnList.add(item);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId the item Id
|
||||
* @param itemToIgnore used during the loop, to avoid returning the same item
|
||||
* @return the item from inventory by itemId
|
||||
*/
|
||||
public L2ItemInstance getItemByItemId(int itemId, L2ItemInstance itemToIgnore)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getId() == itemId) && !item.equals(itemToIgnore))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param objectId the item object Id
|
||||
* @return item from inventory by objectId
|
||||
*/
|
||||
public L2ItemInstance getItemByObjectId(int objectId)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getObjectId() == objectId))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inventory item count by item Id and enchant level including equipped items.
|
||||
* @param itemId the item Id
|
||||
* @param enchantLevel the item enchant level, use -1 to match any enchant level
|
||||
* @return the inventory item count
|
||||
*/
|
||||
public long getInventoryItemCount(int itemId, int enchantLevel)
|
||||
{
|
||||
return getInventoryItemCount(itemId, enchantLevel, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the inventory item count by item Id and enchant level, may include equipped items.
|
||||
* @param itemId the item Id
|
||||
* @param enchantLevel the item enchant level, use -1 to match any enchant level
|
||||
* @param includeEquipped if {@code true} includes equipped items in the result
|
||||
* @return the inventory item count
|
||||
*/
|
||||
public long getInventoryItemCount(int itemId, int enchantLevel, boolean includeEquipped)
|
||||
{
|
||||
long count = 0;
|
||||
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item.getId() == itemId) && ((item.getEnchantLevel() == enchantLevel) || (enchantLevel < 0)) && (includeEquipped || !item.isEquipped()))
|
||||
{
|
||||
if (item.isStackable())
|
||||
{
|
||||
// FIXME: Zoey76: if there are more than one stacks of the same item Id
|
||||
// it will return the count of the last one, if is not possible to
|
||||
// have more than one stacks of the same item Id,
|
||||
// it will continue iterating over all items
|
||||
// possible fixes:
|
||||
// count += item.getCount();
|
||||
// or
|
||||
// count = item.getCount();
|
||||
// break;
|
||||
count = item.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds item to inventory
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param item : L2ItemInstance to be added
|
||||
* @param actor : L2PcInstance Player requesting the item add
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
|
||||
{
|
||||
final L2ItemInstance olditem = getItemByItemId(item.getId());
|
||||
|
||||
// If stackable item is found in inventory just add to current quantity
|
||||
if ((olditem != null) && olditem.isStackable())
|
||||
{
|
||||
final long count = item.getCount();
|
||||
olditem.changeCount(process, count, actor, reference);
|
||||
olditem.setLastChange(L2ItemInstance.MODIFIED);
|
||||
|
||||
// And destroys the item
|
||||
ItemTable.getInstance().destroyItem(process, item, actor, reference);
|
||||
item.updateDatabase();
|
||||
item = olditem;
|
||||
|
||||
// Updates database
|
||||
final float adenaRate = Config.RATE_DROP_AMOUNT_MULTIPLIER.getOrDefault(Inventory.ADENA_ID, 1f);
|
||||
if ((item.getId() == Inventory.ADENA_ID) && (count < (10000 * adenaRate)))
|
||||
{
|
||||
// Small adena changes won't be saved to database all the time
|
||||
if ((GameTimeController.getInstance().getGameTicks() % 5) == 0)
|
||||
{
|
||||
item.updateDatabase();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item.updateDatabase();
|
||||
}
|
||||
}
|
||||
// If item hasn't be found in inventory, create new one
|
||||
else
|
||||
{
|
||||
item.setOwnerId(process, getOwnerId(), actor, reference);
|
||||
item.setItemLocation(getBaseLocation());
|
||||
item.setLastChange((L2ItemInstance.ADDED));
|
||||
|
||||
// Add item in inventory
|
||||
addItem(item);
|
||||
|
||||
// Updates database
|
||||
item.updateDatabase();
|
||||
}
|
||||
|
||||
refreshWeight();
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds item to inventory
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param itemId : int Item Identifier of the item to be added
|
||||
* @param count : int Quantity of items to be added
|
||||
* @param actor : L2PcInstance Player requesting the item add
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance addItem(String process, int itemId, long count, L2PcInstance actor, Object reference)
|
||||
{
|
||||
L2ItemInstance item = getItemByItemId(itemId);
|
||||
|
||||
// If stackable item is found in inventory just add to current quantity
|
||||
if ((item != null) && item.isStackable())
|
||||
{
|
||||
item.changeCount(process, count, actor, reference);
|
||||
item.setLastChange(L2ItemInstance.MODIFIED);
|
||||
// Updates database
|
||||
// If Adena drop rate is not present it will be x1.
|
||||
final float adenaRate = Config.RATE_DROP_AMOUNT_MULTIPLIER.getOrDefault(Inventory.ADENA_ID, 1f);
|
||||
if ((itemId == Inventory.ADENA_ID) && (count < (10000 * adenaRate)))
|
||||
{
|
||||
// Small adena changes won't be saved to database all the time
|
||||
if ((GameTimeController.getInstance().getGameTicks() % 5) == 0)
|
||||
{
|
||||
item.updateDatabase();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item.updateDatabase();
|
||||
}
|
||||
}
|
||||
// If item hasn't be found in inventory, create new one
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
final L2Item template = ItemTable.getInstance().getTemplate(itemId);
|
||||
if (template == null)
|
||||
{
|
||||
_log.log(Level.WARNING, (actor != null ? "[" + actor.getName() + "] " : "") + "Invalid ItemId requested: ", itemId);
|
||||
return null;
|
||||
}
|
||||
|
||||
item = ItemTable.getInstance().createItem(process, itemId, template.isStackable() ? count : 1, actor, reference);
|
||||
item.setOwnerId(getOwnerId());
|
||||
item.setItemLocation(getBaseLocation());
|
||||
item.setLastChange(L2ItemInstance.ADDED);
|
||||
item.setEnchantLevel(template.getDefaultEnchantLevel());
|
||||
|
||||
// Add item in inventory
|
||||
addItem(item);
|
||||
// Updates database
|
||||
item.updateDatabase();
|
||||
|
||||
// If stackable, end loop as entire count is included in 1 instance of item
|
||||
if (template.isStackable() || !Config.MULTIPLE_ITEM_DROP)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refreshWeight();
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfers item to another inventory
|
||||
* @param process string Identifier of process triggering this action
|
||||
* @param objectId Item Identifier of the item to be transfered
|
||||
* @param count Quantity of items to be transfered
|
||||
* @param target the item container where the item will be moved.
|
||||
* @param actor Player requesting the item transfer
|
||||
* @param reference Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the new item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance transferItem(String process, int objectId, long count, ItemContainer target, L2PcInstance actor, Object reference)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final L2ItemInstance sourceitem = getItemByObjectId(objectId);
|
||||
if (sourceitem == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
L2ItemInstance targetitem = sourceitem.isStackable() ? target.getItemByItemId(sourceitem.getId()) : null;
|
||||
|
||||
synchronized (sourceitem)
|
||||
{
|
||||
// check if this item still present in this container
|
||||
if (getItemByObjectId(objectId) != sourceitem)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if requested quantity is available
|
||||
if (count > sourceitem.getCount())
|
||||
{
|
||||
count = sourceitem.getCount();
|
||||
}
|
||||
|
||||
// If possible, move entire item object
|
||||
if ((sourceitem.getCount() == count) && (targetitem == null))
|
||||
{
|
||||
removeItem(sourceitem);
|
||||
target.addItem(process, sourceitem, actor, reference);
|
||||
targetitem = sourceitem;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sourceitem.getCount() > count) // If possible, only update counts
|
||||
{
|
||||
sourceitem.changeCount(process, -count, actor, reference);
|
||||
}
|
||||
else
|
||||
// Otherwise destroy old item
|
||||
{
|
||||
removeItem(sourceitem);
|
||||
ItemTable.getInstance().destroyItem(process, sourceitem, actor, reference);
|
||||
}
|
||||
|
||||
if (targetitem != null) // If possible, only update counts
|
||||
{
|
||||
targetitem.changeCount(process, count, actor, reference);
|
||||
}
|
||||
else
|
||||
// Otherwise add new item
|
||||
{
|
||||
targetitem = target.addItem(process, sourceitem.getId(), count, actor, reference);
|
||||
}
|
||||
}
|
||||
|
||||
// Updates database
|
||||
sourceitem.updateDatabase(true);
|
||||
if ((targetitem != sourceitem) && (targetitem != null))
|
||||
{
|
||||
targetitem.updateDatabase();
|
||||
}
|
||||
if (sourceitem.isAugmented())
|
||||
{
|
||||
sourceitem.getAugmentation().removeBonus(actor);
|
||||
}
|
||||
refreshWeight();
|
||||
target.refreshWeight();
|
||||
}
|
||||
return targetitem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches the item from this item container so it can be used as a single instance.
|
||||
* @param process string Identifier of process triggering this action
|
||||
* @param item the item instance to be detached
|
||||
* @param count the count of items to be detached
|
||||
* @param newLocation the new item location
|
||||
* @param actor Player requesting the item detach
|
||||
* @param reference Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return the detached item instance if operation completes successfully, {@code null} if the item does not exist in this container anymore or item count is not available
|
||||
*/
|
||||
public L2ItemInstance detachItem(String process, L2ItemInstance item, long count, ItemLocation newLocation, L2PcInstance actor, Object reference)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized (item)
|
||||
{
|
||||
if (!_items.contains(item))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count > item.getCount())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (count == item.getCount())
|
||||
{
|
||||
removeItem(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.changeCount(process, -count, actor, reference);
|
||||
item.updateDatabase(true);
|
||||
item = ItemTable.getInstance().createItem(process, item.getId(), count, actor, reference);
|
||||
item.setOwnerId(getOwnerId());
|
||||
}
|
||||
item.setItemLocation(newLocation);
|
||||
item.updateDatabase(true);
|
||||
}
|
||||
|
||||
refreshWeight();
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches the item from this item container so it can be used as a single instance.
|
||||
* @param process string Identifier of process triggering this action
|
||||
* @param itemObjectId the item object id to be detached
|
||||
* @param count the count of items to be detached
|
||||
* @param newLocation the new item location
|
||||
* @param actor Player requesting the item detach
|
||||
* @param reference Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return the detached item instance if operation completes successfully, {@code null} if the item does not exist in this container anymore or item count is not available
|
||||
*/
|
||||
public L2ItemInstance detachItem(String process, int itemObjectId, long count, ItemLocation newLocation, L2PcInstance actor, Object reference)
|
||||
{
|
||||
final L2ItemInstance itemInstance = getItemByObjectId(itemObjectId);
|
||||
if (itemInstance == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return detachItem(process, itemInstance, count, newLocation, actor, reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy item from inventory and updates database
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param item : L2ItemInstance to be destroyed
|
||||
* @param actor : L2PcInstance Player requesting the item destroy
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance destroyItem(String process, L2ItemInstance item, L2PcInstance actor, Object reference)
|
||||
{
|
||||
return this.destroyItem(process, item, item.getCount(), actor, reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy item from inventory and updates database
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param item : L2ItemInstance to be destroyed
|
||||
* @param count
|
||||
* @param actor : L2PcInstance Player requesting the item destroy
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance destroyItem(String process, L2ItemInstance item, long count, L2PcInstance actor, Object reference)
|
||||
{
|
||||
synchronized (item)
|
||||
{
|
||||
// Adjust item quantity
|
||||
if (item.getCount() > count)
|
||||
{
|
||||
item.changeCount(process, -count, actor, reference);
|
||||
item.setLastChange(L2ItemInstance.MODIFIED);
|
||||
|
||||
// don't update often for untraced items
|
||||
if ((process != null) || ((GameTimeController.getInstance().getGameTicks() % 10) == 0))
|
||||
{
|
||||
item.updateDatabase();
|
||||
}
|
||||
|
||||
refreshWeight();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.getCount() < count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean removed = removeItem(item);
|
||||
if (!removed)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemTable.getInstance().destroyItem(process, item, actor, reference);
|
||||
|
||||
item.updateDatabase();
|
||||
refreshWeight();
|
||||
}
|
||||
item.deleteMe();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy item from inventory by using its <B>objectID</B> and updates database
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param objectId : int Item Instance identifier of the item to be destroyed
|
||||
* @param count : int Quantity of items to be destroyed
|
||||
* @param actor : L2PcInstance Player requesting the item destroy
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance destroyItem(String process, int objectId, long count, L2PcInstance actor, Object reference)
|
||||
{
|
||||
final L2ItemInstance item = getItemByObjectId(objectId);
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.destroyItem(process, item, count, actor, reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy item from inventory by using its <B>itemId</B> and updates database
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param itemId : int Item identifier of the item to be destroyed
|
||||
* @param count : int Quantity of items to be destroyed
|
||||
* @param actor : L2PcInstance Player requesting the item destroy
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
* @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
|
||||
*/
|
||||
public L2ItemInstance destroyItemByItemId(String process, int itemId, long count, L2PcInstance actor, Object reference)
|
||||
{
|
||||
final L2ItemInstance item = getItemByItemId(itemId);
|
||||
if (item == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return destroyItem(process, item, count, actor, reference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy all items from inventory and updates database
|
||||
* @param process : String Identifier of process triggering this action
|
||||
* @param actor : L2PcInstance Player requesting the item destroy
|
||||
* @param reference : Object Object referencing current action like NPC selling item or previous item in transformation
|
||||
*/
|
||||
public void destroyAllItems(String process, L2PcInstance actor, Object reference)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
destroyItem(process, item, actor, reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return warehouse Adena.
|
||||
*/
|
||||
public long getAdena()
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getId() == Inventory.ADENA_ID))
|
||||
{
|
||||
return item.getCount();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long getBeautyTickets()
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if ((item != null) && (item.getId() == Inventory.BEAUTY_TICKET_ID))
|
||||
{
|
||||
return item.getCount();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds item to inventory for further adjustments.
|
||||
* @param item : L2ItemInstance to be added from inventory
|
||||
*/
|
||||
protected void addItem(L2ItemInstance item)
|
||||
{
|
||||
_items.add(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes item from inventory for further adjustments.
|
||||
* @param item : L2ItemInstance to be removed from inventory
|
||||
* @return
|
||||
*/
|
||||
protected boolean removeItem(L2ItemInstance item)
|
||||
{
|
||||
return _items.remove(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the weight of equipment loaded
|
||||
*/
|
||||
protected void refreshWeight()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item object from world
|
||||
*/
|
||||
public void deleteMe()
|
||||
{
|
||||
if (getOwner() != null)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
item.updateDatabase(true);
|
||||
item.deleteMe();
|
||||
L2World.getInstance().removeObject(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update database with items in inventory
|
||||
*/
|
||||
public void updateDatabase()
|
||||
{
|
||||
if (getOwner() != null)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
item.updateDatabase(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get back items in container from database
|
||||
*/
|
||||
public void restore()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT object_id, item_id, count, enchant_level, loc, loc_data, custom_type1, custom_type2, mana_left, time FROM items WHERE owner_id=? AND (loc=?)"))
|
||||
{
|
||||
ps.setInt(1, getOwnerId());
|
||||
ps.setString(2, getBaseLocation().name());
|
||||
try (ResultSet inv = ps.executeQuery())
|
||||
{
|
||||
L2ItemInstance item;
|
||||
while (inv.next())
|
||||
{
|
||||
item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
L2World.getInstance().storeObject(item);
|
||||
|
||||
final L2PcInstance owner = getOwner() == null ? null : getOwner().getActingPlayer();
|
||||
|
||||
// If stackable item is found in inventory just add to current quantity
|
||||
if (item.isStackable() && (getItemByItemId(item.getId()) != null))
|
||||
{
|
||||
addItem("Restore", item, owner, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
refreshWeight();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "could not restore container:", e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateCapacity(long slots)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean validateWeight(long weight)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item is stackable validates 1 slot, if the item isn't stackable validates the item count.
|
||||
* @param itemId the item Id to verify
|
||||
* @param count amount of item's weight to validate
|
||||
* @return {@code true} if the item doesn't exists or it validates its slot count
|
||||
*/
|
||||
public boolean validateCapacityByItemId(int itemId, long count)
|
||||
{
|
||||
final L2Item template = ItemTable.getInstance().getTemplate(itemId);
|
||||
return (template == null) || (template.isStackable() ? validateCapacity(1) : validateCapacity(count));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId the item Id to verify
|
||||
* @param count amount of item's weight to validate
|
||||
* @return {@code true} if the item doesn't exists or it validates its weight
|
||||
*/
|
||||
public boolean validateWeightByItemId(int itemId, long count)
|
||||
{
|
||||
final L2Item template = ItemTable.getInstance().getTemplate(itemId);
|
||||
return (template == null) || validateWeight(template.getWeight() * count);
|
||||
}
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.idfactory.IdFactory;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public class Mail extends ItemContainer
|
||||
{
|
||||
private final int _ownerId;
|
||||
private int _messageId;
|
||||
|
||||
public Mail(int objectId, int messageId)
|
||||
{
|
||||
_ownerId = objectId;
|
||||
_messageId = messageId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Mail";
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2PcInstance getOwner()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLocation getBaseLocation()
|
||||
{
|
||||
return ItemLocation.MAIL;
|
||||
}
|
||||
|
||||
public int getMessageId()
|
||||
{
|
||||
return _messageId;
|
||||
}
|
||||
|
||||
public void setNewMessageId(int messageId)
|
||||
{
|
||||
_messageId = messageId;
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
item.setItemLocation(getBaseLocation(), messageId);
|
||||
}
|
||||
|
||||
updateDatabase();
|
||||
}
|
||||
|
||||
public void returnToWh(ItemContainer wh)
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (wh == null)
|
||||
{
|
||||
item.setItemLocation(ItemLocation.WAREHOUSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
transferItem("Expire", item.getObjectId(), item.getCount(), wh, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addItem(L2ItemInstance item)
|
||||
{
|
||||
super.addItem(item);
|
||||
item.setItemLocation(getBaseLocation(), _messageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDatabase()
|
||||
{
|
||||
_items.forEach(i -> i.updateDatabase(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT object_id, item_id, count, enchant_level, loc, loc_data, custom_type1, custom_type2, mana_left, time FROM items WHERE owner_id=? AND loc=? AND loc_data=?"))
|
||||
{
|
||||
ps.setInt(1, getOwnerId());
|
||||
ps.setString(2, getBaseLocation().name());
|
||||
ps.setInt(3, getMessageId());
|
||||
try (ResultSet inv = ps.executeQuery())
|
||||
{
|
||||
L2ItemInstance item;
|
||||
while (inv.next())
|
||||
{
|
||||
item = L2ItemInstance.restoreFromDb(getOwnerId(), inv);
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
L2World.getInstance().storeObject(item);
|
||||
|
||||
// If stackable item is found just add to current quantity
|
||||
if (item.isStackable() && (getItemByItemId(item.getId()) != null))
|
||||
{
|
||||
addItem("Restore", item, null, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "could not restore container:", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwnerId()
|
||||
{
|
||||
return _ownerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMe()
|
||||
{
|
||||
_items.forEach(i ->
|
||||
{
|
||||
i.updateDatabase(true);
|
||||
i.deleteMe();
|
||||
L2World.getInstance().removeObject(i);
|
||||
IdFactory.getInstance().releaseId(i.getObjectId());
|
||||
});
|
||||
_items.clear();
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.stats.Stats;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class PcFreight extends ItemContainer
|
||||
{
|
||||
private final L2PcInstance _owner;
|
||||
private final int _ownerId;
|
||||
|
||||
public PcFreight(int object_id)
|
||||
{
|
||||
_owner = null;
|
||||
_ownerId = object_id;
|
||||
restore();
|
||||
}
|
||||
|
||||
public PcFreight(L2PcInstance owner)
|
||||
{
|
||||
_owner = owner;
|
||||
_ownerId = owner.getObjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwnerId()
|
||||
{
|
||||
return _ownerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2PcInstance getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLocation getBaseLocation()
|
||||
{
|
||||
return ItemLocation.FREIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Freight";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateCapacity(long slots)
|
||||
{
|
||||
final int curSlots = _owner == null ? Config.ALT_FREIGHT_SLOTS : Config.ALT_FREIGHT_SLOTS + (int) _owner.getStat().calcStat(Stats.FREIGHT_LIM, 0, null, null);
|
||||
return ((getSize() + slots) <= curSlots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshWeight()
|
||||
{
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.l2jmobius.gameserver.datatables.ItemTable;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
|
||||
/**
|
||||
* @author DS
|
||||
*/
|
||||
public class PcRefund extends ItemContainer
|
||||
{
|
||||
private final L2PcInstance _owner;
|
||||
|
||||
public PcRefund(L2PcInstance owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Refund";
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2PcInstance getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLocation getBaseLocation()
|
||||
{
|
||||
return ItemLocation.REFUND;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addItem(L2ItemInstance item)
|
||||
{
|
||||
super.addItem(item);
|
||||
try
|
||||
{
|
||||
if (getSize() > 12)
|
||||
{
|
||||
final L2ItemInstance removedItem = _items.remove(0);
|
||||
if (removedItem != null)
|
||||
{
|
||||
ItemTable.getInstance().destroyItem("ClearRefund", removedItem, getOwner(), null);
|
||||
removedItem.updateDatabase(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "addItem()", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshWeight()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMe()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item != null)
|
||||
{
|
||||
ItemTable.getInstance().destroyItem("ClearRefund", item, getOwner(), null);
|
||||
item.updateDatabase(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "deleteMe()", e);
|
||||
}
|
||||
_items.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
public class PcWarehouse extends Warehouse
|
||||
{
|
||||
// private static final Logger _log = Logger.getLogger(PcWarehouse.class.getName());
|
||||
|
||||
private final L2PcInstance _owner;
|
||||
|
||||
public PcWarehouse(L2PcInstance owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Warehouse";
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2PcInstance getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemLocation getBaseLocation()
|
||||
{
|
||||
return ItemLocation.WAREHOUSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateCapacity(long slots)
|
||||
{
|
||||
return ((_items.size() + slots) <= _owner.getWareHouseLimit());
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
import com.l2jmobius.gameserver.datatables.ItemTable;
|
||||
import com.l2jmobius.gameserver.enums.ItemLocation;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PetInstance;
|
||||
import com.l2jmobius.gameserver.model.items.L2Item;
|
||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||
|
||||
public class PetInventory extends Inventory
|
||||
{
|
||||
private final L2PetInstance _owner;
|
||||
|
||||
public PetInventory(L2PetInstance owner)
|
||||
{
|
||||
_owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public L2PetInstance getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwnerId()
|
||||
{
|
||||
// gets the L2PcInstance-owner's ID
|
||||
int id;
|
||||
try
|
||||
{
|
||||
id = _owner.getOwner().getObjectId();
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the weight of equipment loaded
|
||||
*/
|
||||
@Override
|
||||
protected void refreshWeight()
|
||||
{
|
||||
super.refreshWeight();
|
||||
getOwner().updateAndBroadcastStatus(1);
|
||||
}
|
||||
|
||||
public boolean validateCapacity(L2ItemInstance item)
|
||||
{
|
||||
int slots = 0;
|
||||
|
||||
if (!(item.isStackable() && (getItemByItemId(item.getId()) != null)) && !item.getItem().hasExImmediateEffect())
|
||||
{
|
||||
slots++;
|
||||
}
|
||||
|
||||
return validateCapacity(slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateCapacity(long slots)
|
||||
{
|
||||
return ((_items.size() + slots) <= _owner.getInventoryLimit());
|
||||
}
|
||||
|
||||
public boolean validateWeight(L2ItemInstance item, long count)
|
||||
{
|
||||
int weight = 0;
|
||||
final L2Item template = ItemTable.getInstance().getTemplate(item.getId());
|
||||
if (template == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
weight += count * template.getWeight();
|
||||
return validateWeight(weight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateWeight(long weight)
|
||||
{
|
||||
return ((_totalWeight + weight) <= _owner.getMaxLoad());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemLocation getBaseLocation()
|
||||
{
|
||||
return ItemLocation.PET;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemLocation getEquipLocation()
|
||||
{
|
||||
return ItemLocation.PET_EQUIP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore()
|
||||
{
|
||||
super.restore();
|
||||
// check for equiped items from other pets
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
if (item.isEquipped())
|
||||
{
|
||||
if (!item.getItem().checkCondition(getOwner(), getOwner(), false))
|
||||
{
|
||||
unEquipItemInSlot(item.getLocationSlot());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void transferItemsToOwner()
|
||||
{
|
||||
for (L2ItemInstance item : _items)
|
||||
{
|
||||
getOwner().transferItem("return", item.getObjectId(), item.getCount(), getOwner().getOwner().getInventory(), getOwner().getOwner(), getOwner());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.model.itemcontainer;
|
||||
|
||||
/**
|
||||
* This class ...
|
||||
* @version $Revision: 1.3.2.1.2.12 $ $Date: 2005/04/06 16:13:42 $
|
||||
*/
|
||||
public abstract class Warehouse extends ItemContainer
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user