Merged with released L2J-Unity files.
This commit is contained in:
@ -1,37 +1,37 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
/**
|
||||
* Abstract event class.
|
||||
* @author JIV
|
||||
*/
|
||||
public abstract class Event extends Quest
|
||||
{
|
||||
public Event(String name, String descr)
|
||||
{
|
||||
super(-1, name, descr);
|
||||
}
|
||||
|
||||
public abstract boolean eventStart(L2PcInstance eventMaker);
|
||||
|
||||
public abstract boolean eventStop();
|
||||
|
||||
public abstract boolean eventBypass(L2PcInstance activeChar, String bypass);
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
/**
|
||||
* Abstract event class.
|
||||
* @author JIV
|
||||
*/
|
||||
public abstract class Event extends Quest
|
||||
{
|
||||
public Event()
|
||||
{
|
||||
super(-1);
|
||||
}
|
||||
|
||||
public abstract boolean eventStart(L2PcInstance eventMaker);
|
||||
|
||||
public abstract boolean eventStop();
|
||||
|
||||
public abstract boolean eventBypass(L2PcInstance activeChar, String bypass);
|
||||
}
|
@ -0,0 +1,354 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.l2jmobius.commons.util.IGameXmlReader;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
|
||||
import com.l2jmobius.gameserver.data.xml.impl.NpcData;
|
||||
import com.l2jmobius.gameserver.datatables.EventDroplist;
|
||||
import com.l2jmobius.gameserver.datatables.ItemTable;
|
||||
import com.l2jmobius.gameserver.instancemanager.EventShrineManager;
|
||||
import com.l2jmobius.gameserver.model.Location;
|
||||
import com.l2jmobius.gameserver.model.announce.EventAnnouncement;
|
||||
import com.l2jmobius.gameserver.model.drops.GeneralDropItem;
|
||||
import com.l2jmobius.gameserver.script.DateRange;
|
||||
import com.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
/**
|
||||
* Parent class for long time events.<br>
|
||||
* Maintains config reading, spawn of NPC's, adding of event's drop.
|
||||
* @author GKR
|
||||
*/
|
||||
public class LongTimeEvent extends Quest
|
||||
{
|
||||
protected Logger _log = Logger.getLogger(getClass().getName());
|
||||
protected String _eventName;
|
||||
boolean _enableShrines = false;
|
||||
|
||||
// Messages
|
||||
protected String _onEnterMsg = "Event is in process";
|
||||
protected String _endMsg = "Event ends!";
|
||||
|
||||
protected DateRange _eventPeriod = null;
|
||||
protected DateRange _dropPeriod;
|
||||
|
||||
// NPC's to spawm and their spawn points
|
||||
protected final List<NpcSpawn> _spawnList = new ArrayList<>();
|
||||
|
||||
// Drop data for event
|
||||
protected final List<GeneralDropItem> _dropList = new ArrayList<>();
|
||||
|
||||
protected class NpcSpawn
|
||||
{
|
||||
protected final Location loc;
|
||||
protected final int npcId;
|
||||
|
||||
protected NpcSpawn(int pNpcId, Location spawnLoc)
|
||||
{
|
||||
loc = spawnLoc;
|
||||
npcId = pNpcId;
|
||||
}
|
||||
}
|
||||
|
||||
public LongTimeEvent()
|
||||
{
|
||||
super(-1);
|
||||
loadConfig();
|
||||
|
||||
if (_eventPeriod != null)
|
||||
{
|
||||
if (_eventPeriod.isWithinRange(new Date()))
|
||||
{
|
||||
startEvent();
|
||||
_log.info("Event " + _eventName + " active till " + _eventPeriod.getEndDate());
|
||||
}
|
||||
else if (_eventPeriod.getStartDate().after(new Date()))
|
||||
{
|
||||
final long delay = _eventPeriod.getStartDate().getTime() - System.currentTimeMillis();
|
||||
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleStart(), delay);
|
||||
_log.info("Event " + _eventName + " will be started at " + _eventPeriod.getEndDate());
|
||||
}
|
||||
else
|
||||
{
|
||||
_log.info("Event " + _eventName + " has passed... Ignored ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load event configuration file
|
||||
*/
|
||||
private void loadConfig()
|
||||
{
|
||||
new IGameXmlReader()
|
||||
{
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
parseDatapackFile("data/scripts/events/" + getScriptName() + "/config.xml");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parseDocument(Document doc, File f)
|
||||
{
|
||||
if (!doc.getDocumentElement().getNodeName().equalsIgnoreCase("event"))
|
||||
{
|
||||
throw new NullPointerException("WARNING!!! " + getScriptName() + " event: bad config file!");
|
||||
}
|
||||
_eventName = doc.getDocumentElement().getAttributes().getNamedItem("name").getNodeValue();
|
||||
final String period = doc.getDocumentElement().getAttributes().getNamedItem("active").getNodeValue();
|
||||
_eventPeriod = DateRange.parse(period, new SimpleDateFormat("dd MM yyyy", Locale.US));
|
||||
|
||||
if ((doc.getDocumentElement().getAttributes().getNamedItem("enableShrines") != null) && doc.getDocumentElement().getAttributes().getNamedItem("enableShrines").getNodeValue().equalsIgnoreCase("true"))
|
||||
{
|
||||
_enableShrines = true;
|
||||
}
|
||||
|
||||
if (doc.getDocumentElement().getAttributes().getNamedItem("dropPeriod") != null)
|
||||
{
|
||||
final String dropPeriod = doc.getDocumentElement().getAttributes().getNamedItem("dropPeriod").getNodeValue();
|
||||
_dropPeriod = DateRange.parse(dropPeriod, new SimpleDateFormat("dd MM yyyy", Locale.US));
|
||||
// Check if drop period is within range of event period
|
||||
if (!_eventPeriod.isWithinRange(_dropPeriod.getStartDate()) || !_eventPeriod.isWithinRange(_dropPeriod.getEndDate()))
|
||||
{
|
||||
_dropPeriod = _eventPeriod;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_dropPeriod = _eventPeriod; // Drop period, if not specified, assumes all event period.
|
||||
}
|
||||
|
||||
if (_eventPeriod == null)
|
||||
{
|
||||
throw new NullPointerException("WARNING!!! " + getScriptName() + " event: illegal event period");
|
||||
}
|
||||
|
||||
final Date today = new Date();
|
||||
|
||||
if (_eventPeriod.getStartDate().after(today) || _eventPeriod.isWithinRange(today))
|
||||
{
|
||||
final Node first = doc.getDocumentElement().getFirstChild();
|
||||
for (Node n = first; n != null; n = n.getNextSibling())
|
||||
{
|
||||
// Loading droplist
|
||||
if (n.getNodeName().equalsIgnoreCase("droplist"))
|
||||
{
|
||||
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
|
||||
{
|
||||
if (d.getNodeName().equalsIgnoreCase("add"))
|
||||
{
|
||||
try
|
||||
{
|
||||
final int itemId = Integer.parseInt(d.getAttributes().getNamedItem("item").getNodeValue());
|
||||
final int minCount = Integer.parseInt(d.getAttributes().getNamedItem("min").getNodeValue());
|
||||
final int maxCount = Integer.parseInt(d.getAttributes().getNamedItem("max").getNodeValue());
|
||||
final String chance = d.getAttributes().getNamedItem("chance").getNodeValue();
|
||||
int finalChance = 0;
|
||||
|
||||
if (!chance.isEmpty() && chance.endsWith("%"))
|
||||
{
|
||||
finalChance = Integer.parseInt(chance.substring(0, chance.length() - 1)) * 10000;
|
||||
}
|
||||
|
||||
if (ItemTable.getInstance().getTemplate(itemId) == null)
|
||||
{
|
||||
_log.warning(getScriptName() + " event: " + itemId + " is wrong item id, item was not added in droplist");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (minCount > maxCount)
|
||||
{
|
||||
_log.warning(getScriptName() + " event: item " + itemId + " - min greater than max, item was not added in droplist");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((finalChance < 10000) || (finalChance > 1000000))
|
||||
{
|
||||
_log.warning(getScriptName() + " event: item " + itemId + " - incorrect drop chance, item was not added in droplist");
|
||||
continue;
|
||||
}
|
||||
|
||||
_dropList.add(new GeneralDropItem(itemId, minCount, maxCount, finalChance));
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
_log.warning("Wrong number format in config.xml droplist block for " + getScriptName() + " event");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (n.getNodeName().equalsIgnoreCase("spawnlist"))
|
||||
{
|
||||
// Loading spawnlist
|
||||
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
|
||||
{
|
||||
if (d.getNodeName().equalsIgnoreCase("add"))
|
||||
{
|
||||
try
|
||||
{
|
||||
final int npcId = Integer.parseInt(d.getAttributes().getNamedItem("npc").getNodeValue());
|
||||
final int xPos = Integer.parseInt(d.getAttributes().getNamedItem("x").getNodeValue());
|
||||
final int yPos = Integer.parseInt(d.getAttributes().getNamedItem("y").getNodeValue());
|
||||
final int zPos = Integer.parseInt(d.getAttributes().getNamedItem("z").getNodeValue());
|
||||
final int heading = d.getAttributes().getNamedItem("heading").getNodeValue() != null ? Integer.parseInt(d.getAttributes().getNamedItem("heading").getNodeValue()) : 0;
|
||||
|
||||
if (NpcData.getInstance().getTemplate(npcId) == null)
|
||||
{
|
||||
_log.warning(getScriptName() + " event: " + npcId + " is wrong NPC id, NPC was not added in spawnlist");
|
||||
continue;
|
||||
}
|
||||
|
||||
_spawnList.add(new NpcSpawn(npcId, new Location(xPos, yPos, zPos, heading)));
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
_log.warning("Wrong number format in config.xml spawnlist block for " + getScriptName() + " event");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (n.getNodeName().equalsIgnoreCase("messages"))
|
||||
{
|
||||
// Loading Messages
|
||||
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
|
||||
{
|
||||
if (d.getNodeName().equalsIgnoreCase("add"))
|
||||
{
|
||||
final String msgType = d.getAttributes().getNamedItem("type").getNodeValue();
|
||||
final String msgText = d.getAttributes().getNamedItem("text").getNodeValue();
|
||||
if ((msgType != null) && (msgText != null))
|
||||
{
|
||||
if (msgType.equalsIgnoreCase("onEnd"))
|
||||
{
|
||||
_endMsg = msgText;
|
||||
}
|
||||
else if (msgType.equalsIgnoreCase("onEnter"))
|
||||
{
|
||||
_onEnterMsg = msgText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.load();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Maintenance event start - adds global drop, spawns event NPC's, shows start announcement.
|
||||
*/
|
||||
protected void startEvent()
|
||||
{
|
||||
// Add drop
|
||||
if (_dropList != null)
|
||||
{
|
||||
for (GeneralDropItem drop : _dropList)
|
||||
{
|
||||
EventDroplist.getInstance().addGlobalDrop(drop.getItemId(), drop.getMin(), drop.getMax(), (int) drop.getChance(), _dropPeriod);
|
||||
}
|
||||
}
|
||||
|
||||
// Add spawns
|
||||
final Long millisToEventEnd = _eventPeriod.getEndDate().getTime() - System.currentTimeMillis();
|
||||
if (_spawnList != null)
|
||||
{
|
||||
for (NpcSpawn spawn : _spawnList)
|
||||
{
|
||||
addSpawn(spawn.npcId, spawn.loc.getX(), spawn.loc.getY(), spawn.loc.getZ(), spawn.loc.getHeading(), false, millisToEventEnd, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Enable town shrines
|
||||
if (_enableShrines)
|
||||
{
|
||||
EventShrineManager.getInstance().setEnabled(true);
|
||||
}
|
||||
|
||||
// Send message on begin
|
||||
Broadcast.toAllOnlinePlayers(_onEnterMsg);
|
||||
|
||||
// Add announce for entering players
|
||||
AnnouncementsTable.getInstance().addAnnouncement(new EventAnnouncement(_eventPeriod, _onEnterMsg));
|
||||
|
||||
// Schedule event end (now only for message sending)
|
||||
ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleEnd(), millisToEventEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return event period
|
||||
*/
|
||||
public DateRange getEventPeriod()
|
||||
{
|
||||
return _eventPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if now is event period
|
||||
*/
|
||||
public boolean isEventPeriod()
|
||||
{
|
||||
return _eventPeriod.isWithinRange(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if now is drop period
|
||||
*/
|
||||
public boolean isDropPeriod()
|
||||
{
|
||||
return _dropPeriod.isWithinRange(new Date());
|
||||
}
|
||||
|
||||
protected class ScheduleStart implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
startEvent();
|
||||
}
|
||||
}
|
||||
|
||||
protected class ScheduleEnd implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Disable town shrines
|
||||
if (_enableShrines)
|
||||
{
|
||||
EventShrineManager.getInstance().setEnabled(false);
|
||||
}
|
||||
// Send message on end
|
||||
Broadcast.toAllOnlinePlayers(_endMsg);
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.l2jmobius.gameserver.model.KeyValuePair;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class QuestCondition
|
||||
{
|
||||
private final Predicate<L2PcInstance> _condition;
|
||||
private Map<Integer, String> _perNpcDialog;
|
||||
private final String _html;
|
||||
|
||||
public QuestCondition(Predicate<L2PcInstance> cond, String html)
|
||||
{
|
||||
_condition = cond;
|
||||
_html = html;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public QuestCondition(Predicate<L2PcInstance> cond, KeyValuePair<Integer, String>... pairs)
|
||||
{
|
||||
_condition = cond;
|
||||
_html = null;
|
||||
_perNpcDialog = new HashMap<>();
|
||||
Stream.of(pairs).forEach(pair -> _perNpcDialog.put(pair.getKey(), pair.getValue()));
|
||||
}
|
||||
|
||||
public boolean test(L2PcInstance player)
|
||||
{
|
||||
return _condition.test(player);
|
||||
}
|
||||
|
||||
public String getHtml(L2Npc npc)
|
||||
{
|
||||
return _perNpcDialog != null ? _perNpcDialog.get(npc.getId()) : _html;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,153 +1,168 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
public class QuestTimer
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(QuestTimer.class.getName());
|
||||
|
||||
public class ScheduleTimerTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!getIsActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!getIsRepeating())
|
||||
{
|
||||
cancelAndRemove();
|
||||
}
|
||||
getQuest().notifyEvent(getName(), getNpc(), getPlayer());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean _isActive = true;
|
||||
private final String _name;
|
||||
private final Quest _quest;
|
||||
private final L2Npc _npc;
|
||||
private final L2PcInstance _player;
|
||||
private final boolean _isRepeating;
|
||||
private final ScheduledFuture<?> _schedular;
|
||||
|
||||
public QuestTimer(Quest quest, String name, long time, L2Npc npc, L2PcInstance player, boolean repeating)
|
||||
{
|
||||
_name = name;
|
||||
_quest = quest;
|
||||
_player = player;
|
||||
_npc = npc;
|
||||
_isRepeating = repeating;
|
||||
_schedular = repeating ? ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new ScheduleTimerTask(), time, time) : ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleTimerTask(), time);
|
||||
}
|
||||
|
||||
public QuestTimer(Quest quest, String name, long time, L2Npc npc, L2PcInstance player)
|
||||
{
|
||||
this(quest, name, time, npc, player, false);
|
||||
}
|
||||
|
||||
public QuestTimer(QuestState qs, String name, long time)
|
||||
{
|
||||
this(qs.getQuest(), name, time, null, qs.getPlayer(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this quest timer.
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
_isActive = false;
|
||||
if (_schedular != null)
|
||||
{
|
||||
_schedular.cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this quest timer and remove it from the associated quest.
|
||||
*/
|
||||
public void cancelAndRemove()
|
||||
{
|
||||
cancel();
|
||||
_quest.removeQuestTimer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares if this timer matches with the key attributes passed.
|
||||
* @param quest the quest to which the timer is attached
|
||||
* @param name the name of the timer
|
||||
* @param npc the NPC attached to the desired timer (null if no NPC attached)
|
||||
* @param player the player attached to the desired timer (null if no player attached)
|
||||
* @return
|
||||
*/
|
||||
public boolean isMatch(Quest quest, String name, L2Npc npc, L2PcInstance player)
|
||||
{
|
||||
return (quest != null) && (name != null) && (quest == _quest) && name.equalsIgnoreCase(getName()) && (npc == _npc) && (player == _player);
|
||||
}
|
||||
|
||||
public final boolean getIsActive()
|
||||
{
|
||||
return _isActive;
|
||||
}
|
||||
|
||||
public final boolean getIsRepeating()
|
||||
{
|
||||
return _isRepeating;
|
||||
}
|
||||
|
||||
public final Quest getQuest()
|
||||
{
|
||||
return _quest;
|
||||
}
|
||||
|
||||
public final String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public final L2Npc getNpc()
|
||||
{
|
||||
return _npc;
|
||||
}
|
||||
|
||||
public final L2PcInstance getPlayer()
|
||||
{
|
||||
return _player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Npc;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
public class QuestTimer
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(QuestTimer.class.getName());
|
||||
|
||||
public class ScheduleTimerTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!getIsActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (!getIsRepeating())
|
||||
{
|
||||
cancelAndRemove();
|
||||
}
|
||||
getQuest().notifyEvent(getName(), getNpc(), getPlayer());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean _isActive = true;
|
||||
private final String _name;
|
||||
private final Quest _quest;
|
||||
private final L2Npc _npc;
|
||||
private final L2PcInstance _player;
|
||||
private final boolean _isRepeating;
|
||||
private ScheduledFuture<?> _schedular;
|
||||
|
||||
public QuestTimer(Quest quest, String name, long time, L2Npc npc, L2PcInstance player, boolean repeating)
|
||||
{
|
||||
_name = name;
|
||||
_quest = quest;
|
||||
_player = player;
|
||||
_npc = npc;
|
||||
_isRepeating = repeating;
|
||||
if (repeating)
|
||||
{
|
||||
_schedular = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new ScheduleTimerTask(), time, time); // Prepare auto end task
|
||||
}
|
||||
else
|
||||
{
|
||||
_schedular = ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleTimerTask(), time); // Prepare auto end task
|
||||
}
|
||||
}
|
||||
|
||||
public QuestTimer(Quest quest, String name, long time, L2Npc npc, L2PcInstance player)
|
||||
{
|
||||
this(quest, name, time, npc, player, false);
|
||||
}
|
||||
|
||||
public QuestTimer(QuestState qs, String name, long time)
|
||||
{
|
||||
this(qs.getQuest(), name, time, null, qs.getPlayer(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this quest timer.
|
||||
*/
|
||||
public void cancel()
|
||||
{
|
||||
_isActive = false;
|
||||
if (_schedular != null)
|
||||
{
|
||||
_schedular.cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel this quest timer and remove it from the associated quest.
|
||||
*/
|
||||
public void cancelAndRemove()
|
||||
{
|
||||
cancel();
|
||||
_quest.removeQuestTimer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares if this timer matches with the key attributes passed.
|
||||
* @param quest the quest to which the timer is attached
|
||||
* @param name the name of the timer
|
||||
* @param npc the NPC attached to the desired timer (null if no NPC attached)
|
||||
* @param player the player attached to the desired timer (null if no player attached)
|
||||
* @return
|
||||
*/
|
||||
public boolean isMatch(Quest quest, String name, L2Npc npc, L2PcInstance player)
|
||||
{
|
||||
if ((quest == null) || (name == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((quest != _quest) || !name.equalsIgnoreCase(getName()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ((npc == _npc) && (player == _player));
|
||||
}
|
||||
|
||||
public final boolean getIsActive()
|
||||
{
|
||||
return _isActive;
|
||||
}
|
||||
|
||||
public final boolean getIsRepeating()
|
||||
{
|
||||
return _isRepeating;
|
||||
}
|
||||
|
||||
public final Quest getQuest()
|
||||
{
|
||||
return _quest;
|
||||
}
|
||||
|
||||
public final String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public final L2Npc getNpc()
|
||||
{
|
||||
return _npc;
|
||||
}
|
||||
|
||||
public final L2PcInstance getPlayer()
|
||||
{
|
||||
return _player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
@ -1,84 +1,72 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
/**
|
||||
* This class merely enumerates the three necessary states for all quests:<br>
|
||||
* <ul>
|
||||
* <li>CREATED: a quest state is created but the quest is not yet accepted.</li>
|
||||
* <li>STARTED: the player has accepted the quest. Quest is currently in progress</li>
|
||||
* <li>COMPLETED: the quest has been completed.</li>
|
||||
* </ul>
|
||||
* In addition, this class defines two functions for lookup and inverse lookup of the state given a name.<br>
|
||||
* This is useful only for saving the state values into the database with a more readable form and then being able to read the string back and remap them to their correct states.<br>
|
||||
* All quests have these and only these states.
|
||||
* @author Luis Arias; version 2 by Fulminus
|
||||
*/
|
||||
public class State
|
||||
{
|
||||
public static final byte CREATED = 0;
|
||||
public static final byte STARTED = 1;
|
||||
public static final byte COMPLETED = 2;
|
||||
|
||||
/**
|
||||
* Get the quest state's string representation from its byte value.
|
||||
* @param state the byte value of the state
|
||||
* @return the String representation of the quest state (default: Start)
|
||||
*/
|
||||
public static String getStateName(byte state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
return "Started";
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
return "Completed";
|
||||
}
|
||||
default:
|
||||
{
|
||||
return "Start";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the quest state's byte value from its string representation.
|
||||
* @param statename the String representation of the state
|
||||
* @return the byte value of the quest state (default: 0)
|
||||
*/
|
||||
public static byte getStateId(String statename)
|
||||
{
|
||||
switch (statename)
|
||||
{
|
||||
case "Started":
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
case "Completed":
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 com.l2jmobius.gameserver.model.quest;
|
||||
|
||||
/**
|
||||
* This class merely enumerates the three necessary states for all quests:<br>
|
||||
* <ul>
|
||||
* <li>CREATED: a quest state is created but the quest is not yet accepted.</li>
|
||||
* <li>STARTED: the player has accepted the quest. Quest is currently in progress</li>
|
||||
* <li>COMPLETED: the quest has been completed.</li>
|
||||
* </ul>
|
||||
* In addition, this class defines two functions for lookup and inverse lookup of the state given a name.<br>
|
||||
* This is useful only for saving the state values into the database with a more readable form and then being able to read the string back and remap them to their correct states.<br>
|
||||
* All quests have these and only these states.
|
||||
* @author Luis Arias; version 2 by Fulminus
|
||||
*/
|
||||
public class State
|
||||
{
|
||||
public static final byte CREATED = 0;
|
||||
public static final byte STARTED = 1;
|
||||
public static final byte COMPLETED = 2;
|
||||
|
||||
/**
|
||||
* Get the quest state's string representation from its byte value.
|
||||
* @param state the byte value of the state
|
||||
* @return the String representation of the quest state (default: Start)
|
||||
*/
|
||||
public static String getStateName(byte state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case 1:
|
||||
return "Started";
|
||||
case 2:
|
||||
return "Completed";
|
||||
default:
|
||||
return "Start";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the quest state's byte value from its string representation.
|
||||
* @param statename the String representation of the state
|
||||
* @return the byte value of the quest state (default: 0)
|
||||
*/
|
||||
public static byte getStateId(String statename)
|
||||
{
|
||||
switch (statename)
|
||||
{
|
||||
case "Started":
|
||||
return 1;
|
||||
case "Completed":
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user