Fixed LimitShop production display count.

Contributed by Index.
This commit is contained in:
MobiusDevelopment
2022-11-13 23:26:00 +00:00
parent c45d33e59c
commit 3b17bc9a37
18 changed files with 253 additions and 420 deletions

View File

@@ -16,19 +16,21 @@
*/ */
package org.l2jmobius.gameserver.model.holders; package org.l2jmobius.gameserver.model.holders;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author Gustavo Fonseca * @author Gustavo Fonseca
*/ */
public class LimitShopRandomCraftReward public class LimitShopRandomCraftReward
{ {
private final int _itemId; private final int _itemId;
private final int _count; private final AtomicInteger _count;
private final int _rewardIndex; private final int _rewardIndex;
public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex) public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
{ {
_itemId = itemId; _itemId = itemId;
_count = count; _count = new AtomicInteger(count);
_rewardIndex = rewardIndex; _rewardIndex = rewardIndex;
} }
@@ -37,7 +39,7 @@ public class LimitShopRandomCraftReward
return _itemId; return _itemId;
} }
public int getCount() public AtomicInteger getCount()
{ {
return _count; return _count;
} }

View File

@@ -16,9 +16,10 @@
*/ */
package org.l2jmobius.gameserver.network.clientpackets.limitshop; package org.l2jmobius.gameserver.network.clientpackets.limitshop;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.l2jmobius.commons.network.ReadablePacket; import org.l2jmobius.commons.network.ReadablePacket;
import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.commons.util.Rnd;
@@ -44,10 +45,10 @@ import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
*/ */
public class RequestPurchaseLimitShopItemBuy implements ClientPacket public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
private int _shopIndex;
private int _productId; private int _productId;
private int _amount; private int _amount;
private LimitShopProductHolder _product; private LimitShopProductHolder _product;
private int _shopIndex;
@Override @Override
public void read(ReadablePacket packet) public void read(ReadablePacket packet)
@@ -92,24 +93,28 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
if ((_amount < 1) || (_amount > 10000)) if ((_amount < 1) || (_amount > 10000))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (!player.isInventoryUnder80(false)) if (!player.isInventoryUnder80(false))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel())) if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel()))
{ {
player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM); player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class)) if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
@@ -123,6 +128,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? player.sendMessage("You have reached your daily limit."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
@@ -132,11 +138,13 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message? player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
// Check existing items. // Check existing items.
final int remainingInfo = Math.max(0, Math.max(_product.getAccountBuyLimit(), _product.getAccountDailyLimit()));
for (int i = 0; i < _product.getIngredientIds().length; i++) for (int i = 0; i < _product.getIngredientIds().length; i++)
{ {
if (_product.getIngredientIds()[i] == 0) if (_product.getIngredientIds()[i] == 0)
@@ -149,6 +157,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -158,6 +167,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -165,6 +175,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -208,43 +219,42 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
} }
// Reward. // Reward.
final List<LimitShopRandomCraftReward> rewards = new ArrayList<>(); final Map<Integer, LimitShopRandomCraftReward> rewards = new HashMap<>();
if (_product.getProductionId2() > 0) if (_product.getProductionId2() > 0)
{ {
for (int i = 0; i < _amount; i++) for (int i = 0; i < _amount; i++)
{ {
if (Rnd.get(100) < _product.getChance()) if (Rnd.get(100) < _product.getChance())
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0)); rewards.computeIfAbsent(0, k -> new LimitShopRandomCraftReward(_product.getProductionId(), 0, 0)).getCount().addAndGet((int) _product.getCount());
player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0)) else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1)); rewards.computeIfAbsent(1, k -> new LimitShopRandomCraftReward(_product.getProductionId2(), 0, 1)).getCount().addAndGet((int) _product.getCount2());
player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true); player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0)) else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2)); rewards.computeIfAbsent(2, k -> new LimitShopRandomCraftReward(_product.getProductionId3(), 0, 2)).getCount().addAndGet((int) _product.getCount3());
player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true); player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0)) else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId4(), (int) _product.getCount4(), 3)); rewards.computeIfAbsent(3, k -> new LimitShopRandomCraftReward(_product.getProductionId4(), 0, 3)).getCount().addAndGet((int) _product.getCount4());
player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true); player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true);
} }
else if (_product.getProductionId5() > 0) else if (_product.getProductionId5() > 0)
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId5(), (int) _product.getCount5(), 4)); rewards.computeIfAbsent(4, k -> new LimitShopRandomCraftReward(_product.getProductionId5(), 0, 4)).getCount().addAndGet((int) _product.getCount5());
player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true); player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true);
} }
} }
} }
else if (Rnd.get(100) < _product.getChance()) else if (Rnd.get(100) < _product.getChance())
{ {
final int amount = (int) (_product.getCount() * _amount); rewards.put(0, new LimitShopRandomCraftReward(_product.getProductionId(), (int) (_product.getCount() * _amount), 0));
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), amount, 0)); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount() * _amount, player, true);
player.addItem("LCoinShop", _product.getProductionId(), amount, player, true);
} }
// Update account variables. // Update account variables.
@@ -257,7 +267,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount); player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount);
} }
player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards)); player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, Math.max(remainingInfo - _amount, 0), rewards.values()));
player.sendItemList(); player.sendItemList();
// Remove request. // Remove request.

View File

