Noticias:

No tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

Menú Principal

Evento Crazy Rates

Iniciado por Swarlog, Jun 29, 2025, 12:10 AM

Tema anterior - Siguiente tema

Swarlog

CitarNo tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

package events.Rates;
 
import java.util.Calendar;
 
import com.l2jserver.Config;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.quest.Quest;
 
public class Rates extends Quest
{
	private static final boolean ANNOUNCE = true; // announce the rate changes or not.
	private static final int MULTIPLIER = 2; // rate multiplier, choose with caution!
	private static final int DURATION = 60; // in minutes.
	private static final int DELAY = 360; // Delay between server start/script load and event start in minutes.
 
	private static final Byte START_DAY = 0; // zero to disable. !!!Starts with SUNDAY as 1st day of week!!! Accepted values 1-7.
	private static final Byte START_HOUR = 18; // zero to disable. 24 hour system. Must be set if using START_DAY,
																							//otherwise will start at midnight (unless that's what you want).
	private static final Byte START_MINUTE = 30;
 
	private static final int FREQUENCY = 360; // Time between event re-run in minutes, 0 to use daily/weekly system.
 
	public Rates(int questId, String name, String descr)
	{
		super(questId, name, descr);
 
		if (loadGlobalQuestVar("exprate") == "")
		{
			if (START_DAY > 0 || START_HOUR > 0)
				startQuestTimer("START", setStartTime(START_DAY, START_HOUR, START_MINUTE), null, null);
			else
				startQuestTimer("START", DELAY * 60000, null, null);
		}
		else // in case your server crashed before restoring rates...
			startQuestTimer("RESTORE", 60000, null, null);
	}
 
	private long setStartTime(Byte day, Byte hour, Byte minute)
	{
		Calendar starttime = Calendar.getInstance();
		if (day > 0 && day < 8)
			starttime.set( Calendar.DAY_OF_WEEK, day );
		else _log.info("Rates event: wrong day of week set. Skipped.");
		if (hour > 0 && hour < 24)
			starttime.set( Calendar.HOUR_OF_DAY, hour );
		else _log.info("Rates event: wrong hour of day set. Skipped.");
		if (minute > 0 && minute < 60)
			starttime.set( Calendar.MINUTE, minute );
		else if (minute > 60)
			starttime.set( Calendar.MINUTE, minute % 60 );
		if ((starttime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis()) > 0)
			return (starttime.getTimeInMillis() - Calendar.getInstance().getTimeInMillis());
		else return 60000L;
	}
 
	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
	{
		if (event.equalsIgnoreCase("START"))
		{
			saveGlobalQuestVar("exprate", String.valueOf(Config.RATE_XP));
			Config.RATE_XP = MULTIPLIER * Config.RATE_XP;
			saveGlobalQuestVar("sprate", String.valueOf(Config.RATE_SP));
			Config.RATE_SP = MULTIPLIER * Config.RATE_SP;
			saveGlobalQuestVar("droprate", String.valueOf(Config.RATE_DROP_ITEMS));
			Config.RATE_DROP_ITEMS = MULTIPLIER * Config.RATE_DROP_ITEMS;
			saveGlobalQuestVar("raiddroprate", String.valueOf(Config.RATE_DROP_ITEMS_BY_RAID));
			Config.RATE_DROP_ITEMS_BY_RAID = MULTIPLIER * Config.RATE_DROP_ITEMS_BY_RAID;
			saveGlobalQuestVar("adenarate", String.valueOf(Config.RATE_DROP_ITEMS_ID.get(57)));
			Config.RATE_DROP_ITEMS_ID.put(57, (int) Config.RATE_DROP_ITEMS_ID.get(57) * MULTIPLIER);
 
			if (ANNOUNCE)
				Announcements.getInstance().announceToAll("The rates have been changed! For the next " + DURATION + " minutes the rates will be multiplied by "+ MULTIPLIER +"!");
			startQuestTimer("RESTORE", DURATION * 60000, null, null);
			_log.info("Rate event: rates changed, vars set. Restoring rates in " + DURATION + "minutes.");
		}
 
		if (event.equalsIgnoreCase("RESTORE"))
		{
			Config.RATE_XP = Float.valueOf(loadGlobalQuestVar("exprate"));
			Config.RATE_SP = Float.valueOf(loadGlobalQuestVar("sprate"));
			Config.RATE_DROP_ITEMS = Float.valueOf(loadGlobalQuestVar("droprate"));
			Config.RATE_DROP_ITEMS_BY_RAID = Float.valueOf(loadGlobalQuestVar("raiddroprate"));
			Config.RATE_DROP_ITEMS_ID.put(57, Float.valueOf(loadGlobalQuestVar("adenarate")));
			deleteAllGlobalQuestVars();
			_log.info("Rate event: rates restored, vars deleted.");
 
			if (ANNOUNCE)
				Announcements.getInstance().announceToAll("The rates are restored. Congratulations to all who made it!");
			if (START_DAY > 0 || START_HOUR > 0)
				startQuestTimer("START", setStartTime(START_DAY, START_HOUR, START_MINUTE), null, null);
			else if (FREQUENCY > 0)
				startQuestTimer("START", FREQUENCY * 60000, null, null);
		}
		return "";
	}
 
