Jump to content

Recommended Posts

Posted
package events;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import l2s.commons.util.Rnd;
import l2s.gameserver.Config;
import l2s.gameserver.ThreadPoolManager;
import l2s.gameserver.database.mysql;
import l2s.gameserver.instancemanager.ServerVariables;
import l2s.gameserver.listener.actor.OnAbnormalStartEndListener;
import l2s.gameserver.listener.actor.OnDeathListener;
import l2s.gameserver.listener.actor.player.OnPlayerEnterListener;
import l2s.gameserver.listener.script.OnInitScriptListener;
import l2s.gameserver.model.Creature;
import l2s.gameserver.model.GameObjectsStorage;
import l2s.gameserver.model.Player;
import l2s.gameserver.model.actor.instances.creature.Abnormal;
import l2s.gameserver.model.actor.listener.CharListenerList;
import l2s.gameserver.model.actor.variables.PlayerVariables;
import l2s.gameserver.network.l2.components.SystemMsg;
import l2s.gameserver.network.l2.s2c.SystemMessagePacket;
import l2s.gameserver.network.l2.s2c.events.ExBalthusEvent;
import l2s.gameserver.network.l2.s2c.events.ExBalthusEventJackpotUser;
import l2s.gameserver.utils.Functions;

/**
 * @author nexvill
 */
public class BalthusEvent implements OnInitScriptListener
{
	private static final Logger _log = LoggerFactory.getLogger(BalthusEvent.class);

	private class EventListeners implements OnPlayerEnterListener
	{
		@Override
		public void onPlayerEnter(Player player) {
			if (_active) {
				if (player.getAbnormalList().contains(BUFF_ID)) {
					int receivedAmount = player.getVarInt(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, 0);
					player.sendPacket(new ExBalthusEvent(_round, _stage, _jackpotId, BASIC_REWARD_COUNT, receivedAmount, true, false, _time));
				}
				else {
					int receivedAmount = player.getVarInt(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, 0);
					player.sendPacket(new ExBalthusEvent(_round, _stage, _jackpotId, BASIC_REWARD_COUNT, receivedAmount, false, false, _time));
				}
			}
		}
	}

	private class AbnormalStartEndListener implements OnAbnormalStartEndListener
	{
		@Override
		public void onAbnormalStart(Creature actor, Abnormal a) {
			if (actor.isPlayer() && (a.getId() == BUFF_ID) && _active) {
				int receivedAmount = actor.getPlayer().getVarInt(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, 0);
				actor.sendPacket(new ExBalthusEvent(_round, _stage, _jackpotId, BASIC_REWARD_COUNT, receivedAmount, true, false, _time));
			}
		}

		@Override
		public void onAbnormalEnd(Creature actor, Abnormal a) {
			if (actor.isPlayer() && (a.getId() == BUFF_ID) && _active) {
				int receivedAmount = actor.getPlayer().getVarInt(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, 0);
				actor.sendPacket(new ExBalthusEvent(_round, _stage, _jackpotId, BASIC_REWARD_COUNT, receivedAmount, false, false, _time));
			}
		}
	}

	public class MonsterDeathListener implements OnDeathListener
	{
		@Override
		public void onDeath(Creature actor, Creature killer) {
			if (!_active)
				return;

			if (killer == null || !actor.isMonster())
				return;

			Player player = killer.getPlayer();
			if (player == null)
				return;

			if ((killer.getLevel() - actor.getLevel()) > 15)
				return;

			if (Rnd.get(100) < 2)
				player.getInventory().addItem(BASIC_REWARD_ID, 1);
		}

	}

	private class UpdateEvent implements Runnable
	{
		@Override
		public void run() {
			long currentTime = System.currentTimeMillis();
			if ((currentTime > _timeStart) && (currentTime < _timeEnd)) {
				Functions.SetActive(EVENT_NAME, true);
			}
			else {
				Functions.SetActive(EVENT_NAME, false);
			}
		}

	}

	private static final String EVENT_NAME = "BalthusEvent";

	private static final int BUFF_ID = Config.BALTHUS_EVENT_PARTICIPATE_BUFF_ID;

	private EventListeners EVENT_LISTENERS = new EventListeners();
	private final OnAbnormalStartEndListener _abnormalStartEndListener = new AbnormalStartEndListener();

	// Misc
	private int _round = 1;
	private int _stage = 20;
	private int _time = 0;
	private int _jackpotId = 49800;
	private int _hour;
	private boolean _receivedThisHour = false;
	private static final int BASIC_REWARD_COUNT = Config.BALTHUS_EVENT_BASIC_REWARD_COUNT;
	private static final int BASIC_REWARD_ID = Config.BALTHUS_EVENT_BASIC_REWARD_ID;

