Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Eclipse Workspace Patch 1.0
- #P aCis_gameserver
- Index: java/net/sf/l2j/custom/CouponManager.java
- ===================================================================
- --- java/net/sf/l2j/custom/CouponManager.java (nonexistent)
- +++ java/net/sf/l2j/custom/CouponManager.java (working copy)
- @@ -0,0 +1,143 @@
- +package net.sf.l2j.custom;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.util.Set;
- +import java.util.concurrent.ConcurrentHashMap;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import net.sf.l2j.L2DatabaseFactory;
- +import net.sf.l2j.gameserver.idfactory.IdFactory;
- +import net.sf.l2j.gameserver.model.actor.instance.Player;
- +
- +/**
- + * @author Melron
- + */
- +public class CouponManager
- +{
- + private final static Logger _log = Logger.getLogger(CouponManager.class.getName());
- + private static Set<Coupon> coupons = ConcurrentHashMap.newKeySet();
- +
- + public static void loadCoupons()
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement("SELECT owner_objid,coupon_id, coupon_category, grade FROM coupons");
- + ResultSet cpns = statement.executeQuery();
- +
- + while (cpns.next())
- + {
- + Coupon coupon = new Coupon();
- + coupon.setOwnerObjectId(cpns.getInt("owner_objid"));
- + coupon.setId(cpns.getInt("coupon_id"));
- + coupon.setCategory(cpns.getString("coupon_category").toUpperCase());
- + coupon.setGradeType(cpns.getInt("grade"));
- + if (!coupons.contains(coupon))
- + coupons.add(coupon);
- + }
- + cpns.close();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + _log.log(Level.WARNING, "Could not restore coupons: " + e.getMessage(), e);
- + }
- + }
- +
- + /**
- + * @return
- + */
- + public static int getCouponsSize()
- + {
- + return coupons.size();
- + }
- +
- + public static void setCoupons(Player player)
- + {
- + if (coupons.isEmpty() || player == null)
- + return;
- + for (Coupon cpn : coupons)
- + {
- + if (cpn.getOwnerObjectId() == player.getObjectId())
- + player.setCoupon(cpn);
- + }
- + }
- +
- + public static Coupon generateCoupon(String category, Player player)
- + {
- + if (player == null)
- + {
- + System.out.println("Could not generate new coupon ID! Player = null!");
- + return null;
- + }
- +
- + Coupon coupon = new Coupon();
- + coupon.setCategory(category);
- + coupon.setId(IdFactory.getInstance().getNextId());
- + coupon.setOwnerObjectId(player.getObjectId());
- +
- + coupon.setGradeType(Math.max(0, player.getSkillLevel(239)));
- +
- + if (!storeNewCoupon(coupon))
- + {
- + IdFactory.getInstance().releaseId(coupon.getId());
- + return null;
- + }
- +
- + coupons.add(coupon);
- + player.setCoupon(coupon);
- +
- + return coupon;
- +
- + }
- +
- + /**
- + * @param coupon
- + * @return success
- + */
- + private static boolean storeNewCoupon(Coupon coupon)
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement("INSERT INTO coupons (owner_objid,coupon_id,coupon_category,grade) VALUES (?,?,?,?)");
- +
- + statement.setInt(1, coupon.getOwnerObjectId());
- + statement.setInt(2, coupon.getId());
- + statement.setString(3, coupon.getCategory().toUpperCase());
- + statement.setInt(4, coupon.getGradeType());
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + _log.warning("could not save Coupon for objectId :" + coupon.getOwnerObjectId() + "." + e);
- + return false;
- + }
- + return true;
- + }
- +
- +
- + /**
- + * @param coupon
- + */
- + public static void deleteCoupon(Coupon coupon)
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + try (PreparedStatement ps = con.prepareStatement("DELETE FROM coupons where coupon_id = ?"))
- + {
- + ps.setInt(1, coupon.getId());
- + ps.executeUpdate();
- + }
- + IdFactory.getInstance().releaseId(coupon.getId());
- + coupons.remove(coupon);
- + }
- + catch (Exception e)
- + {
- + _log.log(Level.WARNING, "Could not delete coupon: ", e);
- + }
- +
- + }
- +}
- Index: java/net/sf/l2j/custom/Coupon.java
- ===================================================================
- --- java/net/sf/l2j/custom/Coupon.java (nonexistent)
- +++ java/net/sf/l2j/custom/Coupon.java (working copy)
- @@ -0,0 +1,185 @@
- +package net.sf.l2j.custom;
- +
- +import java.util.ArrayList;
- +import java.util.Collections;
- +import java.util.List;
- +
- +import net.sf.l2j.commons.lang.StringUtil;
- +
- +import net.sf.l2j.gameserver.model.holder.IntIntHolder;
- +
- +/**
- + * @author Melron
- + */
- +
- +public class Coupon
- +{
- + public enum GradeType
- + {
- + NG(1),
- + D(2),
- + C(3),
- + B(4),
- + A(5),
- + S(6);
- +
- + private int multiplier;
- +
- + GradeType(int gradeMultiplier)
- + {
- + this.multiplier = gradeMultiplier;
- + }
- +
- + int getGradeMultiplier()
- + {
- + return multiplier;
- + }
- + }
- +
- + private GradeType gradeType;
- + private int couponId;
- + private String couponCategory = "";
- + private int ownerObjectId;
- + private List<IntIntHolder> Rewards = new ArrayList<>();
- +
- + public String getName()
- + {
- + StringBuilder sb = new StringBuilder();
- + StringUtil.append(sb, couponCategory, " Coupon - Grade [", gradeType.name(), "]");
- + return sb.toString();
- + }
- +
- + public String getCategory()
- + {
- + return couponCategory;
- + }
- +
- + public void setId(int val)
- + {
- + couponId = val;
- + }
- +
- + public int getId()
- + {
- + return couponId;
- + }
- +
- + public void setCategory(String val)
- + {
- + couponCategory = val;
- + if (couponCategory == null)
- + couponCategory = "";
- + }
- +
- + public int getOwnerObjectId()
- + {
- + return ownerObjectId;
- + }
- +
- + public void setOwnerObjectId(int objId)
- + {
- + ownerObjectId = objId;
- + }
- +
- + /**
- + * @return
- + */
- + public List<IntIntHolder> getRewards()
- + {
- + final String Silver = "SILVER";
- + final String Gold = "GOLD";
- + final String Platinum = "PLATINUM";
- + Rewards.clear();
- + if (couponCategory.equalsIgnoreCase(Silver))
- + {
- + Rewards.add(new IntIntHolder(8762, 2)); // 1
- + Rewards.add(new IntIntHolder(8762, 7)); // 2
- + Rewards.add(new IntIntHolder(6622, 4)); // 3
- + Rewards.add(new IntIntHolder(6622, 7)); // 4
- + Rewards.add(new IntIntHolder(6578, 10)); // 5
- + Rewards.add(new IntIntHolder(6578, 1)); // 6
- + Rewards.add(new IntIntHolder(57, 1000000000));// 7
- + Rewards.add(new IntIntHolder(6577, 5)); // 8
- + Rewards.add(new IntIntHolder(6577, 20)); // 9
- + Rewards.add(new IntIntHolder(6673, 15)); // 10
- +
- + Rewards.add(new IntIntHolder(8762, 9)); // 11
- + Rewards.add(new IntIntHolder(8762, 4)); // 12
- + Rewards.add(new IntIntHolder(6622, 6)); // 13
- + Rewards.add(new IntIntHolder(6622, 9)); // 14
- + Rewards.add(new IntIntHolder(6578, 12)); // 15
- + Rewards.add(new IntIntHolder(6578, 33)); // 16
- + Rewards.add(new IntIntHolder(57, 500000));// 17
- + Rewards.add(new IntIntHolder(6577, 12)); // 18
- + Rewards.add(new IntIntHolder(6577, 3)); // 19
- + Rewards.add(new IntIntHolder(6673, 50)); // 20
- + }
- + else if (couponCategory.equalsIgnoreCase(Gold))
- + {
- + Rewards.add(new IntIntHolder(8762, 2)); // 1
- + Rewards.add(new IntIntHolder(8762, 7)); // 2
- + Rewards.add(new IntIntHolder(6622, 4)); // 3
- + Rewards.add(new IntIntHolder(6622, 7)); // 4
- + Rewards.add(new IntIntHolder(6578, 10)); // 5
- + Rewards.add(new IntIntHolder(6578, 1)); // 6
- + Rewards.add(new IntIntHolder(57, 1000000000));// 7
- + Rewards.add(new IntIntHolder(6577, 5)); // 8
- + Rewards.add(new IntIntHolder(6577, 20)); // 9
- + Rewards.add(new IntIntHolder(6673, 15)); // 10
- +
- + Rewards.add(new IntIntHolder(8762, 9)); // 11
- + Rewards.add(new IntIntHolder(8762, 4)); // 12
- + Rewards.add(new IntIntHolder(6622, 6)); // 13
- + Rewards.add(new IntIntHolder(6622, 9)); // 14
- + Rewards.add(new IntIntHolder(6578, 12)); // 15
- + Rewards.add(new IntIntHolder(6578, 33)); // 16
- + Rewards.add(new IntIntHolder(57, 500000));// 17
- + Rewards.add(new IntIntHolder(6577, 12)); // 18
- + Rewards.add(new IntIntHolder(6577, 3)); // 19
- + Rewards.add(new IntIntHolder(6673, 50)); // 20
- + }
- + else if (couponCategory.equalsIgnoreCase(Platinum))
- + {
- + Rewards.add(new IntIntHolder(8762, 2)); // 1
- + Rewards.add(new IntIntHolder(8762, 7)); // 2
- + Rewards.add(new IntIntHolder(6622, 4)); // 3
- + Rewards.add(new IntIntHolder(6622, 7)); // 4
- + Rewards.add(new IntIntHolder(6578, 10)); // 5
- + Rewards.add(new IntIntHolder(6578, 1)); // 6
- + Rewards.add(new IntIntHolder(57, 1000000000));// 7
- + Rewards.add(new IntIntHolder(6577, 5)); // 8
- + Rewards.add(new IntIntHolder(6577, 20)); // 9
- + Rewards.add(new IntIntHolder(6673, 15)); // 10
- +
- + Rewards.add(new IntIntHolder(8762, 9)); // 11
- + Rewards.add(new IntIntHolder(8762, 4)); // 12
- + Rewards.add(new IntIntHolder(6622, 6)); // 13
- + Rewards.add(new IntIntHolder(6622, 9)); // 14
- + Rewards.add(new IntIntHolder(6578, 12)); // 15
- + Rewards.add(new IntIntHolder(6578, 33)); // 16
- + Rewards.add(new IntIntHolder(57, 500000));// 17
- + Rewards.add(new IntIntHolder(6577, 12)); // 18
- + Rewards.add(new IntIntHolder(6577, 3)); // 19
- + Rewards.add(new IntIntHolder(6673, 50)); // 20
- + }
- + else
- + return Collections.emptyList();
- + Collections.shuffle(Rewards);
- + return Rewards;
- + }
- +
- + public void setGradeType(int ordinal)
- + {
- + gradeType = GradeType.values()[ordinal];
- + }
- +
- + public int getGradeMultiplier()
- + {
- + return gradeType.getGradeMultiplier();
- + }
- +
- + public int getGradeType()
- + {
- + return gradeType.ordinal();
- + }
- +}
- Index: java/net/sf/l2j/Config.java
- ===================================================================
- --- java/net/sf/l2j/Config.java (revision 3)
- +++ java/net/sf/l2j/Config.java (working copy)
- @@ -461,6 +461,10 @@
- public static boolean STORE_SKILL_COOLTIME;
- public static int BUFFS_MAX_AMOUNT;
- + /** coupons */
- + public static int COUPONS_LIMIT_PER_DAY;
- + public static int[] COUPONS_RESET_LIMIT_AT = new int[2];
- +
- // --------------------------------------------------
- // Sieges
- // --------------------------------------------------
- @@ -1154,6 +1158,15 @@
- BUFFS_MAX_AMOUNT = players.getProperty("MaxBuffsAmount", 20);
- STORE_SKILL_COOLTIME = players.getProperty("StoreSkillCooltime", true);
- +
- + COUPONS_LIMIT_PER_DAY = players.getProperty("CouponsLimit", 0);
- +
- + String[] Time = players.getProperty("ResetCouponsLimitAt", (String[]) null, ":");
- + if (Time != null)
- + {
- + COUPONS_RESET_LIMIT_AT[0] = Integer.parseInt(Time[0]);
- + COUPONS_RESET_LIMIT_AT[1] = Integer.parseInt(Time[1]);
- + }
- }
- /**
- Index: java/net/sf/l2j/gameserver/idfactory/IdFactory.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/idfactory/IdFactory.java (revision 3)
- +++ java/net/sf/l2j/gameserver/idfactory/IdFactory.java (working copy)
- @@ -34,6 +34,10 @@
- {
- "items_on_ground",
- "object_id"
- + },
- + {
- + "coupons",
- + "coupon_id"
- }
- };
- Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 3)
- +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
- @@ -1,11 +1,18 @@
- package net.sf.l2j.gameserver.network.clientpackets;
- +import java.util.List;
- import java.util.StringTokenizer;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- +import net.sf.l2j.commons.lang.StringUtil;
- +import net.sf.l2j.commons.math.MathUtil;
- +import net.sf.l2j.commons.random.Rnd;
- +
- import net.sf.l2j.Config;
- +import net.sf.l2j.custom.Coupon;
- import net.sf.l2j.gameserver.communitybbs.CommunityBoard;
- +import net.sf.l2j.gameserver.data.ItemTable;
- import net.sf.l2j.gameserver.data.xml.AdminData;
- import net.sf.l2j.gameserver.handler.AdminCommandHandler;
- import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
- @@ -15,6 +22,8 @@
- import net.sf.l2j.gameserver.model.actor.instance.OlympiadManagerNpc;
- import net.sf.l2j.gameserver.model.actor.instance.Player;
- import net.sf.l2j.gameserver.model.entity.Hero;
- +import net.sf.l2j.gameserver.model.holder.IntIntHolder;
- +import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
- import net.sf.l2j.gameserver.model.olympiad.OlympiadManager;
- import net.sf.l2j.gameserver.network.FloodProtectors;
- import net.sf.l2j.gameserver.network.FloodProtectors.Action;
- @@ -169,6 +178,87 @@
- final int arenaId = Integer.parseInt(_command.substring(12).trim());
- activeChar.enterOlympiadObserverMode(arenaId);
- }
- + else if (_command.startsWith("list_"))
- + {
- + StringTokenizer st = new StringTokenizer(_command, "_");
- + st.nextToken();
- + int page;
- + try
- + {
- + page = Integer.parseInt(st.nextToken());
- + }
- + catch (NumberFormatException e)
- + {
- + return;
- + }
- +
- + showCoupons(activeChar, page);
- +
- + }
- + else if (_command.startsWith("cpn_"))
- + {
- + StringTokenizer st = new StringTokenizer(_command, "_");
- + st.nextToken();
- +
- + if (!st.hasMoreTokens())
- + return;
- +
- + String nextCommand = st.nextToken();
- + int nextElement;
- + int page = 1;
- +
- + try
- + {
- + nextElement = Integer.parseInt(st.nextToken());
- + if (st.hasMoreTokens())
- + page = Integer.parseInt(st.nextToken());
- + }
- + catch (NumberFormatException e)
- + {
- + return;
- + }
- +
- + if (nextCommand.isEmpty())
- + return;
- +
- + Coupon coupon = activeChar.getCouponById(nextElement);
- +
- + if (coupon == null)
- + return;
- +
- + if (nextCommand.startsWith("list"))
- + {
- + showCategoryReward(activeChar, coupon, 1);
- + }
- +
- + else if (nextCommand.startsWith("redeem"))
- + {
- + if (!activeChar.canUseCoupon())
- + {
- + activeChar.sendMessage("You have reached the daily limit of the coupons you can use. The limit will be lifted at " + (Config.COUPONS_RESET_LIMIT_AT[0] == 0 ? "00" : Config.COUPONS_RESET_LIMIT_AT[0]) + ":" + (Config.COUPONS_RESET_LIMIT_AT[1] == 0 ? "00" : Config.COUPONS_RESET_LIMIT_AT[1]) + ".");
- + return;
- + }
- + final int size = coupon.getRewards().size();
- + IntIntHolder reward = coupon.getRewards().get(Rnd.get(size));
- + final int multiplier = coupon.getGradeMultiplier();
- + ItemInstance item = ItemTable.getInstance().createItem("Redeem", reward.getId(), reward.getValue() * multiplier, activeChar, null);
- + activeChar.addItem("RedeemReward", item, null, true);
- + activeChar.increaseCouponsUsed();
- + activeChar.removeCoupon(coupon);
- + activeChar.sendMessage("Coupon " + coupon.getName() + " have been redeemed.");
- + showCoupons(activeChar, 1);
- + }
- + else if (nextCommand.startsWith("del"))
- + {
- + activeChar.removeCoupon(coupon);
- + activeChar.sendMessage("Coupon: " + coupon.getName() + " have been successfully deleted");
- + showCoupons(activeChar, 1);
- + }
- + else if (nextCommand.startsWith("page"))
- + showCategoryReward(activeChar, coupon, page);
- + else
- + return;
- + }
- }
- catch (Exception e)
- {
- @@ -176,6 +266,97 @@
- }
- }
- + /**
- + * @param activeChar
- + * @param page
- + */
- + private static void showCoupons(Player activeChar, int page)
- + {
- + List<Coupon> coupons = activeChar.getCoupons();
- + // Load static Htm.
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + html.setFile("data/html/custom/couponsList.htm");
- +
- + if (coupons.isEmpty())
- + {
- + html.replace("%coupons%", "<tr><td>You havent any coupons available.</td></tr>");
- + html.replace("%pages%", "");
- + activeChar.sendPacket(html);
- + return;
- + }
- +
- + final int max = MathUtil.countPagesNumber(coupons.size(), 15);
- +
- + coupons = coupons.subList((page - 1) * 15, Math.min(page * 15, coupons.size()));
- +
- + // Generate data.
- + final StringBuilder sb = new StringBuilder(2000);
- +
- + for (Coupon cpn : coupons)
- + StringUtil.append(sb, "<tr><td><a action=\"bypass cpn_list_", cpn.getId(), "\">", cpn.getName(), "</a></td><td width=35></td><td><a action=\"bypass cpn_redeem_", cpn.getId(), "_", page, "\"><FONT COLOR=\"LEVEL\">Redeem</FONT></a></td><td><a action=\"bypass cpn_del_", cpn.getId(), "_", page, "\">", "<FONT COLOR=\"FF9988\">Remove</font></a></td></tr>");
- +
- + html.replace("%coupons%", sb.toString());
- +
- + // Cleanup the sb.
- + sb.setLength(0);
- +
- + // End of table, open a new table for pages system.
- + for (int i = 0; i < max; i++)
- + {
- + final int pagenr = i + 1;
- + if (page == pagenr)
- + StringUtil.append(sb, pagenr, " ");
- + else
- + StringUtil.append(sb, "<a action=\"bypass list_", pagenr, "\">", pagenr, "</a> ");
- + }
- +
- + html.replace("%pages%", sb.toString());
- + activeChar.sendPacket(html);
- + }
- +
- + private static void showCategoryReward(Player activeChar, Coupon coupon, int page)
- + {
- +
- + // Load static Htm.
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + html.setFile("data/html/custom/couponsRewards.htm");
- +
- + List<IntIntHolder> rewards = coupon.getRewards();
- +
- + final int max = MathUtil.countPagesNumber(rewards.size(), 15);
- +
- + rewards = rewards.subList((page - 1) * 15, Math.min(page * 15, rewards.size()));
- +
- + // Generate data.
- + final StringBuilder sb = new StringBuilder();
- +
- + for (IntIntHolder reward : rewards)
- + {
- + String itemName = ItemTable.getInstance().getTemplate(reward.getId()).getName();
- + final int multiplier = coupon.getGradeMultiplier();
- + StringUtil.append(sb, "<tr><td><font color=\"LEVEL\">", itemName, "</font></td><td><font color=\"33cc33\">x", reward.getValue() * multiplier, "</font></td></tr>");
- + }
- +
- + html.replace("%coupons%", sb.toString());
- +
- + // Cleanup the sb.
- + sb.setLength(0);
- +
- + // End of table, open a new table for pages system.
- + for (int i = 0; i < max; i++)
- + {
- + final int pagenr = i + 1;
- + if (page == pagenr)
- + StringUtil.append(sb, pagenr, " ");
- + else
- + StringUtil.append(sb, "<a action=\"bypass cpn_page_", coupon.getId(), "_", pagenr, "\">", pagenr, "</a> ");
- + }
- +
- + html.replace("%pages%", sb.length() == 0 ? "" : sb.toString());
- + html.replace("%couponName%", coupon.getName() + " Rewards!");
- + activeChar.sendPacket(html);
- + }
- +
- private static void playerHelp(Player activeChar, String path)
- {
- if (path.indexOf("..") != -1)
- Index: java/net/sf/l2j/gameserver/handler/usercommandhandlers/Coupons.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/usercommandhandlers/Coupons.java (nonexistent)
- +++ java/net/sf/l2j/gameserver/handler/usercommandhandlers/Coupons.java (working copy)
- @@ -0,0 +1,77 @@
- +package net.sf.l2j.gameserver.handler.usercommandhandlers;
- +
- +import java.util.List;
- +
- +import net.sf.l2j.commons.lang.StringUtil;
- +import net.sf.l2j.commons.math.MathUtil;
- +
- +import net.sf.l2j.custom.Coupon;
- +import net.sf.l2j.gameserver.handler.IUserCommandHandler;
- +import net.sf.l2j.gameserver.model.actor.instance.Player;
- +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- +
- +public class Coupons implements IUserCommandHandler
- +{
- + private static final int[] COMMAND_IDS =
- + {
- + 114
- + };
- +
- + @Override
- + public boolean useUserCommand(int id, Player activeChar)
- + {
- + showCoupons(activeChar, 1);
- + return true;
- + }
- +
- + @Override
- + public int[] getUserCommandList()
- + {
- + return COMMAND_IDS;
- + }
- +
- + private static void showCoupons(Player activeChar, int page)
- + {
- + List<Coupon> coupons = activeChar.getCoupons();
- + // Load static Htm.
- + final NpcHtmlMessage html = new NpcHtmlMessage(0);
- + html.setFile("data/html/custom/couponsList.htm");
- +
- + if (coupons.isEmpty())
- + {
- + html.replace("%coupons%", "<tr><td>You havent any coupons available.</td></tr>");
- + html.replace("%pages%", "");
- + activeChar.sendPacket(html);
- + return;
- + }
- +
- + final int max = MathUtil.countPagesNumber(coupons.size(), 15);
- +
- + coupons = coupons.subList((page - 1) * 15, Math.min(page * 15, coupons.size()));
- +
- + // Generate data.
- + final StringBuilder sb = new StringBuilder(2000);
- +
- + for (Coupon cpn : coupons)
- + StringUtil.append(sb, "<tr><td><a action=\"bypass cpn_list_", cpn.getId(), "\">", cpn.getName(), "</a></td><td width=35></td><td><a action=\"bypass cpn_redeem_", cpn.getId(), "_", page, "\"><FONT COLOR=\"LEVEL\">Redeem</FONT></a></td><td><a action=\"bypass cpn_del_", cpn.getId(), "_", page, "\">", "<FONT COLOR=\"FF9988\">Remove</font></a></td></tr>");
- +
- + html.replace("%coupons%", sb.toString());
- +
- + // Cleanup the sb.
- + sb.setLength(0);
- +
- + // End of table, open a new table for pages system.
- + for (int i = 0; i < max; i++)
- + {
- + final int pagenr = i + 1;
- + if (page == pagenr)
- + StringUtil.append(sb, pagenr, " ");
- + else
- + StringUtil.append(sb, "<a action=\"bypass list_", pagenr, "\">", pagenr, "</a> ");
- + }
- +
- + html.replace("%pages%", sb.toString());
- + activeChar.sendPacket(html);
- + }
- +
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/GameServer.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/GameServer.java (revision 3)
- +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
- @@ -18,6 +18,7 @@
- import net.sf.l2j.Config;
- import net.sf.l2j.L2DatabaseFactory;
- +import net.sf.l2j.custom.CouponManager;
- import net.sf.l2j.gameserver.cache.CrestCache;
- import net.sf.l2j.gameserver.cache.HtmCache;
- import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
- @@ -94,6 +95,7 @@
- import net.sf.l2j.gameserver.network.L2GamePacketHandler;
- import net.sf.l2j.gameserver.scripting.ScriptManager;
- import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
- +import net.sf.l2j.gameserver.taskmanager.CouponsTaskManager;
- import net.sf.l2j.gameserver.taskmanager.DecayTaskManager;
- import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
- import net.sf.l2j.gameserver.taskmanager.ItemsOnGroundTaskManager;
- @@ -216,6 +218,7 @@
- ItemsOnGroundTaskManager.getInstance();
- MovementTaskManager.getInstance();
- PvpFlagTaskManager.getInstance();
- + CouponsTaskManager.getInstance();
- RandomAnimationTaskManager.getInstance();
- ShadowItemTaskManager.getInstance();
- WaterTaskManager.getInstance();
- @@ -281,6 +284,10 @@
- _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
- _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
- + StringUtil.printSection("Coupons");
- + CouponManager.loadCoupons();
- + _log.info("Loadded " + CouponManager.getCouponsSize() + " Coupons.");
- +
- StringUtil.printSection("System");
- Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
- ForumsBBSManager.getInstance();
- Index: java/net/sf/l2j/gameserver/handler/UserCommandHandler.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/UserCommandHandler.java (revision 3)
- +++ java/net/sf/l2j/gameserver/handler/UserCommandHandler.java (working copy)
- @@ -16,6 +16,7 @@
- import net.sf.l2j.gameserver.handler.usercommandhandlers.PartyInfo;
- import net.sf.l2j.gameserver.handler.usercommandhandlers.SiegeStatus;
- import net.sf.l2j.gameserver.handler.usercommandhandlers.Time;
- +import net.sf.l2j.gameserver.handler.usercommandhandlers.Coupons;
- public class UserCommandHandler
- {
- @@ -41,6 +42,7 @@
- registerUserCommandHandler(new PartyInfo());
- registerUserCommandHandler(new SiegeStatus());
- registerUserCommandHandler(new Time());
- + registerUserCommandHandler(new Coupons());
- }
- public void registerUserCommandHandler(IUserCommandHandler handler)
- Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java (revision 3)
- +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminAdmin.java (working copy)
- @@ -5,6 +5,8 @@
- import net.sf.l2j.commons.lang.StringUtil;
- import net.sf.l2j.Config;
- +import net.sf.l2j.custom.Coupon;
- +import net.sf.l2j.custom.CouponManager;
- import net.sf.l2j.gameserver.cache.CrestCache;
- import net.sf.l2j.gameserver.cache.HtmCache;
- import net.sf.l2j.gameserver.data.DoorTable;
- @@ -24,6 +26,7 @@
- import net.sf.l2j.gameserver.model.actor.Creature;
- import net.sf.l2j.gameserver.model.actor.instance.Player;
- import net.sf.l2j.gameserver.network.SystemMessageId;
- +import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
- /**
- * This class handles following admin commands:
- @@ -50,7 +53,8 @@
- "admin_kill",
- "admin_silence",
- "admin_tradeoff",
- - "admin_reload"
- + "admin_reload",
- + "admin_setcoupon"
- };
- @Override
- @@ -58,10 +62,60 @@
- {
- if (command.startsWith("admin_admin"))
- showMainPage(activeChar, command);
- + else if (command.startsWith("admin_setcoupon"))
- + {
- + final String SILVER = "silver";
- + final String GOLD = "gold";
- + final String PLATINUM = "platinum";
- +
- + StringTokenizer st = new StringTokenizer(command, " ");
- + st.nextToken();
- + if (!st.hasMoreTokens())
- + {
- + activeChar.sendMessage("//setcoupon {category} (categories : silver/gold/platinum)");
- + return false;
- + }
- + String category = st.nextToken();
- + if (!category.equalsIgnoreCase(SILVER) && !category.equalsIgnoreCase(GOLD) && !category.equalsIgnoreCase(PLATINUM))
- + {
- + activeChar.sendMessage("//setcoupon {category} (categories : silver/gold/platinum)");
- + return false;
- + }
- + if (activeChar.getTarget() == null)
- + {
- + activeChar.sendMessage("select a target first");
- + return false;
- + }
- + Player target = null;
- +
- + if (activeChar.getTarget() instanceof Player)
- + target = (Player) activeChar.getTarget();
- +
- + if (target != null)
- + {
- + Coupon coupon = CouponManager.generateCoupon(category.toUpperCase(), target);
- + if (coupon != null)
- + {
- + String exMessage = "New Coupon is now available! " + coupon.getName() + " is now activated!";
- + target.sendPacket(new ExShowScreenMessage(1, 0, 2, false, 1, 0, 0, false, 4000, false, exMessage));
- + }
- + }
- + else
- + {
- + activeChar.sendMessage("Player instance allowed");
- + return false;
- + }
- +
- + }
- else if (command.startsWith("admin_gmlist"))
- activeChar.sendMessage((AdminData.getInstance().showOrHideGm(activeChar)) ? "Removed from GMList." : "Registered into GMList.");
- Index: java/net/sf/l2j/gameserver/model/actor/instance/Player.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/actor/instance/Player.java (revision 3)
- +++ java/net/sf/l2j/gameserver/model/actor/instance/Player.java (working copy)
- @@ -27,6 +27,8 @@
- import net.sf.l2j.Config;
- import net.sf.l2j.L2DatabaseFactory;
- +import net.sf.l2j.custom.Coupon;
- +import net.sf.l2j.custom.CouponManager;
- import net.sf.l2j.gameserver.LoginServerThread;
- import net.sf.l2j.gameserver.communitybbs.BB.Forum;
- import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
- @@ -47,6 +49,7 @@
- import net.sf.l2j.gameserver.handler.IItemHandler;
- import net.sf.l2j.gameserver.handler.ItemHandler;
- import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEditChar;
- +import net.sf.l2j.gameserver.idfactory.IdFactory;
- import net.sf.l2j.gameserver.instancemanager.CastleManager;
- import net.sf.l2j.gameserver.instancemanager.CoupleManager;
- import net.sf.l2j.gameserver.instancemanager.CursedWeaponsManager;
- @@ -309,8 +312,8 @@
- private static final String DELETE_SKILL_SAVE = "DELETE FROM character_skills_save WHERE char_obj_id=? AND class_index=?";
- private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- - private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=? WHERE obj_id=?";
- - private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level FROM characters WHERE obj_id=?";
- + private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=?,couponsused=? WHERE obj_id=?";
- + private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,couponsused FROM characters WHERE obj_id=?";
- private static final String RESTORE_CHAR_SUBCLASSES = "SELECT class_id,exp,sp,level,class_index FROM character_subclasses WHERE char_obj_id=? ORDER BY class_index ASC";
- private static final String ADD_CHAR_SUBCLASS = "INSERT INTO character_subclasses (char_obj_id,class_id,exp,sp,level,class_index) VALUES (?,?,?,?,?,?)";
- @@ -5386,6 +5389,8 @@
- player.setDeathPenaltyBuffLevel(rset.getInt("death_penalty_level"));
- + player.setCouponsUsed(rset.getInt("couponsused"));
- +
- // Set the x,y,z position of the Player and make it invisible
- player.getPosition().set(rset.getInt("x"), rset.getInt("y"), rset.getInt("z"));
- @@ -5727,7 +5732,8 @@
- statement.setLong(47, getClanCreateExpiryTime());
- statement.setString(48, getName());
- statement.setLong(49, getDeathPenaltyBuffLevel());
- - statement.setInt(50, getObjectId());
- + statement.setInt(50, getCouponsUsed());
- + statement.setInt(51, getObjectId());
- statement.execute();
- statement.close();
- @@ -10536,4 +10542,108 @@
- }
- }
- }
- +
- + private List<Coupon> coupons = new ArrayList<>();
- +
- + public void setCoupon(Coupon _coupon)
- + {
- + if (_coupon == null)
- + return;
- + if (!coupons.contains(_coupon))
- + coupons.add(_coupon);
- + }
- +
- + public List<Coupon> getCoupons()
- + {
- + return coupons;
- + }
- +
- + /**
- + * @param couponName
- + * @return
- + */
- + public Coupon getCouponsByName(String couponName)
- + {
- + for (Coupon cpn : coupons)
- + {
- + if (cpn.getName().equalsIgnoreCase(couponName))
- + return cpn;
- + }
- + return null;
- + }
- +
- + public Coupon getCouponById(int couponId)
- + {
- + for (Coupon cpn : coupons)
- + {
- + if (cpn.getId() == couponId)
- + return cpn;
- + }
- + return null;
- + }
- +
- + /**
- + * @param coupon
- + */
- + public void removeCoupon(Coupon coupon)
- + {
- + if (coupon == null)
- + return;
- +
- + if (coupons.remove(coupon))
- + {
- + IdFactory.getInstance().releaseId(coupon.getId());
- + CouponManager.deleteCoupon(coupon);
- + }
- + else
- + System.out.println("Cannot remove coupon from character " + this.getName());
- + }
- +
- + private int couponsUsed = 0;
- +
- + public int getCouponsUsed()
- + {
- + return couponsUsed;
- + }
- +
- + public boolean canUseCoupon()
- + {
- + return Config.COUPONS_LIMIT_PER_DAY == 0 ? true : couponsUsed < Config.COUPONS_LIMIT_PER_DAY;
- + }
- +
- + public void increaseCouponsUsed()
- + {
- + if (Config.COUPONS_LIMIT_PER_DAY > 0)
- + {
- + couponsUsed++;
- + storeCouponUsed();
- + }
- + }
- +
- + public void resetCouponsUsed()
- + {
- + couponsUsed = 0;
- + sendMessage("Your coupons limit are now over.");
- + }
- +
- + public void setCouponsUsed(int val)
- + {
- + couponsUsed = val;
- + }
- +
- + public void storeCouponUsed()
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement("UPDATE characters SET couponsused=? WHERE obj_id=?");
- + statement.setInt(1, getCouponsUsed());
- + statement.setInt(2, getObjectId());
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + _log.warning("Error could not store char skills: " + e);
- + }
- + }
- }
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java (revision 3)
- +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java (working copy)
- @@ -8,6 +8,7 @@
- import net.sf.l2j.Config;
- import net.sf.l2j.L2DatabaseFactory;
- +import net.sf.l2j.custom.CouponManager;
- import net.sf.l2j.gameserver.communitybbs.Manager.MailBBSManager;
- import net.sf.l2j.gameserver.data.MapRegionTable.TeleportType;
- import net.sf.l2j.gameserver.data.SkillTable.FrequentSkill;
- @@ -323,6 +324,7 @@
- if (!activeChar.isGM() && (!activeChar.isInSiege() || activeChar.getSiegeState() < 2) && activeChar.isInsideZone(ZoneId.SIEGE))
- activeChar.teleToLocation(TeleportType.TOWN);
- + CouponManager.setCoupons(activeChar);
- activeChar.sendPacket(ActionFailed.STATIC_PACKET);
- }
- Index: java/net/sf/l2j/gameserver/taskmanager/CouponsTaskManager.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/taskmanager/CouponsTaskManager.java (nonexistent)
- +++ java/net/sf/l2j/gameserver/taskmanager/CouponsTaskManager.java (working copy)
- @@ -0,0 +1,83 @@
- +package net.sf.l2j.gameserver.taskmanager;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.text.SimpleDateFormat;
- +import java.util.Calendar;
- +import java.util.logging.Logger;
- +
- +import net.sf.l2j.commons.concurrent.ThreadPool;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.L2DatabaseFactory;
- +import net.sf.l2j.gameserver.model.World;
- +import net.sf.l2j.gameserver.model.actor.instance.Player;
- +
- +/**
- + * @author Melron
- + */
- +public final class CouponsTaskManager implements Runnable
- +{
- + private static final int CalendarHour = Config.COUPONS_RESET_LIMIT_AT[0];
- + private static final int CalendarMinute = Config.COUPONS_RESET_LIMIT_AT[1];
- + private static final int CalendarSecond = 0;
- + private static final long Delay = 86400000; // 1 day
- + private static final SimpleDateFormat sdf = new SimpleDateFormat("yyy MMM dd (EEEE) HH:mm:ss");
- + private static final Logger _log = Logger.getLogger(CouponsTaskManager.class.getName());
- +
- + public static final CouponsTaskManager getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + protected CouponsTaskManager()
- + {
- + ThreadPool.scheduleAtFixedRate(this, getTime(), Delay);
- + _log.info("Next lift: " + sdf.format(System.currentTimeMillis() + getTime()));
- + }
- +
- + /**
- + * @return
- + */
- + private static long getTime()
- + {
- + Calendar calendar = Calendar.getInstance();
- + calendar.set(Calendar.HOUR_OF_DAY, CalendarHour);
- + calendar.set(Calendar.MINUTE, CalendarMinute);
- + calendar.set(Calendar.SECOND, CalendarSecond);
- +
- + if (calendar.getTimeInMillis() <= System.currentTimeMillis())
- + calendar.add(Calendar.DATE, 1);
- +
- + return calendar.getTimeInMillis() - System.currentTimeMillis();
- + }
- +
- + @Override
- + public final void run()
- + {
- + if (Config.COUPONS_LIMIT_PER_DAY > 0)
- + {
- + for (Player activeChar : World.getInstance().getPlayers())
- + if (activeChar != null)
- + activeChar.resetCouponsUsed();
- +
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection())
- + {
- + PreparedStatement statement = con.prepareStatement("UPDATE characters SET couponsused=?");
- + statement.setInt(1, 0);
- + statement.execute();
- + statement.close();
- + }
- + catch (Exception e)
- + {
- + _log.warning("Error could not reset coupon used count: " + e);
- + }
- + _log.info("All coupons limits are lifted. Next lift: " + sdf.format(System.currentTimeMillis() + Delay));
- + }
- + }
- +
- + private static class SingletonHolder
- + {
- + protected static final CouponsTaskManager _instance = new CouponsTaskManager();
- + }
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment