Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2004-2013 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack 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.
- *
- * L2J DataPack 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 l2dc.CastleBattle;
- import java.util.Calendar;
- import java.util.Map;
- import java.util.logging.Logger;
- import javolution.util.FastMap;
- import com.l2jserver.gameserver.Announcements;
- import com.l2jserver.gameserver.ThreadPoolManager;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- /**
- * @author HyperByter
- * @version Beta
- * @build 8.7.2013
- */
- public class CastleBattle
- {
- protected static CastleBattle instance = null;
- public static CastleBattleLoop _task = new CastleBattleLoop();
- private static final Logger _log = Logger.getLogger("CastleBattle");
- private final String htm_path = "data/scripts/l2dc/CastleBattle/";
- /**
- * <ul>
- * <li>0 - Disabled</li>
- * <li>1 - Not in progress</li>
- * <li>2 - Participation</li>
- * <li>3 - Event Started</li>
- * <li>5 - Event Ended
- * </ul>
- */
- private int CB_State;
- private final Map<Integer, L2PcInstance> _participatedPlayers = new FastMap<>();
- private CastleBattle()
- {
- CB_Init();
- }
- public static synchronized CastleBattle getInstance()
- {
- if (instance == null)
- {
- instance = new CastleBattle();
- }
- return instance;
- }
- // Initialize Engine
- private void CB_Init()
- {
- CBState_Set(1); // 1 - ON, 2 - OFF
- if (CBState_Get() == 1)
- {
- SetStartTime();
- }
- }
- public int CBState_Get()
- {
- return CB_State;
- }
- public void CBState_Set(int _state)
- {
- CB_State = _state;
- }
- public void SetStartTime()
- {
- Calendar _nextTime = Calendar.getInstance();
- int _m = _nextTime.get(Calendar.MINUTE);
- int x = 1;
- while (_m > 5)
- {
- _m -= 5;
- x++;
- }
- _nextTime.set(Calendar.MINUTE, x * 5);
- ThreadPoolManager.getInstance().scheduleGeneral(_task, _nextTime.getTimeInMillis() - System.currentTimeMillis());
- }
- public void StartParticipation()
- {
- CBState_Set(2);
- Announcements.getInstance().announceToAll("Castle Battle participation has started.");
- _log.info("Castle Battle participation has started.");
- }
- private void CB_AddPlayer(L2PcInstance _player)
- {
- _participatedPlayers.put(_player.getObjectId(), _player);
- }
- private int CB_GetPlayerCount()
- {
- int _pCount = _participatedPlayers.size();
- return _pCount;
- }
- // HTML Chat Handler
- public void CB_bypass(String _cmd, L2PcInstance _player)
- {
- final NpcHtmlMessage _html = new NpcHtmlMessage(0);
- if (_cmd.startsWith("InitHtmlRequest"))
- {
- switch (CBState_Get())
- {
- case 0:
- _html.setFile(null, htm_path + "CB_Disabled.htm");
- _player.sendPacket(_html);
- break;
- case 1:
- _html.setFile(null, htm_path + "CB_NotRunning.htm");
- _player.sendPacket(_html);
- break;
- case 2:
- _html.setFile(null, htm_path + "CB_Participate.htm");
- _html.replace("%_pCount%", "" + CB_GetPlayerCount());
- _player.sendPacket(_html);
- break;
- }
- }
- if (_cmd.startsWith("CB_Participate"))
- {
- if (_participatedPlayers.containsKey(_player.getObjectId()))
- {
- _html.setFile("", htm_path + "CB_No_AlreadyJoined.htm");
- _player.sendPacket(_html);
- }
- else if (_player.isInOlympiadMode())
- {
- _html.setFile("", htm_path + "CB_No_Olympiad.htm");
- _player.sendPacket(_html);
- }
- else
- {
- CB_AddPlayer(_player);
- _html.setFile("", htm_path + "CB_ParticipateSuccess.htm");
- _player.sendPacket(_html);
- }
- }
- }
- public static void main(String[] args)
- {
- _log.info("# Castle Battle Engine #");
- _log.info("Author : HyperByter");
- _log.info("Version : Beta");
- _log.info("Build : 8.7.2013");
- }
- }
- class CastleBattleLoop implements Runnable
- {
- @Override
- public void run()
- {
- if (CastleBattle.getInstance().CBState_Get() == 1)
- {
- CastleBattle.getInstance().StartParticipation();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment