浏览代码

BETA: Reworking ItemHolder, now there are 3 more alternatives.
* ItemChanceHolder(int id, double chance).
* ItemChanceHolder(int id, double chance, long count).
* QuestItemHolder(int id, int chance).
* QuestItemHolder(int id, int chance, long count).
* UniqueItemHolder(int id, int objectId).
* UniqueItemHolder(int id, int objectId, long count).
* Reviewed by: Zoey76, UnAfraid, Nos, jurchiks

xban1x 11 年之前
父节点
当前提交
3f9b2aeaa5

+ 44 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/holders/ItemChanceHolder.java

@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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.
+ * 
+ * L2J Server 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.l2jserver.gameserver.model.holders;
+
+/**
+ * Item holder, with additional parameter chance.
+ * @author xban1x
+ */
+public final class ItemChanceHolder extends ItemHolder
+{
+	private final double _chance;
+	
+	public ItemChanceHolder(int id, double chance)
+	{
+		this(id, chance, 1);
+	}
+	
+	public ItemChanceHolder(int id, double chance, long count)
+	{
+		super(id, count);
+		_chance = chance;
+	}
+	
+	public double getChance()
+	{
+		return _chance;
+	}
+}

+ 5 - 19
L2J_Server_BETA/java/com/l2jserver/gameserver/model/holders/ItemHolder.java

@@ -18,46 +18,32 @@
  */
 package com.l2jserver.gameserver.model.holders;
 
+import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
+
 /**
- * Holder for item id-count.
+ * Holder for item id and count.
  * @author UnAfraid
  */
-public class ItemHolder
+public class ItemHolder implements IIdentifiable
 {
 	private final int _id;
-	private final int _objectId;
 	private final long _count;
 	
 	public ItemHolder(int id, long count)
 	{
 		_id = id;
-		_objectId = -1;
-		_count = count;
-	}
-	
-	public ItemHolder(int id, int objectId, long count)
-	{
-		_id = id;
-		_objectId = objectId;
 		_count = count;
 	}
 	
 	/**
 	 * @return the item/object identifier.
 	 */
+	@Override
 	public int getId()
 	{
 		return _id;
 	}
 	
-	/**
-	 * @return the object Id
-	 */
-	public int getObjectId()
-	{
-		return _objectId;
-	}
-	
 	/**
 	 * @return the item count.
 	 */

+ 44 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/holders/QuestItemHolder.java

@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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.
+ * 
+ * L2J Server 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.l2jserver.gameserver.model.holders;
+
+/**
+ * Item Holder storing chance in addition for quests.
+ * @author xban1x
+ */
+public final class QuestItemHolder extends ItemHolder
+{
+	private final int _chance;
+	
+	public QuestItemHolder(int id, int chance)
+	{
+		this(id, chance, 1);
+	}
+	
+	public QuestItemHolder(int id, int chance, long count)
+	{
+		super(id, count);
+		_chance = chance;
+	}
+	
+	public int getChance()
+	{
+		return _chance;
+	}
+}

+ 47 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/holders/UniqueItemHolder.java

@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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.
+ * 
+ * L2J Server 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.l2jserver.gameserver.model.holders;
+
+import com.l2jserver.gameserver.model.interfaces.IUniqueId;
+
+/**
+ * Unique object id item holder.
+ * @author xban1x
+ */
+public final class UniqueItemHolder extends ItemHolder implements IUniqueId
+{
+	private final int _objectId;
+	
+	public UniqueItemHolder(int id, int objectId)
+	{
+		this(id, objectId, 1);
+	}
+	
+	public UniqueItemHolder(int id, int objectId, long count)
+	{
+		super(id, count);
+		_objectId = objectId;
+	}
+	
+	@Override
+	public int getObjectId()
+	{
+		return _objectId;
+	}
+}

+ 4 - 4
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestSellItem.java

@@ -31,7 +31,7 @@ import com.l2jserver.gameserver.model.actor.L2Character;
 import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.model.buylist.L2BuyList;
-import com.l2jserver.gameserver.model.holders.ItemHolder;
+import com.l2jserver.gameserver.model.holders.UniqueItemHolder;
 import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
 import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
 import com.l2jserver.gameserver.network.serverpackets.ExBuySellList;
@@ -48,7 +48,7 @@ public final class RequestSellItem extends L2GameClientPacket
 	private static final int BATCH_LENGTH = 16;
 	
 	private int _listId;
-	private List<ItemHolder> _items = null;
+	private List<UniqueItemHolder> _items = null;
 	
 	@Override
 	protected void readImpl()
@@ -71,7 +71,7 @@ public final class RequestSellItem extends L2GameClientPacket
 				_items = null;
 				return;
 			}
-			_items.add(new ItemHolder(itemId, objectId, count));
+			_items.add(new UniqueItemHolder(itemId, objectId, count));
 		}
 	}
 	
@@ -153,7 +153,7 @@ public final class RequestSellItem extends L2GameClientPacket
 		
 		long totalPrice = 0;
 		// Proceed the sell
-		for (ItemHolder i : _items)
+		for (UniqueItemHolder i : _items)
 		{
 			L2ItemInstance item = player.checkItemManipulation(i.getObjectId(), i.getCount(), "sell");
 			if ((item == null) || (!item.isSellable()))