Optional support for running longtime events yearly.
Contributed by Costykiller.
This commit is contained in:
@ -22,6 +22,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -72,7 +73,7 @@ public class LongTimeEvent extends Quest
|
||||
protected final List<EventDropHolder> _dropList = new ArrayList<>();
|
||||
|
||||
// Items to destroy when event ends.
|
||||
protected final List<Integer> _destoyItemsOnEnd = new ArrayList<>();
|
||||
protected final List<Integer> _destroyItemsOnEnd = new ArrayList<>();
|
||||
|
||||
protected class NpcSpawn
|
||||
{
|
||||
@ -107,7 +108,7 @@ public class LongTimeEvent extends Quest
|
||||
else
|
||||
{
|
||||
// Destroy items that must exist only on event period.
|
||||
destoyItemsOnEnd();
|
||||
destroyItemsOnEnd();
|
||||
LOGGER.info("Event " + _eventName + " has passed... Ignored ");
|
||||
}
|
||||
}
|
||||
@ -133,19 +134,44 @@ public class LongTimeEvent extends Quest
|
||||
{
|
||||
throw new NullPointerException("WARNING!!! " + getScriptName() + " event: bad config file!");
|
||||
}
|
||||
final String currentYear = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
|
||||
_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 (period.length() == 21)
|
||||
{
|
||||
// dd MM yyyy-dd MM yyyy
|
||||
_eventPeriod = DateRange.parse(period, new SimpleDateFormat("dd MM yyyy", Locale.US));
|
||||
}
|
||||
else if (period.length() == 11)
|
||||
{
|
||||
// dd MM-dd MM
|
||||
final String start = period.split("-")[0].concat(" ").concat(currentYear);
|
||||
final String end = period.split("-")[1].concat(" ").concat(currentYear);
|
||||
final String activePeriod = start.concat("-").concat(end);
|
||||
_eventPeriod = DateRange.parse(activePeriod, new SimpleDateFormat("dd MM yyyy", Locale.US));
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
if (dropPeriod.length() == 21)
|
||||
{
|
||||
// dd MM yyyy-dd MM yyyy
|
||||
_dropPeriod = DateRange.parse(dropPeriod, new SimpleDateFormat("dd MM yyyy", Locale.US));
|
||||
}
|
||||
else if (dropPeriod.length() == 11)
|
||||
{
|
||||
// dd MM-dd MM
|
||||
final String start = dropPeriod.split("-")[0].concat(" ").concat(currentYear);
|
||||
final String end = dropPeriod.split("-")[1].concat(" ").concat(currentYear);
|
||||
final String activeDropPeriod = start.concat("-").concat(end);
|
||||
_dropPeriod = DateRange.parse(activeDropPeriod, 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()))
|
||||
{
|
||||
@ -159,7 +185,7 @@ public class LongTimeEvent extends Quest
|
||||
|
||||
if (_eventPeriod == null)
|
||||
{
|
||||
throw new NullPointerException("WARNING!!! " + getScriptName() + " event: illegal event period");
|
||||
throw new NullPointerException("WARNING!!! " + getName() + " event: illegal event period");
|
||||
}
|
||||
|
||||
final Date today = new Date();
|
||||
@ -198,19 +224,19 @@ public class LongTimeEvent extends Quest
|
||||
|
||||
if (ItemTable.getInstance().getTemplate(itemId) == null)
|
||||
{
|
||||
LOGGER.warning(getScriptName() + " event: " + itemId + " is wrong item id, item was not added in droplist");
|
||||
LOGGER.warning(getName() + " event: " + itemId + " is wrong item id, item was not added in droplist");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (minCount > maxCount)
|
||||
{
|
||||
LOGGER.warning(getScriptName() + " event: item " + itemId + " - min greater than max, item was not added in droplist");
|
||||
LOGGER.warning(getName() + " event: item " + itemId + " - min greater than max, item was not added in droplist");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((finalChance < 0) || (finalChance > 100))
|
||||
{
|
||||
LOGGER.warning(getScriptName() + " event: item " + itemId + " - incorrect drop chance, item was not added in droplist");
|
||||
LOGGER.warning(getName() + " event: item " + itemId + " - incorrect drop chance, item was not added in droplist");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -218,7 +244,7 @@ public class LongTimeEvent extends Quest
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
LOGGER.warning("Wrong number format in config.xml droplist block for " + getScriptName() + " event");
|
||||
LOGGER.warning("Wrong number format in config.xml droplist block for " + getName() + " event");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -240,7 +266,7 @@ public class LongTimeEvent extends Quest
|
||||
|
||||
if (NpcData.getInstance().getTemplate(npcId) == null)
|
||||
{
|
||||
LOGGER.warning(getScriptName() + " event: " + npcId + " is wrong NPC id, NPC was not added in spawnlist");
|
||||
LOGGER.warning(getName() + " event: " + npcId + " is wrong NPC id, NPC was not added in spawnlist");
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -248,7 +274,7 @@ public class LongTimeEvent extends Quest
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
LOGGER.warning("Wrong number format in config.xml spawnlist block for " + getScriptName() + " event");
|
||||
LOGGER.warning("Wrong number format in config.xml spawnlist block for " + getName() + " event");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -282,7 +308,7 @@ public class LongTimeEvent extends Quest
|
||||
// Load destroy item list at all times.
|
||||
for (Node n = doc.getDocumentElement().getFirstChild(); n != null; n = n.getNextSibling())
|
||||
{
|
||||
if (n.getNodeName().equalsIgnoreCase("destoyItemsOnEnd"))
|
||||
if (n.getNodeName().equalsIgnoreCase("destroyItemsOnEnd"))
|
||||
{
|
||||
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
|
||||
{
|
||||
@ -296,11 +322,11 @@ public class LongTimeEvent extends Quest
|
||||
LOGGER.warning(getScriptName() + " event: Item " + itemId + " does not exist.");
|
||||
continue;
|
||||
}
|
||||
_destoyItemsOnEnd.add(itemId);
|
||||
_destroyItemsOnEnd.add(itemId);
|
||||
}
|
||||
catch (NumberFormatException nfe)
|
||||
{
|
||||
LOGGER.warning("Wrong number format in config.xml destoyItemsOnEnd block for " + getScriptName() + " event");
|
||||
LOGGER.warning("Wrong number format in config.xml destroyItemsOnEnd block for " + getScriptName() + " event");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -402,7 +428,7 @@ public class LongTimeEvent extends Quest
|
||||
}
|
||||
|
||||
// Destroy items that must exist only on event period.
|
||||
destoyItemsOnEnd();
|
||||
destroyItemsOnEnd();
|
||||
|
||||
// Send message on end.
|
||||
if (!_endMsg.isEmpty())
|
||||
@ -418,11 +444,11 @@ public class LongTimeEvent extends Quest
|
||||
}
|
||||
}
|
||||
|
||||
void destoyItemsOnEnd()
|
||||
void destroyItemsOnEnd()
|
||||
{
|
||||
if (!_destoyItemsOnEnd.isEmpty())
|
||||
if (!_destroyItemsOnEnd.isEmpty())
|
||||
{
|
||||
for (int itemId : _destoyItemsOnEnd)
|
||||
for (int itemId : _destroyItemsOnEnd)
|
||||
{
|
||||
// Remove item from online players.
|
||||
for (PlayerInstance player : World.getInstance().getPlayers())
|
||||
|
Reference in New Issue
Block a user