Support for Prime shop account limitations.

This commit is contained in:
MobiusDevelopment
2022-03-08 22:29:24 +00:00
parent 9522f4fefe
commit 7e09528fc1
146 changed files with 3702 additions and 1873 deletions

View File

@@ -29,6 +29,7 @@ import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.gameserver.data.sql.ClanTable;
import org.l2jmobius.gameserver.data.xml.PrimeShopData;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.actor.stat.PlayerStat;
@@ -36,6 +37,8 @@ import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.model.clan.ClanMember;
import org.l2jmobius.gameserver.model.holders.SubClassHolder;
import org.l2jmobius.gameserver.model.olympiad.Olympiad;
import org.l2jmobius.gameserver.model.primeshop.PrimeShopGroup;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
import org.l2jmobius.gameserver.model.variables.PlayerVariables;
import org.l2jmobius.gameserver.network.serverpackets.ExVoteSystemInfo;
import org.l2jmobius.gameserver.network.serverpackets.ExWorldChatCnt;
@@ -108,6 +111,7 @@ public class DailyTaskManager
// Daily tasks.
resetDailySkills();
resetWorldChatPoints();
resetDailyPrimeShopData();
resetRecommends();
resetTrainingCamp();
resetAttendanceRewards();
@@ -442,6 +446,32 @@ public class DailyTaskManager
}
}
private void resetDailyPrimeShopData()
{
for (PrimeShopGroup holder : PrimeShopData.getInstance().getPrimeItems().values())
{
// Update data for offline players.
try (Connection con = DatabaseFactory.getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM account_gsdata WHERE var=?"))
{
ps.setString(1, AccountVariables.PRIME_SHOP_PRODUCT_DAILY_COUNT + holder.getBrId());
ps.executeUpdate();
}
catch (Exception e)
{
LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Could not reset PrimeShopData: " + e);
}
// Update data for online players.
for (Player player : World.getInstance().getPlayers())
{
player.getVariables().remove(AccountVariables.PRIME_SHOP_PRODUCT_DAILY_COUNT + holder.getBrId());
player.getAccountVariables().storeMe();
}
}
LOGGER.info("PrimeShopData has been resetted.");
}
public static DailyTaskManager getInstance()
{
return SingletonHolder.INSTANCE;

View File

@@ -45,8 +45,8 @@ public class PrimeShopGroup
private final int _maxLevel;
private final int _minBirthday;
private final int _maxBirthday;
private final int _restrictionDay;
private final int _availableCount;
private final int _accountDailyLimit;
private final int _accountBuyLimit;
private final List<PrimeShopItem> _items;
public PrimeShopGroup(StatSet set, List<PrimeShopItem> items)
@@ -71,8 +71,8 @@ public class PrimeShopGroup
_maxLevel = set.getInt("maxLevel", 0);
_minBirthday = set.getInt("minBirthday", 0);
_maxBirthday = set.getInt("maxBirthday", 0);
_restrictionDay = set.getInt("restrictionDay", 0);
_availableCount = set.getInt("availableCount", 0);
_accountDailyLimit = set.getInt("accountDailyLimit", 0);
_accountBuyLimit = set.getInt("accountBuyLimit", 0);
_items = items;
}
@@ -186,14 +186,14 @@ public class PrimeShopGroup
return _maxBirthday;
}
public int getRestrictionDay()
public int getAccountDailyLimit()
{
return _restrictionDay;
return _accountDailyLimit;
}
public int getAvailableCount()
public int getAccountBuyLimit()
{
return _availableCount;
return _accountBuyLimit;
}
public List<PrimeShopItem> getItems()

View File

@@ -41,6 +41,8 @@ public class AccountVariables extends AbstractVariables
// Public variable names
public static final String HWID = "HWID";
public static final String HWIDSLIT_VAR = " ";
public static final String PRIME_SHOP_PRODUCT_COUNT = "PSPCount";
public static final String PRIME_SHOP_PRODUCT_DAILY_COUNT = "PSPDailyCount";
private final String _accountName;

View File

