From 8f0bcc4396c28e432f8bf442d9a1f048167d51f4 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Thu, 27 Jan 2022 16:27:13 +0000 Subject: [PATCH] Daily reset for LimitShopData. Contributed by nasseka. --- .../instancemanager/DailyTaskManager.java | 46 +++++++++++++++---- .../model/variables/AccountVariables.java | 2 +- .../RequestPurchaseLimitShopItemBuy.java | 17 ++----- .../ExPurchaseLimitShopItemListNew.java | 15 ++---- .../instancemanager/DailyTaskManager.java | 31 ++++++++++++- .../model/variables/AccountVariables.java | 2 +- .../RequestPurchaseLimitShopItemBuy.java | 17 ++----- .../ExPurchaseLimitShopItemListNew.java | 15 ++---- .../instancemanager/DailyTaskManager.java | 31 ++++++++++++- .../model/variables/AccountVariables.java | 2 +- .../RequestPurchaseLimitShopItemBuy.java | 17 ++----- .../ExPurchaseLimitShopItemListNew.java | 15 ++---- .../instancemanager/DailyTaskManager.java | 31 ++++++++++++- .../model/variables/AccountVariables.java | 2 +- .../RequestPurchaseLimitShopItemBuy.java | 17 ++----- .../ExPurchaseLimitShopItemListNew.java | 15 ++---- 16 files changed, 164 insertions(+), 111 deletions(-) diff --git a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java index 562655515c..ddfe45a994 100644 --- a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java +++ b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java @@ -31,15 +31,18 @@ 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.LimitShopData; import org.l2jmobius.gameserver.data.xml.TimedHuntingZoneData; import org.l2jmobius.gameserver.model.World; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; import org.l2jmobius.gameserver.model.clan.Clan; import org.l2jmobius.gameserver.model.clan.ClanMember; +import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder; import org.l2jmobius.gameserver.model.holders.SubClassHolder; import org.l2jmobius.gameserver.model.holders.TimedHuntingZoneHolder; import org.l2jmobius.gameserver.model.olympiad.Olympiad; +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; @@ -100,10 +103,10 @@ public class DailyTaskManager if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) { clanLeaderApply(); - resetVitalityWeekly(); resetClanContribution(); resetDailyMissionRewards(); resetTimedHuntingZonesWeekly(); + resetVitalityWeekly(); } else // All days, except Wednesday. { @@ -111,14 +114,15 @@ public class DailyTaskManager } // Daily tasks. - resetDailySkills(); - resetWorldChatPoints(); - resetRecommends(); - resetTrainingCamp(); - resetThroneOfHeroes(); - resetTimedHuntingZones(); - resetHomunculusResetPoints(); resetAttendanceRewards(); + resetDailySkills(); + resetDailyLimitShopData(); + resetHomunculusResetPoints(); + resetRecommends(); + resetTimedHuntingZones(); + resetThroneOfHeroes(); + resetTrainingCamp(); + resetWorldChatPoints(); } private void onSave() @@ -590,6 +594,32 @@ public class DailyTaskManager } } + public void resetDailyLimitShopData() + { + for (LimitShopProductHolder holder : LimitShopData.getInstance().getProducts()) + { + // Update data for offline players. + try (Connection con = DatabaseFactory.getConnection(); + PreparedStatement ps = con.prepareStatement("DELETE FROM account_gsdata WHERE var=?")) + { + ps.setString(1, AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + ps.executeUpdate(); + } + catch (Exception e) + { + LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Could not reset LimitShopData: " + e); + } + + // Update data for online players. + for (Player player : World.getInstance().getPlayers()) + { + player.getVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + player.getAccountVariables().storeMe(); + } + } + LOGGER.info("LimitShopData has been resetted."); + } + public static DailyTaskManager getInstance() { return SingletonHolder.INSTANCE; diff --git a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java index dbb4b300bd..bfc010518e 100644 --- a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java +++ b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java @@ -41,8 +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 LCOIN_SHOP_PRODUCT_TIME = "LCSTime"; public static final String LCOIN_SHOP_PRODUCT_COUNT = "LCSCount"; + public static final String LCOIN_SHOP_PRODUCT_DAILY_COUNT = "LCSDailyCount"; private final String _accountName; diff --git a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java index 54a5240d2f..eefee90ae9 100644 --- a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java +++ b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java @@ -21,7 +21,6 @@ import java.util.Collection; import java.util.List; import org.l2jmobius.commons.network.PacketReader; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; import org.l2jmobius.gameserver.data.xml.LimitShopData; @@ -115,16 +114,11 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Check limits. if (_product.getAccountDailyLimit() > 0) // Sale period. { - if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) + if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) { - if ((player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? - player.removeRequest(PrimeShopRequest.class); - return; - } - // Reset limit. - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0); + player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? + player.removeRequest(PrimeShopRequest.class); + return; } } else if (_product.getAccountBuyLimit() > 0) // Count limit. @@ -251,8 +245,7 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Update account variables. if (_product.getAccountDailyLimit() > 0) { - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), Chronos.currentTimeMillis()); - 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_DAILY_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) + _amount); } else if (_product.getAccountBuyLimit() > 0) { diff --git a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java index ecf0dbd8bf..95a69e6689 100644 --- a/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java +++ b/L2J_Mobius_10.0_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.Collections; import org.l2jmobius.commons.network.PacketWriter; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; import org.l2jmobius.gameserver.data.xml.LimitShopData; import org.l2jmobius.gameserver.model.actor.Player; @@ -91,21 +90,13 @@ public class ExPurchaseLimitShopItemListNew implements IClientOutgoingPacket // Check limits. if (product.getAccountDailyLimit() > 0) // Sale period. { - if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) + if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) { - if ((_player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - packet.writeD(0); - } - else // Reset limit. - { - _player.getAccountVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId()); - packet.writeD(product.getAccountDailyLimit()); - } + packet.writeD(0); } else { - packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0)); + packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0)); } } else if (product.getAccountBuyLimit() > 0) // Count limit. diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java index c1e4451b6f..aca8c05819 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java @@ -30,6 +30,7 @@ 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.DailyMissionData; +import org.l2jmobius.gameserver.data.xml.LimitShopData; import org.l2jmobius.gameserver.data.xml.TimedHuntingZoneData; import org.l2jmobius.gameserver.model.DailyMissionDataHolder; import org.l2jmobius.gameserver.model.World; @@ -37,6 +38,7 @@ import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; import org.l2jmobius.gameserver.model.clan.Clan; import org.l2jmobius.gameserver.model.clan.ClanMember; +import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder; import org.l2jmobius.gameserver.model.holders.SubClassHolder; import org.l2jmobius.gameserver.model.holders.TimedHuntingZoneHolder; import org.l2jmobius.gameserver.model.olympiad.Olympiad; @@ -102,8 +104,8 @@ public class DailyTaskManager if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) { clanLeaderApply(); - resetVitalityWeekly(); resetTimedHuntingZonesWeekly(); + resetVitalityWeekly(); } else // All days, except Wednesday. { @@ -113,6 +115,7 @@ public class DailyTaskManager // Daily tasks. resetClanBonus(); resetDailySkills(); + resetDailyLimitShopData(); resetWorldChatPoints(); resetRecommends(); resetTrainingCamp(); @@ -493,6 +496,32 @@ public class DailyTaskManager } } + public void resetDailyLimitShopData() + { + for (LimitShopProductHolder holder : LimitShopData.getInstance().getProducts()) + { + // Update data for offline players. + try (Connection con = DatabaseFactory.getConnection(); + PreparedStatement ps = con.prepareStatement("DELETE FROM account_gsdata WHERE var=?")) + { + ps.setString(1, AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + ps.executeUpdate(); + } + catch (Exception e) + { + LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Could not reset LimitShopData: " + e); + } + + // Update data for online players. + for (Player player : World.getInstance().getPlayers()) + { + player.getVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + player.getAccountVariables().storeMe(); + } + } + LOGGER.info("LimitShopData has been resetted."); + } + public static DailyTaskManager getInstance() { return SingletonHolder.INSTANCE; diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java index 019fd7b35b..db69e5334d 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java @@ -42,8 +42,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 LCOIN_SHOP_PRODUCT_TIME = "LCSTime"; public static final String LCOIN_SHOP_PRODUCT_COUNT = "LCSCount"; + public static final String LCOIN_SHOP_PRODUCT_DAILY_COUNT = "LCSDailyCount"; public static final String VIP_POINTS = "VipPoints"; public static final String VIP_TIER = "VipTier"; public static final String VIP_EXPIRATION = "VipExpiration"; diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java index 1ec77af55e..7d0b0d4322 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java @@ -22,7 +22,6 @@ import java.util.List; import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketReader; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; import org.l2jmobius.gameserver.data.xml.LimitShopData; @@ -115,16 +114,11 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Check limits. if (_product.getAccountDailyLimit() > 0) // Sale period. { - if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) + if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) { - if ((player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? - player.removeRequest(PrimeShopRequest.class); - return; - } - // Reset limit. - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0); + player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? + player.removeRequest(PrimeShopRequest.class); + return; } } else if (_product.getAccountBuyLimit() > 0) // Count limit. @@ -242,8 +236,7 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Update account variables. if (_product.getAccountDailyLimit() > 0) { - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), Chronos.currentTimeMillis()); - 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_DAILY_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) + _amount); } else if (_product.getAccountBuyLimit() > 0) { diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java index 63468d2a8d..d5c40323ef 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.Collections; import org.l2jmobius.commons.network.PacketWriter; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; import org.l2jmobius.gameserver.data.xml.LimitShopData; import org.l2jmobius.gameserver.model.actor.Player; @@ -83,21 +82,13 @@ public class ExPurchaseLimitShopItemListNew implements IClientOutgoingPacket // Check limits. if (product.getAccountDailyLimit() > 0) // Sale period. { - if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) + if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) { - if ((_player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - packet.writeD(0); - } - else // Reset limit. - { - _player.getAccountVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId()); - packet.writeD(product.getAccountDailyLimit()); - } + packet.writeD(0); } else { - packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0)); + packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0)); } } else if (product.getAccountBuyLimit() > 0) // Count limit. diff --git a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java index 163b21782f..1c52a93388 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java @@ -30,6 +30,7 @@ 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.DailyMissionData; +import org.l2jmobius.gameserver.data.xml.LimitShopData; import org.l2jmobius.gameserver.data.xml.TimedHuntingZoneData; import org.l2jmobius.gameserver.model.DailyMissionDataHolder; import org.l2jmobius.gameserver.model.World; @@ -37,6 +38,7 @@ import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; import org.l2jmobius.gameserver.model.clan.Clan; import org.l2jmobius.gameserver.model.clan.ClanMember; +import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder; import org.l2jmobius.gameserver.model.holders.SubClassHolder; import org.l2jmobius.gameserver.model.holders.TimedHuntingZoneHolder; import org.l2jmobius.gameserver.model.olympiad.Olympiad; @@ -102,9 +104,9 @@ public class DailyTaskManager if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) { clanLeaderApply(); - resetVitalityWeekly(); resetMonsterArenaWeekly(); resetTimedHuntingZonesWeekly(); + resetVitalityWeekly(); } else // All days, except Wednesday. { @@ -116,6 +118,7 @@ public class DailyTaskManager resetClanContributionList(); resetClanDonationPoints(); resetDailySkills(); + resetDailyLimitShopData(); resetWorldChatPoints(); resetRecommends(); resetTrainingCamp(); @@ -533,6 +536,32 @@ public class DailyTaskManager } } + public void resetDailyLimitShopData() + { + for (LimitShopProductHolder holder : LimitShopData.getInstance().getProducts()) + { + // Update data for offline players. + try (Connection con = DatabaseFactory.getConnection(); + PreparedStatement ps = con.prepareStatement("DELETE FROM account_gsdata WHERE var=?")) + { + ps.setString(1, AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + ps.executeUpdate(); + } + catch (Exception e) + { + LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Could not reset LimitShopData: " + e); + } + + // Update data for online players. + for (Player player : World.getInstance().getPlayers()) + { + player.getVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + player.getAccountVariables().storeMe(); + } + } + LOGGER.info("LimitShopData has been resetted."); + } + public static DailyTaskManager getInstance() { return SingletonHolder.INSTANCE; diff --git a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java index 019fd7b35b..db69e5334d 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java @@ -42,8 +42,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 LCOIN_SHOP_PRODUCT_TIME = "LCSTime"; public static final String LCOIN_SHOP_PRODUCT_COUNT = "LCSCount"; + public static final String LCOIN_SHOP_PRODUCT_DAILY_COUNT = "LCSDailyCount"; public static final String VIP_POINTS = "VipPoints"; public static final String VIP_TIER = "VipTier"; public static final String VIP_EXPIRATION = "VipExpiration"; diff --git a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java index 556af6a9fe..bb75006321 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java @@ -22,7 +22,6 @@ import java.util.List; import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketReader; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.LimitShopClanData; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; @@ -122,16 +121,11 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Check limits. if (_product.getAccountDailyLimit() > 0) // Sale period. { - if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) + if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) { - if ((player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? - player.removeRequest(PrimeShopRequest.class); - return; - } - // Reset limit. - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0); + player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? + player.removeRequest(PrimeShopRequest.class); + return; } } else if (_product.getAccountBuyLimit() > 0) // Count limit. @@ -262,8 +256,7 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Update account variables. if (_product.getAccountDailyLimit() > 0) { - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), Chronos.currentTimeMillis()); - 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_DAILY_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) + _amount); } else if (_product.getAccountBuyLimit() > 0) { diff --git a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java index d0bf1fdfde..90d67bd73c 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.Collections; import org.l2jmobius.commons.network.PacketWriter; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.data.xml.LimitShopClanData; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; import org.l2jmobius.gameserver.data.xml.LimitShopData; @@ -97,21 +96,13 @@ public class ExPurchaseLimitShopItemListNew implements IClientOutgoingPacket // Check limits. if (product.getAccountDailyLimit() > 0) // Sale period. { - if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) + if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) { - if ((_player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - packet.writeD(0); - } - else // Reset limit. - { - _player.getAccountVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId()); - packet.writeD(product.getAccountDailyLimit()); - } + packet.writeD(0); } else { - packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0)); + packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0)); } } else if (product.getAccountBuyLimit() > 0) // Count limit. diff --git a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java index 163b21782f..1c52a93388 100644 --- a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java +++ b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/instancemanager/DailyTaskManager.java @@ -30,6 +30,7 @@ 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.DailyMissionData; +import org.l2jmobius.gameserver.data.xml.LimitShopData; import org.l2jmobius.gameserver.data.xml.TimedHuntingZoneData; import org.l2jmobius.gameserver.model.DailyMissionDataHolder; import org.l2jmobius.gameserver.model.World; @@ -37,6 +38,7 @@ import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; import org.l2jmobius.gameserver.model.clan.Clan; import org.l2jmobius.gameserver.model.clan.ClanMember; +import org.l2jmobius.gameserver.model.holders.LimitShopProductHolder; import org.l2jmobius.gameserver.model.holders.SubClassHolder; import org.l2jmobius.gameserver.model.holders.TimedHuntingZoneHolder; import org.l2jmobius.gameserver.model.olympiad.Olympiad; @@ -102,9 +104,9 @@ public class DailyTaskManager if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY) { clanLeaderApply(); - resetVitalityWeekly(); resetMonsterArenaWeekly(); resetTimedHuntingZonesWeekly(); + resetVitalityWeekly(); } else // All days, except Wednesday. { @@ -116,6 +118,7 @@ public class DailyTaskManager resetClanContributionList(); resetClanDonationPoints(); resetDailySkills(); + resetDailyLimitShopData(); resetWorldChatPoints(); resetRecommends(); resetTrainingCamp(); @@ -533,6 +536,32 @@ public class DailyTaskManager } } + public void resetDailyLimitShopData() + { + for (LimitShopProductHolder holder : LimitShopData.getInstance().getProducts()) + { + // Update data for offline players. + try (Connection con = DatabaseFactory.getConnection(); + PreparedStatement ps = con.prepareStatement("DELETE FROM account_gsdata WHERE var=?")) + { + ps.setString(1, AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + ps.executeUpdate(); + } + catch (Exception e) + { + LOGGER.log(Level.SEVERE, getClass().getSimpleName() + ": Could not reset LimitShopData: " + e); + } + + // Update data for online players. + for (Player player : World.getInstance().getPlayers()) + { + player.getVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + holder.getProductionId()); + player.getAccountVariables().storeMe(); + } + } + LOGGER.info("LimitShopData has been resetted."); + } + public static DailyTaskManager getInstance() { return SingletonHolder.INSTANCE; diff --git a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java index 019fd7b35b..db69e5334d 100644 --- a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java +++ b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/model/variables/AccountVariables.java @@ -42,8 +42,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 LCOIN_SHOP_PRODUCT_TIME = "LCSTime"; public static final String LCOIN_SHOP_PRODUCT_COUNT = "LCSCount"; + public static final String LCOIN_SHOP_PRODUCT_DAILY_COUNT = "LCSDailyCount"; public static final String VIP_POINTS = "VipPoints"; public static final String VIP_TIER = "VipTier"; public static final String VIP_EXPIRATION = "VipExpiration"; diff --git a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java index 556af6a9fe..bb75006321 100644 --- a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java +++ b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/clientpackets/limitshop/RequestPurchaseLimitShopItemBuy.java @@ -22,7 +22,6 @@ import java.util.List; import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketReader; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.gameserver.data.xml.LimitShopClanData; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; @@ -122,16 +121,11 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Check limits. if (_product.getAccountDailyLimit() > 0) // Sale period. { - if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) + if (player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) >= (_product.getAccountDailyLimit() * _amount)) { - if ((player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? - player.removeRequest(PrimeShopRequest.class); - return; - } - // Reset limit. - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + _product.getProductionId(), 0); + player.sendMessage("You have reached your daily limit."); // TODO: Retail system message? + player.removeRequest(PrimeShopRequest.class); + return; } } else if (_product.getAccountBuyLimit() > 0) // Count limit. @@ -262,8 +256,7 @@ public class RequestPurchaseLimitShopItemBuy implements IClientIncomingPacket // Update account variables. if (_product.getAccountDailyLimit() > 0) { - player.getAccountVariables().set(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + _product.getProductionId(), Chronos.currentTimeMillis()); - 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_DAILY_COUNT + _product.getProductionId(), player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + _product.getProductionId(), 0) + _amount); } else if (_product.getAccountBuyLimit() > 0) { diff --git a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java index d0bf1fdfde..90d67bd73c 100644 --- a/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java +++ b/L2J_Mobius_Essence_6.0_BattleChronicle/java/org/l2jmobius/gameserver/network/serverpackets/limitshop/ExPurchaseLimitShopItemListNew.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.Collections; import org.l2jmobius.commons.network.PacketWriter; -import org.l2jmobius.commons.util.Chronos; import org.l2jmobius.gameserver.data.xml.LimitShopClanData; import org.l2jmobius.gameserver.data.xml.LimitShopCraftData; import org.l2jmobius.gameserver.data.xml.LimitShopData; @@ -97,21 +96,13 @@ public class ExPurchaseLimitShopItemListNew implements IClientOutgoingPacket // Check limits. if (product.getAccountDailyLimit() > 0) // Sale period. { - if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) + if (_player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0) >= product.getAccountDailyLimit()) { - if ((_player.getAccountVariables().getLong(AccountVariables.LCOIN_SHOP_PRODUCT_TIME + product.getProductionId(), 0) + 86400000) > Chronos.currentTimeMillis()) - { - packet.writeD(0); - } - else // Reset limit. - { - _player.getAccountVariables().remove(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId()); - packet.writeD(product.getAccountDailyLimit()); - } + packet.writeD(0); } else { - packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_COUNT + product.getProductionId(), 0)); + packet.writeD(product.getAccountDailyLimit() - _player.getAccountVariables().getInt(AccountVariables.LCOIN_SHOP_PRODUCT_DAILY_COUNT + product.getProductionId(), 0)); } } else if (product.getAccountBuyLimit() > 0) // Count limit.