From f7b82e35b95f11824badb1e9b656e1f3020f4b7f Mon Sep 17 00:00:00 2001
From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Fri, 30 Apr 2021 13:03:23 +0000
Subject: [PATCH] Addition of purchase limit shop item result. Contributed by
Norvox.
---
.../holders/LimitShopRandomCraftReward.java | 49 ++++++++
.../RequestPurchaseLimitShopItemBuy.java | 40 +++++--
.../ExPurchaseLimitShopItemResult.java | 100 +++++++++++++++++
.../holders/LimitShopRandomCraftReward.java | 49 ++++++++
.../RequestPurchaseLimitShopItemBuy.java | 40 +++++--
.../ExPurchaseLimitShopItemResult.java | 106 ++++++++++++++++++
6 files changed, 360 insertions(+), 24 deletions(-)
create mode 100644 L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java
create mode 100644 L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java
create mode 100644 L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java
create mode 100644 L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java
diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java
new file mode 100644
index 0000000000..6c53b1cef2
--- /dev/null
+++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.model.holders;
+
+/**
+ * @author Gustavo Fonseca
+ */
+public class LimitShopRandomCraftReward
+{
+ private final int _itemId;
+ private final int _count;
+ private final int _rewardIndex;
+
+ public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
+ {
+ _itemId = itemId;
+ _count = count;
+ _rewardIndex = rewardIndex;
+ }
+
+ public int getItemId()
+ {
+ return _itemId;
+ }
+
+ public int getCount()
+ {
+ return _count;
+ }
+
+ public int getRewardIndex()
+ {
+ return _rewardIndex;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java
index e138ebdace..308e6d0711 100644
--- a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java
+++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java
@@ -16,6 +16,9 @@
*/
package org.l2jmobius.gameserver.network.clientpackets.limitshop;
+import java.util.ArrayList;
+import java.util.List;
+
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.Rnd;
@@ -24,11 +27,13 @@ import org.l2jmobius.gameserver.data.xml.LimitShopCraftData;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.actor.request.PrimeShopRequest;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
+import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
+import org.l2jmobius.gameserver.network.serverpackets.limitshop.ExPurchaseLimitShopItemResult;
import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct.ExBrProductReplyType;
@@ -40,15 +45,16 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket
private int _productId;
private int _amount;
private LimitShopProductHolder _product;
+ private int _shopIndex;
@Override
public boolean read(GameClient client, PacketReader packet)
{
- final int shopIndex = packet.readC(); // 3 Lcoin Store, 4 Special Craft
+ _shopIndex = packet.readC(); // 3 Lcoin Store, 4 Special Craft
_productId = packet.readD();
_amount = packet.readD();
- switch (shopIndex)
+ switch (_shopIndex)
{
case 3: // Normal Lcoin Shop
{
@@ -170,23 +176,31 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket
}
// Reward.
+ final List rewards = new ArrayList<>();
if (_product.getProductionId2() > 0)
{
- if (Rnd.get(100) < _product.getChance())
+ for (int i = 0; i < _amount; i++)
{
- player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
- }
- else if (Rnd.get(100) < _product.getChance2())
- {
- player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
- }
- else if (_product.getProductionId3() > 0)
- {
- player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
+ if (Rnd.get(100) < _product.getChance())
+ {
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0));
+ player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
+ }
+ else if (Rnd.get(100) < _product.getChance2())
+ {
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1));
+ player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
+ }
+ else if (_product.getProductionId3() > 0)
+ {
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2));
+ player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
+ }
}
}
else
{
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), _amount, 0));
player.addItem("LCoinShop", _product.getProductionId(), _amount, player, true);
}
@@ -201,6 +215,8 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + 1);
}
+ player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards));
+
// Remove request.
player.removeRequest(PrimeShopRequest.class);
}
diff --git a/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java
new file mode 100644
index 0000000000..828f8b4f86
--- /dev/null
+++ b/L2J_Mobius_Essence_4.0_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java
@@ -0,0 +1,100 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.network.serverpackets.limitshop;
+
+import java.util.List;
+
+import org.l2jmobius.commons.network.PacketWriter;
+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.network.OutgoingPackets;
+import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
+
+/**
+ * @author Gustavo Fonseca
+ */
+public class ExPurchaseLimitShopItemResult implements IClientOutgoingPacket
+{
+ private final int _category, _productId;
+ private final boolean _isSuccess;
+ private final List _rewards;
+ private final LimitShopProductHolder _product;
+
+ public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List rewards)
+ {
+ _isSuccess = isSuccess;
+ _category = category;
+ _productId = productId;
+ _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
+ public boolean write(PacketWriter packet)
+ {
+ OutgoingPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(packet);
+ if ((_product == null) || !_isSuccess)
+ {
+ packet.writeC(1);
+ packet.writeC(_category);
+ packet.writeD(_productId);
+ packet.writeD(1);
+ packet.writeC(1);
+ packet.writeD(0);
+ packet.writeQ(0);
+ }
+ else
+ {
+ packet.writeC(0); // success
+ packet.writeC(_category);
+ packet.writeD(_productId);
+ packet.writeD(_rewards.size());
+ int counter = 0;
+ for (LimitShopRandomCraftReward entry : _rewards)
+ {
+ if (counter == _rewards.size())
+ {
+ break;
+ }
+ packet.writeC(entry.getRewardIndex());
+ packet.writeD(0);
+ packet.writeD(entry.getCount());
+ counter++;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java
new file mode 100644
index 0000000000..6c53b1cef2
--- /dev/null
+++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/model/holders/LimitShopRandomCraftReward.java
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.model.holders;
+
+/**
+ * @author Gustavo Fonseca
+ */
+public class LimitShopRandomCraftReward
+{
+ private final int _itemId;
+ private final int _count;
+ private final int _rewardIndex;
+
+ public LimitShopRandomCraftReward(int itemId, int count, int rewardIndex)
+ {
+ _itemId = itemId;
+ _count = count;
+ _rewardIndex = rewardIndex;
+ }
+
+ public int getItemId()
+ {
+ return _itemId;
+ }
+
+ public int getCount()
+ {
+ return _count;
+ }
+
+ public int getRewardIndex()
+ {
+ return _rewardIndex;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java
index d8acfba3de..ded9410a2e 100644
--- a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java
+++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java
@@ -16,6 +16,9 @@
*/
package org.l2jmobius.gameserver.network.clientpackets.limitshop;
+import java.util.ArrayList;
+import java.util.List;
+
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.Rnd;
@@ -26,11 +29,13 @@ import org.l2jmobius.gameserver.enums.SpecialItemType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.actor.request.PrimeShopRequest;
import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder;
+import org.l2jmobius.gameserver.model.holders.LimitShopRandomCraftReward;
import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
+import org.l2jmobius.gameserver.network.serverpackets.limitshop.ExPurchaseLimitShopItemResult;
import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct.ExBrProductReplyType;
@@ -42,15 +47,16 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket
private int _productId;
private int _amount;
private LimitShopProductHolder _product;
+ private int _shopIndex;
@Override
public boolean read(GameClient client, PacketReader packet)
{
- final int shopIndex = packet.readC(); // 3 Lcoin Store, 4 Special Craft, 100 Clan Shop
+ _shopIndex = packet.readC(); // 3 Lcoin Store, 4 Special Craft, 100 Clan Shop
_productId = packet.readD();
_amount = packet.readD();
- switch (shopIndex)
+ switch (_shopIndex)
{
case 3: // Normal Lcoin Shop
{
@@ -190,23 +196,31 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket
}
// Reward.
+ final List rewards = new ArrayList<>();
if (_product.getProductionId2() > 0)
{
- if (Rnd.get(100) < _product.getChance())
+ for (int i = 0; i < _amount; i++)
{
- player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
- }
- else if (Rnd.get(100) < _product.getChance2())
- {
- player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
- }
- else if (_product.getProductionId3() > 0)
- {
- player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
+ if (Rnd.get(100) < _product.getChance())
+ {
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), (int) _product.getCount(), 0));
+ player.addItem("LCoinShop", _product.getProductionId(), _product.getCount(), player, true);
+ }
+ else if (Rnd.get(100) < _product.getChance2())
+ {
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId2(), (int) _product.getCount2(), 1));
+ player.addItem("LCoinShop", _product.getProductionId2(), _product.getCount2(), player, true);
+ }
+ else if (_product.getProductionId3() > 0)
+ {
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId3(), (int) _product.getCount3(), 2));
+ player.addItem("LCoinShop", _product.getProductionId3(), _product.getCount3(), player, true);
+ }
}
}
else
{
+ rewards.add(new LimitShopRandomCraftReward(_product.getProductionId(), _amount, 0));
player.addItem("LCoinShop", _product.getProductionId(), _amount, player, true);
}
@@ -221,6 +235,8 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket
player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) + 1);
}
+ player.sendPacket(new ExPurchaseLimitShopItemResult(true, _shopIndex, _productId, rewards));
+
// Remove request.
player.removeRequest(PrimeShopRequest.class);
}
diff --git a/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java
new file mode 100644
index 0000000000..77cdb6bb49
--- /dev/null
+++ b/L2J_Mobius_Essence_5.0_Sylph/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemResult.java
@@ -0,0 +1,106 @@
+/*
+ * This file is part of the L2J Mobius project.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package org.l2jmobius.gameserver.network.serverpackets.limitshop;
+
+import java.util.List;
+
+import org.l2jmobius.commons.network.PacketWriter;
+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.network.OutgoingPackets;
+import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
+
+/**
+ * @author Gustavo Fonseca
+ */
+public class ExPurchaseLimitShopItemResult implements IClientOutgoingPacket
+{
+ private final int _category, _productId;
+ private final boolean _isSuccess;
+ private final List _rewards;
+ private final LimitShopProductHolder _product;
+
+ public ExPurchaseLimitShopItemResult(boolean isSuccess, int category, int productId, List rewards)
+ {
+ _isSuccess = isSuccess;
+ _category = category;
+ _productId = productId;
+ _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
+ public boolean write(PacketWriter packet)
+ {
+ OutgoingPackets.EX_PURCHASE_LIMIT_SHOP_ITEM_BUY.writeId(packet);
+ if ((_product == null) || !_isSuccess)
+ {
+ packet.writeC(1);
+ packet.writeC(_category);
+ packet.writeD(_productId);
+ packet.writeD(1);
+ packet.writeC(1);
+ packet.writeD(0);
+ packet.writeQ(0);
+ }
+ else
+ {
+ packet.writeC(0); // success
+ packet.writeC(_category);
+ packet.writeD(_productId);
+ packet.writeD(_rewards.size());
+ int counter = 0;
+ for (LimitShopRandomCraftReward entry : _rewards)
+ {
+ if (counter == _rewards.size())
+ {
+ break;
+ }
+ packet.writeC(entry.getRewardIndex());
+ packet.writeD(0);
+ packet.writeD(entry.getCount());
+ counter++;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file