/* This file is part of the ZeroFusion MapleStory Server Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> Matthias Butz <matze@odinms.de> Jan Christian Meyer <vimes@odinms.de> ZeroFusion organized by "RMZero213" <RMZero213@hotmail.com> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation. You may not use, modify or distribute this program under any other version of the GNU Affero General Public License. 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 Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package server.events; import client.MapleCharacter; import java.util.concurrent.ScheduledFuture; import server.Timer.EventTimer; import tools.packet.CField; import tools.packet.CWvsContext; public class MapleSurvival extends MapleEvent { protected long time = 360000; //reduce for less time protected long timeStarted = 0; protected ScheduledFuture<?> olaSchedule; public MapleSurvival(final int channel, final MapleEventType type) { super(channel,type); } @Override public void finished(final MapleCharacter chr) { givePrize(chr); } @Override public void onMapLoad(MapleCharacter chr) { super.onMapLoad(chr); if (isTimerStarted()) { chr.getClient().getSession().write(CField.getClock((int) (getTimeLeft() / 1000))); } } @Override public void startEvent() { // TODO: Messages unreset(); super.reset(); //isRunning = true broadcast(CField.getClock((int) (time / 1000))); this.timeStarted = System.currentTimeMillis(); olaSchedule = EventTimer.getInstance().schedule(new Runnable() { @Override public void run() { for (int i = 0; i < type.mapids.length; i++) { for (MapleCharacter chr : getMap(i).getCharactersThreadsafe()) { warpBack(chr); } unreset(); } } }, this.time); broadcast(CWvsContext.broadcastMsg(0, "The portal has now opened. Press the up arrow key at the portal to enter.")); broadcast(CWvsContext.broadcastMsg(0, "Fall down once, and never get back up again! Get to the top without falling down!")); } public boolean isTimerStarted() { return timeStarted > 0; } public long getTime() { return time; } public void resetSchedule() { this.timeStarted = 0; if (olaSchedule != null) { olaSchedule.cancel(false); } olaSchedule = null; } @Override public void reset() { super.reset(); resetSchedule(); getMap(0).getPortal("join00").setPortalState(false); } @Override public void unreset() { super.unreset(); resetSchedule(); getMap(0).getPortal("join00").setPortalState(true); } public long getTimeLeft() { return time - (System.currentTimeMillis() - timeStarted); } }