@@ -16,11 +16,8 @@
*/ */
package org.l2jmobius.gameserver.network.serverpackets.limitshop; package org.l2jmobius.gameserver.network.serverpackets.limitshop;
import java.util.List; import java.util.Collection;
import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.data.xml.LimitShopData;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward; import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.network.ServerPackets; import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket; import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
@@ -32,66 +29,32 @@ public class ExPurchaseLimitShopItemResult extends ServerPacket
{ {
private final int _category, _productId; private final int _category, _productId;
private final boolean _isSuccess; private final boolean _isSuccess;
private final List<LimitShopRandomCraftReward> _rewards; private final int _remainingInfo;
private final LimitShopProductHolder _product; private final Collection<LimitShopRandomCraftReward> _rewards;
public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List<LimitShopRandomCraftReward> rewards) public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, int remainingInfo, Collection<LimitShopRandomCraftReward> rewards)
{ {
_isSuccess = isSuccess; _isSuccess = isSuccess;
_category = category; _category = category;
_productId = productId; _productId = productId;
_remainingInfo = remainingInfo;
_rewards = rewards; _rewards = rewards;
switch (_category)
{
case 3: // Normal Lcoin Shop
{
_product = LimitShopData.getInstance().getProduct(_productId);
break;
}
case 4: // Lcoin Special Craft
{
_product = LimitShopCraftData.getInstance().getProduct(_productId);
break;
}
default:
{
_product = null;
}
}
} }
@Override @Override
public void write() public void write()
{ {
ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this); ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this);
if ((_product == null) || !_isSuccess) writeByte(_isSuccess ? 0 : 1);
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
for (LimitShopRandomCraftReward entry : _rewards)
{ {
writeByte(1); writeByte(entry.getRewardIndex());
writeByte(_category); writeInt(entry.getItemId());
writeInt(_productId); writeInt(entry.getCount().get());
writeInt(1);
writeByte(1);
writeInt(0);
writeLong(0);
}
else
{
writeByte(0); // success
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
int counter = 0;
for (LimitShopRandomCraftReward entry : _rewards)
{
if (counter == _rewards.size())
{
break;
}
writeByte(entry.getRewardIndex());
writeInt(0);
writeInt(entry.getCount());
counter++;
}
} }
writeInt(_remainingInfo);
} }
} }

View File

@@ -16,19 +16,21 @@
*/ */
package org.l2jmobius.gameserver.model.holders; package org.l2jmobius.gameserver.model.holders;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author Gustavo Fonseca * @author Gustavo Fonseca
*/ */
public class LimitShopRandomCraftReward public class LimitShopRandomCraftReward
{ {
private final int _itemId; private final int _itemId;
private final int _count; private final AtomicInteger _count;
private final int _rewardIndex; private final int _rewardIndex;
public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex) public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
{ {
_itemId = itemId; _itemId = itemId;
_count = count; _count = new AtomicInteger(count);
_rewardIndex = rewardIndex; _rewardIndex = rewardIndex;
} }
@@ -37,7 +39,7 @@ public class LimitShopRandomCraftReward
return _itemId; return _itemId;
} }
public int getCount() public AtomicInteger getCount()
{ {
return _count; return _count;
} }

View File

@@ -16,9 +16,10 @@
*/ */
package org.l2jmobius.gameserver.network.clientpackets.limitshop; package org.l2jmobius.gameserver.network.clientpackets.limitshop;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.l2jmobius.commons.network.ReadablePacket; import org.l2jmobius.commons.network.ReadablePacket;
import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.commons.util.Rnd;
@@ -45,10 +46,10 @@ import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
*/ */
public class RequestPurchaseLimitShopItemBuy implements ClientPacket public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
private int _shopIndex;
private int _productId; private int _productId;
private int _amount; private int _amount;
private LimitShopProductHolder _product; private LimitShopProductHolder _product;
private int _shopIndex;
@Override @Override
public void read(ReadablePacket packet) public void read(ReadablePacket packet)
@@ -96,24 +97,28 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
if ((_amount < 1) || (_amount > 10000)) if ((_amount < 1) || (_amount > 10000))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (!player.isInventoryUnder80(false)) if (!player.isInventoryUnder80(false))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel())) if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel()))
{ {
player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM); player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class)) if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
@@ -127,6 +132,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? player.sendMessage("You have reached your daily limit."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
@@ -136,11 +142,13 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message? player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
// Check existing items. // Check existing items.
final int remainingInfo = Math.max(0, Math.max(_product.getAccountBuyLimit(), _product.getAccountDailyLimit()));
for (int i = 0; i < _product.getIngredientIds().length; i++) for (int i = 0; i < _product.getIngredientIds().length; i++)
{ {
if (_product.getIngredientIds()[i] == 0) if (_product.getIngredientIds()[i] == 0)
@@ -153,6 +161,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -162,6 +171,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -171,6 +181,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -178,6 +189,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -227,43 +239,42 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
} }
// Reward. // Reward.
final List<LimitShopRandomCraftReward> rewards = new ArrayList<>(); final Map<Integer, LimitShopRandomCraftReward> rewards = new HashMap<>();
if (_product.getProductionId2() > 0) if (_product.getProductionId2() > 0)
{ {
for (int i = 0; i < _amount; i++) for (int i = 0; i < _amount; i++)
{ {
if (Rnd.get(100) < _product.getChance()) if (Rnd.get(100) < _product.getChance())
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0)); rewards.computeIfAbsent(0, k -> new LimitShopRandomCraftReward(_product.getProductionId(), 0, 0)).getCount().addAndGet((int) _product.getCount());
player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0)) else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1)); rewards.computeIfAbsent(1, k -> new LimitShopRandomCraftReward(_product.getProductionId2(), 0, 1)).getCount().addAndGet((int) _product.getCount2());
player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true); player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0)) else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2)); rewards.computeIfAbsent(2, k -> new LimitShopRandomCraftReward(_product.getProductionId3(), 0, 2)).getCount().addAndGet((int) _product.getCount3());
player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true); player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0)) else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId4(), (int) _product.getCount4(), 3)); rewards.computeIfAbsent(3, k -> new LimitShopRandomCraftReward(_product.getProductionId4(), 0, 3)).getCount().addAndGet((int) _product.getCount4());
player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true); player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true);
} }
else if (_product.getProductionId5() > 0) else if (_product.getProductionId5() > 0)
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId5(), (int) _product.getCount5(), 4)); rewards.computeIfAbsent(4, k -> new LimitShopRandomCraftReward(_product.getProductionId5(), 0, 4)).getCount().addAndGet((int) _product.getCount5());
player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true); player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true);
} }
} }
} }
else if (Rnd.get(100) < _product.getChance()) else if (Rnd.get(100) < _product.getChance())
{ {
final int amount = (int) (_product.getCount() * _amount); rewards.put(0, new LimitShopRandomCraftReward(_product.getProductionId(), (int) (_product.getCount() * _amount), 0));
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), amount, 0)); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount() * _amount, player, true);
player.addItem("LCoinShop", _product.getProductionId(), amount, player, true);
} }
// Update account variables. // Update account variables.
@@ -276,7 +287,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount); player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount);
} }
player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards)); player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, Math.max(remainingInfo - _amount, 0), rewards.values()));
player.sendItemList(); player.sendItemList();
// Remove request. // Remove request.

