Package services

Source Code of services.RateBonus

/*
* 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 <http://www.gnu.org/licenses/>.
*/
package services;

import java.util.Date;

import lineage2.gameserver.Config;
import lineage2.gameserver.cache.Msg;
import lineage2.gameserver.dao.AccountBonusDAO;
import lineage2.gameserver.data.htm.HtmCache;
import lineage2.gameserver.data.xml.holder.ItemHolder;
import lineage2.gameserver.model.Player;
import lineage2.gameserver.model.actor.instances.player.Bonus;
import lineage2.gameserver.network.loginservercon.LoginServerCommunication;
import lineage2.gameserver.network.loginservercon.gspackets.BonusRequest;
import lineage2.gameserver.network.serverpackets.ExBR_PremiumState;
import lineage2.gameserver.network.serverpackets.components.SystemMsg;
import lineage2.gameserver.scripts.Functions;
import lineage2.gameserver.utils.Log;

/**
* @author Mobius
* @version $Revision: 1.0 $
*/
public class RateBonus extends Functions
{
  /**
   * Method list.
   */
  public void list()
  {
    Player player = getSelf();
    if (Config.SERVICES_RATE_TYPE == Bonus.NO_BONUS)
    {
      show(HtmCache.getInstance().getNotNull("npcdefault.htm", player), player);
      return;
    }
    String html;
    if (player.getNetConnection().getBonus() >= 1.)
    {
      int endtime = player.getNetConnection().getBonusExpire();
      if (endtime >= (System.currentTimeMillis() / 1000L))
      {
        html = HtmCache.getInstance().getNotNull("scripts/services/RateBonusAlready.htm", player).replaceFirst("endtime", new Date(endtime * 1000L).toString());
      }
      else
      {
        html = HtmCache.getInstance().getNotNull("scripts/services/RateBonus.htm", player);
        String add = "";
        for (int i = 0; i < Config.SERVICES_RATE_BONUS_DAYS.length; i++)
        {
          add += "<a action=\"bypass -h scripts_services.RateBonus:get " + i + "\">" + (int) ((Config.SERVICES_RATE_BONUS_VALUE[i] * 100) - 100) + "% for " + Config.SERVICES_RATE_BONUS_DAYS[i] + " days - " + Config.SERVICES_RATE_BONUS_PRICE[i] + " " + ItemHolder.getInstance().getTemplate(Config.SERVICES_RATE_BONUS_ITEM[i]).getName() + "</a><br>";
        }
        html = html.replaceFirst("%toreplace%", add);
      }
    }
    else
    {
      html = HtmCache.getInstance().getNotNull("scripts/services/RateBonusNo.htm", player);
    }
    show(html, player);
  }
 
  /**
   * Method get.
   * @param param String[]
   */
  public void get(String[] param)
  {
    Player player = getSelf();
    if (Config.SERVICES_RATE_TYPE == Bonus.NO_BONUS)
    {
      show(HtmCache.getInstance().getNotNull("npcdefault.htm", player), player);
      return;
    }
    int i = Integer.parseInt(param[0]);
    if (!player.getInventory().destroyItemByItemId(Config.SERVICES_RATE_BONUS_ITEM[i], Config.SERVICES_RATE_BONUS_PRICE[i]))
    {
      if (Config.SERVICES_RATE_BONUS_ITEM[i] == 57)
      {
        player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
      }
      else
      {
        player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
      }
      return;
    }
    if ((Config.SERVICES_RATE_TYPE == Bonus.BONUS_GLOBAL_ON_LOGINSERVER) && LoginServerCommunication.getInstance().isShutdown())
    {
      list();
      return;
    }
    Log.add(player.getName() + "|" + player.getObjectId() + "|rate bonus|" + Config.SERVICES_RATE_BONUS_VALUE[i] + "|" + Config.SERVICES_RATE_BONUS_DAYS[i] + "|", "services");
    double bonus = Config.SERVICES_RATE_BONUS_VALUE[i];
    int bonusExpire = (int) (System.currentTimeMillis() / 1000L) + (Config.SERVICES_RATE_BONUS_DAYS[i] * 24 * 60 * 60);
    switch (Config.SERVICES_RATE_TYPE)
    {
      case Bonus.BONUS_GLOBAL_ON_LOGINSERVER:
        LoginServerCommunication.getInstance().sendPacket(new BonusRequest(player.getAccountName(), bonus, bonusExpire));
        break;
      case Bonus.BONUS_GLOBAL_ON_GAMESERVER:
        AccountBonusDAO.getInstance().insert(player.getAccountName(), bonus, bonusExpire);
        break;
    }
    player.getNetConnection().setBonus(bonus);
    player.getNetConnection().setBonusExpire(bonusExpire);
    player.stopBonusTask();
    player.startBonusTask();
    if (player.getParty() != null)
    {
      player.getParty().recalculatePartyData();
    }
    player.sendPacket(new ExBR_PremiumState(player, true));
    show(HtmCache.getInstance().getNotNull("scripts/services/RateBonusGet.htm", player), player);
  }
}
TOP

Related Classes of services.RateBonus

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.