Você não é registrado, por favor registre-se para ter acesso ao conteúdo completo.
Caso seja registrado, efetue login.
Esqueceu sua senha? Clique aqui
Recomendamos o uso do Mozilla Firefox para uma melhor visualização.    


Início Postados Hoje Marcar Fóruns Como Lidos Álbums Banidos SE Team Medalhas
Voltar   Secret Experience > Área L2J > [L2J] Pedidos
Registrar Loteria VIPStaff SERegras do fórum Comunidade Arcade Postados Hoje Pesquisar Experience
   

Secret Experience.NET   Secret Experience Corporation - Welcome To The Real World
     Anúncios SE

Tópico Trancado
 
LinkBack Ferramentas do Tópico Modos de Exibição
Antigo 29-07-2010, 10:03 PM   #1 (permalink)
Amigo SE
 
Avatar de C.Bartowski
 
Registrado em: Feb 2010
Localização: Caxias do Sul - RS
Posts: 644
Agradeceu: 405
Agradecido 582 Vezes em 224 Posts
Achei Ruim:
Acharam ruim Vezes em Posts
Rate Designer: Iniciante
Meu Estado:
Enviar mensagem via Windows Live Messenger para C.Bartowski
Nome Real: Henrique Galafassi Dalssaso

Inventório de C.Bartowski

Padrão Mod CTF para Interlude

Pow galera blz?

Então to muito precisado do Mod do CTF para Interlude...

Pois eu só tenho para Gracia... Mesmo eu Tentando adaptar...

Ta dando errado...

Então vim aqui pedir para voces pra quem tenha o Mod...

Postar aqui para Mim...

AAA UM PORÉM TEM QUE SER AUTOMATICO... POR FAVOR =)

Vlw's

__________________
[Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar] [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar] [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
C.Bartowski está offline  
Links Patrocinados
Antigo 30-07-2010, 01:21 AM   #2 (permalink)
Membro - Veterano
 
Avatar de Maxmilian
 
Registrado em: May 2009
Localização: Dentro do HD
Posts: 532
Agradeceu: 153
Agradecido 220 Vezes em 134 Posts
Achei Ruim:
Acharam ruim Vezes em Posts
Meu Sistema
Meu Estado:
Enviar mensagem via Windows Live Messenger para Maxmilian Enviar mensagem via Yahoo para Maxmilian
Nome Real: Lennielson

Inventório de Maxmilian

Padrão

So uma Duvida sacodalssaso15
Nao reparei muito bem no Pack L2JTeon e L2JMack.
Mais acho que nesse peck deve ter, Mod add CTF ou ate mesmo na L2JRox la tem e fufando bacanda.

Maxmilian está offline  
Antigo 30-07-2010, 08:51 AM   #3 (permalink)
Amigo SE
 
Avatar de SaraxD
 
Registrado em: May 2009
Localização: Praia Grande - SP
Posts: 1,235
Agradeceu: 95
Agradecido 952 Vezes em 495 Posts
Achei Ruim:
Acharam ruim Vezes em Posts
Rate Designer: Iniciante
Meu Estado:
Enviar mensagem via Windows Live Messenger para SaraxD
Nome Real: Sara Banni

Inventório de SaraxD

Padrão

@secodalssaso15
xD
Porquê acha que postei lá no tópico so falto a ctf ?
Já Tentei Arruma-la de Todos os jeitos ainda não Consegui *--*

__________________
[Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
[Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
Thx Arayashiki
SaraxD está offline  
Antigo 30-07-2010, 09:28 AM   #4 (permalink)
Membro - Karma
 
Avatar de B1Z4R0
 
Registrado em: Sep 2009
Localização: Rio Verde GO
Posts: 383
Agradeceu: 265
Agradecido 274 Vezes em 113 Posts
Achei Ruim:
Acharam ruim Vezes em Posts
Meu Sistema
Meu Estado:
Enviar mensagem via Windows Live Messenger para B1Z4R0
Nome Real: Paulo Eduardo Ferreira

Inventório de B1Z4R0

Padrão

CTF Interlude^^
so nao auto, mas developer da rev ai trabalha um pouco, ele coloca

Spoiler
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/network/SystemMessageId.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/network/SystemMessageId.java (revision 146)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/network/SystemMessageId.java (revision 310)
@@ -4779,6 +4779,18 @@
* Message: Observers cannot participate.
*/
- OBSERVERS_CANNOT_PARTICIPATE(781);
-
+ OBSERVERS_CANNOT_PARTICIPATE(781),
+
+ /**
+ * ID: 782<br>
+ * Message: YOU CANNOT MOUNT A STEED WHILE HOLDING A FLAG.
+ */
+ YOU_CANNOT_MOUNT_A_STEED_WHILE_HOLDING_A_FLAG(782) ,
+
+ /**
+ * ID: 783<br>
+ * Message: YOU_CANNOT_MOUNT_A_STEED_WHILE_A_PET_OR_A_SERVITOR _IS_SUMMONED.
+ */
+ YOU_CANNOT_MOUNT_A_STEED_WHILE_A_PET_OR_A_SERVITOR _IS_SUMMONED(783);
+
private int _id;

Index: /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 310)
@@ -30,7 +30,9 @@
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.L2World;
+import net.sf.l2j.gameserver.model.actor.instance.L2Class MasterInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2NpcIn stance;
import net.sf.l2j.gameserver.model.actor.instance.L2PcIns tance;
import net.sf.l2j.gameserver.model.entity.L2Event;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.network.serverpackets.Action Failed;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtm lMessage;
@@ -122,4 +124,25 @@
((L2NpcInstance)object).onBypassFeedback(activeCha r, _command.substring(endOfId+1));
}
+ if (_command.substring(endOfId+1).startsWith("ctf_pla yer_join "))
+ {
+ String teamName = _command.substring(endOfId+1).substring(16);
+
+ if (CTF._joining)
+ CTF.addPlayer(activeChar, teamName);
+ else
+ activeChar.sendMessage("The event is already started. You can not join now!");
+ }
+ else if (_command.substring(endOfId+1).startsWith("ctf_pla yer_leave"))
+ {
+ if (CTF._joining)
+ CTF.removePlayer(activeChar);
+ else
+ activeChar.sendMessage("The event is already started. You can not leave now!");
+ }
+ else if (object instanceof L2ClassMasterInstance || (object instanceof L2NpcInstance && endOfId > 0 && activeChar.isInsideRadius(object, L2NpcInstance.INTERACTION_DISTANCE, false, false)))
+ {
+ ((L2NpcInstance)object).onBypassFeedback(activeCha r, _command.substring(endOfId+1));
+ }
+
activeChar.sendPacket(ActionFailed.STATIC_PACKET);
}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestUnEquipItem.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestUnEquipItem.java (revision 9)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestUnEquipItem.java (revision 310)
@@ -63,4 +63,9 @@
if (activeChar == null)
return;
+ if (activeChar._haveFlagCTF)
+ {
+ activeChar.sendMessage("You can't unequip a CTF flag.");
+ return;
+ }

L2ItemInstance item = activeChar.getInventory().getPaperdollItemByL2Item Id(_slot);
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java (revision 301)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java (revision 310)
@@ -55,4 +55,5 @@
import net.sf.l2j.gameserver.model.entity.Siege;
import net.sf.l2j.gameserver.model.entity.TvTEvent;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.model.quest.Quest;
//import net.sf.l2j.gameserver.model.quest.QuestState;
@@ -461,4 +462,7 @@
TvTEvent.onLogin(activeChar);

+ if (CTF._savePlayers.contains(activeChar.getName()))
+ CTF.addDisconnectedPlayer(activeChar);
+
if(Config.SOCIAL_ENTER_WORLD)
{
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java (revision 231)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestRestart.java (revision 310)
@@ -82,5 +82,14 @@
return;
}
-
+ if (player.isCastingNow())
+ {
+ player.abortCast();
+ }
+
+ if (player.isTeleporting())
+ {
+ player.sendMessage("Sorry you can't logout while use teleport.");
+ return;
+ }
player.getInventory().updateDatabase();

Index: /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestActionUse.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestActionUse.java (revision 231)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestActionUse.java (revision 310)
@@ -161,8 +161,10 @@
activeChar.isInsidePeaceZone(pet, target))
{
+ if(!activeChar.isInFunEvent() || !target.isInFunEvent())
+ {
activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
return;
}
-
+ }
if (target.isAutoAttackable(activeChar) || _ctrlPressed)
{
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/CursedWeapon.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/CursedWeapon.java (revision 9)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/CursedWeapon.java (revision 310)
@@ -30,4 +30,5 @@
import net.sf.l2j.gameserver.instancemanager.CursedWeapon sManager;
import net.sf.l2j.gameserver.model.actor.instance.L2PcIns tance;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.Earthq uake;
@@ -366,5 +367,10 @@
}
}
-
+ if(player._inEventCTF && !Config.CTF_JOIN_CURSED)
+ {
+ if(player._inEventCTF)
+ CTF.removePlayer(player);
+ }
+
_isActivated = true;

Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Summon.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Summon.java (revision 231)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Summon.java (revision 310)
@@ -596,7 +596,11 @@
&& (getOwner().getAccessLevel() < Config.GM_PEACEATTACK))
{
- sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
+ if(!this.isInFunEvent() || !target.isInFunEvent())
+ {
+ // If summon or target is in a peace zone, send a system message TARGET_IN_PEACEZONE
+ sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
return;
}
+ }

if (getOwner() != null && getOwner().isInOlympiadMode() && !getOwner().isOlympiadStart()){
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2NpcInstance.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2NpcInstance.java (revision 231)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2NpcInstance.java (revision 310)
@@ -63,4 +63,5 @@
import net.sf.l2j.gameserver.model.entity.Castle;
import net.sf.l2j.gameserver.model.entity.L2Event;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.model.quest.Quest;
import net.sf.l2j.gameserver.model.quest.QuestState;
@@ -123,5 +124,6 @@
private int _castleIndex = -2;

- public boolean isEventMob = false;
+ public String _CTF_FlagTeamName;
+ public boolean isEventMob = false, _isEventMobCTF = false, _isCTF_throneSpawn = false, _isCTF_Flag = false;
private boolean _isInTown = false;

@@ -657,4 +659,11 @@
// Open a chat window on client with the text of the L2NpcInstance
if(isEventMob){ L2Event.showEventHtml(player, String.valueOf(getObjectId())); }
+ else if (_isEventMobCTF)
+ CTF.showEventHtml(player, String.valueOf(getObjectId()));
+ else if (_isCTF_Flag && player._inEventCTF)
+ CTF.showFlagHtml(player, String.valueOf(this.getObjectId()), _CTF_FlagTeamName);
+ else if (_isCTF_throneSpawn)
+ CTF.CheckRestoreFlags();
+
else
{
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2VillageMasterInstance.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2VillageMasterInstance.java (revision 263)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2VillageMasterInstance.java (revision 310)
@@ -315,4 +315,9 @@
return;
}
+ if (player._inEventCTF)
+ {
+ player.sendMessage("You have already been registered in a waiting list of an event.");
+ return;
+ }

if (allowAddition)
@@ -387,4 +392,9 @@
* Note: paramOne = classIndex
*/
+ if (player._inEventCTF)
+ {
+ player.sendMessage("You have already been registered in a waiting list of an event.");
+ return;
+ }

if (Olympiad.getInstance().isRegisteredInComp(player)
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 310)
@@ -27,4 +27,5 @@
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -134,4 +135,5 @@
import net.sf.l2j.gameserver.model.entity.Siege;
import net.sf.l2j.gameserver.model.entity.TvTEvent;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.model.quest.Quest;
import net.sf.l2j.gameserver.model.quest.QuestState;
@@ -606,5 +608,12 @@
public boolean eventSitForced = false;
public boolean atEvent = false;
-
+
+ /** CTF Engine parameters */
+ public String _teamNameCTF, _teamNameHaveFlagCTF, _originalTitleCTF;
+ public int _originalNameColorCTF, _originalKarmaCTF, _countCTFflags;
+ public boolean _inEventCTF = false, _haveFlagCTF = false;
+ public Future<?> _posCheckerCTF = null;
+
+
/** new loto ticket **/
private int _loto[] = new int[5];
@@ -2412,4 +2421,6 @@
sendMessage("A dark force beyond your mortal understanding makes your knees to shake when you try to stand up ...");
}
+ else if (CTF._sitForced && _inEventCTF)
+ sendMessage("The Admin/GM handle if you sit or stand in this match!");
else if (isAway())
sendMessage("You can't stand up if your Status is Away");
@@ -3419,4 +3430,12 @@
return;
}
+ if (CTF._started && !Config.CTF_ALLOW_INTERFERENCE)
+ {
+ if ((_inEventCTF && !player._inEventCTF) || (!_inEventCTF && player._inEventCTF))
+ {
+ sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }
+ }

// Check if the L2PcInstance is confused
@@ -3450,5 +3469,5 @@
{
// Check if this L2PcInstance is autoAttackable
- if (isAutoAttackable(player))
+ if (isAutoAttackable(player) || (player._inEventCTF && CTF._started))
{
if (Config.ANTI_PK_LOW_LEVEL)
@@ -3573,5 +3592,4 @@
}
}
-