View File

@@ -16,11 +16,8 @@
*/ */
package org.l2jmobius.gameserver.network.serverpackets.limitshop; package org.l2jmobius.gameserver.network.serverpackets.limitshop;
import java.util.List; import java.util.Collection;
import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.data.xml.LimitShopData;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward; import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.network.ServerPackets; import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket; import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
@@ -32,66 +29,32 @@ public class ExPurchaseLimitShopItemResult extends ServerPacket
{ {
private final int _category, _productId; private final int _category, _productId;
private final boolean _isSuccess; private final boolean _isSuccess;
private final List<LimitShopRandomCraftReward> _rewards; private final int _remainingInfo;
private final LimitShopProductHolder _product; private final Collection<LimitShopRandomCraftReward> _rewards;
public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List<LimitShopRandomCraftReward> rewards) public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, int remainingInfo, Collection<LimitShopRandomCraftReward> rewards)
{ {
_isSuccess = isSuccess; _isSuccess = isSuccess;
_category = category; _category = category;
_productId = productId; _productId = productId;
_remainingInfo = remainingInfo;
_rewards = rewards; _rewards = rewards;
switch (_category)
{
case 3: // Normal Lcoin Shop
{
_product = LimitShopData.getInstance().getProduct(_productId);
break;
}
case 4: // Lcoin Special Craft
{
_product = LimitShopCraftData.getInstance().getProduct(_productId);
break;
}
default:
{
_product = null;
}
}
} }
@Override @Override
public void write() public void write()
{ {
ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this); ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this);
if ((_product == null) || !_isSuccess) writeByte(_isSuccess ? 0 : 1);
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
for (LimitShopRandomCraftReward entry : _rewards)
{ {
writeByte(1); writeByte(entry.getRewardIndex());
writeByte(_category); writeInt(entry.getItemId());
writeInt(_productId); writeInt(entry.getCount().get());
writeInt(1);
writeByte(1);
writeInt(0);
writeLong(0);
}
else
{
writeByte(0); // success
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
int counter = 0;
for (LimitShopRandomCraftReward entry : _rewards)
{
if (counter == _rewards.size())
{
break;
}
writeByte(entry.getRewardIndex());
writeInt(0);
writeInt(entry.getCount());
counter++;
}
} }
writeInt(_remainingInfo);
} }
} }

View File

@@ -16,19 +16,21 @@
*/ */
package org.l2jmobius.gameserver.model.holders; package org.l2jmobius.gameserver.model.holders;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author Gustavo Fonseca * @author Gustavo Fonseca
*/ */
public class LimitShopRandomCraftReward public class LimitShopRandomCraftReward
{ {
private final int _itemId; private final int _itemId;
private final int _count; private final AtomicInteger _count;
private final int _rewardIndex; private final int _rewardIndex;
public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex) public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
{ {
_itemId = itemId; _itemId = itemId;
_count = count; _count = new AtomicInteger(count);
_rewardIndex = rewardIndex; _rewardIndex = rewardIndex;
} }
@@ -37,7 +39,7 @@ public class LimitShopRandomCraftReward
return _itemId; return _itemId;
} }
public int getCount() public AtomicInteger getCount()
{ {
return _count; return _count;
} }

View File

