Merged with released L2J-Unity files.

This commit is contained in:
mobiusdev
2016-06-12 01:34:09 +00:00
parent e003e87887
commit 635557f5da
18352 changed files with 3245113 additions and 2892959 deletions

View File

@@ -1,117 +1,103 @@
/*
* 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);
}
}
/*
* 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.OnPlayerClanWHItemAdd;
import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerClanWHItemDestroy;
import com.l2jmobius.gameserver.model.events.impl.character.player.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;
}
@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);
}
}

View File

@@ -1,174 +1,164 @@
/*
* 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.DatabaseFactory;
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)
{
transferItem("Expire", item.getObjectId(), item.getCount(), wh, null, null);
}
else
{
item.setItemLocation(ItemLocation.WAREHOUSE);
}
}
}
@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 = DatabaseFactory.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();
}
/*
* 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.DatabaseFactory;
import com.l2jmobius.gameserver.enums.ItemLocation;
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.values())
{
item.setItemLocation(getBaseLocation(), messageId);
}
updateDatabase();
}
public void returnToWh(ItemContainer wh)
{
for (L2ItemInstance item : _items.values())
{
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);
}
/*
* Allow saving of the items without owner
*/
@Override
public void updateDatabase()
{
for (L2ItemInstance item : _items.values())
{
item.updateDatabase(true);
}
}
@Override
public void restore()
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT * FROM items WHERE owner_id=? AND loc=? AND loc_data=?"))
{
statement.setInt(1, getOwnerId());
statement.setString(2, getBaseLocation().name());
statement.setInt(3, getMessageId());
try (ResultSet inv = statement.executeQuery())
{
while (inv.next())
{
final L2ItemInstance item = new L2ItemInstance(inv);
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 void deleteMe()
{
for (L2ItemInstance item : _items.values())
{
item.updateDatabase(true);
item.deleteMe();
L2World.getInstance().removeObject(item);
}
_items.clear();
}
@Override
public int getOwnerId()
{
return _ownerId;
}
}

View File

@@ -1,79 +1,79 @@
/*
* 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)
{
return (getSize() + slots) <= (_owner == null ? Config.ALT_FREIGHT_SLOTS : Config.ALT_FREIGHT_SLOTS + (int) _owner.getStat().calcStat(Stats.FREIGHT_LIM, 0, null, null));
}
@Override
public void refreshWeight()
{
}
/*
* 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;
/**
* @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;
return ((getSize() + slots) <= curSlots);
}
@Override
public void refreshWeight()
{
}
}

View File

@@ -1,108 +1,105 @@
/*
* 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()
{
}
/*
* 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.values())
{
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()
{
}
}

View File

@@ -1,56 +1,54 @@
/*
* 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();
}
}
/*
* 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 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());
}
}

View File

@@ -1,135 +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() && !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());
}
}
}
/*
* 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.values())
{
if (item.isEquipped())
{
if (!item.getItem().checkCondition(getOwner(), getOwner(), false))
{
unEquipItemInSlot(item.getLocationSlot());
}
}
}
}
public void transferItemsToOwner()
{
for (L2ItemInstance item : _items.values())
{
getOwner().transferItem("return", item.getObjectId(), item.getCount(), getOwner().getOwner().getInventory(), getOwner().getOwner(), getOwner());
}
}
}

View File

@@ -1,25 +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
{
}
/*
* 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
{
}