это файл TvTEvent.class не знаю в этом файле надо рыскать или в каком?
package net.sf.l2j.gameserver.model.entity;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javolution.util.FastMap;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.Olympiad;
import net.sf.l2j.gameserver.datatables.DoorTable;
import net.sf.l2j.gameserver.datatables.ItemTable;
import net.sf.l2j.gameserver.datatables.NpcTable;
import net.sf.l2j.gameserver.datatables.SpawnTable;
import net.sf.l2j.gameserver.model.L2Character;
import net.sf.l2j.gameserver.model.L2Effect;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2Spawn;
import net.sf.l2j.gameserver.model.L2Summon;
import net.sf.l2j.gameserver.model.PcInventory;
import net.sf.l2j.gameserver.model.actor.instance.L2DoorInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2SummonInstance;
import net.sf.l2j.gameserver.network.L2GameClient;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.serverpackets.CreatureSay;
import net.sf.l2j.gameserver.serverpackets.MagicSkillUser;
import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
import net.sf.l2j.gameserver.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.templates.L2NpcTemplate;
import net.sf.l2j.util.Rnd;
public class TvTEvent
{
protected static final Logger _log = Logger.getLogger(TvTEvent.class.getName());
private static TvTEventTeam[] _teams = new TvTEventTeam[2];
private static EventState _state = EventState.INACTIVE;
private static L2Spawn _npcSpawn = null;
private static L2NpcInstance _lastNpcSpawn = null;
private static FastMap<String, Integer> _ips = new FastMap();
public static void init()
{
_teams[0] = new TvTEventTeam(Config.TVT_EVENT_TEAM_1_NAME, Config.TVT_EVENT_TEAM_1_COORDINATES);
_teams[1] = new TvTEventTeam(Config.TVT_EVENT_TEAM_2_NAME, Config.TVT_EVENT_TEAM_2_COORDINATES);
}
public static boolean startParticipation()
{
L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(Config.TVT_EVENT_PARTICIPATION_NPC_ID);
if (tmpl == null) {
_log.warning("TvTEventEngine[TvTEvent.startParticipation()]: L2NpcTemplate is a NullPointer -> Invalid npc id in configs?");
return false;
}
try
{
_npcSpawn = new L2Spawn(tmpl);
_npcSpawn.setLocx(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[0]);
_npcSpawn.setLocy(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[1]);
_npcSpawn.setLocz(Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES[2]);
_npcSpawn.setAmount(1);
_npcSpawn.setHeading(0);
_npcSpawn.setRespawnDelay(1);
SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
_npcSpawn.init();
_lastNpcSpawn = _npcSpawn.getLastSpawn();
_lastNpcSpawn.setCurrentHp(_lastNpcSpawn.getMaxHp());
_lastNpcSpawn.setTitle("TvT Event Participation");
_lastNpcSpawn.isAggressive();
_lastNpcSpawn.decayMe();
_lastNpcSpawn.spawnMe(_npcSpawn.getLastSpawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
_lastNpcSpawn.broadcastPacket(new MagicSkillUser(_lastNpcSpawn, _lastNpcSpawn, 1034, 1, 1, 1));
} catch (Exception e) {
_log.warning("TvTEventEngine[TvTEvent.startParticipation()]: exception: " + e);
return false;
}
setState(EventState.PARTICIPATING);
return true;
}
public static boolean startFight()
{
setState(EventState.STARTING);
if ((_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS) || (_teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS))
{
setState(EventState.INACTIVE);
_teams[0].cleanMe();
_teams[1].cleanMe();
clearIp();
unSpawnNpc();
return false;
}
openDoors();
closeDoors();
setState(EventState.STARTED);
TvTEventTeam team;
for (team : _teams)
{
for (L2PcInstance playerInstance : team.getParticipatedPlayers().values()) {
if (playerInstance != null)
{
new TvTEventTeleporter(playerInstance, team.getCoordinates(), false, false);
playerInstance.stopAllEffects();
for (L2Effect effect : playerInstance.getAllEffects()) {
if (effect != null) {
effect.exit();
}
}
}
}
}
return true;
}
public static String calculateRewards()
{
if (_teams[0].getPoints() == _teams[1].getPoints())
{
if ((_teams[0].getParticipatedPlayerCount() == 0) || (_teams[1].getParticipatedPlayerCount() == 0))
{
setState(EventState.REWARDING);
return "TvT Event: Event has ended. No team won due to inactivity!";
}
sysMsgToAllParticipants("TvT Event: Event has ended, both teams have tied.");
if (Config.TVT_REWARD_TEAM_TIE)
{
rewardTeamOne();
rewardTeamTwo();
return "TvT Event: Event has ended with both teams tying.";
}
return "TvT Event: Event has ended with both teams tying.";
}
setState(EventState.REWARDING);
TvTEventTeam team = _teams[1];
TvTEventTeam teamLost = _teams[1];
if (team == _teams[0])
rewardTeamOne();
else {
rewardTeamTwo();
}
return "TvT Event: Эвент завершен. Команда " + team.getName() + " выиграла со счетом " + team.getPoints() + " : " + teamLost.getPoints() + " очков.";
}
private static void rewardTeamOne()
{
TvTEventTeam team = _teams[0];
for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
{
boolean _canreward = true;
if (playerInstance != null)
{
if (playerInstance.getTvTKills() < 7)
{
_canreward = false;
}
SystemMessage systemMessage = null;
if (_canreward)
{
for (int[] reward : Config.TVT_EVENT_REWARDS) {
PcInventory inv = playerInstance.getInventory();
if (ItemTable.getInstance().createDummyItem(reward[0]).isStackable()) {
inv.addItem("TvT Event", reward[0], reward[1], playerInstance, playerInstance);
if (reward[1] > 1) {
systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
systemMessage.addItemName(reward[0]);
systemMessage.addNumber(reward[1]);
} else {
systemMessage = new SystemMessage(SystemMessageId.EARNED_ITEM);
systemMessage.addItemName(reward[0]);
}
playerInstance.sendPacket(systemMessage);
} else {
for (int i = 0; i < reward[1]; i++) {
inv.addItem("TvT Event", reward[0], 1, playerInstance, playerInstance);
systemMessage = new SystemMessage(SystemMessageId.EARNED_ITEM);
systemMessage.addItemName(reward[0]);
playerInstance.sendPacket(systemMessage);
}
}
}
StatusUpdate statusUpdate = new StatusUpdate(playerInstance.getObjectId());
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
statusUpdate.addAttribute(14, playerInstance.getCurrentLoad());
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Your team won the event. Look in your inventory, there should be your reward.</body></html>");
playerInstance.sendPacket(statusUpdate);
playerInstance.sendPacket(npcHtmlMessage);
}
}
}
}
private static void rewardTeamTwo()
{
TvTEventTeam team = _teams[1];
for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
{
boolean _canreward = true;
if (playerInstance != null)
{
if (playerInstance.getTvTKills() < 7)
{
_canreward = false;
}
SystemMessage systemMessage = null;
if (_canreward)
{
for (int[] reward : Config.TVT_EVENT_REWARDS) {
PcInventory inv = playerInstance.getInventory();
if (ItemTable.getInstance().createDummyItem(reward[0]).isStackable()) {
inv.addItem("TvT Event", reward[0], reward[1], playerInstance, playerInstance);
if (reward[1] > 1) {
systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
systemMessage.addItemName(reward[0]);
systemMessage.addNumber(reward[1]);
} else {
systemMessage = new SystemMessage(SystemMessageId.EARNED_ITEM);
systemMessage.addItemName(reward[0]);
}
playerInstance.sendPacket(systemMessage);
} else {
for (int i = 0; i < reward[1]; i++) {
inv.addItem("TvT Event", reward[0], 1, playerInstance, playerInstance);
systemMessage = new SystemMessage(SystemMessageId.EARNED_ITEM);
systemMessage.addItemName(reward[0]);
playerInstance.sendPacket(systemMessage);
}
}
}
StatusUpdate statusUpdate = new StatusUpdate(playerInstance.getObjectId());
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
statusUpdate.addAttribute(14, playerInstance.getCurrentLoad());
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Your team won the event. Look in your inventory, there should be your reward.</body></html>");
playerInstance.sendPacket(statusUpdate);
playerInstance.sendPacket(npcHtmlMessage);
}
}
}
}
public static void stopFight()
{
setState(EventState.INACTIVATING);
unSpawnNpc();
openDoors();
for (TvTEventTeam team : _teams) {
for (L2PcInstance playerInstance : team.getParticipatedPlayers().values())
{
if (playerInstance != null) {
new TvTEventTeleporter(playerInstance, Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES, false, false);
}
}
}
_teams[0].cleanMe();
_teams[1].cleanMe();
clearIp();
setState(EventState.INACTIVE);
}
public static synchronized boolean addParticipant(L2PcInstance playerInstance)
{
if (playerInstance == null) {
return false;
}
byte teamId = 0;
if (_teams[0].getParticipatedPlayerCount() == _teams[1].getParticipatedPlayerCount()) {
teamId = (byte)Rnd.get(2);
addPlayerIp(playerInstance.getClient().getHWID());
} else {
teamId = (byte)(_teams[0].getParticipatedPlayerCount() > _teams[1].getParticipatedPlayerCount() ? 1 : 0);
addPlayerIp(playerInstance.getClient().getHWID());
}
return _teams[teamId].addPlayer(playerInstance);
}
public static boolean removeParticipant(L2PcInstance player)
{
byte teamId = getParticipantTeamId(player.getObjectId());
if (teamId != -1)
{
_teams[teamId].removePlayer(player.getObjectId());
if (player.getClient().getHWID() != null)
removePlayerIp(player.getClient().getHWID());
return true;
}
return false;
}
public static void addPlayerIp(String ip) {
Integer count = (Integer)_ips.get(ip);
if (count == null)
_ips.put(ip, Integer.valueOf(1));
else if ((count != null) && (count.intValue() >= 1))
_ips.put(ip, Integer.valueOf(count.intValue() + 1));
}
public static void removePlayerIp(String ip)
{
Integer count = (Integer)_ips.get(ip);
if ((count != null) && (count.intValue() > 1))
_ips.put(ip, Integer.valueOf(count.intValue() - 1));
else if ((count != null) && (count.intValue() < 2))
_ips.remove(ip);
}
public static void clearIp()
{
_ips.clear();
}
public static void sysMsgToAllParticipants(String message)
{
for (L2PcInstance playerInstance : _teams[0].getParticipatedPlayers().values()) {
if (playerInstance != null) {
playerInstance.sendMessage(message);
}
}
for (L2PcInstance playerInstance : _teams[1].getParticipatedPlayers().values())
if (playerInstance != null)
playerInstance.sendMessage(message);
}
private static void closeDoors()
{
for (Iterator i$ = Config.TVT_DOORS_IDS_TO_CLOSE.iterator(); i$.hasNext(); ) { int doorId = ((Integer)i$.next()).intValue();
L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(Integer.valueOf(doorId));
if (doorInstance != null)
doorInstance.closeMe();
}
}
private static void openDoors()
{
for (Iterator i$ = Config.TVT_DOORS_IDS_TO_OPEN.iterator(); i$.hasNext(); ) { int doorId = ((Integer)i$.next()).intValue();
L2DoorInstance doorInstance = DoorTable.getInstance().getDoor(Integer.valueOf(doorId));
if (doorInstance != null)
doorInstance.openMe();
}
}
private static void unSpawnNpc()
{
_lastNpcSpawn.deleteMe();
_npcSpawn.stopRespawn();
_npcSpawn = null;
_lastNpcSpawn = null;
}
public static void onLogin(L2PcInstance playerInstance)
{
if ((playerInstance == null) || ((!isStarting()) && (!isStarted())))
{
return;
}
byte teamId = getParticipantTeamId(playerInstance.getObjectId());
if (teamId == -1) {
return;
}
_teams[teamId].addPlayer(playerInstance);
new TvTEventTeleporter(playerInstance, _teams[teamId].getCoordinates(), true, false);
}
public static void onLogout(L2PcInstance player)
{
if ((player != null) && ((isStarting()) || (isStarted()) || (isParticipating())))
{
removeParticipant(player);
}
}
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();
String ip = playerInstance.getClient().getHWID();
if ((_ips.get(ip) != null) && (((Integer)_ips.get(ip)).intValue() >= 1))
{
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>DUAL BOX.</body></html>");
}
else if (playerInstance.isCursedWeaponEquiped())
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Cursed weapon owners are not allowed to participate.</body></html>");
else if (playerInstance.getKarma() > 0)
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Chaotic players are not allowed to participate.</body></html>");
else if ((playerLevel < Config.TVT_EVENT_MIN_LVL) || (playerLevel > Config.TVT_EVENT_MAX_LVL))
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Only players from level " + Config.TVT_EVENT_MIN_LVL + " to level " + Config.TVT_EVENT_MAX_LVL + " are allowed tro participate.</body></html>");
else if ((playerInstance.isInOlympiadMode()) || (Olympiad.getInstance().isRegistered(playerInstance)) || (playerInstance._inEventCTF))
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>Вы зарегистрированы на олимпиаде или на CTF!</body></html>");
else if ((_teams[0].getParticipatedPlayerCount() == Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS) && (_teams[1].getParticipatedPlayerCount() == Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS))
{
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>The event is full! Only " + Config.TVT_EVENT_MAX_PLAYERS_IN_TEAMS + " players are allowed per team.</body></html>");
}
else if (addParticipant(playerInstance))
{
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are on the registration list now.</body></html>");
}
else
{
return;
}
playerInstance.sendPacket(npcHtmlMessage);
} else if (command.equals("tvt_event_remove_participation")) {
removeParticipant(playerInstance);
NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
npcHtmlMessage.setHtml("<html><head><title>TvT Event</title></head><body>You are not longer on the registration list.</body></html>");
playerInstance.sendPacket(npcHtmlMessage);
}
}
public static boolean onAction(L2PcInstance playerInstance, int targetedPlayerObjectId)
{
if ((playerInstance == null) || (!isStarted())) {
return true;
}
if (playerInstance.isGM()) {
return true;
}
byte playerTeamId = getParticipantTeamId(playerInstance.getObjectId());
byte targetedPlayerTeamId = getParticipantTeamId(targetedPlayerObjectId);
if ((playerTeamId != -1) && (targetedPlayerTeamId == -1))
{
return false;
}
if ((playerTeamId != -1) && (targetedPlayerTeamId != -1) && (playerTeamId == targetedPlayerTeamId) && (playerInstance.getObjectId() != targetedPlayerObjectId) && (!Config.TVT_EVENT_TARGET_TEAM_MEMBERS_ALLOWED))
{
return false;
}
return true;
}
public static boolean onScrollUse(int playerObjectId)
{
if (!isStarted()) {
return true;
}
if ((isPlayerParticipant(playerObjectId)) && (!Config.TVT_EVENT_SCROLL_ALLOWED)) {
return false;
}
return true;
}
public static boolean onPotionUse(int playerObjectId)
{
if (!isStarted()) {
return true;
}
if ((isPlayerParticipant(playerObjectId)) && (!Config.TVT_EVENT_POTIONS_ALLOWED)) {
return false;
}
return true;
}
public static boolean onEscapeUse(int playerObjectId)
{
if (!isStarted()) {
return true;
}
if (isPlayerParticipant(playerObjectId)) {
return false;
}
return true;
}
public static boolean onItemSummon(int playerObjectId)
{
if (!isStarted()) {
return true;
}
if ((isPlayerParticipant(playerObjectId)) && (!Config.TVT_EVENT_SUMMON_BY_ITEM_ALLOWED)) {
return false;
}
return true;
}
public static void onKill(L2Character killerCharacter, L2PcInstance killedPlayerInstance)
{
if ((killedPlayerInstance == null) || (!isStarted())) {
return;
}
byte killedTeamId = getParticipantTeamId(killedPlayerInstance.getObjectId());
if (killedTeamId == -1) {
return;
}
new TvTEventTeleporter(killedPlayerInstance, _teams[killedTeamId].getCoordinates(), false, false);
if (killerCharacter == null) {
return;
}
L2PcInstance killerPlayerInstance = null;
if (((killerCharacter instanceof L2PetInstance)) || ((killerCharacter instanceof L2SummonInstance))) {
killerPlayerInstance = ((L2Summon)killerCharacter).getOwner();
if (killerPlayerInstance != null);
}
else if ((killerCharacter instanceof L2PcInstance)) {
killerPlayerInstance = (L2PcInstance)killerCharacter;
} else {
return;
}
byte killerTeamId = getParticipantTeamId(killerPlayerInstance.getObjectId());
CreatureSay cs;
if ((killerTeamId != -1) && (killedTeamId != -1) && (killerTeamId != killedTeamId)) {
TvTEventTeam killerTeam = _teams[killerTeamId];
killerTeam.increasePoints();
killerPlayerInstance.increaseTvTKills();
cs = new CreatureSay(killerPlayerInstance.getObjectId(), 2, killerPlayerInstance.getName(), "I have killed " + killedPlayerInstance.getName() + "!");
for (L2PcInstance playerInstance : _teams[killerTeamId].getParticipatedPlayers().values())
if (playerInstance != null)
playerInstance.sendPacket(cs);
}
}
private static void setState(EventState state)
{
synchronized (_state) {
_state = state;
}
}
public static boolean isInactive()
{
boolean isInactive;
synchronized (_state) {
isInactive = _state == EventState.INACTIVE;
}
return isInactive;
}
public static boolean isInactivating()
{
boolean isInactivating;
synchronized (_state) {
isInactivating = _state == EventState.INACTIVATING;
}
return isInactivating;
}
public static boolean isParticipating()
{
boolean isParticipating;
synchronized (_state) {
isParticipating = _state == EventState.PARTICIPATING;
}
return isParticipating;
}
public static boolean isStarting()
{
boolean isStarting;
synchronized (_state) {
isStarting = _state == EventState.STARTING;
}
return isStarting;
}
public static boolean isStarted()
{
boolean isStarted;
synchronized (_state) {
isStarted = _state == EventState.STARTED;
}
return isStarted;
}
public static boolean isRewarding()
{
boolean isRewarding;
synchronized (_state) {
isRewarding = _state == EventState.REWARDING;
}
return isRewarding;
}
public static byte getParticipantTeamId(int playerObjectId)
{
return (byte)(_teams[1].containsPlayer(playerObjectId) ? 1 : _teams[0].containsPlayer(playerObjectId) ? 0 : -1);
}
public static TvTEventTeam getParticipantTeam(int playerObjectId)
{
return _teams[1].containsPlayer(playerObjectId) ? _teams[1] : _teams[0].containsPlayer(playerObjectId) ? _teams[0] : null;
}
public static TvTEventTeam getParticipantEnemyTeam(int playerObjectId)
{
return _teams[1].containsPlayer(playerObjectId) ? _teams[0] : _teams[0].containsPlayer(playerObjectId) ? _teams[1] : null;
}
public static int[] getParticipantTeamCoordinates(int playerObjectId)
{
return _teams[1].containsPlayer(playerObjectId) ? _teams[1].getCoordinates() : _teams[0].containsPlayer(playerObjectId) ? _teams[0].getCoordinates() : null;
}
public static boolean isPlayerParticipant(int playerObjectId)
{
if ((!isParticipating()) && (!isStarting()) && (!isStarted())) {
return false;
}
return (_teams[0].containsPlayer(playerObjectId)) || (_teams[1].containsPlayer(playerObjectId));
}
public static int getParticipatedPlayersCount()
{
if ((!isParticipating()) && (!isStarting()) && (!isStarted())) {
return 0;
}
return _teams[0].getParticipatedPlayerCount() + _teams[1].getParticipatedPlayerCount();
}
public static String[] getTeamNames()
{
return new String[] { _teams[0].getName(), _teams[1].getName() };
}
public static int[] getTeamsPlayerCounts()
{
return new int[] { _teams[0].getParticipatedPlayerCount(), _teams[1].getParticipatedPlayerCount() };
}
public static int[] getTeamsPoints()
{
return new int[] { _teams[0].getPoints(), _teams[1].getPoints() };
}
static enum EventState
{
INACTIVE,
INACTIVATING,
PARTICIPATING,
STARTING,
STARTED,
REWARDING;
}
}