@@ -16,9 +16,10 @@
*/ */
package org.l2jmobius.gameserver.network.clientpackets.limitshop; package org.l2jmobius.gameserver.network.clientpackets.limitshop;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.network.ReadablePacket; import org.l2jmobius.commons.network.ReadablePacket;
@@ -44,10 +45,10 @@ import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
*/ */
public class RequestPurchaseLimitShopItemBuy implements ClientPacket public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
private int _shopIndex;
private int _productId; private int _productId;
private int _amount; private int _amount;
private LimitShopProductHolder _product; private LimitShopProductHolder _product;
private int _shopIndex;
@Override @Override
public void read(ReadablePacket packet) public void read(ReadablePacket packet)
@@ -92,24 +93,28 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
if ((_amount < 1) || (_amount > 10000)) if ((_amount < 1) || (_amount > 10000))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (!player.isInventoryUnder80(false)) if (!player.isInventoryUnder80(false))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel())) if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel()))
{ {
player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM); player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class)) if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
@@ -123,6 +128,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? player.sendMessage("You have reached your daily limit."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
@@ -132,11 +138,13 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message? player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
// Check existing items. // Check existing items.
final int remainingInfo = Math.max(0, Math.max(_product.getAccountBuyLimit(), _product.getAccountDailyLimit()));
for (int i = 0; i < _product.getIngredientIds().length; i++) for (int i = 0; i < _product.getIngredientIds().length; i++)
{ {
if (_product.getIngredientIds()[i] == 0) if (_product.getIngredientIds()[i] == 0)
@@ -149,6 +157,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -156,6 +165,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -199,43 +209,42 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
} }
// Reward. // Reward.
final List<LimitShopRandomCraftReward> rewards = new ArrayList<>(); final Map<Integer, LimitShopRandomCraftReward> rewards = new HashMap<>();
if (_product.getProductionId2() > 0) if (_product.getProductionId2() > 0)
{ {
for (int i = 0; i < _amount; i++) for (int i = 0; i < _amount; i++)
{ {
if (Rnd.get(100) < _product.getChance()) if (Rnd.get(100) < _product.getChance())
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0)); rewards.computeIfAbsent(0, k -> new LimitShopRandomCraftReward(_product.getProductionId(), 0, 0)).getCount().addAndGet((int) _product.getCount());
player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0)) else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1)); rewards.computeIfAbsent(1, k -> new LimitShopRandomCraftReward(_product.getProductionId2(), 0, 1)).getCount().addAndGet((int) _product.getCount2());
player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true); player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0)) else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2)); rewards.computeIfAbsent(2, k -> new LimitShopRandomCraftReward(_product.getProductionId3(), 0, 2)).getCount().addAndGet((int) _product.getCount3());
player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true); player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0)) else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId4(), (int) _product.getCount4(), 3)); rewards.computeIfAbsent(3, k -> new LimitShopRandomCraftReward(_product.getProductionId4(), 0, 3)).getCount().addAndGet((int) _product.getCount4());
player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true); player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true);
} }
else if (_product.getProductionId5() > 0) else if (_product.getProductionId5() > 0)
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId5(), (int) _product.getCount5(), 4)); rewards.computeIfAbsent(4, k -> new LimitShopRandomCraftReward(_product.getProductionId5(), 0, 4)).getCount().addAndGet((int) _product.getCount5());
player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true); player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true);
} }
} }
} }
else if (Rnd.get(100) < _product.getChance()) else if (Rnd.get(100) < _product.getChance())
{ {
final int amount = (int) (_product.getCount() * _amount); rewards.put(0, new LimitShopRandomCraftReward(_product.getProductionId(), (int) (_product.getCount() * _amount), 0));
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), amount, 0)); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount() * _amount, player, true);
player.addItem("LCoinShop", _product.getProductionId(), amount, player, true);
} }
// Update account variables. // Update account variables.
@@ -248,7 +257,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount); player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount);
} }
player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards)); player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, Math.max(remainingInfo - _amount, 0), rewards.values()));
player.sendItemList(); player.sendItemList();
// Remove request. // Remove request.

View File

@@ -16,11 +16,8 @@
*/ */
package org.l2jmobius.gameserver.network.serverpackets.limitshop; package org.l2jmobius.gameserver.network.serverpackets.limitshop;
import java.util.List; import java.util.Collection;
import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.data.xml.LimitShopData;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward; import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.network.ServerPackets; import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket; import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
@@ -32,66 +29,32 @@ public class ExPurchaseLimitShopItemResult extends ServerPacket
{ {
private final int _category, _productId; private final int _category, _productId;
private final boolean _isSuccess; private final boolean _isSuccess;
private final List<LimitShopRandomCraftReward> _rewards; private final int _remainingInfo;
private final LimitShopProductHolder _product; private final Collection<LimitShopRandomCraftReward> _rewards;
public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List<LimitShopRandomCraftReward> rewards) public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, int remainingInfo, Collection<LimitShopRandomCraftReward> rewards)
{ {
_isSuccess = isSuccess; _isSuccess = isSuccess;
_category = category; _category = category;
_productId = productId; _productId = productId;
_remainingInfo = remainingInfo;
_rewards = rewards; _rewards = rewards;
switch (_category)
{
case 3: // Normal Lcoin Shop
{
_product = LimitShopData.getInstance().getProduct(_productId);
break;
}
case 4: // Lcoin Special Craft
{
_product = LimitShopCraftData.getInstance().getProduct(_productId);
break;
}
default:
{
_product = null;
}
}
} }
@Override @Override
public void write() public void write()
{ {
ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this); ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this);
if ((_product == null) || !_isSuccess) writeByte(_isSuccess ? 0 : 1);
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
for (LimitShopRandomCraftReward entry : _rewards)
{ {
writeByte(1); writeByte(entry.getRewardIndex());
writeByte(_category); writeInt(entry.getItemId());
writeInt(_productId); writeInt(entry.getCount().get());
writeInt(1);
writeByte(1);
writeInt(0);
writeLong(0);
}
else
{
writeByte(0); // success
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
int counter = 0;
for (LimitShopRandomCraftReward entry : _rewards)
{
if (counter == _rewards.size())
{
break;
}
writeByte(entry.getRewardIndex());
writeInt(0);
writeInt(entry.getCount());
counter++;
}
} }
writeInt(_remainingInfo);
} }
} }

View File

@@ -16,19 +16,21 @@
*/ */
package org.l2jmobius.gameserver.model.holders; package org.l2jmobius.gameserver.model.holders;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author Gustavo Fonseca * @author Gustavo Fonseca
*/ */
public class LimitShopRandomCraftReward public class LimitShopRandomCraftReward
{ {
private final int _itemId; private final int _itemId;
private final int _count; private final AtomicInteger _count;
private final int _rewardIndex; private final int _rewardIndex;
public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex) public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
{ {
_itemId = itemId; _itemId = itemId;
_count = count; _count = new AtomicInteger(count);
_rewardIndex = rewardIndex; _rewardIndex = rewardIndex;
} }
@@ -37,7 +39,7 @@ public class LimitShopRandomCraftReward
return _itemId; return _itemId;
} }
public int getCount() public AtomicInteger getCount()
{ {
return _count; return _count;
} }

View File

