|
@@ -19,192 +19,171 @@ import java.io.BufferedReader;
|
|
|
import java.io.DataInputStream;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
import java.util.logging.Level;
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
+import javolution.util.FastList;
|
|
|
+import javolution.util.FastMap;
|
|
|
+
|
|
|
+import com.l2jserver.gameserver.cache.HtmCache;
|
|
|
import com.l2jserver.gameserver.datatables.NpcTable;
|
|
|
import com.l2jserver.gameserver.datatables.SpawnTable;
|
|
|
import com.l2jserver.gameserver.model.L2Spawn;
|
|
|
import com.l2jserver.gameserver.model.L2World;
|
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
|
+import com.l2jserver.gameserver.network.serverpackets.CharInfo;
|
|
|
+import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
|
|
|
import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
|
|
|
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
|
|
|
+import com.l2jserver.gameserver.network.serverpackets.UserInfo;
|
|
|
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
|
|
|
-import com.l2jserver.gameserver.util.Broadcast;
|
|
|
-import com.l2jserver.util.EventData;
|
|
|
-import com.l2jserver.util.StringUtil;
|
|
|
-
|
|
|
+import com.l2jserver.util.PlayerEventStatus;
|
|
|
+import com.l2jserver.util.ValueSortMap;
|
|
|
|
|
|
/**
|
|
|
- * This class ...
|
|
|
- *
|
|
|
- * @version $Revision: 1.3.4.1 $ $Date: 2005/03/27 15:29:32 $
|
|
|
+ * @since $Revision: 1.3.4.1 $ $Date: 2005/03/27 15:29:32 $
|
|
|
+ * This ancient thingie got reworked by Nik at $Date: 2011/05/17 21:51:39 $
|
|
|
+ * Yeah, for 6 years no one bothered reworking this buggy event engine.
|
|
|
*/
|
|
|
|
|
|
public class L2Event
|
|
|
{
|
|
|
protected static final Logger _log = Logger.getLogger(L2Event.class.getName());
|
|
|
- public static String eventName = "";
|
|
|
- public static int teamsNumber = 0;
|
|
|
- public static final HashMap<Integer, String> names = new HashMap<Integer, String>();
|
|
|
- public static final LinkedList<String> participatingPlayers = new LinkedList<String>(); //TODO store by objid
|
|
|
- public static final HashMap<Integer, LinkedList<String>> players = new HashMap<Integer, LinkedList<String>>();
|
|
|
- public static int id = 12760;
|
|
|
- public static final LinkedList<String> npcs = new LinkedList<String>();
|
|
|
- public static boolean active = false;
|
|
|
- public static final HashMap<String, EventData> connectionLossData = new HashMap<String, EventData>();
|
|
|
+ public static EventState eventState = EventState.OFF;
|
|
|
+ public static String _eventName = "";
|
|
|
+ public static String _eventCreator = "";
|
|
|
+ public static String _eventInfo = "";
|
|
|
+ public static int _teamsNumber = 0;
|
|
|
+ public static final Map<Integer, String> _teamNames = new FastMap<Integer, String>();
|
|
|
+ public static final List<L2PcInstance> _registeredPlayers = new FastList<L2PcInstance>();
|
|
|
+ public static final Map<Integer, FastList<L2PcInstance>> _teams = new FastMap<Integer, FastList<L2PcInstance>>();
|
|
|
+ public static int _npcId = 0;
|
|
|
+ //public static final List<L2Npc> _npcs = new FastList<L2Npc>();
|
|
|
+ private static final Map<L2PcInstance, PlayerEventStatus> _connectionLossData = new FastMap<L2PcInstance, PlayerEventStatus>();
|
|
|
|
|
|
- public static int getTeamOfPlayer(String name)
|
|
|
+ public enum EventState
|
|
|
{
|
|
|
- for (int i = 1; i <= players.size(); i++)
|
|
|
+ OFF, // Not running
|
|
|
+ STANDBY, // Waiting for participants to register
|
|
|
+ ON // Registration is over and the event has started.
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param player
|
|
|
+ * @return The team ID where the player is in, or -1 if player is null or team not found.
|
|
|
+ */
|
|
|
+ public static int getPlayerTeamId(L2PcInstance player)
|
|
|
+ {
|
|
|
+ if (player == null)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ for (Entry<Integer, FastList<L2PcInstance>> team : _teams.entrySet())
|
|
|
{
|
|
|
- LinkedList<String> temp = players.get(i);
|
|
|
- Iterator<String> it = temp.iterator();
|
|
|
- while (it.hasNext())
|
|
|
- {
|
|
|
- if (it.next().equals(name))
|
|
|
- return i;
|
|
|
- }
|
|
|
+ if (team.getValue().contains(player))
|
|
|
+ return team.getKey();
|
|
|
}
|
|
|
- return 0;
|
|
|
+
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
- public static String[] getTopNKillers(int N)
|
|
|
- { //this will return top N players sorted by kills, first element in the array will be the one with more kills
|
|
|
- String[] killers = new String[N];
|
|
|
- String playerTemp = "";
|
|
|
- int kills = 0;
|
|
|
- LinkedList<String> killersTemp = new LinkedList<String>();
|
|
|
+ public static List<L2PcInstance> getTopNKillers(int n)
|
|
|
+ {
|
|
|
+ Map<L2PcInstance, Integer> tmp = new FastMap<L2PcInstance, Integer>();
|
|
|
|
|
|
- for (int k = 0; k < N; k++)
|
|
|
+ for (FastList<L2PcInstance> teamList : _teams.values())
|
|
|
{
|
|
|
- kills = 0;
|
|
|
- for (int i = 1; i <= teamsNumber; i++)
|
|
|
+ for (L2PcInstance player : teamList)
|
|
|
{
|
|
|
- LinkedList<String> temp = players.get(i);
|
|
|
- Iterator<String> it = temp.iterator();
|
|
|
- while (it.hasNext())
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- L2PcInstance player = L2World.getInstance().getPlayer(it.next());
|
|
|
- if (!killersTemp.contains(player.getName()))
|
|
|
- {
|
|
|
- if (player.kills.size() > kills)
|
|
|
- {
|
|
|
- kills = player.kills.size();
|
|
|
- playerTemp = player.getName();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
+ if (player.getEventStatus() == null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ tmp.put(player, player.getEventStatus().kills.size());
|
|
|
}
|
|
|
- killersTemp.add(playerTemp);
|
|
|
}
|
|
|
|
|
|
- for (int i = 0; i < N; i++)
|
|
|
+ ValueSortMap.sortMapByValue(tmp, false);
|
|
|
+
|
|
|
+ // If the map size is less than "n", n will be as much as the map size
|
|
|
+ if (tmp.size() <= n)
|
|
|
{
|
|
|
- kills = 0;
|
|
|
- Iterator<String> it = killersTemp.iterator();
|
|
|
- while (it.hasNext())
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- L2PcInstance player = L2World.getInstance().getPlayer(it.next());
|
|
|
- if (player.kills.size() > kills)
|
|
|
- {
|
|
|
- kills = player.kills.size();
|
|
|
- playerTemp = player.getName();
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- killers[i] = playerTemp;
|
|
|
- killersTemp.remove(playerTemp);
|
|
|
+ List<L2PcInstance> toReturn = new FastList<L2PcInstance>();
|
|
|
+ toReturn.addAll(tmp.keySet());
|
|
|
+ return toReturn;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ List<L2PcInstance> toReturn = new FastList<L2PcInstance>();
|
|
|
+ toReturn.addAll(tmp.keySet());
|
|
|
+ return toReturn.subList(1, n);
|
|
|
}
|
|
|
- return killers;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public static void showEventHtml(L2PcInstance player, String objectid)
|
|
|
- {
|
|
|
- try
|
|
|
+ {//TODO: work on this
|
|
|
+
|
|
|
+ if (eventState == EventState.STANDBY)
|
|
|
{
|
|
|
- NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
|
|
|
-
|
|
|
- DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("data/events/" + eventName)));
|
|
|
- BufferedReader inbr = new BufferedReader(new InputStreamReader(in));
|
|
|
-
|
|
|
- final StringBuilder replyMSG = new StringBuilder();
|
|
|
- StringUtil.append(replyMSG,
|
|
|
- "<html><body>" +
|
|
|
- "<center><font color=\"LEVEL\">",
|
|
|
- eventName,
|
|
|
- "</font><font color=\"FF0000\"> bY ",
|
|
|
- inbr.readLine(),
|
|
|
- "</font></center><br>" +
|
|
|
- "<br>",
|
|
|
- inbr.readLine()
|
|
|
- );
|
|
|
-
|
|
|
- if (L2Event.participatingPlayers.contains(player.getName())) {
|
|
|
- replyMSG.append("<br><center>You are already in the event players list !!</center></body></html>");
|
|
|
- } else {
|
|
|
- StringUtil.append(replyMSG,
|
|
|
- "<br><center><button value=\"Participate !! \" action=\"bypass -h npc_",
|
|
|
- String.valueOf(objectid),
|
|
|
- "_event_participate\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>"
|
|
|
- );
|
|
|
+ try
|
|
|
+ {
|
|
|
+ final String htmContent;
|
|
|
+ NpcHtmlMessage html = new NpcHtmlMessage(5);
|
|
|
+
|
|
|
+ if (_registeredPlayers.contains(player))
|
|
|
+ htmContent = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/mods/EventEngine/Participating.htm");
|
|
|
+ else
|
|
|
+ htmContent = HtmCache.getInstance().getHtm(player.getHtmlPrefix(), "data/html/mods/EventEngine/Participation.htm");
|
|
|
+
|
|
|
+ if (htmContent != null)
|
|
|
+ html.setHtml(htmContent);
|
|
|
+
|
|
|
+ html.replace("%objectId%", objectid); // Yeah, we need this.
|
|
|
+ html.replace("%eventName%", _eventName);
|
|
|
+ html.replace("%eventCreator%", _eventCreator);
|
|
|
+ html.replace("%eventInfo%", _eventInfo);
|
|
|
+ player.sendPacket(html);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ _log.log(Level.WARNING, "Exception on showEventHtml(): " + e.getMessage(), e);
|
|
|
}
|
|
|
-
|
|
|
- adminReply.setHtml(replyMSG.toString());
|
|
|
- player.sendPacket(adminReply);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- _log.log(Level.WARNING, "Exception on showEventHtml(): " + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void spawn(L2PcInstance target, int npcid)
|
|
|
+ /**
|
|
|
+ * Spawns an event participation NPC near the player.
|
|
|
+ * The npc id used to spawning is L2Event._npcId
|
|
|
+ */
|
|
|
+ public static void spawnEventNpc(L2PcInstance target)
|
|
|
{
|
|
|
|
|
|
- L2NpcTemplate template1 = NpcTable.getInstance().getTemplate(npcid);
|
|
|
+ L2NpcTemplate template = NpcTable.getInstance().getTemplate(_npcId);
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- //L2MonsterInstance mob = new L2MonsterInstance(template1);
|
|
|
-
|
|
|
- L2Spawn spawn = new L2Spawn(template1);
|
|
|
+ L2Spawn spawn = new L2Spawn(template);
|
|
|
|
|
|
spawn.setLocx(target.getX() + 50);
|
|
|
spawn.setLocy(target.getY() + 50);
|
|
|
spawn.setLocz(target.getZ());
|
|
|
spawn.setAmount(1);
|
|
|
spawn.setHeading(target.getHeading());
|
|
|
- spawn.setRespawnDelay(1);
|
|
|
|
|
|
SpawnTable.getInstance().addNewSpawn(spawn, false);
|
|
|
|
|
|
spawn.init();
|
|
|
spawn.getLastSpawn().setCurrentHp(999999999);
|
|
|
- spawn.getLastSpawn().setName("event inscriptor");
|
|
|
- spawn.getLastSpawn().setTitle(L2Event.eventName);
|
|
|
+ spawn.getLastSpawn().setTitle(_eventName);
|
|
|
spawn.getLastSpawn().isEventMob = true;
|
|
|
- spawn.getLastSpawn().isAggressive();
|
|
|
- spawn.getLastSpawn().decayMe();
|
|
|
- spawn.getLastSpawn().spawnMe(spawn.getLastSpawn().getX(), spawn.getLastSpawn().getY(), spawn.getLastSpawn().getZ());
|
|
|
+ //spawn.getLastSpawn().decayMe();
|
|
|
+ //spawn.getLastSpawn().spawnMe(spawn.getLastSpawn().getX(), spawn.getLastSpawn().getY(), spawn.getLastSpawn().getZ());
|
|
|
|
|
|
spawn.getLastSpawn().broadcastPacket(new MagicSkillUse(spawn.getLastSpawn(), spawn.getLastSpawn(), 1034, 1, 1, 1));
|
|
|
|
|
|
- npcs.add(String.valueOf(spawn.getLastSpawn().getObjectId()));
|
|
|
+ //_npcs.add(spawn.getLastSpawn());
|
|
|
|
|
|
}
|
|
|
catch (Exception e)
|
|
@@ -214,88 +193,312 @@ public class L2Event
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static void announceAllPlayers(String text)
|
|
|
+ public static void unspawnEventNpcs()
|
|
|
{
|
|
|
- Broadcast.announceToOnlinePlayers(text);
|
|
|
+ //Its a little rough, but for sure it will remove every damn event NPC.
|
|
|
+ for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
|
|
|
+ {
|
|
|
+ if (spawn.getLastSpawn() != null && spawn.getLastSpawn().isEventMob)
|
|
|
+ {
|
|
|
+ spawn.getLastSpawn().deleteMe();
|
|
|
+ spawn.stopRespawn();
|
|
|
+ SpawnTable.getInstance().deleteSpawn(spawn, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //for (L2Npc npc : _npcs)
|
|
|
+ // npc.deleteMe();
|
|
|
}
|
|
|
|
|
|
- public static boolean isOnEvent(L2PcInstance player)
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @return False: If player is null, his event status is null or the event state is off.
|
|
|
+ * True: if the player is inside the _registeredPlayers list while the event state is STANDBY.
|
|
|
+ * If the event state is ON, it will check if the player is inside in one of the teams.
|
|
|
+ */
|
|
|
+ public static boolean isParticipant(L2PcInstance player)
|
|
|
{
|
|
|
+ if (player == null || player.getEventStatus() == null)
|
|
|
+ return false;
|
|
|
|
|
|
- for (int k = 0; k < L2Event.teamsNumber; k++)
|
|
|
+ switch (eventState)
|
|
|
{
|
|
|
- Iterator<String> it = L2Event.players.get(k + 1).iterator();
|
|
|
- boolean temp = false;
|
|
|
- while (it.hasNext())
|
|
|
- {
|
|
|
- temp = player.getName().equalsIgnoreCase(it.next());
|
|
|
- if (temp)
|
|
|
- return true;
|
|
|
- }
|
|
|
+ case OFF:
|
|
|
+ return false;
|
|
|
+ case STANDBY:
|
|
|
+ return _registeredPlayers.contains(player);
|
|
|
+ case ON:
|
|
|
+ for (FastList<L2PcInstance> teamList : _teams.values())
|
|
|
+ {
|
|
|
+ if (teamList.contains(player))
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static void inscribePlayer(L2PcInstance player)
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Adds the player to the list of participants.
|
|
|
+ * If the event state is NOT STANDBY, the player wont be registered.
|
|
|
+ */
|
|
|
+ public static void registerPlayer(L2PcInstance player)
|
|
|
+ {
|
|
|
+ if (eventState != EventState.STANDBY)
|
|
|
+ {
|
|
|
+ player.sendMessage("The registration period for this event is over.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _registeredPlayers.add(player);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * Removes the player from the participating players and the teams and restores
|
|
|
+ * his init stats before he registered at the event (loc, pvp, pk, title etc)
|
|
|
+ */
|
|
|
+ public static void removeAndResetPlayer(L2PcInstance player)
|
|
|
{
|
|
|
|
|
|
try
|
|
|
- {
|
|
|
- L2Event.participatingPlayers.add(player.getName());
|
|
|
- player.eventkarma = player.getKarma();
|
|
|
- player.eventX = player.getX();
|
|
|
- player.eventY = player.getY();
|
|
|
- player.eventZ = player.getZ();
|
|
|
- player.eventpkkills = player.getPkKills();
|
|
|
- player.eventpvpkills = player.getPvpKills();
|
|
|
- player.eventTitle = player.getTitle();
|
|
|
- player.kills.clear();
|
|
|
- player.atEvent = true;
|
|
|
+ {
|
|
|
+ if (isParticipant(player))
|
|
|
+ {
|
|
|
+ if (player.isDead())
|
|
|
+ {
|
|
|
+ player.restoreExp(100.0);
|
|
|
+ player.doRevive();
|
|
|
+ player.setCurrentHpMp(player.getMaxHp(), player.getMaxMp());
|
|
|
+ player.setCurrentCp(player.getMaxCp());
|
|
|
+ }
|
|
|
+
|
|
|
+ player.getPoly().setPolyInfo(null, "1");
|
|
|
+ player.decayMe();
|
|
|
+ player.spawnMe(player.getX(), player.getY(), player.getZ());
|
|
|
+ CharInfo info1 = new CharInfo(player);
|
|
|
+ player.broadcastPacket(info1);
|
|
|
+ UserInfo info2 = new UserInfo(player);
|
|
|
+ player.sendPacket(info2);
|
|
|
+ player.broadcastPacket(new ExBrExtraUserInfo(player));
|
|
|
+
|
|
|
+ player.stopTransformation(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (player.getEventStatus() != null)
|
|
|
+ player.getEventStatus().restoreInits();
|
|
|
+
|
|
|
+ player.setEventStatus(null);
|
|
|
+
|
|
|
+ _registeredPlayers.remove(player);
|
|
|
+ int teamId = getPlayerTeamId(player);
|
|
|
+ if (_teams.containsKey(teamId))
|
|
|
+ _teams.get(teamId).remove(player);
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
- _log.log(Level.WARNING, "Error when signing in the event:" + e.getMessage(), e);
|
|
|
+ _log.log(Level.WARNING, "Error at unregisterAndResetPlayer in the event:" + e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * The player's event status will be saved at _connectionLossData
|
|
|
+ */
|
|
|
+ public static void savePlayerEventStatus(L2PcInstance player)
|
|
|
+ {
|
|
|
+ _connectionLossData.put(player, player.getEventStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * If _connectionLossData contains the player, it will restore the player's event status.
|
|
|
+ * Also it will remove the player from the _connectionLossData.
|
|
|
+ */
|
|
|
+ public static void restorePlayerEventStatus(L2PcInstance player)
|
|
|
+ {
|
|
|
+ if (_connectionLossData.containsKey(player))
|
|
|
+ {
|
|
|
+ player.setEventStatus(_connectionLossData.get(player));
|
|
|
+ _connectionLossData.remove(player);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void restoreChar(L2PcInstance player)
|
|
|
+ /**
|
|
|
+ * If the event is ON or STANDBY, it will not start.
|
|
|
+ * Sets the event state to STANDBY and spawns registration NPCs
|
|
|
+ * @return a string with information if the event participation has been successfully started or not.
|
|
|
+ */
|
|
|
+ public static String startEventParticipation()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- player.eventX = connectionLossData.get(player.getName()).eventX;
|
|
|
- player.eventY = connectionLossData.get(player.getName()).eventY;
|
|
|
- player.eventZ = connectionLossData.get(player.getName()).eventZ;
|
|
|
- player.eventkarma = connectionLossData.get(player.getName()).eventKarma;
|
|
|
- player.eventpvpkills = connectionLossData.get(player.getName()).eventPvpKills;
|
|
|
- player.eventpkkills = connectionLossData.get(player.getName()).eventPkKills;
|
|
|
- player.eventTitle = connectionLossData.get(player.getName()).eventTitle;
|
|
|
- player.kills = connectionLossData.get(player.getName()).kills;
|
|
|
- player.eventSitForced = connectionLossData.get(player.getName()).eventSitForced;
|
|
|
- player.atEvent = true;
|
|
|
+ switch (eventState)
|
|
|
+ {
|
|
|
+ case ON:
|
|
|
+ return "Cannot start event, it is already on.";
|
|
|
+ case STANDBY:
|
|
|
+ return "Cannot start event, it is on standby mode.";
|
|
|
+ case OFF: // Event is off, so no problem turning it on.
|
|
|
+ eventState = EventState.STANDBY;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Just in case
|
|
|
+ unspawnEventNpcs();
|
|
|
+ _registeredPlayers.clear();
|
|
|
+ //_npcs.clear();
|
|
|
+
|
|
|
+ if (NpcTable.getInstance().getTemplate(_npcId) == null)
|
|
|
+ return "Cannot start event, invalid npc id.";
|
|
|
+
|
|
|
+ DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("data/events/" + _eventName)));
|
|
|
+ BufferedReader inbr = new BufferedReader(new InputStreamReader(in));
|
|
|
+ _eventCreator = inbr.readLine();
|
|
|
+ _eventInfo = inbr.readLine();
|
|
|
+
|
|
|
+ List<L2PcInstance> temp = new FastList<L2PcInstance>();
|
|
|
+ for (L2PcInstance player : L2World.getInstance().getAllPlayers().values())
|
|
|
+ {
|
|
|
+ if (!player.isOnline()) // Offline shops?
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (!temp.contains(player))
|
|
|
+ {
|
|
|
+ spawnEventNpc(player);
|
|
|
+ temp.add(player);
|
|
|
+ }
|
|
|
+ for (L2PcInstance playertemp : player.getKnownList().getKnownPlayers().values())
|
|
|
+ {
|
|
|
+ if ((Math.abs(playertemp.getX() - player.getX()) < 1000) && (Math.abs(playertemp.getY() - player.getY()) < 1000) && (Math.abs(playertemp.getZ() - player.getZ()) < 1000))
|
|
|
+ temp.add(playertemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
+ e.printStackTrace();
|
|
|
+ return "Cannot start event participation, an error has occured.";
|
|
|
}
|
|
|
+
|
|
|
+ return "The event participation has been successfully started.";
|
|
|
}
|
|
|
|
|
|
- public static void restoreAndTeleChar(L2PcInstance target)
|
|
|
+ /**
|
|
|
+ * If the event is ON or OFF, it will not start.
|
|
|
+ * Sets the event state to ON, creates the teams,
|
|
|
+ * adds the registered players ordered by level at the teams
|
|
|
+ * and adds a new event status to the players.
|
|
|
+ * @return a string with information if the event has been successfully started or not.
|
|
|
+ */
|
|
|
+ public static String startEvent()
|
|
|
{
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
- restoreChar(target);
|
|
|
- target.setTitle(target.eventTitle);
|
|
|
- target.setKarma(target.eventkarma);
|
|
|
- target.setPvpKills(target.eventpvpkills);
|
|
|
- target.setPkKills(target.eventpkkills);
|
|
|
- target.teleToLocation(target.eventX, target.eventY, target.eventZ, true);
|
|
|
- target.kills.clear();
|
|
|
- target.eventSitForced = false;
|
|
|
- target.atEvent = false;
|
|
|
+ switch (eventState)
|
|
|
+ {
|
|
|
+ case ON:
|
|
|
+ return "Cannot start event, it is already on.";
|
|
|
+ case STANDBY:
|
|
|
+ eventState = EventState.ON;
|
|
|
+ break;
|
|
|
+ case OFF: // Event is off, so no problem turning it on.
|
|
|
+ return "Cannot start event, it is off. Participation start is required.";
|
|
|
+ }
|
|
|
+
|
|
|
+ // Clean the things we will use, just in case.
|
|
|
+ unspawnEventNpcs();
|
|
|
+ _teams.clear();
|
|
|
+ _connectionLossData.clear();
|
|
|
+
|
|
|
+ // Insert empty lists at _teams.
|
|
|
+ for (int i = 0; i < _teamsNumber; i++)
|
|
|
+ _teams.put(i + 1, new FastList<L2PcInstance>());
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ while (!_registeredPlayers.isEmpty())
|
|
|
+ {
|
|
|
+ //Get the player with the biggest level
|
|
|
+ int max = 0;
|
|
|
+ L2PcInstance biggestLvlPlayer = null;
|
|
|
+ for (L2PcInstance player : _registeredPlayers)
|
|
|
+ {
|
|
|
+ if (player == null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (max < player.getLevel())
|
|
|
+ {
|
|
|
+ max = player.getLevel();
|
|
|
+ biggestLvlPlayer = player;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (biggestLvlPlayer == null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ _registeredPlayers.remove(biggestLvlPlayer);
|
|
|
+ _teams.get(i + 1).add(biggestLvlPlayer);
|
|
|
+ biggestLvlPlayer.setEventStatus();
|
|
|
+ i = (i + 1) % _teamsNumber;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
+ e.printStackTrace();
|
|
|
+ return "Cannot start event, an error has occured.";
|
|
|
}
|
|
|
+
|
|
|
+ return "The event has been successfully started.";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * If the event state is OFF, it will not finish.
|
|
|
+ * Sets the event state to OFF, unregisters and resets the players,
|
|
|
+ * unspawns and clers the event NPCs, clears the teams, registered players,
|
|
|
+ * connection loss data, sets the teams number to 0, sets the event name to empty.
|
|
|
+ * @return a string with information if the event has been successfully stopped or not.
|
|
|
+ */
|
|
|
+ public static String finishEvent()
|
|
|
+ {
|
|
|
+ switch (eventState)
|
|
|
+ {
|
|
|
+ case OFF:
|
|
|
+ return "Cannot finish event, it is already off.";
|
|
|
+ case STANDBY:
|
|
|
+ for (L2PcInstance player : _registeredPlayers)
|
|
|
+ removeAndResetPlayer(player);
|
|
|
+
|
|
|
+ unspawnEventNpcs();
|
|
|
+ //_npcs.clear();
|
|
|
+ _registeredPlayers.clear();
|
|
|
+ _teams.clear();
|
|
|
+ _connectionLossData.clear();
|
|
|
+ _teamsNumber = 0;
|
|
|
+ _eventName = "";
|
|
|
+ eventState = EventState.OFF;
|
|
|
+ return "The event has been stopped at STANDBY mode, all players unregistered and all event npcs unspawned.";
|
|
|
+ case ON:
|
|
|
+ for (FastList<L2PcInstance> teamList : _teams.values())
|
|
|
+ {
|
|
|
+ for (L2PcInstance player : teamList)
|
|
|
+ removeAndResetPlayer(player);
|
|
|
+ }
|
|
|
+
|
|
|
+ eventState = EventState.OFF;
|
|
|
+ unspawnEventNpcs(); // Just in case
|
|
|
+ //_npcs.clear();
|
|
|
+ _registeredPlayers.clear();
|
|
|
+ _teams.clear();
|
|
|
+ _connectionLossData.clear();
|
|
|
+ _teamsNumber = 0;
|
|
|
+ _eventName = "";
|
|
|
+ _npcId = 0;
|
|
|
+ _eventCreator = "";
|
|
|
+ _eventInfo = "";
|
|
|
+ return "The event has been stopped, all players unregistered and all event npcs unspawned.";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "The event has been successfully finished.";
|
|
|
}
|
|
|
}
|