/*
* 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 .
*/
package com.l2jserver.gameserver.model.entity;
import java.io.BufferedInputStream;
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.logging.Level;
import java.util.logging.Logger;
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.MagicSkillUse;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
import com.l2jserver.gameserver.util.Broadcast;
import com.l2jserver.util.EventData;
import com.l2jserver.util.StringUtil;
/**
* This class ...
*
* @version $Revision: 1.3.4.1 $ $Date: 2005/03/27 15:29:32 $
*/
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 names = new HashMap();
public static final LinkedList participatingPlayers = new LinkedList(); //TODO store by objid
public static final HashMap> players = new HashMap>();
public static int id = 12760;
public static final LinkedList npcs = new LinkedList();
public static boolean active = false;
public static final HashMap connectionLossData = new HashMap();
public static int getTeamOfPlayer(String name)
{
for (int i = 1; i <= players.size(); i++)
{
LinkedList temp = players.get(i);
Iterator it = temp.iterator();
while (it.hasNext())
{
if (it.next().equals(name))
return i;
}
}
return 0;
}
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 killersTemp = new LinkedList();
for (int k = 0; k < N; k++)
{
kills = 0;
for (int i = 1; i <= teamsNumber; i++)
{
LinkedList temp = players.get(i);
Iterator 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)
{
}
}
}
killersTemp.add(playerTemp);
}
for (int i = 0; i < N; i++)
{
kills = 0;
Iterator 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);
}
return killers;
}
public static void showEventHtml(L2PcInstance player, String objectid)
{
try
{
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,
"" +
"
",
eventName,
" bY ",
inbr.readLine(),
"
" +
" ",
inbr.readLine()
);
if (L2Event.participatingPlayers.contains(player.getName())) {
replyMSG.append("