@@ -16,9 +16,10 @@
*/ */
package org.l2jmobius.gameserver.network.clientpackets.limitshop; package org.l2jmobius.gameserver.network.clientpackets.limitshop;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.network.ReadablePacket; import org.l2jmobius.commons.network.ReadablePacket;
@@ -46,10 +47,10 @@ import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
*/ */
public class RequestPurchaseLimitShopItemBuy implements ClientPacket public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
private int _shopIndex;
private int _productId; private int _productId;
private int _amount; private int _amount;
private LimitShopProductHolder _product; private LimitShopProductHolder _product;
private int _shopIndex;
@Override @Override
public void read(ReadablePacket packet) public void read(ReadablePacket packet)
@@ -99,24 +100,28 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
if ((_amount < 1) || (_amount > 10000)) if ((_amount < 1) || (_amount > 10000))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (!player.isInventoryUnder80(false)) if (!player.isInventoryUnder80(false))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel())) if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel()))
{ {
player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM); player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class)) if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
@@ -130,6 +135,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? player.sendMessage("You have reached your daily limit."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
@@ -139,11 +145,13 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message? player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
// Check existing items. // Check existing items.
final int remainingInfo = Math.max(0, Math.max(_product.getAccountBuyLimit(), _product.getAccountDailyLimit()));
for (int i = 0; i < _product.getIngredientIds().length; i++) for (int i = 0; i < _product.getIngredientIds().length; i++)
{ {
if (_product.getIngredientIds()[i] == 0) if (_product.getIngredientIds()[i] == 0)
@@ -156,6 +164,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -165,6 +174,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -172,6 +182,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -219,43 +230,42 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
} }
// Reward. // Reward.
final List<LimitShopRandomCraftReward> rewards = new ArrayList<>(); final Map<Integer, LimitShopRandomCraftReward> rewards = new HashMap<>();
if (_product.getProductionId2() > 0) if (_product.getProductionId2() > 0)
{ {
for (int i = 0; i < _amount; i++) for (int i = 0; i < _amount; i++)
{ {
if (Rnd.get(100) < _product.getChance()) if (Rnd.get(100) < _product.getChance())
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0)); rewards.computeIfAbsent(0, k -> new LimitShopRandomCraftReward(_product.getProductionId(), 0, 0)).getCount().addAndGet((int) _product.getCount());
player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0)) else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1)); rewards.computeIfAbsent(1, k -> new LimitShopRandomCraftReward(_product.getProductionId2(), 0, 1)).getCount().addAndGet((int) _product.getCount2());
player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true); player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0)) else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2)); rewards.computeIfAbsent(2, k -> new LimitShopRandomCraftReward(_product.getProductionId3(), 0, 2)).getCount().addAndGet((int) _product.getCount3());
player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true); player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0)) else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId4(), (int) _product.getCount4(), 3)); rewards.computeIfAbsent(3, k -> new LimitShopRandomCraftReward(_product.getProductionId4(), 0, 3)).getCount().addAndGet((int) _product.getCount4());
player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true); player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true);
} }
else if (_product.getProductionId5() > 0) else if (_product.getProductionId5() > 0)
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId5(), (int) _product.getCount5(), 4)); rewards.computeIfAbsent(4, k -> new LimitShopRandomCraftReward(_product.getProductionId5(), 0, 4)).getCount().addAndGet((int) _product.getCount5());
player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true); player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true);
} }
} }
} }
else if (Rnd.get(100) < _product.getChance()) else if (Rnd.get(100) < _product.getChance())
{ {
final int amount = (int) (_product.getCount() * _amount); rewards.put(0, new LimitShopRandomCraftReward(_product.getProductionId(), (int) (_product.getCount() * _amount), 0));
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), amount, 0)); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount() * _amount, player, true);
player.addItem("LCoinShop", _product.getProductionId(), amount, player, true);
} }
// Update account variables. // Update account variables.
@@ -268,7 +278,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount); player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount);
} }
player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards)); player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, Math.max(remainingInfo - _amount, 0), rewards.values()));
player.sendItemList(); player.sendItemList();
// Remove request. // Remove request.

View File

@@ -16,12 +16,8 @@
*/ */
package org.l2jmobius.gameserver.network.serverpackets.limitshop; package org.l2jmobius.gameserver.network.serverpackets.limitshop;
import java.util.List; import java.util.Collection;
import org.l2jmobius.gameserver.data.xml.LimitShopClanData;
import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.data.xml.LimitShopData;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward; import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.network.ServerPackets; import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket; import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
@@ -33,71 +29,32 @@ public class ExPurchaseLimitShopItemResult extends ServerPacket
{ {
private final int _category, _productId; private final int _category, _productId;
private final boolean _isSuccess; private final boolean _isSuccess;
private final List<LimitShopRandomCraftReward> _rewards; private final int _remainingInfo;
private final LimitShopProductHolder _product; private final Collection<LimitShopRandomCraftReward> _rewards;
public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List<LimitShopRandomCraftReward> rewards) public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, int remainingInfo, Collection<LimitShopRandomCraftReward> rewards)
{ {
_isSuccess = isSuccess; _isSuccess = isSuccess;
_category = category; _category = category;
_productId = productId; _productId = productId;
_remainingInfo = remainingInfo;
_rewards = rewards; _rewards = rewards;
switch (_category)
{
case 3: // Normal Lcoin Shop
{
_product = LimitShopData.getInstance().getProduct(_productId);
break;
}
case 4: // Lcoin Special Craft
{
_product = LimitShopCraftData.getInstance().getProduct(_productId);
break;
}
case 100: // Clan Shop
{
_product = LimitShopClanData.getInstance().getProduct(_productId);
break;
}
default:
{
_product = null;
}
}
} }
@Override @Override
public void write() public void write()
{ {
ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this); ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this);
if ((_product == null) || !_isSuccess) writeByte(_isSuccess ? 0 : 1);
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
for (LimitShopRandomCraftReward entry : _rewards)
{ {
writeByte(1); writeByte(entry.getRewardIndex());
writeByte(_category); writeInt(entry.getItemId());
writeInt(_productId); writeInt(entry.getCount().get());
writeInt(1);
writeByte(1);
writeInt(0);
writeLong(0);
}
else
{
writeByte(0); // success
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
int counter = 0;
for (LimitShopRandomCraftReward entry : _rewards)
{
if (counter == _rewards.size())
{
break;
}
writeByte(entry.getRewardIndex());
writeInt(0);
writeInt(entry.getCount());
counter++;
}
} }
writeInt(_remainingInfo);
} }
} }

