");
replyMSG.append(" ... description: " + _eventDesc + " ");
if (!_started && !_joining)
replyMSG.append("The event is underway! ");
else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
{
if (!TvT._started)
{
replyMSG.append("Currently participating : " + _playersShuffle.size() +". ");
replyMSG.append("Admin set max players : " + _maxPlayers + " ");
replyMSG.append("You can't participate to this event. ");
}
}
else if (eventPlayer.isCursedWeaponEquipped() && !Config.TVT_JOIN_CURSED)
{
replyMSG.append("You can't participate to this event with a cursed Weapon. ");
}
else if (!_started && _joining && eventPlayer.getLevel()>=_minlvl && eventPlayer.getLevel()<_maxlvl)
{
if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
{
if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
replyMSG.append("You are already participating in team " + eventPlayer._teamNameTvT + " ");
else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
replyMSG.append("You are already participating! ");
replyMSG.append("");
replyMSG.append("Wait till event start or ");
replyMSG.append(" ");
replyMSG.append("your participation! ");
replyMSG.append("
");
}
else
{
replyMSG.append("You want to participate in the event? ");
replyMSG.append("Admin set min lvl : " + _minlvl + " ");
replyMSG.append("Admin set max lvl : " + _maxlvl + " ");
if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
{
replyMSG.append("");
for (String team : _teams)
{
replyMSG.append("" + team + " (" + teamPlayersCount(team) + " joined) ");
replyMSG.append(" ");
}
replyMSG.append("
");
}
else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
{
replyMSG.append("");
for (String team : _teams)
replyMSG.append("" + team + " ");
replyMSG.append("
");
replyMSG.append("");
replyMSG.append("Teams will be reandomly generated!");
}
}
}
else if (_started && !_joining)
replyMSG.append("TvT match is in progress. ");
else if (eventPlayer.getLevel()<_minlvl || eventPlayer.getLevel()>_maxlvl )
{
replyMSG.append("Your lvl : " + eventPlayer.getLevel() +" ");
replyMSG.append("Admin set min lvl : " + _minlvl + " ");
replyMSG.append("Admin set max lvl : " + _maxlvl + " ");
replyMSG.append("You can't participate to this event. ");
}
replyMSG.append("");
adminReply.setHtml(replyMSG.toString());
eventPlayer.sendPacket(adminReply);
// Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
eventPlayer.actionFailed();
}
catch (Exception e)
{
_log.warn("TvT Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
}
}
public static void addPlayer(L2PcInstance player, String teamName)
{
if (!addPlayerOk(teamName, player))
return;
if (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE"))
{
player._teamNameTvT = teamName;
_players.add(player);
setTeamPlayersCount(teamName, teamPlayersCount(teamName)+1);
}
else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
_playersShuffle.add(player);
player._inEventTvT = true;
player._countTvTkills = 0;
}
public static void removeOfflinePlayers()
{
try
{
if(_playersShuffle== null || _playersShuffle.isEmpty())
return;
if(_playersShuffle!= null && !_playersShuffle.isEmpty())
{
for(L2PcInstance player: _playersShuffle)
{
if(player==null || player.isOnline()==0)
_playersShuffle.remove(player);
}
}
}
catch (Exception e){}
}
public static boolean checkShufflePlayers(L2PcInstance eventPlayer)
{
try
{
for(L2PcInstance player: _playersShuffle)
{
if(player==null)
{
_playersShuffle.remove(player);
continue;
}
else if(player.getObjectId()==eventPlayer.getObjectId())
{
eventPlayer._inEventTvT = true;
eventPlayer._countTvTkills = 0;
return true;
}
//this 1 is incase player got new objectid after DC or reconnect
else if(player.getName().equals(eventPlayer.getName()))
{
_playersShuffle.remove(player);
_playersShuffle.add(eventPlayer);
eventPlayer._inEventTvT = true;
eventPlayer._countTvTkills = 0;
return true;
}
}
}
catch (Exception e){}
return false;
}
public static boolean addPlayerOk(String teamName, L2PcInstance eventPlayer)
{
try
{
if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventTvT)
{
eventPlayer.sendMessage("You are already participating in the event!");
return false;
}
if (eventPlayer._inEventFOS || eventPlayer._inEventCTF || eventPlayer._inEventDM || eventPlayer._inEventVIP)
{
eventPlayer.sendMessage("You are already participating in another event!");
return false;
}
for(L2PcInstance player: _players)
{
if(player.getObjectId()==eventPlayer.getObjectId())
{
eventPlayer.sendMessage("You are already participating in the event!");
return false;
}
else if(player.getName()==eventPlayer.getName())
{
eventPlayer.sendMessage("You are already participating in the event!");
return false;
}
}
if(_players.contains(eventPlayer))
{
eventPlayer.sendMessage("You are already participating in the event!");
return false;
}
if (CTF._savePlayers.contains(eventPlayer.getName()))
{
eventPlayer.sendMessage("You are already participating in another event!");
return false;
}
}
catch (Exception e)
{
_log.warn("TvT Engine exception: " + e.getMessage());
}
if (Config.TVT_EVEN_TEAMS.equals("NO"))
return true;
else if (Config.TVT_EVEN_TEAMS.equals("BALANCE"))
{
boolean allTeamsEqual = true;
int countBefore = -1;
for (int playersCount : _teamPlayersCount)
{
if (countBefore == -1)
countBefore = playersCount;
if (countBefore != playersCount)
{
allTeamsEqual = false;
break;
}
countBefore = playersCount;
}
if (allTeamsEqual)
return true;
countBefore = Integer.MAX_VALUE;
for (int teamPlayerCount : _teamPlayersCount)
{
if (teamPlayerCount < countBefore)
countBefore = teamPlayerCount;
}
Vector joinableTeams = new Vector();
for (String team : _teams)
{
if (teamPlayersCount(team) == countBefore)
joinableTeams.add(team);
}
if (joinableTeams.contains(teamName))
return true;
}
else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
return true;
eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
return false;
}
public static synchronized void addDisconnectedPlayer(L2PcInstance player)
{
if ((Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started)) || (Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started)))
{
if (Config.TVT_ON_START_REMOVE_ALL_EFFECTS)
{
for (L2Effect e : player.getAllEffects())
{
if (e != null)
e.exit();
}
}
player._teamNameTvT = _savePlayerTeams.get(_savePlayers.indexOf(player.getName()));
for (L2PcInstance p : _players)
{
if (p==null)
{
_players.remove(p);
continue;
}
//check by name incase player got new objectId
else if (p.getName().equals(player.getName()))
{
player._originalNameColorTvT = player.getAppearance().getNameColor();
player._originalKarmaTvT = player.getKarma();
player._inEventTvT = true;
player._countTvTkills=p._countTvTkills;
_players.remove(p); //removing old object id from vector
_players.add(player); //adding new objectId to vector
break;
}
}
player.getAppearance().setNameColor(_teamColors.get(_teams.indexOf(player._teamNameTvT)));
player.setKarma(0);
player.broadcastUserInfo();
player.teleToLocation(_teamsX.get(_teams.indexOf(player._teamNameTvT)), _teamsY.get(_teams.indexOf(player._teamNameTvT)), _teamsZ.get(_teams.indexOf(player._teamNameTvT)));
}
}
public static void removePlayer(L2PcInstance player)
{
if(player._inEventTvT)
{
if(!_joining)
{
player.getAppearance().setNameColor(player._originalNameColorTvT);
player.setKarma(player._originalKarmaTvT);
player.broadcastUserInfo();
}
player._teamNameTvT = new String();
player._countTvTkills = 0;
player._inEventTvT = false;
if ((Config.TVT_EVEN_TEAMS.equals("NO") || Config.TVT_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
{
setTeamPlayersCount(player._teamNameTvT, teamPlayersCount(player._teamNameTvT)-1);
_players.remove(player);
}
else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
_playersShuffle.remove(player);
}
}
public static void cleanTvT()
{
_log.info("TvT : Cleaning players.");
for (L2PcInstance player : _players)
{
if(player != null)
{
removePlayer(player);
if(_savePlayers.contains(player.getName()))
_savePlayers.remove(player.getName());
player._inEventTvT = false;
}
}
if (_playersShuffle != null && !_playersShuffle.isEmpty())
{
for (L2PcInstance player : _playersShuffle)
{
if(player != null)
player._inEventTvT = false;
}
}
_log.info("TvT : Cleaning teams.");
for (String team : _teams)
{
int index = _teams.indexOf(team);
_teamPlayersCount.set(index, 0);
_teamKillsCount.set(index, 0);
}
_topKills = 0;
_topTeam = new String();
_players = new Vector();
_playersShuffle = new Vector();
_savePlayers = new Vector();
_savePlayerTeams = new Vector();
_log.info("Cleaning TvT done.");
}
public static void unspawnEventNpc()
{
if (_npcSpawn == null)
return;
_npcSpawn.getLastSpawn().deleteMe();
_npcSpawn.stopRespawn();
SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
}
public static void teleportFinish()
{
Announcements.getInstance().announceToAll(_eventName + "(TvT): Teleport back to participation NPC in 20 seconds!");
ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
{
public void run()
{
for (L2PcInstance player : _players)
{
if (player != null && player.isOnline()!=0)
player.teleToLocation(_npcX, _npcY, _npcZ, false);
}
_log.info("TvT: Teleport done.");
cleanTvT();
}
}, 20000);
}
public static int teamKillsCount(String teamName)
{
int index = _teams.indexOf(teamName);
if (index == -1)
return -1;
return _teamKillsCount.get(index);
}
public static void setTeamKillsCount(String teamName, int teamKillsCount)
{
int index = _teams.indexOf(teamName);
if (index == -1)
return;
_teamKillsCount.set(index, teamKillsCount);
}
public static int teamPlayersCount(String teamName)
{
int index = _teams.indexOf(teamName);
if (index == -1)
return -1;
return _teamPlayersCount.get(index);
}
public static void setTeamPlayersCount(String teamName, int teamPlayersCount)
{
int index = _teams.indexOf(teamName);
if (index == -1)
return;
_teamPlayersCount.set(index, teamPlayersCount);
}
}