	public static void main(String[] args)
	{
		new Rates(-1, "Rates", "events");
	}
}

By jurchiks



CitarNo tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

/*
 * 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 events.CrazyRates;

import com.l2jserver.Config;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.quest.Quest;

/**
 * Crazy Rates event rev 1.0
 * @author LasTravel
 */

public class CrazyRates extends Quest
{
	//Few Configs
	private static final boolean AutomaticEvent = true;

	//Other config
	private static final String EventName = "Crazy Rates";
	private static final int RateMultipler = 500;
	private static final int OriginalAdenaRate = 1;

	//Time configs all are on minutes
	private static final int AfterRestart = 1; //First start after restart
	private static final int TimeWithNewRates = 1; //The time with the new rates
	private static final int TimeForStartEventAgain = 2; //The time for change rates again

	public CrazyRates(int questId, String name, String descr)
	{
		super(questId, name, descr);

		//First Start After Restart or Load the script
		startQuestTimer("FirstStartAfterRestart",AfterRestart*60000, null, null);		
	}

	public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
	{
		if (event.equalsIgnoreCase("FirstStartAfterRestart"))
		{
			Config.RATE_XP = RateMultipler*Config.RATE_XP;
			Config.RATE_SP = RateMultipler*Config.RATE_SP;
			Config.RATE_DROP_ITEMS = RateMultipler*Config.RATE_DROP_ITEMS;
			Config.RATE_DROP_ITEMS_BY_RAID = RateMultipler*Config.RATE_DROP_ITEMS_BY_RAID;
			Config.RATE_DROP_ITEMS_ID.put(57, RateMultipler);
			
			Announcements.getInstance().announceToAll(EventName +", for " + TimeWithNewRates + " minute(s) the rates are  multiplied for "+ RateMultipler +"!");
			startQuestTimer("RestoreRates",TimeWithNewRates*60000, null, null);
		}

		if (event.equalsIgnoreCase("RestoreRates"))
		{
			Config.RATE_XP = Config.RATE_XP/RateMultipler;
			Config.RATE_SP = Config.RATE_SP/RateMultipler;
			Config.RATE_DROP_ITEMS = Config.RATE_DROP_ITEMS/RateMultipler;
			Config.RATE_DROP_ITEMS_BY_RAID = Config.RATE_DROP_ITEMS_BY_RAID/RateMultipler;
			Config.RATE_DROP_ITEMS_ID.put(57, OriginalAdenaRate);

			Announcements.getInstance().announceToAll(EventName + ", the rates are restored!");

			if (AutomaticEvent)
			{
				startQuestTimer("FirstStartAfterRestart",TimeForStartEventAgain*60000, null, null);
			}
		}
	return "";
	}

	public static void main(String[] args)
	{
		new CrazyRates(-1, "CrazyRates", "events");
	}
}

By LasTravel