View File

@@ -16,19 +16,21 @@
*/ */
package org.l2jmobius.gameserver.model.holders; package org.l2jmobius.gameserver.model.holders;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author Gustavo Fonseca * @author Gustavo Fonseca
*/ */
public class LimitShopRandomCraftReward public class LimitShopRandomCraftReward
{ {
private final int _itemId; private final int _itemId;
private final int _count; private final AtomicInteger _count;
private final int _rewardIndex; private final int _rewardIndex;
public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex) public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
{ {
_itemId = itemId; _itemId = itemId;
_count = count; _count = new AtomicInteger(count);
_rewardIndex = rewardIndex; _rewardIndex = rewardIndex;
} }
@@ -37,7 +39,7 @@ public class LimitShopRandomCraftReward
return _itemId; return _itemId;
} }
public int getCount() public AtomicInteger getCount()
{ {
return _count; return _count;
} }

View File

@@ -16,9 +16,10 @@
*/ */
package org.l2jmobius.gameserver.network.clientpackets.limitshop; package org.l2jmobius.gameserver.network.clientpackets.limitshop;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.network.ReadablePacket; import org.l2jmobius.commons.network.ReadablePacket;
@@ -46,10 +47,10 @@ import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
*/ */
public class RequestPurchaseLimitShopItemBuy implements ClientPacket public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
private int _shopIndex;
private int _productId; private int _productId;
private int _amount; private int _amount;
private LimitShopProductHolder _product; private LimitShopProductHolder _product;
private int _shopIndex;
@Override @Override
public void read(ReadablePacket packet) public void read(ReadablePacket packet)
@@ -99,24 +100,28 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
if ((_amount < 1) || (_amount > 10000)) if ((_amount < 1) || (_amount > 10000))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (!player.isInventoryUnder80(false)) if (!player.isInventoryUnder80(false))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel())) if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel()))
{ {
player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM); player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class)) if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
@@ -130,6 +135,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? player.sendMessage("You have reached your daily limit."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
@@ -139,11 +145,13 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message? player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
// Check existing items. // Check existing items.
final int remainingInfo = Math.max(0, Math.max(_product.getAccountBuyLimit(), _product.getAccountDailyLimit()));
for (int i = 0; i < _product.getIngredientIds().length; i++) for (int i = 0; i < _product.getIngredientIds().length; i++)
{ {
if (_product.getIngredientIds()[i] == 0) if (_product.getIngredientIds()[i] == 0)
@@ -156,6 +164,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -165,6 +174,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -172,6 +182,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -219,43 +230,42 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
} }
// Reward. // Reward.
final List<LimitShopRandomCraftReward> rewards = new ArrayList<>(); final Map<Integer, LimitShopRandomCraftReward> rewards = new HashMap<>();
if (_product.getProductionId2() > 0) if (_product.getProductionId2() > 0)
{ {
for (int i = 0; i < _amount; i++) for (int i = 0; i < _amount; i++)
{ {
if (Rnd.get(100) < _product.getChance()) if (Rnd.get(100) < _product.getChance())
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0)); rewards.computeIfAbsent(0, k -> new LimitShopRandomCraftReward(_product.getProductionId(), 0, 0)).getCount().addAndGet((int) _product.getCount());
player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0)) else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1)); rewards.computeIfAbsent(1, k -> new LimitShopRandomCraftReward(_product.getProductionId2(), 0, 1)).getCount().addAndGet((int) _product.getCount2());
player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true); player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0)) else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2)); rewards.computeIfAbsent(2, k -> new LimitShopRandomCraftReward(_product.getProductionId3(), 0, 2)).getCount().addAndGet((int) _product.getCount3());
player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true); player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0)) else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId4(), (int) _product.getCount4(), 3)); rewards.computeIfAbsent(3, k -> new LimitShopRandomCraftReward(_product.getProductionId4(), 0, 3)).getCount().addAndGet((int) _product.getCount4());
player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true); player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true);
} }
else if (_product.getProductionId5() > 0) else if (_product.getProductionId5() > 0)
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId5(), (int) _product.getCount5(), 4)); rewards.computeIfAbsent(4, k -> new LimitShopRandomCraftReward(_product.getProductionId5(), 0, 4)).getCount().addAndGet((int) _product.getCount5());
player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true); player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true);
} }
} }
} }
else if (Rnd.get(100) < _product.getChance()) else if (Rnd.get(100) < _product.getChance())
{ {
final int amount = (int) (_product.getCount() * _amount); rewards.put(0, new LimitShopRandomCraftReward(_product.getProductionId(), (int) (_product.getCount() * _amount), 0));
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), amount, 0)); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount() * _amount, player, true);
player.addItem("LCoinShop", _product.getProductionId(), amount, player, true);
} }
// Update account variables. // Update account variables.
@@ -268,7 +278,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount); player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount);
} }
player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards)); player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, Math.max(remainingInfo - _amount, 0), rewards.values()));
player.sendItemList(); player.sendItemList();
// Remove request. // Remove request.

View File