	private static boolean _active = false;
	private static long _timeStart, _timeEnd;

	@Override
	public void onInit() {
		if (isActive()) {
			_active = true;
			CharListenerList.addGlobal(EVENT_LISTENERS);
			CharListenerList.addGlobal(_abnormalStartEndListener);
			_hour = ZonedDateTime.now().getHour();
			_round = _hour + 1;
			_time = ZonedDateTime.now().getMinute() * 60;
			ThreadPoolManager.getInstance().schedule(new UpdateEvent(), _timeEnd);
			ThreadPoolManager.getInstance().scheduleAtFixedRate(() -> updateTimer(), 1000L, 1000L);
			_log.info("Loaded Event: Balthus Event [state: activated]");
		}
		else {
			ThreadPoolManager.getInstance().schedule(new UpdateEvent(), _timeStart);
			_log.info("Loaded Event: Balthus Event [state: deactivated]");
		}
	}

	private static boolean isActive() {
		LocalDateTime localDateTime = LocalDateTime.parse(Config.BALTHUS_EVENT_TIME_START, DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
		_timeStart = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
		localDateTime = LocalDateTime.parse(Config.BALTHUS_EVENT_TIME_END, DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
		_timeEnd = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
		long currentTime = System.currentTimeMillis();
		if ((currentTime > _timeStart) && (currentTime < _timeEnd)) {
			Functions.SetActive(EVENT_NAME, true);
		}
		else {
			Functions.SetActive(EVENT_NAME, false);
			mysql.set("DELETE FROM `character_variables` WHERE `value` = \"balthus_received_amount\";");
		}
		return Functions.IsActive(EVENT_NAME);
	}

	private void updateTimer() {
		_time++;
		if (_time >= 3600) {
			_time = 0;
			_stage = 20;
			_round++;
			_receivedThisHour = false;
			if (_round > 24) {
				_round = 1;
			}
			manageJackpot();
			updateEvent();
			saveVars();
		}
		else if (((_time == 3500) || (_time == 2880) || (_time == 2160) || (_time == 1440) || (_time == 720)) && !_receivedThisHour) {
			if (_time != 3500) {
				_stage += 20;
			}
			eventRun();
			saveVars();
		}
	}

	private void saveVars() {
		ServerVariables.set("balthus_round", _round);
		ServerVariables.set("balthus_stage", _stage);
		ServerVariables.set("balthus_jackpot", _jackpotId);
		ServerVariables.set("balthus_received_hour", _receivedThisHour);
	}

	private void eventRun() {
		int participantsCount = 0;
		if (!_receivedThisHour && (Rnd.get(100) < Config.BALTHUS_EVENT_JACKPOT_CHANCE)) {
			_receivedThisHour = true;
			for (Player player : GameObjectsStorage.getPlayers(false, false)) {
				if (player.getAbnormalList().contains(BUFF_ID)) {
					participantsCount++;
					player.setVar(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, player.getVarInt(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, 0) + BASIC_REWARD_COUNT);
				}
				player.sendPacket(new ExBalthusEventJackpotUser());
				player.sendPacket(new SystemMessagePacket(SystemMsg.THE_SECRET_SUPPLIES_OF_THE_BALTHUS_KNIGHTS_ARRIVED_SOMEONE_RECEIVED_S1).addItemName(_jackpotId));
			}
			if (!(participantsCount < 1)) {
				int number = Rnd.get(participantsCount);
				int i = 0;
				for (Player player : GameObjectsStorage.getPlayers(false, false)) {
					if (player.getAbnormalList().contains(BUFF_ID)) {
						if (number == i) {
							player.getInventory().addItem(_jackpotId, 1);
							break;
						}
						i++;
					}
				}
			}
		}
		updateEvent();
	}

	private void updateEvent() {
		for (Player player : GameObjectsStorage.getPlayers(false, false)) {
			boolean participate = false;
			if (player.getAbnormalList().contains(BUFF_ID)) {
				participate = true;
			}
			int receivedAmount = player.getVarInt(PlayerVariables.BALTHUS_RECEIVED_AMOUNT, 0);
			player.sendPacket(new ExBalthusEvent(_round, _stage, _jackpotId, BASIC_REWARD_COUNT, receivedAmount, participate, _receivedThisHour, _time));
		}
	}

	private void manageJackpot() {
		if (_hour < 1)
			_jackpotId = 95876; // Balthus Knights' High-grade Spellbook Chest
		else if (_hour < 17)
			_jackpotId = 49800; // Sibi's Coin Pack
		else if (_hour < 18)
			_jackpotId = 94875; // Balthus Knights' Enchanted Talisman Pack
		else if (_hour < 19)
			_jackpotId = 95872; // Balthus Knights' Master Book Chest
		else if (_hour < 20)
			_jackpotId = 94873; // Balthus Knights' Blessed Dragon Belt
		else if (_hour < 21)
			_jackpotId = 95873; // Balthus Knights' Enchanted Armor Pack
		else if (_hour < 22)
			_jackpotId = 95874; // Balthus Knights' Package: Hardin's Soul Crystal
		else if (_hour < 23)
			_jackpotId = 94877; // Balthus Knight's Package: Enhanced Einhasad's Pendant
		else if (_hour == 23)
			_jackpotId = 95875; // Balthus Knight's Enchanted Weapon Pack
	}
}

free

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • 寒冷的冬天 — 火热的折扣。使用促销代码 WINTER 即可在我们商店的所有购买中获得 10% 折扣! 有效链接: 数字商品商店(网站): 前往 其他服务和产品: 商店 Telegram 机器人: 前往 – 通过 Telegram 信使方便访问商店。 虚拟号码服务: 前往 用于购买 Telegram Stars 的 Telegram 机器人: 前往 – 在 Telegram 中快速且优惠地购买 Stars。 SMM 面板: 前往 – 推广您的社交媒体账户。 我们想向您展示当前的 促销和特别优惠列表 ,用于购买我们服务的产品和服务: 1. 您可以在首次购买时使用促销代码:SOCNET(15% 折扣) 2. 获取 $1 商店余额或 10–20% 折扣——只需在我们的网站注册后按以下模板填写您的用户名:"SEND ME BONUS, MY USERNAME IS..." ——您需要在我们的论坛主题中发布! 3. SMM 面板首次试用可获得 $1:只需在我们的网站(Support)提交主题为 “Get Trial Bonus” 的工单。 4. 我们的 Telegram 频道和 Stars 购买机器人中每周都会赠送 Telegram Stars! 新闻: ➡ Telegram 频道: https://t.me/accsforyou_shop ➡ WhatsApp 频道: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord 服务器: https://discord.gg/y9AStFFsrh 联系方式和支持: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Cold winter — hot discounts. Use promo code WINTER and get 10% off on all purchases in our store! Active links: Digital goods store (Website): Go to Other services and products: Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. We want to present to you the current list of promotions and special offers for purchasing products and services of our service: 1. You can use a promo code for your first purchase: SOCNET (15% discount) 2. Get $1 on your store balance or a 10–20% discount — just write your username after registering on our website using the following template: "SEND ME BONUS, MY USERNAME IS..." – you need to post this in our forum thread! 3. Get $1 for the first trial launch of the SMM Panel: just open a ticket with the subject “Get Trial Bonus” on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our bot for purchasing stars! News: ➡ Telegram channel: https://t.me/accsforyou_shop ➡ WhatsApp channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord server: https://discord.gg/y9AStFFsrh Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Cold winter — hot discounts. Use promo code WINTER and get 10% off on all purchases in our store! Active links: Digital goods store (Website): Go to Other services and products: Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. We want to present to you the current list of promotions and special offers for purchasing products and services of our service: 1. You can use a promo code for your first purchase: SOCNET (15% discount) 2. Get $1 on your store balance or a 10–20% discount — just write your username after registering on our website using the following template: "SEND ME BONUS, MY USERNAME IS..." – you need to post this in our forum thread! 3. Get $1 for the first trial launch of the SMM Panel: just open a ticket with the subject “Get Trial Bonus” on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our bot for purchasing stars! News: ➡ Telegram channel: https://t.me/accsforyou_shop ➡ WhatsApp channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord server: https://discord.gg/y9AStFFsrh Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Telegram Stars — a new digital currency inside Telegram. And right now, the best opportunities are opening for profitable purchases and participation in exclusive events. And you can purchase Telegram Stars safely and at the best price in our bot. Active links: Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. Other services and products: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store via the Telegram messenger. Virtual numbers service: Go to SMM Panel: Go to – promotion of your social media accounts. We want to present to you the current list of promotions and special offers for purchasing products and services of our service: 1. You can use a promo code for your first purchase: SOCNET (15% discount) 2. Get $1 on your store balance or a 10–20% discount — just write your username after registering on our website using the following template: "SEND ME BONUS, MY USERNAME IS..." — you need to post this in our forum thread! 3. Get $1 for the first trial launch of the SMM Panel: just open a ticket with the subject “Get Trial Bonus” on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our bot for purchasing stars! News: ➡ Telegram channel: https://t.me/accsforyou_shop ➡ WhatsApp channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord server: https://discord.gg/y9AStFFsrh Contacts and support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock