/**
* Called when a player logs in
*
* @param playerInstance
*/
public static void onLogin(L2PcInstance playerInstance)
{
if (playerInstance == null || (!isStarting() && !isStarted()))
return;
byte teamId = getParticipantTeamId(playerInstance.getName());
if (teamId == -1)
return;
_teams[teamId].addPlayer(playerInstance);
new TvTEventTeleporter(playerInstance, _teams[teamId].getCoordinates(), true, false);
}
/**
* Called when a player logs out
*
* @param playerInstance
*/
public static void onLogout(L2PcInstance playerInstance)
{
if (playerInstance == null || (!isStarting() && !isStarted()))
return;
removeParticipant(playerInstance.getName());
}
/**
* Called on every bypass by npc of type L2TvTEventNpc
* Needs synchronization cause of the max player check
*
* @param command
* @param playerInstance
*/
public static synchronized void onBypass(String command, L2PcInstance playerInstance)
{
if (playerInstance == null || !isParticipating())
return;
if (command.equals("tvt_event_participation"))
{
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
int playerLevel = playerInstance.getLevel();
if (playerInstance.isCursedWeaponEquiped())
npcHtmlMessage.setHtml("
TvT EventCursed weapon owners are not allowed to participate.");
else if (playerInstance.getKarma() > 0)
npcHtmlMessage.setHtml("TvT EventChaotic players are not allowed to participate.");
else if (_teams[0].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS && _teams[1].getParticipatedPlayerCount() >= Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS)
npcHtmlMessage.setHtml("TvT EventSorry the event is full!");
else if (playerLevel < Config.TVT_EVENT_MIN_LVL || playerLevel > Config.TVT_EVENT_MAX_LVL)
npcHtmlMessage.setHtml("TvT EventOnly players from level " + Config.TVT_EVENT_MIN_LVL + " to level " + Config.TVT_EVENT_MAX_LVL + " are allowed tro participate.");
else if (_teams[0].getParticipatedPlayerCount() > 19 && _teams[1].getParticipatedPlayerCount() > 19)
npcHtmlMessage.setHtml("TvT EventThe event is full! Maximum of " + Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS + " player are allowed in one team.");
else if (addParticipant(playerInstance))
npcHtmlMessage.setHtml("TvT EventYou are on the registration list now.");
else // addParticipant returned false cause playerInstance == null
return;
playerInstance.sendPacket(npcHtmlMessage);
}
else if (command.equals("tvt_event_remove_participation"))
{
removeParticipant(playerInstance.getName());
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
npcHtmlMessage.setHtml("TvT EventYou are not longer on the registration list.");
playerInstance.sendPacket(npcHtmlMessage);
}
}
/**
* Called on every onAction in L2PcIstance
*
* @param playerName
* @param targetPlayerName
* @return boolean
*/
public static boolean onAction(String playerName, String targetPlayerName)
{
if (!isStarted())
return true;
L2PcInstance playerInstance = L2World.getInstance().getPlayer(playerName);
if (playerInstance == null)
return false;
if (playerInstance.isGM())
return true;
byte playerTeamId = getParticipantTeamId(playerName);
byte targetPlayerTeamId = getParticipantTeamId(targetPlayerName);
if ((playerTeamId != -1 && targetPlayerTeamId == -1) ||
(playerTeamId == -1 && targetPlayerTeamId != -1))
return false;
if (playerTeamId != -1 && targetPlayerTeamId != -1 && playerTeamId == targetPlayerTeamId && !Config.TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED)
return false;
return true;
}