@@ -16,12 +16,8 @@
*/ */
package org.l2jmobius.gameserver.network.serverpackets.limitshop; package org.l2jmobius.gameserver.network.serverpackets.limitshop;
import java.util.List; import java.util.Collection;
import org.l2jmobius.gameserver.data.xml.LimitShopClanData;
import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.data.xml.LimitShopData;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward; import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.network.ServerPackets; import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket; import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
@@ -33,71 +29,32 @@ public class ExPurchaseLimitShopItemResult extends ServerPacket
{ {
private final int _category, _productId; private final int _category, _productId;
private final boolean _isSuccess; private final boolean _isSuccess;
private final List<LimitShopRandomCraftReward> _rewards; private final int _remainingInfo;
private final LimitShopProductHolder _product; private final Collection<LimitShopRandomCraftReward> _rewards;
public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List<LimitShopRandomCraftReward> rewards) public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, int remainingInfo, Collection<LimitShopRandomCraftReward> rewards)
{ {
_isSuccess = isSuccess; _isSuccess = isSuccess;
_category = category; _category = category;
_productId = productId; _productId = productId;
_remainingInfo = remainingInfo;
_rewards = rewards; _rewards = rewards;
switch (_category)
{
case 3: // Normal Lcoin Shop
{
_product = LimitShopData.getInstance().getProduct(_productId);
break;
}
case 4: // Lcoin Special Craft
{
_product = LimitShopCraftData.getInstance().getProduct(_productId);
break;
}
case 100: // Clan Shop
{
_product = LimitShopClanData.getInstance().getProduct(_productId);
break;
}
default:
{
_product = null;
}
}
} }
@Override @Override
public void write() public void write()
{ {
ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this); ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this);
if ((_product == null) || !_isSuccess) writeByte(_isSuccess ? 0 : 1);
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
for (LimitShopRandomCraftReward entry : _rewards)
{ {
writeByte(1); writeByte(entry.getRewardIndex());
writeByte(_category); writeInt(entry.getItemId());
writeInt(_productId); writeInt(entry.getCount().get());
writeInt(1);
writeByte(1);
writeInt(0);
writeLong(0);
}
else
{
writeByte(0); // success
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
int counter = 0;
for (LimitShopRandomCraftReward entry : _rewards)
{
if (counter == _rewards.size())
{
break;
}
writeByte(entry.getRewardIndex());
writeInt(0);
writeInt(entry.getCount());
counter++;
}
} }
writeInt(_remainingInfo);
} }
} }

View File

@@ -16,19 +16,21 @@
*/ */
package org.l2jmobius.gameserver.model.holders; package org.l2jmobius.gameserver.model.holders;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* @author Gustavo Fonseca * @author Gustavo Fonseca
*/ */
public class LimitShopRandomCraftReward public class LimitShopRandomCraftReward
{ {
private final int _itemId; private final int _itemId;
private final int _count; private final AtomicInteger _count;
private final int _rewardIndex; private final int _rewardIndex;
public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex) public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
{ {
_itemId = itemId; _itemId = itemId;
_count = count; _count = new AtomicInteger(count);
_rewardIndex = rewardIndex; _rewardIndex = rewardIndex;
} }
@@ -37,7 +39,7 @@ public class LimitShopRandomCraftReward
return _itemId; return _itemId;
} }
public int getCount() public AtomicInteger getCount()
{ {
return _count; return _count;
} }

View File