/**
@@ -4311,4 +4329,25 @@

TvTEvent.onKill(killer, this);
+ if (_inEventCTF)
+ {
+ if (CTF._teleport || CTF._started)
+ {
+ sendMessage("You will be revived and teleported to team flag in " + Config.CTF_REVIVE_DELAY / 1000 + " seconds!");
+
+ if (_haveFlagCTF)
+ removeCTFFlagOnDie();
+
+ ThreadPoolManager.getInstance().scheduleGeneral(ne w Runnable()
+ {
+ public void run()
+ {
+ teleToLocation(CTF._teamsX.get(CTF._teams.indexOf( _teamNameCTF)), CTF._teamsY.get(CTF._teams.indexOf(_teamNameCTF)), CTF._teamsZ
+ .get(CTF._teams.indexOf(_teamNameCTF)), false);
+ doRevive();
+ }
+ }, Config.CTF_REVIVE_DELAY);
+ }
+ }
+

if (atEvent && pk != null)
@@ -4417,8 +4456,16 @@
return true;
}
-
+ public void removeCTFFlagOnDie()
+ {
+ CTF._flagsTaken.set(CTF._teams.indexOf(_teamNameHa veFlagCTF), false);
+ CTF.spawnFlag(_teamNameHaveFlagCTF);
+ CTF.removeFlagFromPlayer(this);
+ broadcastUserInfo();
+ _haveFlagCTF = false;
+ CTF.AnnounceToPlayers(false, CTF._eventName + "(CTF): " + _teamNameHaveFlagCTF + "'s flag returned.");
+ }
private void onDieDropItem(L2Character killer)
{
- if (atEvent || killer == null)
+ if (atEvent || (CTF._started && _inEventCTF) || killer == null)
return;

@@ -4536,4 +4583,7 @@
if (target == null) return;
if (!(target instanceof L2PlayableInstance)) return;
+
+ if (_inEventCTF)
+ return;

L2PcInstance targetPlayer = null;
@@ -4623,4 +4673,7 @@
public void increasePvpKills()
{
+ if (CTF._started && _inEventCTF)
+ return;
+
// Add karma to attacker and increase its PK counter
setPvpKills(getPvpKills() + 1);
@@ -4705,4 +4758,7 @@
public void increasePkKillsAndKarma(int targLVL)
{
+ if (CTF._started && _inEventCTF)
+ return;
+
int baseKarma = Config.KARMA_MIN_KARMA;
int newKarma = baseKarma;
@@ -4782,4 +4838,7 @@
public void updatePvPStatus()
{
+ if (CTF._started && _inEventCTF)
+ return;
+
if (isInsideZone(ZONE_PVP)) return;
setPvpFlagLasts(System.currentTimeMillis() + Config.PVP_NORMAL_TIME);
@@ -4800,4 +4859,7 @@
if (player_target == null)
return;
+
+ if (CTF._started && _inEventCTF && player_target._inEventCTF)
+ return;

if ((isInDuel() && player_target.getDuelId() == getDuelId())) return;
@@ -4865,5 +4927,5 @@
// Calculate the Experience loss
long lostExp = 0;
- if (!atEvent)
+ if (!atEvent && !_inEventCTF)
if (lvl < Experience.MAX_LEVEL)
lostExp = Math.round((getStat().getExpForLevel(lvl+1) - getStat().getExpForLevel(lvl)) * percentLost /100);
@@ -7226,5 +7288,12 @@
public void useMagic(L2Skill skill, boolean forceUse, boolean dontMove)
{
- if (isDead())
+ if (_haveFlagCTF)
+ {
+ // You cannot mount a steed while holding a flag.
+ SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_S TEED_WHILE_HOLDING_A_FLAG);
+ return;
+ }
+ else if (isDead())
+
{
abortCast();
@@ -7487,9 +7556,12 @@
if ((isInsidePeaceZone(this, target)) && (getAccessLevel() < Config.GM_PEACEATTACK))
{
- // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
- sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
+ if(!this.isInFunEvent() || !target.isInFunEvent())
+ {
+ // If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
+ sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
+ sendPacket(ActionFailed.STATIC_PACKET);
+ return ;
}
+ }

if (isInOlympiadMode() && !isOlympiadStart()){
@@ -7502,8 +7574,19 @@
if (!target.isAttackable() && (getAccessLevel() < Config.GM_PEACEATTACK))
{
- // If target is not attackable, send a Server->Client packet ActionFailed
- sendPacket(ActionFailed.STATIC_PACKET);
- return;
- }
+ if(!this.isInFunEvent() || !target.isInFunEvent())
+ {
+ // If target is not attackable, send a Server->Client packet ActionFailed
+ sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }
+ if(!this.isInFunEvent() || !target.isInFunEvent())
+ {
+ //Sends a sys msg to client
+ sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
+ // Send a Server->Client packet ActionFailed to the L2PcInstance
+ sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }
+ }

// Check if a Forced ATTACK is in progress on non-attackable target
@@ -7625,4 +7708,7 @@
if (!checkPvpSkill(target, skill) && (getAccessLevel() < Config.GM_PEACEATTACK))
{
+ if(!this.isInFunEvent() || !target.isInFunEvent())
+ {
+
// Send a System Message to the L2PcInstance
sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT) );
@@ -7633,5 +7719,5 @@
}
}
-
+ }
if (sklTargetType == SkillTargetType.TARGET_HOLY &&
!TakeCastle.checkIfOkToCastSealOfRule(this, false))
@@ -7695,4 +7781,7 @@
public boolean checkPvpSkill(L2Object target, L2Skill skill)
{
+ if (_inEventCTF && CTF._started)
+ return true;
+
// check for PC->PC Pvp status
if (
@@ -9261,4 +9350,11 @@
getParty().getDimensionalRift().memberRessurected( this);
}
+ if (_inEventCTF && CTF._started && Config.CTF_REVIVE_RECOVERY)
+ {
+ getStatus().setCurrentHp(getMaxHp());
+ getStatus().setCurrentMp(getMaxMp());
+ getStatus().setCurrentCp(getMaxCp());
+ }
+
}

Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java (revision 9)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/actor/stat/PcStat.java (revision 310)
@@ -29,4 +29,5 @@
import net.sf.l2j.gameserver.model.actor.instance.L2PetIn stance;
import net.sf.l2j.gameserver.model.base.Experience;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.Pledge ShowMemberListUpdate;
@@ -216,4 +217,11 @@
getActiveChar().broadcastPacket(new SocialAction(getActiveChar().getObjectId(), 15));
getActiveChar().sendPacket(new SystemMessage(SystemMessageId.YOU_INCREASED_YOUR_L EVEL));
+
+ if (getActiveChar().isInFunEvent())
+ {
+ if (getActiveChar()._inEventCTF && CTF._maxlvl == getLevel() && !CTF._started)
+ CTF.removePlayer(getActiveChar());
+ getActiveChar().sendMessage("Your event sign up was canceled.");
+ }
}

Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Radar.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Radar.java (revision 9)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Radar.java (revision 310)
@@ -20,4 +20,5 @@
import java.util.Vector;

+import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.model.actor.instance.L2PcIns tance;
import net.sf.l2j.gameserver.network.serverpackets.RadarC ontrol;
@@ -110,3 +111,31 @@
}
}
+ public class RadarOnPlayer implements Runnable
+ {
+ private final L2PcInstance _myTarget, _me;
+
+ public RadarOnPlayer(L2PcInstance target, L2PcInstance me)
+ {
+ _me = me;
+ _myTarget = target;
+ }
+
+ public void run()
+ {
+ try
+ {
+ if (_me == null || _me.isOnline()==0)
+ return;
+
+ _me.sendPacket(new RadarControl(1, 1, _me.getX(), _me.getY(), _me.getZ()));
+ if (_myTarget == null || _myTarget.isOnline()==0 || !_myTarget._haveFlagCTF)
+ return;
+
+ _me.sendPacket(new RadarControl(0, 1, _myTarget.getX(), _myTarget.getY(), _myTarget.getZ()));
+ ThreadPoolManager.getInstance().scheduleGeneral(ne w RadarOnPlayer(_myTarget,_me), 15000);
+ }
+ catch(Throwable t)
+ {}
+ }
+ }
}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Object.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Object.java (revision 301)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Object.java (revision 310)
@@ -390,3 +390,13 @@
return "" + getObjectId();
}
+ public boolean isInFunEvent()
+ {
+ L2PcInstance player = getActingPlayer();
+
+ return (player == null ? false : player.isInFunEvent());
+ }
+ public L2PcInstance getActingPlayer()
+ {
+ return null;
+ }
}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Skill.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Skill.java (revision 231)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Skill.java (revision 310)
@@ -27,4 +27,5 @@
import javolution.text.TextBuilder;
import javolution.util.FastList;
+import net.sf.l2j.Config;
import net.sf.l2j.gameserver.GeoData;
import net.sf.l2j.gameserver.datatables.HeroSkillTable;
@@ -39,4 +40,5 @@
import net.sf.l2j.gameserver.model.actor.instance.L2Playa bleInstance;
import net.sf.l2j.gameserver.model.actor.instance.L2Summo nInstance;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.model.base.ClassId;
import net.sf.l2j.gameserver.network.SystemMessageId;
@@ -1571,5 +1573,11 @@
if (partyMember == null) continue;
if (partyMember == player) continue;
-
+ //check if allow interference is allowed if player is not on event but target is on event
+ if ((CTF._started && !Config.CTF_ALLOW_INTERFERENCE) && !player.isGM())
+ {
+ if ((partyMember._inEventCTF && !player._inEventCTF) || (!partyMember._inEventCTF && player._inEventCTF))
+ continue;
+ }
+
if (!partyMember.isDead()
&& Util.checkIfInRange(getSkillRadius(), activeChar, partyMember, true))
@@ -1735,4 +1743,10 @@
}
}
+ //check if allow interference is allowed if player is not on event but target is on event
+ if ((CTF._started && !Config.CTF_ALLOW_INTERFERENCE) && !player.isGM())
+ {
+ if ((newTarget._inEventCTF && !player._inEventCTF) || (!newTarget._inEventCTF && player._inEventCTF))
+ continue;
+ }
if (player.isInDuel() &&
(
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Character.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Character.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/L2Character.java (revision 310)
@@ -4977,6 +4977,10 @@
{
// If L2Character or target is in a peace zone, send a system message TARGET_IN_PEACEZONE a Server->Client packet ActionFailed
- player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
- player.sendPacket(ActionFailed.STATIC_PACKET);
+ if(!player.isInFunEvent() || !player.getTarget().isInFunEvent())
+ {
+ player.sendPacket(new SystemMessage(SystemMessageId.TARGET_IN_PEACEZONE) );
+ player.sendPacket(ActionFailed.STATIC_PACKET);
+ }
+
}
else if (player.isInOlympiadMode() && player.getTarget() != null)
@@ -5028,5 +5032,10 @@
public boolean isInsidePeaceZone(L2PcInstance attacker)
{
+ if(!this.isInFunEvent() || !attacker.isInFunEvent())
+ {
return isInsidePeaceZone(attacker, this);
+ }
+ return false;
+
}

Index: /trunk/GameServer/java/net/sf/l2j/gameserver/model/entity/CTF.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/model/entity/CTF.java (revision 310)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/model/entity/CTF.java (revision 310)
@@ -0,0 +1,2262 @@
+/* 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 2, 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
+ */
+package net.sf.l2j.gameserver.model.entity;
+
+/**
+ *
+ * @author Administrator
+ */
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Vector;
+
+import javolution.text.TextBuilder;
+
+import java.util.logging.Logger;
+
+import net.sf.l2j.Config;
+import net.sf.l2j.L2DatabaseFactory;
+import net.sf.l2j.gameserver.Announcements;
+import net.sf.l2j.gameserver.ThreadPoolManager;
+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.L2Effect;
+import net.sf.l2j.gameserver.model.L2ItemInstance;
+import net.sf.l2j.gameserver.model.L2Party;
+import net.sf.l2j.gameserver.model.L2Radar;
+import net.sf.l2j.gameserver.model.L2Spawn;
+import net.sf.l2j.gameserver.model.L2Summon;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcIns tance;
+import net.sf.l2j.gameserver.model.actor.instance.L2PetIn stance;
+import net.sf.l2j.gameserver.model.Inventory;
+import net.sf.l2j.gameserver.network.SystemMessageId;
+import net.sf.l2j.gameserver.network.serverpackets.Action Failed;
+import net.sf.l2j.gameserver.network.serverpackets.Creatu reSay;
+import net.sf.l2j.gameserver.network.serverpackets.Invent oryUpdate;
+import net.sf.l2j.gameserver.network.serverpackets.ItemLi st;
+import net.sf.l2j.gameserver.network.serverpackets.MagicS killUser;
+import net.sf.l2j.gameserver.network.serverpackets.NpcHtm lMessage;
+import net.sf.l2j.gameserver.network.serverpackets.PlaySo und;
+import net.sf.l2j.gameserver.network.serverpackets.RadarC ontrol;
+import net.sf.l2j.gameserver.network.serverpackets.System Message;
+import net.sf.l2j.gameserver.network.serverpackets.Social Action;
+import net.sf.l2j.gameserver.templates.L2NpcTemplate;
+import net.sf.l2j.util.Rnd;
+
+public class CTF
+{
+ private final static Logger _log = Logger.getLogger(CTF.class.getName());
+ private static int _FlagNPC = 35062, _FLAG_IN_HAND_ITEM_ID = 6718;
+ public static String _eventName = new String(), _eventDesc = new String(), _topTeam = new String(), _joiningLocationName = new String();
+ public static Vector<String> _teams = new Vector<String>(), _savePlayers = new Vector<String>(), _savePlayerTeams = new Vector<String>();
+ public static Vector<L2PcInstance> _players = new Vector<L2PcInstance>(), _playersShuffle = new Vector<L2PcInstance>();
+ public static Vector<Integer> _teamPlayersCount = new Vector<Integer>(), _teamColors = new Vector<Integer>(), _teamsX = new Vector<Integer>(),
+ _teamsY = new Vector<Integer>(), _teamsZ = new Vector<Integer>();
+ public static boolean _joining = false, _teleport = false, _started = false, _sitForced = false;
+ public static L2Spawn _npcSpawn;
+ public static int _npcId = 0, _npcX = 0, _npcY = 0, _npcZ = 0, _npcHeading = 0, _rewardId = 0, _rewardAmount = 0,
+ _minlvl = 0, _maxlvl = 0, _joinTime = 0, _eventTime = 0, _minPlayers = 0, _maxPlayers = 0;
+ public static Vector<Integer> _teamPointsCount = new Vector<Integer>();
+ public static Vector<Integer> _flagIds = new Vector<Integer>(), _flagsX = new Vector<Integer>(), _flagsY = new Vector<Integer>(),
+ _flagsZ = new Vector<Integer>();
+ public static Vector<L2Spawn> _flagSpawns = new Vector<L2Spawn>(), _throneSpawns = new Vector<L2Spawn>();
+ public static Vector<Boolean> _flagsTaken = new Vector<Boolean>();
+ public static int _topScore = 0, eventCenterX = 0, eventCenterY = 0, eventCenterZ = 0, eventOffset = 0;
+
+ public static void showFlagHtml(L2PcInstance eventPlayer, String objectId, String teamName)
+ {
+ if (eventPlayer == null)
+ return;
+
+ try
+ {
+ NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
+
+ TextBuilder replyMSG = new TextBuilder("<html><body><center>");
+ replyMSG.append("CTF Flag<br><br>");
+ replyMSG.append("<font color=\"00FF00\">" + teamName + "'s Flag</font><br1>");
+ if (eventPlayer._teamNameCTF != null && eventPlayer._teamNameCTF.equals(teamName))
+ replyMSG.append("<font color=\"LEVEL\">This is your Flag</font><br1>");
+ else
+ replyMSG.append("<font color=\"LEVEL\">Enemy Flag!</font><br1>");
+ if (_started)
+ {
+ processInFlagRange(eventPlayer);
+ }
+ else
+ replyMSG.append("CTF match is not in progress yet.<br>Wait for a GM to start the event<br>");
+ replyMSG.append("</center></body></html>");
+ adminReply.setHtml(replyMSG.toString());
+ eventPlayer.sendPacket(adminReply);
+ }
+ catch (Exception e)
+ {
+ _log.warning("" + "CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception: " + e.getStackTrace());
+ }
+ }
+
+ public static void CheckRestoreFlags()
+ {
+ Vector<Integer> teamsTakenFlag = new Vector<Integer>();
+ try
+ {
+ for (L2PcInstance player : _players)
+ { //if there's a player with a flag
+ //add the index of the team who's FLAG WAS TAKEN to the list
+ if (player != null)
+ {
+ if (player.isOnline() == 0 && player._haveFlagCTF)// logged off with a flag in his hands
+ {
+ AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " logged off with a CTF flag!");
+ player._haveFlagCTF = false;
+ if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
+ {
+ if (_flagsTaken.get(_teams.indexOf(player._teamNameHa veFlagCTF)))
+ {
+ _flagsTaken.set(_teams.indexOf(player._teamNameHav eFlagCTF), false);
+ spawnFlag(player._teamNameHaveFlagCTF);
+ AnnounceToPlayers(false, _eventName + "(CTF): " + player._teamNameHaveFlagCTF + " flag now returned to place.");
+ }
+ }
+ removeFlagFromPlayer(player);
+ player._teamNameHaveFlagCTF = null;
+ return;
+ }
+ else if (player._haveFlagCTF)
+ teamsTakenFlag.add(_teams.indexOf(player._teamName HaveFlagCTF));
+ }
+ }
+ //Go over the list of ALL teams
+ for (String team : _teams)
+ {
+ if (team == null)
+ continue;
+ int index = _teams.indexOf(team);
+ if (!teamsTakenFlag.contains(index))
+ {
+ if (_flagsTaken.get(index))
+ {
+ _flagsTaken.set(index, false);
+ spawnFlag(team);
+ AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag returned due to player error.");
+ }
+ }
+ }
+ //Check if a player ran away from the event holding a flag:
+ for (L2PcInstance player : _players)
+ {
+ if (player != null && player._haveFlagCTF)
+ {
+ if (isOutsideCTFArea(player))
+ {
+ AnnounceToPlayers(false, _eventName + "(CTF): " + player.getName() + " escaped from the event holding a flag!");
+ player._haveFlagCTF = false;
+ if (_teams.indexOf(player._teamNameHaveFlagCTF) >= 0)
+ {
+ if (_flagsTaken.get(_teams.indexOf(player._teamNameHa veFlagCTF)))
+ {
+ _flagsTaken.set(_teams.indexOf(player._teamNameHav eFlagCTF), false);
+ spawnFlag(player._teamNameHaveFlagCTF);
+ AnnounceToPlayers(false, _eventName + "(CTF): " + player._teamNameHaveFlagCTF + " flag now returned to place.");
+ }
+ }
+ removeFlagFromPlayer(player);
+ player._teamNameHaveFlagCTF = null;
+ player.teleToLocation(_teamsX.get(_teams.indexOf(p layer._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ
+ .get(_teams.indexOf(player._teamNameCTF)));
+ player.sendMessage("You have been returned to your team spawn");
+ return;
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF.restoreFlags() Error:" + e.toString());
+ }
+ }
+
+ public static void kickPlayerFromCTf(L2PcInstance playerToKick)
+ {
+ if (playerToKick == null)
+ return;
+
+ if (_joining)
+ {
+ _playersShuffle.remove(playerToKick);
+ _players.remove(playerToKick);
+ playerToKick._inEventCTF = false;
+ playerToKick._teamNameCTF = new String();
+ }
+ if (_started || _teleport)
+ {
+ _playersShuffle.remove(playerToKick);
+ playerToKick._inEventCTF = false;
+ removePlayer(playerToKick);
+ if (playerToKick.isOnline() != 0)
+ {
+ playerToKick.getAppearance().setNameColor(playerTo Kick._originalNameColorCTF);
+ playerToKick.setKarma(playerToKick._originalKarmaC TF);
+ playerToKick.setTitle(playerToKick._originalTitleC TF);
+ playerToKick.broadcastUserInfo();
+ playerToKick.sendMessage("You have been kicked from the CTF.");
+ playerToKick.teleToLocation(_npcX, _npcY, _npcZ, false);
+ }
+ }
+ }
+
+ public static void AnnounceToPlayers(Boolean toall, String announce)
+ {
+ if (toall)
+ Announcements.getInstance().announceToAll(announce );
+ else
+ {
+ CreatureSay cs = new CreatureSay(0, 2, "", "Announcements : " + announce);
+ if (_players != null && !_players.isEmpty())
+ {
+ for (L2PcInstance player : _players)
+ {
+ if (player != null && player.isOnline() != 0)
+ player.sendPacket(cs);
+ }
+ }
+ }
+ }
+
+ public static void Started(L2PcInstance player)
+ {
+ player._teamNameHaveFlagCTF = null;
+ player._haveFlagCTF = false;
+ }
+
+ public static void StartEvent()
+ {
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ player._teamNameHaveFlagCTF = null;
+ player._haveFlagCTF = false;
+ }
+ }
+ AnnounceToPlayers(false, _eventName + "(CTF): Started. Go Capture the Flags!");
+ }
+
+ public static void addFlagToPlayer(L2PcInstance _player)
+ {
+ //remove items from the player hands (right, left, both)
+ // This is NOT a BUG, I don't want them to see the icon they have 8D
+ L2ItemInstance wpn = _player.getInventory().getPaperdollItem(Inventory. PAPERDOLL_RHAND);
+ if (wpn == null)
+ {
+ wpn = _player.getInventory().getPaperdollItem(Inventory. PAPERDOLL_RHAND);
+ if (wpn != null)
+ _player.getInventory().unEquipItemInBodySlotAndRec ord(Inventory.PAPERDOLL_RHAND);
+ }
+ else
+ {
+ _player.getInventory().unEquipItemInBodySlotAndRec ord(Inventory.PAPERDOLL_RHAND);
+ wpn = _player.getInventory().getPaperdollItem(Inventory. PAPERDOLL_LHAND);
+ if (wpn != null)
+ _player.getInventory().unEquipItemInBodySlotAndRec ord(Inventory.PAPERDOLL_LHAND);
+ }
+ //add the flag in his hands
+ _player.getInventory().equipItem(ItemTable.getInst ance().createItem("", CTF._FLAG_IN_HAND_ITEM_ID, 1, _player, null));
+ _player.broadcastPacket(new SocialAction(_player.getObjectId(), 16)); //amazing glow
+ _player._haveFlagCTF = true;
+ _player.broadcastUserInfo();
+ CreatureSay cs = new CreatureSay(_player.getObjectId(), 15, ":", "You got it! Run back! ::"); // 8D
+ _player.sendPacket(cs);
+ }
+
+ public static void removeFlagFromPlayer(L2PcInstance player)
+ {
+ L2ItemInstance wpn = player.getInventory().getPaperdollItem(Inventory.P APERDOLL_RHAND);
+ player._haveFlagCTF = false;
+ if (wpn != null)
+ {
+ L2ItemInstance[] unequiped = player.getInventory().unEquipItemInBodySlotAndReco rd(wpn.getItem().getBodyPart());
+ player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
+ InventoryUpdate iu = new InventoryUpdate();
+ for (L2ItemInstance element : unequiped)
+ iu.addModifiedItem(element);
+ player.sendPacket(iu);
+ player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
+ player.abortAttack();
+ player.broadcastUserInfo();
+ }
+ else
+ {
+ player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
+ player.sendPacket(new ItemList(player, true)); // get your weapon back now ...
+ player.abortAttack();
+ player.broadcastUserInfo();
+ }
+ }
+
+ public static void setTeamFlag(String teamName, L2PcInstance activeChar)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+ addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, activeChar.getX(), activeChar.getY(), activeChar.getZ());
+ }
+
+ public static void setTeamFlag(String teamName, int x, int y, int z)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+ addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, x, y, z);
+ }
+
+ public static void spawnAllFlags()
+ {
+ while (_flagSpawns.size() < _teams.size())
+ _flagSpawns.add(null);
+ while (_throneSpawns.size() < _teams.size())
+ _throneSpawns.add(null);
+ for (String team : _teams)
+ {
+ int index = _teams.indexOf(team);
+ L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(in dex));
+ L2NpcTemplate throne = NpcTable.getInstance().getTemplate(32027);
+ try
+ {
+ //spawn throne
+ _throneSpawns.set(index, new L2Spawn(throne));
+ _throneSpawns.get(index).setLocx(_flagsX.get(index ));
+ _throneSpawns.get(index).setLocy(_flagsY.get(index ));
+ _throneSpawns.get(index).setLocz(_flagsZ.get(index ) - 10);
+ _throneSpawns.get(index).setAmount(1);
+ _throneSpawns.get(index).setHeading(0);
+ _throneSpawns.get(index).setRespawnDelay(1);
+ SpawnTable.getInstance().addNewSpawn(_throneSpawns .get(index), false);
+ _throneSpawns.get(index).init();
+ _throneSpawns.get(index).getLastSpawn().getStatus( ).setCurrentHp(999999999);
+ _throneSpawns.get(index).getLastSpawn().decayMe();
+ _throneSpawns.get(index).getLastSpawn().spawnMe(_t hroneSpawns.get(index).getLastSpawn().getX(), _throneSpawns.get(index).getLastSpawn().getY(),
+ _throneSpawns.get(index).getLastSpawn().getZ());
+ _throneSpawns.get(index).getLastSpawn().setTitle(t eam + " Throne");
+ _throneSpawns.get(index).getLastSpawn().broadcastP acket(
+ new MagicSkillUser(_throneSpawns.get(index).getLastSpa wn(), _throneSpawns.get(index).getLastSpawn(), 1036, 1, 5500, 1));
+ _throneSpawns.get(index).getLastSpawn()._isCTF_thr oneSpawn = true;
+ //spawn flag
+ _flagSpawns.set(index, new L2Spawn(tmpl));
+ _flagSpawns.get(index).setLocx(_flagsX.get(index)) ;
+ _flagSpawns.get(index).setLocy(_flagsY.get(index)) ;
+ _flagSpawns.get(index).setLocz(_flagsZ.get(index)) ;
+ _flagSpawns.get(index).setAmount(1);
+ _flagSpawns.get(index).setHeading(0);
+ _flagSpawns.get(index).setRespawnDelay(1);
+ SpawnTable.getInstance().addNewSpawn(_flagSpawns.g et(index), false);
+ _flagSpawns.get(index).init();
+ _flagSpawns.get(index).getLastSpawn().getStatus(). setCurrentHp(999999999);
+ _flagSpawns.get(index).getLastSpawn().setTitle(tea m + "'s Flag");
+ _flagSpawns.get(index).getLastSpawn()._CTF_FlagTea mName = team;
+ _flagSpawns.get(index).getLastSpawn().decayMe();
+ _flagSpawns.get(index).getLastSpawn().spawnMe(_fla gSpawns.get(index).getLastSpawn().getX(), _flagSpawns.get(index).getLastSpawn().getY(),
+ _flagSpawns.get(index).getLastSpawn().getZ());
+ _flagSpawns.get(index).getLastSpawn()._isCTF_Flag = true;
+ calculateOutSideOfCTF(); // sets event boundaries so players don't run with the flag.
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Engine[spawnAllFlags()]: exception: " + e.getStackTrace());
+ }
+ }
+ }
+
+ public static void processTopTeam()
+ {
+
+ _topTeam = null;
+ for (String team : _teams)
+ {
+ if (teamPointsCount(team) == _topScore && _topScore > 0)
+ _topTeam = null;
+ if (teamPointsCount(team) > _topScore)
+ {
+ _topTeam = team;
+ _topScore = teamPointsCount(team);
+ }
+ }
+ if (_topScore <= 0)
+ {
+ AnnounceToPlayers(true, _eventName + "(CTF): No flags taken).");
+ }
+ else
+ {
+ if (_topTeam == null)
+ AnnounceToPlayers(true, _eventName + "(CTF): Maximum flags taken : " + _topScore + " flags! No one won.");
+ else
+ {
+ AnnounceToPlayers(true, _eventName + "(CTF): Team " + _topTeam + " wins the match, with " + _topScore + " flags taken!");
+ rewardTeam(_topTeam);
+ }
+ }
+ teleportFinish();
+ }
+
+ public static void unspawnAllFlags()
+ {
+ try
+ {
+ if (_throneSpawns == null || _flagSpawns == null || _teams == null)
+ return;
+ for (String team : _teams)
+ {
+ int index = _teams.indexOf(team);
+ if (_throneSpawns.get(index) != null)
+ {
+ _throneSpawns.get(index).getLastSpawn().deleteMe() ;
+ _throneSpawns.get(index).stopRespawn();
+ SpawnTable.getInstance().deleteSpawn(_throneSpawns .get(index), true);
+ }
+ if (_flagSpawns.get(index) != null)
+ {
+ _flagSpawns.get(index).getLastSpawn().deleteMe();
+ _flagSpawns.get(index).stopRespawn();
+ SpawnTable.getInstance().deleteSpawn(_flagSpawns.g et(index), true);
+ }
+ }
+ _throneSpawns.removeAllElements();
+ }
+ catch (Throwable t)
+ {
+ _log.warning("CTF Engine[unspawnAllFlags()]: exception: " + t.getStackTrace());
+ }
+ }
+
+ private static void unspawnFlag(String teamName)
+ {
+ int index = _teams.indexOf(teamName);
+
+ _flagSpawns.get(index).getLastSpawn().deleteMe();
+ _flagSpawns.get(index).stopRespawn();
+ SpawnTable.getInstance().deleteSpawn(_flagSpawns.g et(index), true);
+ }
+
+ public static void spawnFlag(String teamName)
+ {
+ int index = _teams.indexOf(teamName);
+ L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_flagIds.get(in dex));
+
+ try
+ {
+ _flagSpawns.set(index, new L2Spawn(tmpl));
+
+ _flagSpawns.get(index).setLocx(_flagsX.get(index)) ;
+ _flagSpawns.get(index).setLocy(_flagsY.get(index)) ;
+ _flagSpawns.get(index).setLocz(_flagsZ.get(index)) ;
+ _flagSpawns.get(index).setAmount(1);
+ _flagSpawns.get(index).setHeading(0);
+ _flagSpawns.get(index).setRespawnDelay(1);
+
+ SpawnTable.getInstance().addNewSpawn(_flagSpawns.g et(index), false);
+
+ _flagSpawns.get(index).init();
+ _flagSpawns.get(index).getLastSpawn().getStatus(). setCurrentHp(999999999);
+ _flagSpawns.get(index).getLastSpawn().setTitle(tea mName + "'s Flag");
+ _flagSpawns.get(index).getLastSpawn()._CTF_FlagTea mName = teamName;
+ _flagSpawns.get(index).getLastSpawn()._isCTF_Flag = true;
+ _flagSpawns.get(index).getLastSpawn().decayMe();
+ _flagSpawns.get(index).getLastSpawn().spawnMe(_fla gSpawns.get(index).getLastSpawn().getX(), _flagSpawns.get(index).getLastSpawn().getY(),
+ _flagSpawns.get(index).getLastSpawn().getZ());
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Engine[spawnFlag(" + teamName + ")]: exception: " + e.getStackTrace());
+ }
+ }
+
+ public static boolean InRangeOfFlag(L2PcInstance _player, int flagIndex, int offset)
+ {
+ if (_player.getX() > CTF._flagsX.get(flagIndex) - offset && _player.getX() < CTF._flagsX.get(flagIndex) + offset
+ && _player.getY() > CTF._flagsY.get(flagIndex) - offset && _player.getY() < CTF._flagsY.get(flagIndex) + offset
+ && _player.getZ() > CTF._flagsZ.get(flagIndex) - offset && _player.getZ() < CTF._flagsZ.get(flagIndex) + offset)
+ return true;
+ return false;
+ }
+
+ public static void processInFlagRange(L2PcInstance _player)
+ {
+ try
+ {
+ CheckRestoreFlags();
+ for (String team : _teams)
+ {
+ if (team.equals(_player._teamNameCTF))
+ {
+ int indexOwn = _teams.indexOf(_player._teamNameCTF);
+
+ //if player is near his team flag holding the enemy flag
+ if (InRangeOfFlag(_player, indexOwn, 100) && !_flagsTaken.get(indexOwn) && _player._haveFlagCTF)
+ {
+ int indexEnemy = _teams.indexOf(_player._teamNameHaveFlagCTF);
+ //return enemy flag to place
+ _flagsTaken.set(indexEnemy, false);
+ spawnFlag(_player._teamNameHaveFlagCTF);
+ //remove the flag from this player
+ _player.broadcastPacket(new SocialAction(_player.getObjectId(), 16)); // amazing glow
+ _player.broadcastUserInfo();
+ _player.broadcastPacket(new SocialAction(_player.getObjectId(), 3)); // Victory
+ _player.broadcastUserInfo();
+ removeFlagFromPlayer(_player);
+ _teamPointsCount.set(indexOwn, teamPointsCount(team) + 1);
+ _player.broadcastPacket(new PlaySound(0, "ItemSound.quest_finish", 1, _player.getObjectId(), _player.getX(), _player.getY(), _player
+ .getZ()));
+ _player.broadcastUserInfo();
+ AnnounceToPlayers(false, _eventName + "(CTF): " + _player.getName() + " scores for " + _player._teamNameCTF + ".");
+ }
+ }
+ else
+ {
+ int indexEnemy = _teams.indexOf(team);
+ //if the player is near a enemy flag
+ if (InRangeOfFlag(_player, indexEnemy, 100) && !_flagsTaken.get(indexEnemy) && !_player._haveFlagCTF && !_player.isDead())
+ {
+ if(_player.isRiding() || _player.isFlying())
+ {
+ _player.sendPacket(new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_S TEED_WHILE_A_PET_OR_A_SERVITOR_IS_SUMMONED));
+ break;
+ }
+
+ _flagsTaken.set(indexEnemy, true);
+ unspawnFlag(team);
+ _player._teamNameHaveFlagCTF = team;
+ addFlagToPlayer(_player);
+ _player.broadcastUserInfo();
+ _player._haveFlagCTF = true;
+ AnnounceToPlayers(false, _eventName + "(CTF): " + team + " flag taken by " + _player.getName() + "...");
+ pointTeamTo(_player, team);
+ break;
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public static void pointTeamTo(L2PcInstance hasFlag, String ourFlag)
+ {
+ try
+ {
+ for (L2PcInstance player : _players)
+ {
+ if (player != null && player.isOnline() != 0)
+ {
+ if (player._teamNameCTF.equals(ourFlag))
+ {
+ player.sendMessage(hasFlag.getName() + " took your flag!");
+ if (player._haveFlagCTF)
+ {
+ player.sendMessage("You can not return the flag to headquarters, until your flag is returned to it's place.");
+ player.sendPacket(new RadarControl(1, 1, player.getX(), player.getY(), player.getZ()));
+ }
+ else
+ {
+ player.sendPacket(new RadarControl(0, 1, hasFlag.getX(), hasFlag.getY(), hasFlag.getZ()));
+ L2Radar rdr = new L2Radar(player);
+ L2Radar.RadarOnPlayer radar = rdr.new RadarOnPlayer(hasFlag, player);
+ ThreadPoolManager.getInstance().scheduleGeneral(ra dar,+ 10000 + Rnd.get(30000));
+ }
+ }
+ }
+ }
+ }
+ catch (Throwable t)
+ {
+ }
+ }
+
+ public static int teamPointsCount(String teamName)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return -1;
+
+ return _teamPointsCount.get(index);
+ }
+
+ public static void setTeamPointsCount(String teamName, int teamPointCount)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+
+ _teamPointsCount.set(index, teamPointCount);
+ }
+
+ 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);
+ }
+
+ public static void setNpcPos(L2PcInstance activeChar)
+ {
+ _npcX = activeChar.getX();
+ _npcY = activeChar.getY();
+ _npcZ = activeChar.getZ();
+ _npcHeading = activeChar.getHeading();
+ }
+
+ public static void setNpcPos(int x, int y, int z)
+ {
+ _npcX = x;
+ _npcY = y;
+ _npcZ = z;
+ }
+
+ public static void addTeam(String teamName)
+ {
+ if (!checkTeamOk())
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[addTeam(" + teamName + ")]: checkTeamOk() = false");
+ return;
+ }
+
+ if (teamName.equals(" "))
+ return;
+
+ _teams.add(teamName);
+ _teamPlayersCount.add(0);
+ _teamColors.add(0);
+ _teamsX.add(0);
+ _teamsY.add(0);
+ _teamsZ.add(0);
+ _teamPointsCount.add(0);
+ addOrSet(_teams.indexOf(teamName), null, false, _FlagNPC, 0, 0, 0);
+ }
+
+ private static void addOrSet(int listSize, L2Spawn flagSpawn, boolean flagsTaken, int flagId, int flagX, int flagY, int flagZ)
+ {
+ while (_flagsX.size() <= listSize)
+ {
+ _flagSpawns.add(null);
+ _flagsTaken.add(false);
+ _flagIds.add(_FlagNPC);
+ _flagsX.add(0);
+ _flagsY.add(0);
+ _flagsZ.add(0);
+ }
+ _flagSpawns.set(listSize, flagSpawn);
+ _flagsTaken.set(listSize, flagsTaken);
+ _flagIds.set(listSize, flagId);
+ _flagsX.set(listSize, flagX);
+ _flagsY.set(listSize, flagY);
+ _flagsZ.set(listSize, flagZ);
+ }
+
+ public static boolean checkMaxLevel(int maxlvl)
+ {
+ if (_minlvl >= maxlvl)
+ return false;
+
+ return true;
+ }
+
+ public static boolean checkMinLevel(int minlvl)
+ {
+ if (_maxlvl <= minlvl)
+ return false;
+
+ return true;
+ }
+
+ /** returns true if participated players is higher or equal then minimum needed players */
+ public static boolean checkMinPlayers(int players)
+ {
+ if (_minPlayers <= players)
+ return true;
+
+ return false;
+ }
+
+ /** returns true if max players is higher or equal then participated players */
+ public static boolean checkMaxPlayers(int players)
+ {
+ if (_maxPlayers > players)
+ return true;
+
+ return false;
+ }
+
+ public static void removeTeam(String teamName)
+ {
+ if (!checkTeamOk() || _teams.isEmpty())
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[removeTeam(" + teamName + ")]: checkTeamOk() = false");
+ return;
+ }
+
+ if (teamPlayersCount(teamName) > 0)
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[removeTeam(" + teamName + ")]: teamPlayersCount(teamName) > 0");
+ return;
+ }
+
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+
+ _teamsZ.remove(index);
+ _teamsY.remove(index);
+ _teamsX.remove(index);
+ _teamColors.remove(index);
+ _teamPointsCount.remove(index);
+ _teamPlayersCount.remove(index);
+ _teams.remove(index);
+ _flagSpawns.remove(index);
+ _flagsTaken.remove(index);
+ _flagIds.remove(index);
+ _flagsX.remove(index);
+ _flagsY.remove(index);
+ _flagsZ.remove(index);
+ }
+
+ public static void setTeamPos(String teamName, L2PcInstance activeChar)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+
+ _teamsX.set(index, activeChar.getX());
+ _teamsY.set(index, activeChar.getY());
+ _teamsZ.set(index, activeChar.getZ());
+ }
+
+ public static void setTeamPos(String teamName, int x, int y, int z)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+
+ _teamsX.set(index, x);
+ _teamsY.set(index, y);
+ _teamsZ.set(index, z);
+ }
+
+ public static void setTeamColor(String teamName, int color)
+ {
+ if (!checkTeamOk())
+ return;
+
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+
+ _teamColors.set(index, color);
+ }
+
+ public static boolean checkTeamOk()
+ {
+ if (_started || _teleport || _joining)
+ return false;
+
+ return true;
+ }
+
+ public static void startJoin(L2PcInstance activeChar)
+ {
+ if (!startJoinOk())
+ {
+ activeChar.sendMessage("Event not setted propertly.");
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[startJoin(" + activeChar.getName() + ")]: startJoinOk() = false");
+ return;
+ }
+
+ _joining = true;
+ spawnEventNpc(activeChar);
+ AnnounceToPlayers(true, _eventName + " (CTF)!");
+ if (Config.CTF_ANNOUNCE_REWARD)
+ AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).get Name());
+ AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
+ AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
+ }
+
+ public static void startJoin()
+ {
+ if (!startJoinOk())
+ {
+ _log.warning("Event not setted propertly.");
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[startJoin(startJoinOk() = false");
+ return;
+ }
+
+ _joining = true;
+ spawnEventNpc();
+ AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
+ AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
+ if (Config.CTF_ANNOUNCE_REWARD)
+ AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).get Name());
+ }
+
+ public static boolean startAutoJoin()
+ {
+ if (!startJoinOk())
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[startJoin]: startJoinOk() = false");
+ return false;
+ }
+
+ _joining = true;
+ spawnEventNpc();
+ AnnounceToPlayers(true, _eventName + " (CTF)!");
+ if (Config.CTF_ANNOUNCE_REWARD)
+ AnnounceToPlayers(true, "Reward: " + _rewardAmount + " " + ItemTable.getInstance().getTemplate(_rewardId).get Name());
+ AnnounceToPlayers(true, "Recruiting levels " + _minlvl + " to " + _maxlvl);
+ AnnounceToPlayers(true, "Joinable in " + _joiningLocationName + "!");
+ return true;
+ }
+
+ public static boolean startJoinOk()
+ {
+ if (_started || _teleport || _joining || _teams.size() < 2 || _eventName.equals("") || _joiningLocationName.equals("") || _eventDesc.equals("")
+ || _npcId == 0 || _npcX == 0 || _npcY == 0 || _npcZ == 0 || _rewardId == 0 || _rewardAmount == 0 || _teamsX.contains(0) || _teamsY.contains(0)
+ || _teamsZ.contains(0))
+ return false;
+ try
+ {
+ if (_flagsX.contains(0) || _flagsY.contains(0) || _flagsZ.contains(0) || _flagIds.contains(0))
+ return false;
+ if (_flagsX.size() < _teams.size() || _flagsY.size() < _teams.size() || _flagsZ.size() < _teams.size() || _flagIds.size() < _teams.size())
+ return false;
+ }
+ catch (ArrayIndexOutOfBoundsException e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private static void spawnEventNpc(L2PcInstance activeChar)
+ {
+ L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
+
+ try
+ {
+ _npcSpawn = new L2Spawn(tmpl);
+
+ _npcSpawn.setLocx(_npcX);
+ _npcSpawn.setLocy(_npcY);
+ _npcSpawn.setLocz(_npcZ);
+ _npcSpawn.setAmount(1);
+ _npcSpawn.setHeading(_npcHeading);
+ _npcSpawn.setRespawnDelay(1);
+
+ SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
+
+ _npcSpawn.init();
+ _npcSpawn.getLastSpawn().getStatus().setCurrentHp( 999999999);
+ _npcSpawn.getLastSpawn().setTitle(_eventName);
+ _npcSpawn.getLastSpawn()._isEventMobCTF = true;
+ _npcSpawn.getLastSpawn().isAggressive();
+ _npcSpawn.getLastSpawn().decayMe();
+ _npcSpawn.getLastSpawn().spawnMe(_npcSpawn.getLast Spawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
+
+ _npcSpawn.getLastSpawn().broadcastPacket(new MagicSkillUser(_npcSpawn.getLastSpawn(), _npcSpawn.getLastSpawn(), 1034, 1, 1, 1));
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Engine[spawnEventNpc(" + activeChar.getName() + ")]: exception: " + e.getMessage());
+ }
+ }
+
+ private static void spawnEventNpc()
+ {
+ L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(_npcId);
+
+ try
+ {
+ _npcSpawn = new L2Spawn(tmpl);
+
+ _npcSpawn.setLocx(_npcX);
+ _npcSpawn.setLocy(_npcY);
+ _npcSpawn.setLocz(_npcZ);
+ _npcSpawn.setAmount(1);
+ _npcSpawn.setHeading(_npcHeading);
+ _npcSpawn.setRespawnDelay(1);
+
+ SpawnTable.getInstance().addNewSpawn(_npcSpawn, false);
+
+ _npcSpawn.init();
+ _npcSpawn.getLastSpawn().getStatus().setCurrentHp( 999999999);
+ _npcSpawn.getLastSpawn().setTitle(_eventName);
+ _npcSpawn.getLastSpawn()._isEventMobCTF = true;
+ _npcSpawn.getLastSpawn().isAggressive();
+ _npcSpawn.getLastSpawn().decayMe();
+ _npcSpawn.getLastSpawn().spawnMe(_npcSpawn.getLast Spawn().getX(), _npcSpawn.getLastSpawn().getY(), _npcSpawn.getLastSpawn().getZ());
+
+ _npcSpawn.getLastSpawn().broadcastPacket(new MagicSkillUser(_npcSpawn.getLastSpawn(), _npcSpawn.getLastSpawn(), 1034, 1, 1, 1));
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Engine[spawnEventNpc(exception: " + e.getMessage());
+ }
+ }
+
+ public static void teleportStart()
+ {
+ if (!_joining || _started || _teleport)
+ return;
+
+ if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
+ {
+ removeOfflinePlayers();
+ shuffleTeams();
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
+ {
+ AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
+ return;
+ }
+
+ _joining = false;
+ AnnounceToPlayers(true, _eventName + "(CTF): Teleport to team spot in 20 seconds!");
+
+ setUserData();
+ ThreadPoolManager.getInstance().scheduleGeneral(ne w Runnable()
+ {
+ public void run()
+ {
+ CTF.sit();
+ CTF.spawnAllFlags();
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ if (Config.CTF_ON_START_UNSUMMON_PET)
+ {
+ //Remove Summon's buffs
+ if (player.getPet() != null)
+ {
+ L2Summon summon = player.getPet();
+ for (L2Effect e : summon.getAllEffects())
+ if (e != null)
+ e.exit();
+
+ if (summon instanceof L2PetInstance)
+ summon.unSummon(player);
+ }
+ }
+
+ if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
+ {
+ for (L2Effect e : player.getAllEffects())
+ {
+ if (e != null)
+ e.exit();
+ }
+ }
+
+ //Remove player from his party
+ if (player.getParty() != null)
+ {
+ L2Party party = player.getParty();
+ party.removePartyMember(player);
+ }
+ player.teleToLocation(_teamsX.get(_teams.indexOf(p layer._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ
+ .get(_teams.indexOf(player._teamNameCTF)));
+ }
+ }
+ }
+ }, 20000);
+ _teleport = true;
+ }
+
+ public static boolean teleportAutoStart()
+ {
+ if (!_joining || _started || _teleport)
+ return false;
+
+ if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && checkMinPlayers(_playersShuffle.size()))
+ {
+ removeOfflinePlayers();
+ shuffleTeams();
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMinPlayers(_playersShuffle.size()))
+ {
+ AnnounceToPlayers(true, "Not enough players for event. Min Requested : " + _minPlayers + ", Participating : " + _playersShuffle.size());
+ return false;
+ }
+
+ _joining = false;
+ AnnounceToPlayers(false, _eventName + "(CTF): Teleport to team spot in 20 seconds!");
+
+ setUserData();
+ ThreadPoolManager.getInstance().scheduleGeneral(ne w Runnable()
+ {
+ public void run()
+ {
+ sit();
+ spawnAllFlags();
+
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ if (Config.CTF_ON_START_UNSUMMON_PET)
+ {
+ //Remove Summon's buffs
+ if (player.getPet() != null)
+ {
+ L2Summon summon = player.getPet();
+ for (L2Effect e : summon.getAllEffects())
+ if (e != null)
+ e.exit();
+
+ if (summon instanceof L2PetInstance)
+ summon.unSummon(player);
+ }
+ }
+
+ if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
+ {
+ for (L2Effect e : player.getAllEffects())
+ {
+ if (e != null)
+ e.exit();
+ }
+ }
+
+ //Remove player from his party
+ if (player.getParty() != null)
+ {
+ L2Party party = player.getParty();
+ party.removePartyMember(player);
+ }
+
+ player.teleToLocation(_teamsX.get(_teams.indexOf(p layer._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ
+ .get(_teams.indexOf(player._teamNameCTF)));
+ }
+ }
+ }
+ }, 20000);
+ _teleport = true;
+ return true;
+ }
+
+ public static void startEvent(L2PcInstance activeChar)
+ {
+ if (!startEventOk())
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[startEvent(" + activeChar.getName()+ ")]: startEventOk() = false");
+ return;
+ }
+
+ _teleport = false;
+ sit();
+ _started = true;
+ StartEvent();
+ }
+
+ public static void setJoinTime(int time)
+ {
+ _joinTime = time;
+ }
+
+ public static void setEventTime(int time)
+ {
+ _eventTime = time;
+ }
+
+ public static boolean startAutoEvent()
+ {
+ if (!startEventOk())
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[startEvent]: startEventOk() = false");
+ return false;
+ }
+
+ _teleport = false;
+ sit();
+ AnnounceToPlayers(true, _eventName + "(CTF): Started. Go Capture the Flags!");
+ _started = true;
+ return true;
+ }
+
+ public static void autoEvent()
+ {
+ if (startAutoJoin())
+ {
+ if (_joinTime > 0)
+ waiter(_joinTime * 60 * 1000); // minutes for join event
+ else if (_joinTime <= 0)
+ {
+ abortEvent();
+ return;
+ }
+ if (teleportAutoStart())
+ {
+ waiter(1 * 30 * 1000); // 30 seconds wait time untill start fight after teleported
+ if (startAutoEvent())
+ {
+ waiter(_eventTime * 60 * 1000); // minutes for event time
+ finishEvent();
+ }
+ }
+ else if (!teleportAutoStart())
+ {
+ abortEvent();
+ }
+ }
+ }
+
+ private static void waiter(long interval)
+ {
+ long startWaiterTime = System.currentTimeMillis();
+ int seconds = (int) (interval / 1000);
+
+ while (startWaiterTime + interval > System.currentTimeMillis())
+ {
+ seconds--; // here because we don't want to see two time announce at the same time
+
+ if (_joining || _started || _teleport)
+ {
+ switch (seconds)
+ {
+ case 3600: // 1 hour left
+ if (_joining)
+ {
+ AnnounceToPlayers(true, _eventName + "(CTF): Joinable in " + _joiningLocationName + "!");
+ AnnounceToPlayers(true, "CTF Event: " + seconds / 60 / 60 + " hour(s) till registration close!");
+ }
+ else if (_started)
+ AnnounceToPlayers(false, "CTF Event: " + seconds / 60 / 60 + " hour(s) till event finish!");
+
+ break;
+ case 1800: // 30 minutes left
+ case 600: // 10 minutes left
+ case 180: // 3 minutes left
+ case 120: // 2 minutes left
+ case 60: // 1 minute left
+ if (_joining)
+ {
+ removeOfflinePlayers();
+ AnnounceToPlayers(true, _eventName + "(CTF): Joinable in " + _joiningLocationName + "!");
+ AnnounceToPlayers(true, "CTF Event: " + seconds / 60 + " minute(s) till registration ends!");
+ }
+ else if (_started)
+ AnnounceToPlayers(false, "CTF Event: " + seconds / 60 + " minute(s) till event ends!");
+
+ break;
+ case 30: // 30 seconds left
+ case 10: // 10 seconds left
+ case 3: // 3 seconds left
+ case 2: // 2 seconds left
+ case 1: // 1 seconds left
+ if (_joining)
+ AnnounceToPlayers(true, "CTF Event: " + seconds + " second(s) till registration close!");
+ else if (_teleport)
+ AnnounceToPlayers(false, "CTF Event: " + seconds + " seconds(s) till fight starts!");
+ else if (_started)
+ AnnounceToPlayers(false, "CTF Event: " + seconds + " second(s) till event ends!");
+
+ break;
+ }
+ }
+
+ long startOneSecondWaiterStartTime = System.currentTimeMillis();
+
+ // only the try catch with Thread.sleep(1000) give bad countdown on high wait times
+ while (startOneSecondWaiterStartTime + 1000 > System.currentTimeMillis())
+ {
+ try
+ {
+ Thread.sleep(1);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+ }
+ }
+
+ private static boolean startEventOk()
+ {
+ if (_joining || !_teleport || _started)
+ return false;
+
+ if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
+ {
+ if (_teamPlayersCount.contains(0))
+ return false;
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ {
+ Vector<L2PcInstance> playersShuffleTemp = new Vector<L2PcInstance>();
+ int loopCount = 0;
+
+ loopCount = _playersShuffle.size();
+
+ for (int i = 0; i < loopCount; ++i)
+ {
+ if (_playersShuffle != null)
+ playersShuffleTemp.add(_playersShuffle.get(i));
+ }
+
+ _playersShuffle = playersShuffleTemp;
+ playersShuffleTemp.clear();
+
+ // if (_playersShuffle.size() < (_teams.size()*2)){
+ // return false;
+ // }
+ }
+
+ return true;
+ }
+
+ public static void shuffleTeams()
+ {
+ int teamCount = 0, playersCount = 0;
+
+ for (;;)
+ {
+ if (_playersShuffle.isEmpty())
+ break;
+
+ int playerToAddIndex = Rnd.nextInt(_playersShuffle.size());
+ L2PcInstance player = null;
+ player = _playersShuffle.get(playerToAddIndex);
+ player._originalNameColorCTF = player.getAppearance().getNameColor();
+ player._originalKarmaCTF = player.getKarma();
+
+ _players.add(player);
+ _players.get(playersCount)._teamNameCTF = _teams.get(teamCount);
+ _savePlayers.add(_players.get(playersCount).getNam e());
+ _savePlayerTeams.add(_teams.get(teamCount));
+ ++playersCount;
+
+ if (teamCount == _teams.size() - 1)
+ teamCount = 0;
+ else
+ ++teamCount;
+
+ _playersShuffle.remove(playerToAddIndex);
+ }
+ }
+
+ public static void setUserData()
+ {
+ for (L2PcInstance player : _players)
+ {
+ player.getAppearance().setNameColor(_teamColors.ge t(_teams.indexOf(player._teamNameCTF)));
+ player.setKarma(0);
+ player.broadcastUserInfo();
+ }
+ }
+
+ public static void finishEvent()
+ {
+ if (!finishEventOk())
+ {
+ if (Config.DEBUG)
+ _log.fine("CTF Engine[finishEvent]: finishEventOk() = false");
+ return;
+ }
+
+ _started = false;
+ unspawnEventNpc();
+ unspawnAllFlags();
+ processTopTeam();
+
+ if (_topScore != 0)
+ playKneelAnimation(_topTeam);
+
+ if (Config.CTF_ANNOUNCE_TEAM_STATS)
+ {
+ AnnounceToPlayers(true, _eventName + " Team Statistics:");
+ for (String team : _teams)
+ {
+ int _flags_ = teamFlagCount(team);
+ AnnounceToPlayers(true, "Team: " + team + " - Flags taken: " + _flags_);
+ }
+ }
+
+ teleportFinish();
+ }
+
+ //show loosers and winners animations
+ public static void playKneelAnimation(String teamName)
+ {
+ for (L2PcInstance player : _players)
+ {
+ if (player != null && player.isOnline() != 0 && player._inEventCTF == true)
+ {
+ if (!player._teamNameCTF.equals(teamName))
+ {
+ player.broadcastPacket(new SocialAction(player.getObjectId(), 7));
+ }
+ else if (player._teamNameCTF.equals(teamName))
+ {
+ player.broadcastPacket(new SocialAction(player.getObjectId(), 3));
+ }
+ }
+ }
+ }
+
+ private static boolean finishEventOk()
+ {
+ if (!_started)
+ return false;
+
+ return true;
+ }
+
+ public static void rewardTeam(String teamName)
+ {
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ if (player._teamNameCTF.equals(teamName))
+ {
+ player.addItem("CTF Event: " + _eventName, _rewardId, _rewardAmount, player, true);
+
+ NpcHtmlMessage nhm = new NpcHtmlMessage(5);
+ TextBuilder replyMSG = new TextBuilder("");
+
+ replyMSG.append("<html><body>Your team wins the event. Look in your inventory for the reward.</body></html>");
+
+ nhm.setHtml(replyMSG.toString());
+ player.sendPacket(nhm);
+
+ // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
+ player.sendPacket(ActionFailed.STATIC_PACKET);
+ }
+ }
+ }
+ }
+
+ public static void abortEvent()
+ {
+ if (!_joining && !_teleport && !_started)
+ return;
+ if (_joining && !_teleport && !_started)
+ {
+ unspawnEventNpc();
+ cleanCTF();
+ _joining = false;
+ AnnounceToPlayers(true, _eventName + "(CTF): Match aborted!");
+ return;
+ }
+ _joining = false;
+ _teleport = false;
+ _started = false;
+ unspawnEventNpc();
+ unspawnAllFlags();
+ AnnounceToPlayers(true, _eventName + "(CTF): Match aborted!");
+ teleportFinish();
+ }
+
+ public static void sit()
+ {
+ if (_sitForced)
+ _sitForced = false;
+ else
+ _sitForced = true;
+
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ if (_sitForced)
+ {
+ player.stopMove(null, false);
+ player.abortAttack();
+ player.abortCast();
+
+ if (!player.isSitting())
+ player.sitDown();
+ }
+ else
+ {
+ if (player.isSitting())
+ player.standUp();
+ }
+ }
+ }
+ }
+
+ public static void dumpData()
+ {
+ _log.warning("");
+ _log.warning("");
+
+ if (!_joining && !_teleport && !_started)
+ {
+ _log.warning("<<---------------------------------->>");
+ _log.warning(">> CTF Engine infos dump (INACTIVE) <<");
+ _log.warning("<<--^----^^-----^----^^------^^----->>");
+ }
+ else if (_joining && !_teleport && !_started)
+ {
+ _log.warning("<<--------------------------------->>");
+ _log.warning(">> CTF Engine infos dump (JOINING) <<");
+ _log.warning("<<--^----^^-----^----^^------^----->>");
+ }
+ else if (!_joining && _teleport && !_started)
+ {
+ _log.warning("<<---------------------------------->>");
+ _log.warning(">> CTF Engine infos dump (TELEPORT) <<");
+ _log.warning("<<--^----^^-----^----^^------^^----->>");
+ }
+ else if (!_joining && !_teleport && _started)
+ {
+ _log.warning("<<--------------------------------->>");
+ _log.warning(">> CTF Engine infos dump (STARTED) <<");
+ _log.warning("<<--^----^^-----^----^^------^----->>");
+ }
+
+ _log.warning("Name: " + _eventName);
+ _log.warning("Desc: " + _eventDesc);
+ _log.warning("Join location: " + _joiningLocationName);
+ _log.warning("Min lvl: " + _minlvl);
+ _log.warning("Max lvl: " + _maxlvl);
+ _log.warning("");
+ _log.warning("##########################");
+ _log.warning("# _teams(Vector<String>) #");
+ _log.warning("##########################");
+
+ for (String team : _teams)
+ _log.warning(team + " Flags Taken :" + _teamPointsCount.get(_teams.indexOf(team)));
+
+ if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ {
+ _log.warning("");
+ _log.warning("#################################### #####");
+ _log.warning("# _playersShuffle(Vector<L2PcInstance>) #");
+ _log.warning("#################################### #####");
+
+ for (L2PcInstance player : _playersShuffle)
+ {
+ if (player != null)
+ _log.warning("Name: " + player.getName());
+ }
+ }
+
+ _log.warning("");
+ _log.warning("##################################") ;
+ _log.warning("# _players(Vector<L2PcInstance>) #");
+ _log.warning("##################################") ;
+
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ _log.warning("Name: " + player.getName() + " + Team: " + player._teamNameCTF + " Flags :" + player._countCTFflags);
+ }
+
+ _log.warning("");
+ _log.warning("#################################### #################################");
+ _log.warning("# _savePlayers(Vector<String>) and _savePlayerTeams(Vector<String>) #");
+ _log.warning("#################################### #################################");
+
+ for (String player : _savePlayers)
+ _log.warning("Name: " + player + " Team: " + _savePlayerTeams.get(_savePlayers.indexOf(player)) );
+
+ _log.warning("");
+ _log.warning("");
+ _log.warning("**********==CTF==************");
+ _log.warning("CTF._teamPointsCount:" + _teamPointsCount.toString());
+ _log.warning("CTF._flagIds:" + _flagIds.toString());
+ _log.warning("CTF._flagSpawns:" + _flagSpawns.toString());
+ _log.warning("CTF._throneSpawns:" + _throneSpawns.toString());
+ _log.warning("CTF._flagsTaken:" + _flagsTaken.toString());
+ _log.warning("CTF._flagsX:" + _flagsX.toString());
+ _log.warning("CTF._flagsY:" + _flagsY.toString());
+ _log.warning("CTF._flagsZ:" + _flagsZ.toString());
+ _log.warning("************EOF**************");
+ _log.warning("");
+ }
+
+ public static void loadData()
+ {
+ _eventName = new String();
+ _eventDesc = new String();
+ _topTeam = new String();
+ _joiningLocationName = new String();
+ _teams = new Vector<String>();
+ _savePlayers = new Vector<String>();
+ _savePlayerTeams = new Vector<String>();
+ _players = new Vector<L2PcInstance>();
+ _playersShuffle = new Vector<L2PcInstance>();
+ _teamPlayersCount = new Vector<Integer>();
+ _teamPointsCount = new Vector<Integer>();
+ _teamColors = new Vector<Integer>();
+ _teamsX = new Vector<Integer>();
+ _teamsY = new Vector<Integer>();
+ _teamsZ = new Vector<Integer>();
+
+ _throneSpawns = new Vector<L2Spawn>();
+ _flagSpawns = new Vector<L2Spawn>();
+ _flagsTaken = new Vector<Boolean>();
+ _flagIds = new Vector<Integer>();
+ _flagsX = new Vector<Integer>();
+ _flagsY = new Vector<Integer>();
+ _flagsZ = new Vector<Integer>();
+
+ _joining = false;
+ _teleport = false;
+ _started = false;
+ _sitForced = false;
+ _npcId = 0;
+ _npcX = 0;
+ _npcY = 0;
+ _npcZ = 0;
+ _npcHeading = 0;
+ _rewardId = 0;
+ _rewardAmount = 0;
+ _topScore = 0;
+ _minlvl = 0;
+ _maxlvl = 0;
+ _joinTime = 0;
+ _eventTime = 0;
+ _minPlayers = 0;
+ _maxPlayers = 0;
+
+ Connection con = null;
+ try
+ {
+ PreparedStatement statement;
+ ResultSet rs;
+
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ statement = con.prepareStatement("Select * from ctf");
+ rs = statement.executeQuery();
+
+ int teams = 0;
+
+ while (rs.next())
+ {
+ _eventName = rs.getString("eventName");
+ _eventDesc = rs.getString("eventDesc");
+ _joiningLocationName = rs.getString("joiningLocation");
+ _minlvl = rs.getInt("minlvl");
+ _maxlvl = rs.getInt("maxlvl");
+ _npcId = rs.getInt("npcId");
+ _npcX = rs.getInt("npcX");
+ _npcY = rs.getInt("npcY");
+ _npcZ = rs.getInt("npcZ");
+ _npcHeading = rs.getInt("npcHeading");
+ _rewardId = rs.getInt("rewardId");
+ _rewardAmount = rs.getInt("rewardAmount");
+ teams = rs.getInt("teamsCount");
+ _joinTime = rs.getInt("joinTime");
+ _eventTime = rs.getInt("eventTime");
+ _minPlayers = rs.getInt("minPlayers");
+ _maxPlayers = rs.getInt("maxPlayers");
+ }
+ statement.close();
+
+ int index = -1;
+ if (teams > 0)
+ index = 0;
+ while (index < teams && index > -1)
+ {
+ statement = con.prepareStatement("Select * from ctf_teams where teamId = ?");
+ statement.setInt(1, index);
+ rs = statement.executeQuery();
+ while (rs.next())
+ {
+ _teams.add(rs.getString("teamName"));
+ _teamPlayersCount.add(0);
+ _teamPointsCount.add(0);
+ _teamColors.add(0);
+ _teamsX.add(0);
+ _teamsY.add(0);
+ _teamsZ.add(0);
+ _teamsX.set(index, rs.getInt("teamX"));
+ _teamsY.set(index, rs.getInt("teamY"));
+ _teamsZ.set(index, rs.getInt("teamZ"));
+ _teamColors.set(index, rs.getInt("teamColor"));
+ _flagsX.add(0);
+ _flagsY.add(0);
+ _flagsZ.add(0);
+ _flagsX.set(index, rs.getInt("flagX"));
+ _flagsY.set(index, rs.getInt("flagY"));
+ _flagsZ.set(index, rs.getInt("flagZ"));
+ _flagSpawns.add(null);
+ _flagIds.add(_FlagNPC);
+ _flagsTaken.add(false);
+
+ }
+ ++index;
+ statement.close();
+ }
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: CTF.loadData(): " + e.getMessage());
+ }
+ finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } }
+ }
+
+ public static void saveData()
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement statement;
+
+ statement = con.prepareStatement("Delete from ctf");
+ statement.execute();
+ statement.close();
+
+ statement = con
+ .prepareStatement("INSERT INTO ctf (eventName, eventDesc, joiningLocation, minlvl, maxlvl, npcId, npcX, npcY, npcZ, npcHeading, rewardId, rewardAmount, teamsCount, joinTime, eventTime, minPlayers, maxPlayers) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ statement.setString(1, _eventName);
+ statement.setString(2, _eventDesc);
+ statement.setString(3, _joiningLocationName);
+ statement.setInt(4, _minlvl);
+ statement.setInt(5, _maxlvl);
+ statement.setInt(6, _npcId);
+ statement.setInt(7, _npcX);
+ statement.setInt(8, _npcY);
+ statement.setInt(9, _npcZ);
+ statement.setInt(10, _npcHeading);
+ statement.setInt(11, _rewardId);
+ statement.setInt(12, _rewardAmount);
+ statement.setInt(13, _teams.size());
+ statement.setInt(14, _joinTime);
+ statement.setInt(15, _eventTime);
+ statement.setInt(16, _minPlayers);
+ statement.setInt(17, _maxPlayers);
+ statement.execute();
+ statement.close();
+
+ statement = con.prepareStatement("Delete from ctf_teams");
+ statement.execute();
+ statement.close();
+
+ for (String teamName : _teams)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+ statement = con
+ .prepareStatement("INSERT INTO ctf_teams (teamId ,teamName, teamX, teamY, teamZ, teamColor, flagX, flagY, flagZ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ statement.setInt(1, index);
+ statement.setString(2, teamName);
+ statement.setInt(3, _teamsX.get(index));
+ statement.setInt(4, _teamsY.get(index));
+ statement.setInt(5, _teamsZ.get(index));
+ statement.setInt(6, _teamColors.get(index));
+ statement.setInt(7, _flagsX.get(index));
+ statement.setInt(8, _flagsY.get(index));
+ statement.setInt(9, _flagsZ.get(index));
+ statement.execute();
+ statement.close();
+ }
+ }
+ catch (Exception e)
+ {
+ _log.warning("Exception: CTF.saveData(): " + e.getMessage());
+ }
+ finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } }
+ }
+
+ public static void showEventHtml(L2PcInstance eventPlayer, String objectId)
+ {
+ try
+ {
+ NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
+
+ TextBuilder replyMSG = new TextBuilder("<html><body>");
+ replyMSG.append("CTF Match<br><br><br>");
+ replyMSG.append("Current event...<br1>");
+ replyMSG.append(" ... description:&nbsp;<font color=\"00FF00\">" + _eventDesc + "</font><br>");
+ if (Config.CTF_ANNOUNCE_REWARD)
+ replyMSG.append(" ... reward: (" + _rewardAmount + ") " + ItemTable.getInstance().getTemplate(_rewardId).get Name() + "<br>");
+
+ if (!_started && !_joining)
+ replyMSG.append("<center>Wait till the admin/gm start the participation.</center>");
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !checkMaxPlayers(_playersShuffle.size()))
+ {
+ if (!CTF._started)
+ {
+ replyMSG
+ .append("<font color=\"FFFF00\">The event has reached its maximum capacity.</font><br>Keep checking, someone may crit and you can steal their spot.");
+ }
+ }
+ else if (eventPlayer.isCursedWeaponEquiped() && !Config.CTF_JOIN_CURSED)
+ {
+ replyMSG.append("<font color=\"FFFF00\">You can't participate in this event with a cursed Weapon.</font><br>");
+ }
+ else if (!_started && _joining && eventPlayer.getLevel() >= _minlvl && eventPlayer.getLevel() < _maxlvl)
+ {
+ if (_players.contains(eventPlayer) || checkShufflePlayers(eventPlayer))
+ {
+ if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
+ replyMSG.append("You are already participating in team <font color=\"LEVEL\">" + eventPlayer._teamNameCTF + "</font><br><br>");
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ replyMSG.append("You are already participating!<br><br>");
+
+ replyMSG.append("<table border=\"0\"><tr>");
+ replyMSG.append("<td width=\"200\">Wait till event start or</td>");
+ replyMSG.append("<td width=\"60\"><center><button value=\"remove\" action=\"bypass -h npc_" + objectId
+ + "_ctf_player_leave\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></td>");
+ replyMSG.append("<td width=\"100\">your participation!</td>");
+ replyMSG.append("</tr></table>");
+ }
+ else
+ {
+ replyMSG.append("<td width=\"200\">Your level : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font></td><br>");
+ replyMSG.append("<td width=\"200\">Min level : <font color=\"00FF00\">" + _minlvl + "</font></td><br>");
+ replyMSG.append("<td width=\"200\">Max level : <font color=\"00FF00\">" + _maxlvl + "</font></td><br><br>");
+
+ if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
+ {
+ replyMSG.append("<center><table border=\"0\">");
+
+ for (String team : _teams)
+ {
+ replyMSG
+ .append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font>&nbsp;(" + teamPlayersCount(team) + " joined)</td>");
+ replyMSG.append("<td width=\"60\"><button value=\"Join\" action=\"bypass -h npc_" + objectId + "_ctf_player_join " + team
+ + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
+ }
+
+ replyMSG.append("</table></center>");
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ {
+ replyMSG.append("<center><table border=\"0\">");
+
+ for (String team : _teams)
+ replyMSG.append("<tr><td width=\"100\"><font color=\"LEVEL\">" + team + "</font></td>");
+
+ replyMSG.append("</table></center><br>");
+
+ replyMSG.append("<button value=\"Join\" action=\"bypass -h npc_" + objectId
+ + "_ctf_player_join eventShuffle\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
+ replyMSG.append("Teams will be randomly generated!");
+ }
+ }
+ }
+ else if (_started && !_joining)
+ replyMSG.append("<center>CTF match is in progress.</center>");
+ else if (eventPlayer.getLevel() < _minlvl || eventPlayer.getLevel() > _maxlvl)
+ {
+ replyMSG.append("Your lvl : <font color=\"00FF00\">" + eventPlayer.getLevel() + "</font><br>");
+ replyMSG.append("Min level : <font color=\"00FF00\">" + _minlvl + "</font><br>");
+ replyMSG.append("Max level : <font color=\"00FF00\">" + _maxlvl + "</font><br><br>");
+ replyMSG.append("<font color=\"FFFF00\">You can't participatein this event.</font><br>");
+ }
+ // Show how many players joined & how many are still needed to join
+ replyMSG.append("<br>There are " + _playersShuffle.size() + " player(s) participating in this event.<br>");
+ if (_joining)
+ {
+ if (_playersShuffle.size() < _minPlayers)
+ {
+ int playersNeeded = _minPlayers - _playersShuffle.size();
+ replyMSG.append("The event will not start unless " + playersNeeded + " more player(s) joins!");
+ }
+ }
+
+ replyMSG.append("</body></html>");
+ 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.sendPacket(ActionFailed.STATIC_PACKET) ;
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Engine[showEventHtlm(" + eventPlayer.getName() + ", " + objectId + ")]: exception" + e.getMessage());
+ }
+ }
+
+ public static void addPlayer(L2PcInstance player, String teamName)
+ {
+ if (!addPlayerOk(teamName, player))
+ return;
+
+ if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
+ {
+ player._teamNameCTF = teamName;
+ _players.add(player);
+ setTeamPlayersCount(teamName, teamPlayersCount(teamName) + 1);
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ _playersShuffle.add(player);
+
+ player._inEventCTF = true;
+ player._countCTFflags = 0;
+ }
+
+ public static void removeOfflinePlayers()
+ {
+ try
+ {
+ if (_playersShuffle == null)
+ return;
+ else if (_playersShuffle.isEmpty())
+ return;
+ else if (_playersShuffle.size() > 0)
+ {
+ for (L2PcInstance player : _playersShuffle)
+ {
+ if (player == null)
+ _playersShuffle.remove(player);
+ else if (player.isOnline() == 0 || player.isInJail())
+ removePlayer(player);
+ if (_playersShuffle.size() == 0 || _playersShuffle.isEmpty())
+ break;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Engine exception: " + e.getMessage());
+ return;
+ }
+ }
+
+ public static boolean checkShufflePlayers(L2PcInstance eventPlayer)
+ {
+ try
+ {
+ for (L2PcInstance player : _playersShuffle)
+ {
+ if (player == null || player.isOnline() == 0)
+ {
+ _playersShuffle.remove(player);
+ eventPlayer._inEventCTF = false;
+ continue;
+ }
+ else if (player.getObjectId() == eventPlayer.getObjectId())
+ {
+ eventPlayer._inEventCTF = true;
+ eventPlayer._countCTFflags = 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._inEventCTF = true;
+ eventPlayer._countCTFflags = 0;
+ return true;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ return false;
+ }
+
+ public static boolean addPlayerOk(String teamName, L2PcInstance eventPlayer)
+ {
+ try
+ {
+ if (checkShufflePlayers(eventPlayer) || eventPlayer._inEventCTF)
+ {
+ eventPlayer.sendMessage("You are already participating in the 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;
+ }
+ }
+ catch (Exception e)
+ {
+ _log.warning("CTF Siege Engine exception: " + e.getMessage());
+ }
+
+ if (Config.CTF_EVEN_TEAMS.equals("NO"))
+ return true;
+ else if (Config.CTF_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<String> joinableTeams = new Vector<String>();
+
+ for (String team : _teams)
+ {
+ if (teamPlayersCount(team) == countBefore)
+ joinableTeams.add(team);
+ }
+
+ if (joinableTeams.contains(teamName))
+ return true;
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ return true;
+
+ eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
+ return false;
+ }
+
+ public static synchronized void addDisconnectedPlayer(L2PcInstance player)
+ {
+ /*
+ * !!! CAUTION !!!
+ * Do NOT fix multiple object Ids on this event or you will ruin the flag reposition check!!!
+ * All Multiple object Ids will be collected by the Garbage Collector, after the event ends, memory sweep is made!!!
+ */
+
+ if ((Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (_teleport || _started))
+ || (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE") && (_teleport || _started)))
+ {
+ if (Config.CTF_ON_START_REMOVE_ALL_EFFECTS)
+ {
+ for (L2Effect e : player.getAllEffects())
+ {
+ if (e != null)
+ e.exit();
+ }
+ }
+
+ player._teamNameCTF = _savePlayerTeams.get(_savePlayers.indexOf(player.g etName()));
+ for (L2PcInstance p : _players)
+ {
+ if (p == null)
+ {
+ continue;
+ }
+ //check by name incase player got new objectId
+ else if (p.getName().equals(player.getName()))
+ {
+ player._originalNameColorCTF = player.getAppearance().getNameColor();
+ player._originalKarmaCTF = player.getKarma();
+ player._inEventCTF = true;
+ player._countCTFflags = p._countCTFflags;
+ _players.remove(p); //removing old object id from vector
+ _players.add(player); //adding new objectId to vector
+ break;
+ }
+ }
+ player.getAppearance().setNameColor(_teamColors.ge t(_teams.indexOf(player._teamNameCTF)));
+ player.setKarma(0);
+ player.broadcastUserInfo();
+ player.teleToLocation(_teamsX.get(_teams.indexOf(p layer._teamNameCTF)), _teamsY.get(_teams.indexOf(player._teamNameCTF)), _teamsZ.get(_teams
+ .indexOf(player._teamNameCTF)));
+ Started(player);
+ CheckRestoreFlags();
+ }
+ }
+
+ public static void removePlayer(L2PcInstance player)
+ {
+ if (player._inEventCTF)
+ {
+ if (!_joining)
+ {
+ player.getAppearance().setNameColor(player._origin alNameColorCTF);
+ player.setKarma(player._originalKarmaCTF);
+ player.broadcastUserInfo();
+ }
+ player._teamNameCTF = new String();
+ player._countCTFflags = 0;
+ player._inEventCTF = false;
+
+ if ((Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE")) && _players.contains(player))
+ {
+ setTeamPlayersCount(player._teamNameCTF, teamPlayersCount(player._teamNameCTF) - 1);
+ _players.remove(player);
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && (!_playersShuffle.isEmpty() && _playersShuffle.contains(player)))
+ _playersShuffle.remove(player);
+ }
+ }
+
+ public static void cleanCTF()
+ {
+ _log.warning("CTF : Cleaning players.");
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ if (player._haveFlagCTF)
+ removeFlagFromPlayer(player);
+ else
+ player.getInventory().destroyItemByItemId("", CTF._FLAG_IN_HAND_ITEM_ID, 1, player, null);
+ player._haveFlagCTF = false;
+ removePlayer(player);
+ if (_savePlayers.contains(player.getName()))
+ _savePlayers.remove(player.getName());
+ player._inEventCTF = false;
+ }
+ }
+ if (_playersShuffle != null && !_playersShuffle.isEmpty())
+ {
+ for (L2PcInstance player : _playersShuffle)
+ {
+ if (player != null)
+ player._inEventCTF = false;
+ }
+ }
+ _log.warning("CTF : Cleaning teams and flags.");
+ for (String team : _teams)
+ {
+ int index = _teams.indexOf(team);
+ _teamPointsCount.set(index, 0);
+ _flagSpawns.set(index, null);
+ _flagsTaken.set(index, false);
+ _teamPlayersCount.set(index, 0);
+ _teamPointsCount.set(index, 0);
+ }
+ _topScore = 0;
+ _topTeam = new String();
+ _players = new Vector<L2PcInstance>();
+ _playersShuffle = new Vector<L2PcInstance>();
+ _savePlayers = new Vector<String>();
+ _savePlayerTeams = new Vector<String>();
+ _teamPointsCount = new Vector<Integer>();
+ _flagSpawns = new Vector<L2Spawn>();
+ _flagsTaken = new Vector<Boolean>();
+ _teamPlayersCount = new Vector<Integer>();
+ _log.warning("Cleaning CTF done.");
+ _log.warning("Loading new data from MySql");
+ loadData();
+ }
+
+ public static void unspawnEventNpc()
+ {
+ if (_npcSpawn == null)
+ return;
+
+ _npcSpawn.getLastSpawn().deleteMe();
+ _npcSpawn.stopRespawn();
+ SpawnTable.getInstance().deleteSpawn(_npcSpawn, true);
+ }
+
+ public static void teleportFinish()
+ {
+ AnnounceToPlayers(false, _eventName + "(CTF): Teleport back to participation NPC in 20 seconds!");
+ ThreadPoolManager.getInstance().scheduleGeneral(ne w Runnable()
+ {
+ public void run()
+ {
+ for (L2PcInstance player : _players)
+ {
+ if (player != null)
+ {
+ if (player.isOnline() != 0)
+ player.teleToLocation(_npcX, _npcY, _npcZ, false);
+ else
+ {
+ Connection con = null;
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+
+ PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
+ statement.setInt(1, _npcX);
+ statement.setInt(2, _npcY);
+ statement.setInt(3, _npcZ);
+ statement.setString(4, player.getName());
+ statement.execute();
+ statement.close();
+ }
+ catch (SQLException se)
+ {
+ _log.warning("CTF Engine exception: " + se.getMessage());
+ }
+ finally { try { if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } }
+ }
+ }
+ }
+ cleanCTF();
+ }
+ }, 20000);
+ }
+
+ public static int teamFlagCount(String teamName)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return -1;
+
+ return _teamPointsCount.get(index);
+ }
+
+ public static void setTeamFlagCount(String teamName, int teamFlagCount)
+ {
+ int index = _teams.indexOf(teamName);
+
+ if (index == -1)
+ return;
+
+ _teamPointsCount.set(index, teamFlagCount);
+ }
+
+ /**
+ * Used to calculate the event CTF area, so that players don't run off with the flag.
+ * Essential, since a player may take the flag just so other teams can't score points.
+ * This function is Only called upon ONE time on BEGINING OF EACH EVENT right after we spawn the flags.
+ */
+ private static void calculateOutSideOfCTF()
+ {
+ if (_teams == null || _flagSpawns == null || _teamsX == null || _teamsY == null || _teamsZ == null)
+ return;
+
+ int division = _teams.size() * 2, pos = 0;
+ int[] locX = new int[division], locY = new int[division], locZ = new int[division];
+ //Get all coordinates inorder to create a polygon:
+ for (L2Spawn flag : _flagSpawns)
+ {
+ locX[pos] = flag.getLocx();
+ locY[pos] = flag.getLocy();
+ locZ[pos] = flag.getLocz();
+ ++pos;
+ if (pos > division / 2)
+ break;
+ }
+
+ for (int x = 0; x < _teams.size(); ++ x)
+ {
+ locX[pos] = _teamsX.get(x);
+ locY[pos] = _teamsY.get(x);
+ locZ[pos] = _teamsZ.get(x);
+ ++pos;
+ if (pos > division)
+ break;
+ }
+
+ //find the polygon center, note that it's not the mathematical center of the polygon,
+ //rather than a point which centers all coordinates:
+ int centerX = 0, centerY = 0, centerZ = 0;
+ for (int x = 0; x < pos;++ x)
+ {
+ centerX = (locX[x] / division);
+ centerY = (locY[x] / division);
+ centerZ = (locZ[x] / division);
+ }
+
+ //now let's find the furthest distance from the "center" to the egg shaped sphere
+ //surrounding the polygon, size x1.5 (for maximum logical area to wander...):
+ int maxX = 0, maxY = 0, maxZ = 0;
+ for (int x = 0; x < pos;++ x)
+ {
+ if (maxX < 2 * Math.abs(centerX - locX[x]))
+ maxX = (2 * Math.abs(centerX - locX[x]));
+ if (maxY < 2 * Math.abs(centerY - locY[x]))
+ maxY = (2 * Math.abs(centerY - locY[x]));
+ if (maxZ < 2 * Math.abs(centerZ - locZ[x]))
+ maxZ = (2 * Math.abs(centerZ - locZ[x]));
+ }
+
+ //centerX,centerY,centerZ are the coordinates of the "event center".
+ //so let's save those coordinates to check on the players:
+ eventCenterX = centerX;
+ eventCenterY = centerY;
+ eventCenterZ = centerZ;
+ eventOffset = maxX;
+ if (eventOffset < maxY)
+ eventOffset = maxY;
+ if (eventOffset < maxZ)
+ eventOffset = maxZ;
+ }
+
+ public static boolean isOutsideCTFArea(L2PcInstance _player)
+ {
+ if (_player == null || _player.isOnline() == 0)
+ return true;
+ if (!(_player.getX() > eventCenterX - eventOffset && _player.getX() < eventCenterX + eventOffset && _player.getY() > eventCenterY - eventOffset
+ && _player.getY() < eventCenterY + eventOffset && _player.getZ() > eventCenterZ - eventOffset && _player.getZ() < eventCenterZ + eventOffset))
+ return true;
+ return false;
+ }
+}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java (revision 310)
@@ -26,4 +26,5 @@
package net.sf.l2j.gameserver.handler.itemhandlers;

+import net.sf.l2j.Config;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.NpcTable;
@@ -38,6 +39,8 @@
import net.sf.l2j.gameserver.model.actor.instance.L2PetIn stance;
import net.sf.l2j.gameserver.model.actor.instance.L2Playa bleInstance;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.model.entity.TvTEvent;
import net.sf.l2j.gameserver.network.SystemMessageId;
+import net.sf.l2j.gameserver.network.serverpackets.Action Failed;
import net.sf.l2j.gameserver.network.serverpackets.MagicS killLaunched;
import net.sf.l2j.gameserver.network.serverpackets.MagicS killUser;
@@ -73,5 +76,11 @@
if (activeChar.inObserverMode())
return;
-
+
+ if (activeChar._inEventCTF && CTF._started && !Config.CTF_ALLOW_SUMMON)
+ {
+ activeChar.sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }
+
if (activeChar.isInOlympiadMode())
{
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/ScrollOfEscape.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/ScrollOfEscape.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/ScrollOfEscape.java (revision 310)
@@ -78,4 +78,9 @@
return;
}
+ if (activeChar._inEventCTF)
+ {
+ activeChar.sendMessage("You may not use an escape skill in a Event.");
+ return;
+ }

if (activeChar.isInOlympiadMode())
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Potions.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Potions.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/itemhandlers/Potions.java (revision 310)
@@ -22,4 +22,5 @@
import java.util.logging.Logger;

+import net.sf.l2j.Config;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.SkillTable;
@@ -31,4 +32,5 @@
import net.sf.l2j.gameserver.model.actor.instance.L2PetIn stance;
import net.sf.l2j.gameserver.model.actor.instance.L2Playa bleInstance;
+import net.sf.l2j.gameserver.model.entity.CTF;
import net.sf.l2j.gameserver.model.entity.TvTEvent;
import net.sf.l2j.gameserver.network.SystemMessageId;
@@ -105,4 +107,9 @@
return;
}
+ if (activeChar._inEventCTF && CTF._started && !Config.CTF_ALLOW_POTIONS)
+ {
+ activeChar.sendPacket(ActionFailed.STATIC_PACKET);
+ return;
+ }

if (activeChar.isInOlympiadMode())
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/skillhandlers/Recall.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/skillhandlers/Recall.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/skillhandlers/Recall.java (revision 310)
@@ -73,5 +73,11 @@
continue;
}
-
+ // Check to see if the current player target is in CTF
+ if (targetChar._inEventCTF)
+ {
+ targetChar.sendMessage("You may not use an escape skill in a Event.");
+ continue;
+ }
+
// Check to see if player is in jail
if (targetChar.isInJail())
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 310)
@@ -68,4 +68,5 @@
registerAdminCommandHandler(new AdminAnnouncements());
registerAdminCommandHandler(new AdminCreateItem());
+ registerAdminCommandHandler(new AdminCTFEngine());
registerAdminCommandHandler(new AdminHeal());
registerAdminCommandHandler(new AdminHelpPage());
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java (revision 310)
@@ -92,4 +92,6 @@
registerVoicedCommandHandler(new TvTEventCmds());
}
+ registerVoicedCommandHandler(new CTFCmd());
+
_log.config("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminCTFEngine.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminCTFEngine.java (revision 310)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminCTFEngine.java (revision 310)
@@ -0,0 +1,509 @@
+/* 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 2, 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
+ */
+package net.sf.l2j.gameserver.handler.admincommandhandlers ;
+
+/**
+ *
+ * @author Administrator
+ */
+import net.sf.l2j.Config;
+import net.sf.l2j.gameserver.datatables.ItemTable;
+import net.sf.l2j.gameserver.handler.ihandlers.IAdminComm andHandler;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcIns tance;
+import net.sf.l2j.gameserver.model.entity.CTF;
+import net.sf.l2j.gameserver.network.serverpackets.NpcHtm lMessage;
+
+
+import javolution.text.TextBuilder;
+
+public class AdminCTFEngine implements IAdminCommandHandler
+{
+ private static final String[] ADMIN_COMMANDS =
+ {
+ "admin_ctf",
+ "admin_ctf_name",
+ "admin_ctf_desc",
+ "admin_ctf_join_loc",
+ "admin_ctf_edit",
+ "admin_ctf_control",
+ "admin_ctf_minlvl",
+ "admin_ctf_maxlvl",
+ "admin_ctf_tele_npc",
+ "admin_ctf_tele_team",
+ "admin_ctf_tele_flag",
+ "admin_ctf_npc",
+ "admin_ctf_npc_pos",
+ "admin_ctf_reward",
+ "admin_ctf_reward_amount",
+ "admin_ctf_team_add",
+ "admin_ctf_team_remove",
+ "admin_ctf_team_pos",
+ "admin_ctf_team_color",
+ "admin_ctf_team_flag",
+ "admin_ctf_join",
+ "admin_ctf_teleport",
+ "admin_ctf_start",
+ "admin_ctf_abort",
+ "admin_ctf_finish",
+ "admin_ctf_sit",
+ "admin_ctf_dump",
+ "admin_ctf_save",
+ "admin_ctf_load",
+ "admin_ctf_jointime",
+ "admin_ctf_eventtime",
+ "admin_ctf_autoevent",
+ "admin_ctf_minplayers",
+ "admin_ctf_maxplayers" };
+
+ private static final int REQUIRED_LEVEL = 100;
+
+ public boolean useAdminCommand(String command, L2PcInstance activeChar)
+ {
+ try
+ {
+ if (command.equals("admin_ctf"))
+ showMainPage(activeChar);
+ else if (command.startsWith("admin_ctf_name "))
+ {
+ CTF._eventName = command.substring(15);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_desc "))
+ {
+ CTF._eventDesc = command.substring(15);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_minlvl "))
+ {
+ if (!CTF.checkMinLevel(Integer.valueOf(command.substr ing(17))))
+ return false;
+ CTF._minlvl = Integer.valueOf(command.substring(17));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_team_flag "))
+ {
+ String[] params;
+
+ params = command.split(" ");
+
+ if (params.length != 2)
+ {
+ activeChar.sendMessage("Wrong usge: //ctf_team_flag <teamName>");
+ return false;
+ }
+
+ CTF.setTeamFlag(params[1], activeChar);
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_edit"))
+ {
+ showEditPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_control"))
+ {
+ showControlPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_tele_npc"))
+ {
+ activeChar.teleToLocation(CTF._npcX, CTF._npcY, CTF._npcZ);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_tele_team "))
+ {
+ for (String t : CTF._teams)
+ if (t.equals(command.substring(20)))
+ {
+ int index = CTF._teams.indexOf(t);
+ activeChar.teleToLocation(CTF._teamsX.get(index), CTF._teamsY.get(index), CTF._teamsZ.get(index));
+ }
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_tele_flag "))
+ {
+ for (String t : CTF._teams)
+ if (t.equals(command.substring(20)))
+ {
+ int index = CTF._teams.indexOf(t);
+ activeChar.teleToLocation(CTF._flagsX.get(index), CTF._flagsY.get(index), CTF._flagsZ.get(index));
+ }
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_maxlvl "))
+ {
+ if (!CTF.checkMaxLevel(Integer.valueOf(command.substr ing(17))))
+ return false;
+ CTF._maxlvl = Integer.valueOf(command.substring(17));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_minplayers "))
+ {
+ CTF._minPlayers = Integer.valueOf(command.substring(21));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_maxplayers "))
+ {
+ CTF._maxPlayers = Integer.valueOf(command.substring(21));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_join_loc "))
+ {
+ CTF._joiningLocationName = command.substring(19);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_npc "))
+ {
+ CTF._npcId = Integer.valueOf(command.substring(14));
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_npc_pos"))
+ {
+ CTF.setNpcPos(activeChar);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_reward "))
+ {
+ CTF._rewardId = Integer.valueOf(command.substring(17));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_reward_amount "))
+ {
+ CTF._rewardAmount = Integer.valueOf(command.substring(24));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_jointime "))
+ {
+ CTF._joinTime = Integer.valueOf(command.substring(19));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_eventtime "))
+ {
+ CTF._eventTime = Integer.valueOf(command.substring(20));
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_team_add "))
+ {
+ String teamName = command.substring(19);
+
+ CTF.addTeam(teamName);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_team_remove "))
+ {
+ String teamName = command.substring(22);
+
+ CTF.removeTeam(teamName);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_team_pos "))
+ {
+ String teamName = command.substring(19);
+
+ CTF.setTeamPos(teamName, activeChar);
+ showMainPage(activeChar);
+ }
+ else if (command.startsWith("admin_ctf_team_color "))
+ {
+ String[] params;
+
+ params = command.split(" ");
+
+ if (params.length != 3)
+ {
+ activeChar.sendMessage("Wrong usege: //ctf_team_color <colorHex> <teamName>");
+ return false;
+ }
+
+ // name/title color in client is BGR, not RGB
+ CTF.setTeamColor(command.substring(params[0].length() + params[1].length() + 2), Integer.decode("0x" + (params[1])));
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_join"))
+ {
+ CTF.startJoin(activeChar);
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_teleport"))
+ {
+ CTF.teleportStart();
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_start"))
+ {
+ CTF.startEvent(activeChar);
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_abort"))
+ {
+ activeChar.sendMessage("Aborting event");
+ CTF.abortEvent();
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_finish"))
+ {
+ CTF.finishEvent();
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_sit"))
+ {
+ CTF.sit();
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_load"))
+ {
+ CTF.loadData();
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_autoevent"))
+ {
+ if (CTF._joinTime > 0 && CTF._eventTime > 0)
+ CTF.autoEvent();
+ else
+ activeChar.sendMessage("Wrong usege: join time or event time invallid.");
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_save"))
+ {
+ CTF.saveData();
+ showMainPage(activeChar);
+ }
+ else if (command.equals("admin_ctf_dump"))
+ CTF.dumpData();
+
+ return true;
+ }
+ catch (Exception e)
+ {
+ activeChar.sendMessage("The command was not used correctly");
+ return false;
+ }
+ }
+
+ public String[] getAdminCommandList()
+ {
+ return ADMIN_COMMANDS;
+ }
+
+ private boolean checkLevel(int level)
+ {
+ return (level >= REQUIRED_LEVEL);
+ }
+
+ public void showEditPage(L2PcInstance activeChar)
+ {
+ NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
+ TextBuilder replyMSG = new TextBuilder("<html><body>");
+
+ replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine]</font></center><br><br><br>");
+ replyMSG.append("<table><tr><td><edit var=\"input1\" width=\"125\"></td><td><edit var=\"input2\" width=\"125\"></td></tr></table>");
+ replyMSG.append("<table border=\"0\"><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Name\" action=\"bypass -h admin_ctf_name $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Description\" action=\"bypass -h admin_ctf_desc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Join Location\" action=\"bypass -h admin_ctf_join_loc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Max lvl\" action=\"bypass -h admin_ctf_maxlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Min lvl\" action=\"bypass -h admin_ctf_minlvl $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Max players\" action=\"bypass -h admin_ctf_maxplayers $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Min players\" action=\"bypass -h admin_ctf_minplayers $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"NPC\" action=\"bypass -h admin_ctf_npc $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"NPC Pos\" action=\"bypass -h admin_ctf_npc_pos\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Reward\" action=\"bypass -h admin_ctf_reward $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Reward Amount\" action=\"bypass -h admin_ctf_reward_amount $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Join Time\" action=\"bypass -h admin_ctf_jointime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Event Time\" action=\"bypass -h admin_ctf_eventtime $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Team Add\" action=\"bypass -h admin_ctf_team_add $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Team Color\" action=\"bypass -h admin_ctf_team_color $input1 $input2\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Team Pos\" action=\"bypass -h admin_ctf_team_pos $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Team Flag\" action=\"bypass -h admin_ctf_team_flag $input1 $input2\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Team Remove\" action=\"bypass -h admin_ctf_team_remove $input1\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br>");
+ replyMSG
+ .append("<br><center><button value=\"Back\" action=\"bypass -h admin_ctf\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
+ adminReply.setHtml(replyMSG.toString());
+ activeChar.sendPacket(adminReply);
+ }
+
+ public void showControlPage(L2PcInstance activeChar)
+ {
+ NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
+ TextBuilder replyMSG = new TextBuilder("<html><body>");
+
+ replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine]</font></center><br><br><br>");
+ replyMSG.append("<table border=\"0\"><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Join\" action=\"bypass -h admin_ctf_join\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Teleport\" action=\"bypass -h admin_ctf_teleport\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Start\" action=\"bypass -h admin_ctf_start\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Abort\" action=\"bypass -h admin_ctf_abort\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Finish\" action=\"bypass -h admin_ctf_finish\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Sit Force\" action=\"bypass -h admin_ctf_sit\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Dump\" action=\"bypass -h admin_ctf_dump\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br><br><table><tr>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Save\" action=\"bypass -h admin_ctf_save\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Load\" action=\"bypass -h admin_ctf_load\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Auto Event\" action=\"bypass -h admin_ctf_autoevent\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br>");
+ replyMSG
+ .append("<br><center><button value=\"Back\" action=\"bypass -h admin_ctf\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
+ adminReply.setHtml(replyMSG.toString());
+ activeChar.sendPacket(adminReply);
+ }
+
+ public void showMainPage(L2PcInstance activeChar)
+ {
+ NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
+ TextBuilder replyMSG = new TextBuilder("<html><body>");
+
+ replyMSG.append("<center><font color=\"LEVEL\">[CTF Engine]</font></center><br><br><br>");
+
+ replyMSG.append("<table><tr>");
+ if (!CTF._joining && !CTF._started && !CTF._teleport)
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Edit\" action=\"bypass -h admin_ctf_edit\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG
+ .append("<td width=\"100\"><button value=\"Control\" action=\"bypass -h admin_ctf_control\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
+ replyMSG.append("</tr></table><br>");
+
+ replyMSG.append("<br><font color=\"LEVEL\">Current event...</font><br1>");
+ replyMSG.append(" ... name:&nbsp;<font color=\"00FF00\">" + CTF._eventName + "</font><br1>");
+ replyMSG.append(" ... description:&nbsp;<font color=\"00FF00\">" + CTF._eventDesc + "</font><br1>");
+ replyMSG.append(" ... joining location name:&nbsp;<font color=\"00FF00\">" + CTF._joiningLocationName + "</font><br1>");
+ replyMSG.append(" ... joining NPC ID:&nbsp;<font color=\"00FF00\">" + CTF._npcId + " on pos " + CTF._npcX + "," + CTF._npcY + "," + CTF._npcZ
+ + "</font><br1>");
+ replyMSG
+ .append(" <button value=\"Tele->NPC\" action=\"bypass -h admin_ctf_tele_npc\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br>");
+ replyMSG.append(" ... reward ID:&nbsp;<font color=\"00FF00\">" + CTF._rewardId + "</font><br1>");
+ if (ItemTable.getInstance().getTemplate(CTF._rewardId ) != null)
+ replyMSG
+ .append(" ... reward Item:&nbsp;<font color=\"00FF00\">" + ItemTable.getInstance().getTemplate(CTF._rewardId) .getName() + "</font><br1>");
+ else
+ replyMSG.append(" ... reward Item:&nbsp;<font color=\"00FF00\">(unknown)</font><br1>");
+ replyMSG.append(" ... reward Amount:&nbsp;<font color=\"00FF00\">" + CTF._rewardAmount + "</font><br>");
+ replyMSG.append(" ... Min lvl:&nbsp;<font color=\"00FF00\">" + CTF._minlvl + "</font><br1>");
+ replyMSG.append(" ... Max lvl:&nbsp;<font color=\"00FF00\">" + CTF._maxlvl + "</font><br><br>");
+ replyMSG.append(" ... Min Players:&nbsp;<font color=\"00FF00\">" + CTF._minPlayers + "</font><br1>");
+ replyMSG.append(" ... Max Players:&nbsp;<font color=\"00FF00\">" + CTF._maxPlayers + "</font><br>");
+ replyMSG.append(" ... Joining Time:&nbsp;<font color=\"00FF00\">" + CTF._joinTime + "</font><br1>");
+ replyMSG.append(" ... Event Time:&nbsp;<font color=\"00FF00\">" + CTF._eventTime + "</font><br>");
+ if (CTF._teams != null && !CTF._teams.isEmpty())
+ replyMSG.append("<font color=\"LEVEL\">Current teams:</font><br1>");
+ replyMSG.append("<center><table border=\"0\">");
+
+ for (String team : CTF._teams)
+ {
+ replyMSG.append("<tr><td width=\"100\">Name: <font color=\"FF0000\">" + team + "</font>");
+
+ if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE"))
+ replyMSG.append("&nbsp;(" + CTF.teamPlayersCount(team) + " joined)");
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE"))
+ {
+ if (CTF._teleport || CTF._started)
+ replyMSG.append("&nbsp;(" + CTF.teamPlayersCount(team) + " in)");
+ }
+ replyMSG.append("</td></tr><tr><td>");
+
+ String c = Integer.toHexString(CTF._teamColors.get(CTF._teams .indexOf(team)));
+ while (c.length() < 6)
+ c = "0" + c;
+ replyMSG.append("Color: <font color=\"00FF00\">0x" + c.toUpperCase() + "</font><font color=\"" + c + "\"> =) </font>");
+
+ replyMSG.append("</td></tr><tr><td>");
+ replyMSG.append("<button value=\"Tele->Team\" action=\"bypass -h admin_ctf_tele_team " + team
+ + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
+ replyMSG.append("</td></tr><tr><td>");
+ replyMSG.append(CTF._teamsX.get(CTF._teams.indexOf (team)) + ", " + CTF._teamsY.get(CTF._teams.indexOf(team)) + ", "
+ + CTF._teamsZ.get(CTF._teams.indexOf(team)));
+ replyMSG.append("</td></tr><tr><td>");
+ replyMSG.append("Flag Id: <font color=\"00FF00\">" + CTF._flagIds.get(CTF._teams.indexOf(team)) + "</font>");
+ replyMSG.append("</td></tr><tr><td>");
+ replyMSG.append("<button value=\"Tele->Flag\" action=\"bypass -h admin_ctf_tele_flag " + team
+ + "\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
+ replyMSG.append("</td></tr><tr><td>");
+ replyMSG.append(CTF._flagsX.get(CTF._teams.indexOf (team)) + ", " + CTF._flagsY.get(CTF._teams.indexOf(team)) + ", "
+ + CTF._flagsZ.get(CTF._teams.indexOf(team)) + "</td></tr>");
+ if (!CTF._joining && !CTF._started && !CTF._teleport)
+ replyMSG.append("<tr><td width=\"60\"><button value=\"Remove\" action=\"bypass -h admin_ctf_team_remove " + team
+ + "\" width=50 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr><tr></tr>");
+ }
+
+ replyMSG.append("</table></center>");
+
+ if (!CTF._joining && !CTF._started && !CTF._teleport)
+ {
+ if (CTF.startJoinOk())
+ {
+ replyMSG.append("<br1>");
+ replyMSG.append("Event is now set up. Press JOIN to start the registration.<br1>");
+ replyMSG
+ .append(" <button value=\"Join\" action=\"bypass -h admin_ctf_join\" width=90 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"><br1>");
+ replyMSG.append("<br>");
+ }
+ else
+ {
+ replyMSG.append("<br1>");
+ replyMSG
+ .append("Event is NOT set up. Press <font color=\"LEVEL\">EDIT</font> to create a new event, or <font color=\"LEVEL\">CONTROL</font> to load an existing event.<br1>");
+ replyMSG.append("<br>");
+ }
+ }
+ else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE") && !CTF._started)
+ {
+ replyMSG.append("<br1>");
+ replyMSG.append(CTF._playersShuffle.size() + " players participating. Waiting to shuffle in teams(done on teleport)!");
+ replyMSG.append("<br><br>");
+ }
+
+ replyMSG.append("</body></html>");
+ adminReply.setHtml(replyMSG.toString());
+ activeChar.sendPacket(adminReply);
+ }
+}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/CTFCmd.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/CTFCmd.java (revision 310)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/CTFCmd.java (revision 310)
@@ -0,0 +1,176 @@
+/* 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 2, 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
+ */
+package net.sf.l2j.gameserver.handler.voicedcommandhandler s;
+
+/**
+ *
+ * @author Administrator
+ */
+import net.sf.l2j.gameserver.handler.ihandlers.IVoicedCom mandHandler;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcIns tance;
+import net.sf.l2j.gameserver.model.entity.CTF;
+import net.sf.l2j.gameserver.network.serverpackets.NpcHtm lMessage;
+
+public class CTFCmd implements IVoicedCommandHandler
+{
+ private static final String[] VOICED_COMMANDS = { "joinctf", "leavectf", "infoctf" };
+
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (command.startsWith("joinctf"))
+ {
+ JoinCTF(activeChar);
+ }
+ else if(command.startsWith("leavectf"))
+ {
+ LeaveCTF(activeChar);
+ }
+
+ else if(command.startsWith("infoctf"))
+ {
+ SendCTFinfo(activeChar);
+ }
+
+ return true;
+ }
+
+ public String[] getVoicedCommandList()
+ {
+ return VOICED_COMMANDS;
+ }
+
+ public boolean JoinCTF (L2PcInstance activeChar)
+ {
+ if ( activeChar == null)
+ {
+ return false;
+ }
+ NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage( 0 );
+
+ int playerLevel = activeChar.getLevel();
+
+ if (!CTF._joining) //check if ctf event is running or/and joining is avaliable
+ {
+ npcHtmlMessage.setHtml("<html><body>You can not register now: CTF event joining is not avaliable.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if (activeChar._inEventCTF) //check if player is already registered in ctf event
+ {
+ npcHtmlMessage.setHtml("<html><body>You are participating this event already.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if ( activeChar.isCursedWeaponEquiped()) //check if player is holding a cursed weapon
+ {
+ npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event holding a Cursed Weapon.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if ( activeChar.isInOlympiadMode()) //check if player is in olympiads - dunno why, but sometimes simple doesnt work this check =/
+ {
+ npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event while in Olympiad.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if (activeChar.isInJail()) //check if player is in jail
+ {
+ npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event while in Jail.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if (activeChar.getLevel() < CTF._minlvl)
+ {
+ npcHtmlMessage.setHtml("<html><body>Your level is too low to participate at this Event.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if (activeChar.getKarma() > 0) //check player karma - dunno why karma players cant participate - looks useless since player can register while not with karma and do pk after that ;)
+ {
+ npcHtmlMessage.setHtml("<html><body>You are not allowed to participate to the Event with Karma.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if (CTF._maxPlayers == CTF._playersShuffle.size()) //check player karma - dunno why karma players cant participate - looks useless since player can register while not with karma and do pk after that ;)
+ {
+ npcHtmlMessage.setHtml("<html><body>Sorry,CTF Event is full.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else //send dialog confirmation to player that he is registered in ctf event and add him
+ {
+ npcHtmlMessage.setHtml("<html><body>Your participation in the CTF event has been aproved.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ CTF.addPlayer(activeChar,"");
+ return true;
+ }
+ }
+
+ public boolean LeaveCTF (L2PcInstance activeChar)
+ {
+ if ( activeChar == null)
+ {
+ return false;
+ }
+
+ NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage( 0 );
+
+ if (!CTF._joining) //check if CTF event is running or joining is avaliable
+ {
+ npcHtmlMessage.setHtml("<html><body>You can not unregister now cause there is no CTF event running.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else if (CTF._teleport || CTF._started) //check if ctf event has already teleported and started
+ {
+ npcHtmlMessage.setHtml("<html><body>You can not leave after CTF event has started.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ else //send dialog confirmation to player that he is unregistered from ctf event and remove him
+ {
+ npcHtmlMessage.setHtml("<html><body>Your participation in the CTF event has been removed.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ CTF.removePlayer(activeChar);
+ return true;
+ }
+ }
+ public boolean SendCTFinfo (L2PcInstance activeChar)
+ {
+ if ( activeChar == null)
+ {
+ return false;
+ }
+ NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage( 0 );
+
+ int playerLevel = activeChar.getLevel();
+
+ if (CTF._joining || CTF._teleport || CTF._started)
+ {
+ npcHtmlMessage.setHtml("<html><body>There are " + CTF._playersShuffle.size() + " players participating in this event.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return true;
+ }
+ else
+ {
+ npcHtmlMessage.setHtml("<html><body>There is no Event in progress.</body></html>");
+ activeChar.sendPacket( npcHtmlMessage );
+ return false;
+ }
+ }
+}
Index: /trunk/GameServer/java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java (revision 303)
+++ /trunk/GameServer/java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java (revision 310)
@@ -65,4 +65,10 @@
return false;
}
+ // Check to see if the current player is in CTF
+ if (activeChar.isInFunEvent())
+ {
+ activeChar.sendMessage("You may not escape from an Event.");
+ return false;
+ }

// Check to see if player is in jail
Index: /trunk/GameServer/java/net/sf/l2j/Config.java
================================================== =================
--- /trunk/GameServer/java/net/sf/l2j/Config.java (revision 306)
+++ /trunk/GameServer/java/net/sf/l2j/Config.java (revision 310)
@@ -480,5 +480,16 @@
public static byte TVT_EVENT_MAX_LVL;
public static boolean TVT_EVENT_COMMANDS;
-
+ public static String CTF_EVEN_TEAMS;
+ public static boolean CTF_ALLOW_INTERFERENCE;
+ public static boolean CTF_ALLOW_POTIONS;
+ public static boolean CTF_ALLOW_SUMMON;
+ public static boolean CTF_ON_START_REMOVE_ALL_EFFECTS;
+ public static boolean CTF_ON_START_UNSUMMON_PET;
+ public static boolean CTF_ANNOUNCE_TEAM_STATS;
+ public static boolean CTF_ANNOUNCE_REWARD;
+ public static boolean CTF_JOIN_CURSED;
+ public static boolean CTF_REVIVE_RECOVERY;
+ public static long CTF_REVIVE_DELAY;
+
/** Alternative Settings Parameters */
public static int TRADE_UNITS;
@@ -1922,4 +1933,20 @@
TVT_EVENT_RUNNING_TIME = Integer.parseInt(Events.getProperty("TvTEventRunni ngTime", "1800"));
TVT_EVENT_PARTICIPATION_NPC_ID = Integer.parseInt(Events.getProperty("TvTEventParti cipationNpcId", "0"));
+ CTF_EVEN_TEAMS = Events.getProperty("CTFEvenTeams", "BALANCE");
+ CTF_ALLOW_INTERFERENCE = Boolean.parseBoolean(Events.getProperty("CTFAllowI nterference", "false"));
+ CTF_ALLOW_POTIONS = Boolean.parseBoolean(Events.getProperty("CTFAllowP otions", "false"));
+ CTF_ALLOW_SUMMON = Boolean.parseBoolean(Events.getProperty("CTFAllowS ummon", "false"));
+ CTF_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(Events.getProperty("CTFOnStar tRemoveAllEffects", "true"));
+ CTF_ON_START_UNSUMMON_PET = Boolean.parseBoolean(Events.getProperty("CTFOnStar tUnsummonPet", "true"));
+ CTF_ANNOUNCE_TEAM_STATS = Boolean.parseBoolean(Events.getProperty("CTFAnnoun ceTeamStats", "false"));
+ CTF_ANNOUNCE_REWARD = Boolean.parseBoolean(Events.getProperty("CTFAnnoun ceReward", "false"));
+ CTF_JOIN_CURSED = Boolean.parseBoolean(Events.getProperty("CTFJoinWi thCursedWeapon", "true"));
+ CTF_REVIVE_RECOVERY = Boolean.parseBoolean(Events.getProperty("CTFRevive Recovery", "false"));
+ CTF_REVIVE_DELAY = Long.parseLong(Events.getProperty("CTFReviveDelay" , "20000"));
+
+ if (CTF_REVIVE_DELAY < 1000)
+ CTF_REVIVE_DELAY = 1000; //can't be set less then 1 second
+
+
if (TVT_EVENT_PARTICIPATION_NPC_ID == 0)
{
@@ -2435,4 +2462,11 @@
else if (pName.equalsIgnoreCase("TvTEventRunningTime")) TVT_EVENT_RUNNING_TIME = Integer.parseInt(pValue);
else if (pName.equalsIgnoreCase("TvTEventParticipationNpcI d")) TVT_EVENT_PARTICIPATION_NPC_ID = Integer.parseInt(pValue);
+ else if (pName.equalsIgnoreCase("CTFEvenTeams")) CTF_EVEN_TEAMS = pValue;
+ else if (pName.equalsIgnoreCase("CTFAllowInterference")) CTF_ALLOW_INTERFERENCE = Boolean.parseBoolean(pValue);
+ else if (pName.equalsIgnoreCase("CTFAllowPotions")) CTF_ALLOW_POTIONS = Boolean.parseBoolean(pValue);
+ else if (pName.equalsIgnoreCase("CTFAllowSummon")) CTF_ALLOW_SUMMON = Boolean.parseBoolean(pValue);
+ else if (pName.equalsIgnoreCase("CTFOnStartRemoveAllEffect s")) CTF_ON_START_REMOVE_ALL_EFFECTS = Boolean.parseBoolean(pValue);
+ else if (pName.equalsIgnoreCase("CTFOnStartUnsummonPet")) CTF_ON_START_UNSUMMON_PET = Boolean.parseBoolean(pValue);
+ else if (pName.equalsIgnoreCase("CTFReviveDelay")) CTF_REVIVE_DELAY = Long.parseLong(pValue);
else if (pName.equalsIgnoreCase("MinKarma")) KARMA_MIN_KARMA = Integer.parseInt(pValue);
else if (pName.equalsIgnoreCase("MaxKarma")) KARMA_MAX_KARMA = Integer.parseInt(pValue);
Index: /trunk/GameServer/Settings/Modifications/Events.properties
================================================== =================
--- /trunk/GameServer/Settings/Modifications/Events.properties (revision 231)
+++ /trunk/GameServer/Settings/Modifications/Events.properties (revision 310)
@@ -61,2 +61,29 @@
# no ";" at the start or end
TvTEventDoorsCloseOpenOnStartEnd =
+
+# Setting for Capture The Flag
+# CTFEvenTeams = NO|BALANCE|SHUFFLE
+# NO means: not even teams.
+# BALANCE means: Players can only join team with lowest player count.
+# SHUFFLE means: Players can only participate to the event and not direct to a team. Teams will be shuffled on teams teleport.
+CTFEvenTeams = SHUFFLE
+# Players that are not participating in CTF can target ctf participants?
+CTFAllowInterference = False
+# CTF participants can use potions?
+CTFAllowPotions = False
+# CTF participants can summon by item?
+CTFAllowSummon = False
+# Remove all effects of CTF participants on event start?
+CTFOnStartRemoveAllEffects = True
++# Unsummon pet of CTF participants on event start?
+CTFOnStartUnsummonPet = True
+# On revive participants regain full HP/MP/CP?
+CTFReviveRecovery = False
+# Announce all team statistics
+CTFAnnounceTeamStats = False
+# Announce reward
+CTFAnnounceReward = False
+# Players with cursed weapon are allowed to join?
+CTFJoinWithCursedWeapon = True
+# Delay on revive when dead, NOTE: 20000 equals to 20 seconds, minimum 1000 (1 second)
+CTFReviveDelay = 20000

B1Z4R0 está offline  
Os Seguintes 2 Usuários disseram Obrigado(a) para B1Z4R0 por gostarem deste post :
C.Bartowski (30-07-2010), l2blackice (30-07-2010)
Antigo 30-07-2010, 11:15 AM   #5 (permalink)
Amigo SE
 
Avatar de C.Bartowski
 
Registrado em: Feb 2010
Localização: Caxias do Sul - RS
Posts: 644
Agradeceu: 405
Agradecido 582 Vezes em 224 Posts
Achei Ruim:
Acharam ruim Vezes em Posts
Rate Designer: Iniciante
Meu Estado:
Enviar mensagem via Windows Live Messenger para C.Bartowski
Nome Real: Henrique Galafassi Dalssaso

Inventório de C.Bartowski

Padrão

Vllwwww B1Z4R0...

Vlw's mesmo velhow...

Tipo vamos tentar tranformar para automatico mas tudo bem se não for também...

Vlw's Mesmow Galerinha

attention

Atenção

Tópico Trancado




__________________
[Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar] [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar] [Somente Usuários Registrados Podem Visualizar os Links Desta PáginaClique aqui para se Registrar]
C.Bartowski está offline  
O seguinte membro ao lado disse Obrigado(a) a : C.Bartowski por gostar deste Post :
l2blackice (30-07-2010)
Tópico Trancado


Regras para Posts
Você não pode postar novos tópicos
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar seus posts

Código [IMG] Sim
Código HTML Não
Trackbacks are Sim
Pingbacks are Sim
Refbacks are Sim



Horários baseados na GMT -3. Agora são 10:24 AM.