@@ -28,6 +28,7 @@ import org.l2jmobius.gameserver.model.actor.request.PrimeShopRequest;
import org.l2jmobius.gameserver.model.itemcontainer.Inventory;
import org.l2jmobius.gameserver.model.primeshop.PrimeShopGroup;
import org.l2jmobius.gameserver.model.primeshop.PrimeShopItem;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.primeshop.ExBRBuyProduct;
@@ -105,6 +106,16 @@ public class RequestBRBuyProduct implements IClientIncomingPacket
player.addItem("PrimeShop", subItem.getId(), subItem.getCount() * _count, player, true);
}
// Update account variables.
if (item.getAccountDailyLimit() > 0)
{
player.getAccountVariables().set(AccountVariables.PRIME_SHOP_PRODUCT_DAILY_COUNT + item.getBrId(), player.getAccountVariables().getInt(AccountVariables.PRIME_SHOP_PRODUCT_DAILY_COUNT + item.getBrId(), 0) + (item.getCount() * _count));
}
else if (item.getAccountBuyLimit() > 0)
{
player.getAccountVariables().set(AccountVariables.PRIME_SHOP_PRODUCT_COUNT + item.getBrId(), player.getAccountVariables().getInt(AccountVariables.PRIME_SHOP_PRODUCT_COUNT + item.getBrId(), 0) + (item.getCount() * _count));
}
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.SUCCESS));
player.sendPacket(new ExBRGamePoint(player));
}
@@ -168,6 +179,16 @@ public class RequestBRBuyProduct implements IClientIncomingPacket
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.AFTER_SALE_DATE));
return false;
}
else if ((item.getAccountDailyLimit() > 0) && ((count + player.getAccountVariables().getInt(AccountVariables.PRIME_SHOP_PRODUCT_DAILY_COUNT + item.getBrId(), 0)) > item.getAccountDailyLimit()))
{
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.SOLD_OUT));
return false;
}
else if ((item.getAccountBuyLimit() > 0) && ((count + player.getAccountVariables().getInt(AccountVariables.PRIME_SHOP_PRODUCT_COUNT + item.getBrId(), 0)) > item.getAccountBuyLimit()))
{
player.sendPacket(new ExBRBuyProduct(ExBrProductReplyType.SOLD_OUT));
return false;
}
final int weight = item.getWeight() * count;
final long slots = item.getCount() * count;

View File

@@ -22,6 +22,7 @@ import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.primeshop.PrimeShopGroup;
import org.l2jmobius.gameserver.model.primeshop.PrimeShopItem;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
@@ -64,15 +65,49 @@ public class ExBRProductList implements IClientOutgoingPacket
packet.writeC(brItem.getStartMinute());
packet.writeC(brItem.getStopHour());
packet.writeC(brItem.getStopMinute());
packet.writeD(brItem.getStock());
packet.writeD(brItem.getTotal());
// Daily account limit.
if ((brItem.getAccountDailyLimit() > 0) && (_player.getAccountVariables().getInt(AccountVariables.PRIME_SHOP_PRODUCT_DAILY_COUNT + brItem.getBrId(), 0) >= brItem.getAccountDailyLimit()))
{
packet.writeD(brItem.getAccountDailyLimit());
packet.writeD(brItem.getAccountDailyLimit());
}
// General account limit.
else if ((brItem.getAccountBuyLimit() > 0) && (_player.getAccountVariables().getInt(AccountVariables.PRIME_SHOP_PRODUCT_COUNT + brItem.getBrId(), 0) >= brItem.getAccountBuyLimit()))
{
packet.writeD(brItem.getAccountBuyLimit());
packet.writeD(brItem.getAccountBuyLimit());
}
else
{
packet.writeD(brItem.getStock());
packet.writeD(brItem.getTotal());
}
packet.writeC(brItem.getSalePercent());
packet.writeC(brItem.getMinLevel());
packet.writeC(brItem.getMaxLevel());
packet.writeD(brItem.getMinBirthday());
packet.writeD(brItem.getMaxBirthday());
packet.writeD(brItem.getRestrictionDay());
packet.writeD(brItem.getAvailableCount());
// Daily account limit.
if (brItem.getAccountDailyLimit() > 0)
{
packet.writeD(1); // Days
packet.writeD(brItem.getAccountDailyLimit()); // Amount
}
// General account limit.
else if (brItem.getAccountBuyLimit() > 0)
{
packet.writeD(-1); // Days
packet.writeD(brItem.getAccountBuyLimit()); // Amount
}
else
{
packet.writeD(0); // Days
packet.writeD(0); // Amount
}
packet.writeC(brItem.getItems().size());
for (PrimeShopItem item : brItem.getItems())
{