@@ -16,9 +16,10 @@
*/ */
package org.l2jmobius.gameserver.network.clientpackets.limitshop; package org.l2jmobius.gameserver.network.clientpackets.limitshop;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.network.ReadablePacket; import org.l2jmobius.commons.network.ReadablePacket;
@@ -47,10 +48,10 @@ import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
*/ */
public class RequestPurchaseLimitShopItemBuy implements ClientPacket public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
private int _shopIndex;
private int _productId; private int _productId;
private int _amount; private int _amount;
private LimitShopProductHolder _product; private LimitShopProductHolder _product;
private int _shopIndex;
@Override @Override
public void read(ReadablePacket packet) public void read(ReadablePacket packet)
@@ -103,24 +104,28 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
if ((_amount < 1) || (_amount > 10000)) if ((_amount < 1) || (_amount > 10000))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (!player.isInventoryUnder80(false)) if (!player.isInventoryUnder80(false))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVENTORY_OVERFLOW));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel())) if ((player.getLevel() < _product.getMinLevel()) || (player.getLevel() > _product.getMaxLevel()))
{ {
player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM); player.sendPacket(SystemMessageId.YOUR_LEVEL_CANNOT_PURCHASE_THIS_ITEM);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class)) if (player.hasItemRequest() || player.hasRequest(PrimeShopRequest.class))
{ {
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE)); player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.INVALID_USER_STATE));
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
@@ -134,6 +139,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? player.sendMessage("You have reached your daily limit."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
@@ -143,11 +149,13 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message? player.sendMessage("You cannot buy any more of this item."); // TODO: Retail system message?
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, 0, Collections.emptyList()));
return; return;
} }
} }
// Check existing items. // Check existing items.
final int remainingInfo = Math.max(0, Math.max(_product.getAccountBuyLimit(), _product.getAccountDailyLimit()));
for (int i = 0; i < _product.getIngredientIds().length; i++) for (int i = 0; i < _product.getIngredientIds().length; i++)
{ {
if (_product.getIngredientIds()[i] == 0) if (_product.getIngredientIds()[i] == 0)
@@ -160,6 +168,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -169,6 +178,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -178,6 +188,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -185,6 +196,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
{ {
player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2); player.sendPacket(SystemMessageId.INCORRECT_ITEM_COUNT_2);
player.removeRequest(PrimeShopRequest.class); player.removeRequest(PrimeShopRequest.class);
player.sendPacket(new ExPurchaseLimitShopItemResult(false, _shopIndex, _productId, remainingInfo, Collections.emptyList()));
return; return;
} }
} }
@@ -238,43 +250,42 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
} }
// Reward. // Reward.
final List<LimitShopRandomCraftReward> rewards = new ArrayList<>(); final Map<Integer, LimitShopRandomCraftReward> rewards = new HashMap<>();
if (_product.getProductionId2() > 0) if (_product.getProductionId2() > 0)
{ {
for (int i = 0; i < _amount; i++) for (int i = 0; i < _amount; i++)
{ {
if (Rnd.get(100) < _product.getChance()) if (Rnd.get(100) < _product.getChance())
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0)); rewards.computeIfAbsent(0, k -> new LimitShopRandomCraftReward(_product.getProductionId(), 0, 0)).getCount().addAndGet((int) _product.getCount());
player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0)) else if ((Rnd.get(100) < _product.getChance2()) || (_product.getProductionId3() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1)); rewards.computeIfAbsent(1, k -> new LimitShopRandomCraftReward(_product.getProductionId2(), 0, 1)).getCount().addAndGet((int) _product.getCount2());
player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true); player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0)) else if ((Rnd.get(100) < _product.getChance3()) || (_product.getProductionId4() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2)); rewards.computeIfAbsent(2, k -> new LimitShopRandomCraftReward(_product.getProductionId3(), 0, 2)).getCount().addAndGet((int) _product.getCount3());
player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true); player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
} }
else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0)) else if ((Rnd.get(100) < _product.getChance4()) || (_product.getProductionId5() == 0))
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId4(), (int) _product.getCount4(), 3)); rewards.computeIfAbsent(3, k -> new LimitShopRandomCraftReward(_product.getProductionId4(), 0, 3)).getCount().addAndGet((int) _product.getCount4());
player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true); player.addItem("LCoinShop", _product.getProductionId4(), _product.getCount4(), player, true);
} }
else if (_product.getProductionId5() > 0) else if (_product.getProductionId5() > 0)
{ {
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId5(), (int) _product.getCount5(), 4)); rewards.computeIfAbsent(4, k -> new LimitShopRandomCraftReward(_product.getProductionId5(), 0, 4)).getCount().addAndGet((int) _product.getCount5());
player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true); player.addItem("LCoinShop", _product.getProductionId5(), _product.getCount5(), player, true);
} }
} }
} }
else if (Rnd.get(100) < _product.getChance()) else if (Rnd.get(100) < _product.getChance())
{ {
final int amount = (int) (_product.getCount() * _amount); rewards.put(0, new LimitShopRandomCraftReward(_product.getProductionId(), (int) (_product.getCount() * _amount), 0));
rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), amount, 0)); player.addItem("LCoinShop", _product.getProductionId(), _product.getCount() * _amount, player, true);
player.addItem("LCoinShop", _product.getProductionId(), amount, player, true);
} }
// Update account variables. // Update account variables.
@@ -287,7 +298,7 @@ public class RequestPurchaseLimitShopItemBuy implements ClientPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount); player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + _amount);
} }
player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards)); player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, Math.max(remainingInfo - _amount, 0), rewards.values()));
player.sendItemList(); player.sendItemList();
// Remove request. // Remove request.

View File

@@ -16,12 +16,8 @@
*/ */
package org.l2jmobius.gameserver.network.serverpackets.limitshop; package org.l2jmobius.gameserver.network.serverpackets.limitshop;
import java.util.List; import java.util.Collection;
import org.l2jmobius.gameserver.data.xml.LimitShopClanData;
import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.data.xml.LimitShopData;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward; import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.network.ServerPackets; import org.l2jmobius.gameserver.network.ServerPackets;
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket; import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
@@ -33,71 +29,32 @@ public class ExPurchaseLimitShopItemResult extends ServerPacket
{ {
private final int _category, _productId; private final int _category, _productId;
private final boolean _isSuccess; private final boolean _isSuccess;
private final List<LimitShopRandomCraftReward> _rewards; private final int _remainingInfo;
private final LimitShopProductHolder _product; private final Collection<LimitShopRandomCraftReward> _rewards;
public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List<LimitShopRandomCraftReward> rewards) public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, int remainingInfo, Collection<LimitShopRandomCraftReward> rewards)
{ {
_isSuccess = isSuccess; _isSuccess = isSuccess;
_category = category; _category = category;
_productId = productId; _productId = productId;
_remainingInfo = remainingInfo;
_rewards = rewards; _rewards = rewards;
switch (_category)
{
case 3: // Normal Lcoin Shop
{
_product = LimitShopData.getInstance().getProduct(_productId);
break;
}
case 4: // Lcoin Special Craft
{
_product = LimitShopCraftData.getInstance().getProduct(_productId);
break;
}
case 100: // Clan Shop
{
_product = LimitShopClanData.getInstance().getProduct(_productId);
break;
}
default:
{
_product = null;
}
}
} }
@Override @Override
public void write() public void write()
{ {
ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this); ServerPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(this);
if ((_product == null) || !_isSuccess) writeByte(_isSuccess ? 0 : 1);
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
for (LimitShopRandomCraftReward entry : _rewards)
{ {
writeByte(1); writeByte(entry.getRewardIndex());
writeByte(_category); writeInt(entry.getItemId());
writeInt(_productId); writeInt(entry.getCount().get());
writeInt(1);
writeByte(1);
writeInt(0);
writeLong(0);
}
else
{
writeByte(0); // success
writeByte(_category);
writeInt(_productId);
writeInt(_rewards.size());
int counter = 0;
for (LimitShopRandomCraftReward entry : _rewards)
{
if (counter == _rewards.size())
{
break;
}
writeByte(entry.getRewardIndex());
writeInt(0);
writeInt(entry.getCount());
counter++;
}
} }
writeInt(_remainingInfo);
} }
} }