Autor Tema: [MOD - EventCooperative] - Error  (Leído 313 veces)

canonmagic

  • Jr. Member
  • **
  • Mensajes: 52
  • Karma: +0/-0
    • Ver Perfil
[MOD - EventCooperative] - Error
« en: Julio 10, 2018, 01:12:58 pm »
Buenas, hoy estuve andando un poco con los eventos cooperativos "TVT,CTF,DM,etc"; encontre que al momento de que terminara el timer y lanzara el evento este no realiza el teletransporte de los inscritos al evento "ninguno de ellos". Dentro del codigo hay un "World.add(ph), (El comentario dice que es el encargado del teleport)" Pero no comprendo del todo la creacion de los Worlds asi que no pude analizar mas a fondo si estaba alli el error. Y pues sucede que al realizarse el chequeo de los jugadores dentro del evento como no hay jugadores en la zona el world se elimina automaticamente y el jugador es eliminado del array de "PlayersInEvent".

Nota: El metodo de la revision de IP tenia un pequeño error el cual aun dejando el config de CheckIp como false seguia rechazando la inscripcion. Y en el config de FlagHolder habia un numero faltante en el ID. Aqui dejo el diff

Código
### Eclipse Workspace Patch 1.0
#P C4_Mods
Index: src/main/engine/events/cooperative/EventCooperativeManager.java
===================================================================
--- src/main/engine/events/cooperative/EventCooperativeManager.java (revision 1100)
+++ src/main/engine/events/cooperative/EventCooperativeManager.java (working copy)
@@ -228,7 +228,8 @@
 
  if (isRegisterPlayerIp(ph, false))
  {
- return false;
+ registerPlayers.add(ph.getObjectId());
+ return true;
  }
 
  registerPlayers.add(ph.getObjectId());
@@ -276,7 +277,7 @@
  */
  public static boolean isRegisterPlayerIp(PlayerHolder ph, boolean removeOffline)
  {
- if (ConfigData.COOPERATIVE_CHECK_PLAYER_IP)
+ if (ConfigData.COOPERATIVE_CHECK_PLAYER_IP == false)
  {
  return false;
  }

Código
### Eclipse Workspace Patch 1.0
#P C4_GameServer
Index: dist/game/config/engine/EventsCooperative.properties
===================================================================
--- dist/game/config/engine/EventsCooperative.properties (revision 1100)
+++ dist/game/config/engine/EventsCooperative.properties (working copy)
@@ -76,7 +76,7 @@
 CtF_FlagId = 60018
 
 # Holder npc id
-Ctf_HolderId = 6001
+Ctf_HolderId = 60019
 
 # Points deliver flag
 Ctf_DeliverFlag = 30

fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 196
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #1 en: Julio 10, 2018, 03:06:57 pm »
los worlds tienen un purge q se ejecuta cada 10 min, es muy loco pensar q se ejecuta justo en esos 5 seg q demora entre q se crea y se envia los players pero en alguna ocacion puede pasar, asique cambie para q no esos no se purgen y te dejoa lgun q otro cambio.

Código
Index: src/main/engine/events/cooperative/AbstractCooperative.java
===================================================================
--- src/main/engine/events/cooperative/AbstractCooperative.java (revision 1121)
+++ src/main/engine/events/cooperative/AbstractCooperative.java (working copy)
@@ -132,7 +132,7 @@
  }
  case PREPARE_TO_TELEPORT:
  {
- world = WorldData.create(WORLD_ID, true);
+ world = WorldData.create(WORLD_ID, false);
  // Create doors
  addSpawnDoor(24190001);
  addSpawnDoor(24190002);
Index: src/main/engine/events/cooperative/EventCooperativeManager.java
===================================================================
--- src/main/engine/events/cooperative/EventCooperativeManager.java (revision 1121)
+++ src/main/engine/events/cooperative/EventCooperativeManager.java (working copy)
@@ -257,31 +257,31 @@
  * <li>We check that all registered players are online.</li>
  * <li>Check the player's ip with the others registered.</li>
  * @param ph
- * @param removeOffline -> remove offline players from {@link #_registerPlayers}
+ * @param removeOffline -> remove offline players from {@link #registerPlayers}
  * @return
  */
  public static boolean isRegisterPlayerIp(PlayerHolder ph, boolean removeOffline)
  {
- if (ConfigData.COOPERATIVE_CHECK_PLAYER_IP)
+ if (removeOffline)
  {
- return false;
+ checkPlayerRegister();
  }
 
- if (removeOffline)
+ if (!ConfigData.COOPERATIVE_CHECK_PLAYER_IP)
  {
- checkPlayerRegister();
+ return false;
  }
 
  for (var objId : registerPlayers)
  {
- var pc = L2World.getInstance().getPlayer(objId);
-
  // Do not check the ip of the same player in case it was already registered
- if (ph.getObjectId() == pc.getObjectId())
+ if (ph.getObjectId() == objId)
  {
  continue;
  }
 
+ var pc = L2World.getInstance().getPlayer(objId);
+
  if (pc.getConnection().getIP().equals(ph.getInstance().getConnection().getIP()))
  {
  return true;

si no funciona tendre q sentarme a testearlo yo :s

canonmagic

  • Jr. Member
  • **
  • Mensajes: 52
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #2 en: Julio 12, 2018, 04:59:19 pm »
Disculpa por la tardanza anduve sin internet un par de dias... Bueno aplique el diff y nada el problema sigue igual, pero un dato que se me olvido mencionarte es que yo en medio de los chequeos que le hize introduje un print que me mandara el array de los playersOnEvent dentro del CTF al momento en que spawnea las flags. Y este me mostraba que el array en ese punto llegaba vacio; El array dudo mucho que funcione mal debido a que en el NPC al registrar va funcionando bien. Lo unico que deduzco es que el teleport al World no esta funcionando correctamente. Aun eliminando el autodelete el evento realiza un proceso de Chequeo de playersOnEvent y este al no encontrar al personaje dentro de la zona world lo asume inmediatamente como si estuviece desconectado o fuera del evento por lo cual lo elimina de la lista y debido a esto el evento queda a medias. Incluso active el evento y fui al coliseo y las puertas estaban generadas y cerradas como deberia ser. Pero las banderas de CTF o los mob de Survive no estaban spawneados... Nose si esto te servira de algo.

fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 196
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #3 en: Julio 13, 2018, 12:42:23 am »
Código
Index: .
===================================================================
--- . (revision 1121)
+++ . (working copy)

Property changes on: .
___________________________________________________________________
Modified: svn:ignore
## -1 +1,2 ##
+bin
 build
Index: dist/game/config/engine/EventsCooperative.properties
===================================================================
--- dist/game/config/engine/EventsCooperative.properties (revision 1121)
+++ dist/game/config/engine/EventsCooperative.properties (working copy)
@@ -76,7 +76,7 @@
 CtF_FlagId = 60018
 
 # Holder npc id
-Ctf_HolderId = 6001
+Ctf_HolderId = 60019
 
 # Points deliver flag
 Ctf_DeliverFlag = 30
Index: src/main/data/ConfigData.java
===================================================================
--- src/main/data/ConfigData.java (revision 1121)
+++ src/main/data/ConfigData.java (working copy)
@@ -282,7 +282,7 @@
  loadPvpReward();
  loadSpreeKills();
  loadSubclassAcumulatives();
- loadCoperative();
+ loadCooperative();
  loadRandoms();
  }
 
@@ -307,7 +307,7 @@
  ALL_FLAGS_Enabled = config.getProperty("Flags_Enabled", true);
  }
 
- private static void loadCoperative()
+ private static void loadCooperative()
  {
  UtilProperties config = load(COOPERATIVE_FILE);
 
Index: src/main/engine/events/cooperative/AbstractCooperative.java
===================================================================
--- src/main/engine/events/cooperative/AbstractCooperative.java (revision 1121)
+++ src/main/engine/events/cooperative/AbstractCooperative.java (working copy)
@@ -115,9 +115,9 @@
  /**
  * Launch the events and their times.
  */
- public void start(List<Integer> playersInEvent)
+ public void start(List<Integer> list)
  {
- playersInEvent.addAll(playersInEvent);
+ playersInEvent.addAll(list);
 
  start = ThreadPoolManager.getInstance().scheduleAtFixedRate(() ->
  {
@@ -132,7 +132,7 @@
  }
  case PREPARE_TO_TELEPORT:
  {
- world = WorldData.create(WORLD_ID, true);
+ world = WorldData.create(WORLD_ID, false);
  // Create doors
  addSpawnDoor(24190001);
  addSpawnDoor(24190002);
@@ -172,12 +172,14 @@
  giveBuff(ph);
  });
 
+ // The characters are sent to a custom world
+ getPlayersInEvent().forEach(ph -> world.add(ph));
+
  // Create teams.
  createTeams();
+ // Create partys.
+ createParty();
 
- // The characters are sent to a custom world
- getPlayersInEvent().forEach(ph -> world.add(ph));
-
  // Define the next state
  setEventState(EventState.PREPARE_TO_FIGHT);
  break;
@@ -204,7 +206,6 @@
  setEventState(EventState.START);
  }
 
- createParty();
  break;
  }
  case START:
@@ -472,8 +473,9 @@
  {
  // prevent memory leak
  ph.setTeam(TeamType.NONE);
+ // remove from custom world
  world.remove(ph);
-
+ // sql query from new xyz
  removeOfflinePlayer(objId);
  }
  else
@@ -481,7 +483,7 @@
  players.add(ph);
  }
  });
-
+ players.forEach(id -> System.out.println(id.getName() + ";"));
  return players;
  }
 
@@ -534,9 +536,9 @@
  */
  public boolean playerInEvent(CharacterHolder... players)
  {
- for (var player : players)
+ for (var p : players)
  {
- if (!playersInEvent.contains(player.getObjectId()))
+ if (!playersInEvent.contains(p.getObjectId()))
  {
  return false;
  }
Index: src/main/engine/events/cooperative/EventCooperativeManager.java
===================================================================
--- src/main/engine/events/cooperative/EventCooperativeManager.java (revision 1121)
+++ src/main/engine/events/cooperative/EventCooperativeManager.java (working copy)
@@ -257,31 +257,31 @@
  * <li>We check that all registered players are online.</li>
  * <li>Check the player's ip with the others registered.</li>
  * @param ph
- * @param removeOffline -> remove offline players from {@link #_registerPlayers}
+ * @param removeOffline -> remove offline players from {@link #registerPlayers}
  * @return
  */
  public static boolean isRegisterPlayerIp(PlayerHolder ph, boolean removeOffline)
  {
- if (ConfigData.COOPERATIVE_CHECK_PLAYER_IP)
+ if (removeOffline)
  {
- return false;
+ checkPlayerRegister();
  }
 
- if (removeOffline)
+ if (!ConfigData.COOPERATIVE_CHECK_PLAYER_IP)
  {
- checkPlayerRegister();
+ return false;
  }
 
  for (var objId : registerPlayers)
  {
- var pc = L2World.getInstance().getPlayer(objId);
-
  // Do not check the ip of the same player in case it was already registered
- if (ph.getObjectId() == pc.getObjectId())
+ if (ph.getObjectId() == objId)
  {
  continue;
  }
 
+ var pc = L2World.getInstance().getPlayer(objId);
+
  if (pc.getConnection().getIP().equals(ph.getInstance().getConnection().getIP()))
  {
  return true;
@@ -299,7 +299,7 @@
  // Check the characters offline
  List<Integer> aux = registerPlayers.stream().filter(objId -> L2World.getInstance().getPlayer(objId) == null).collect(Collectors.toList());
  // Remove offline players from the registry
- aux.forEach(objId -> registerPlayers.remove(Integer.valueOf(objId)));
+ aux.forEach(objId -> registerPlayers.remove(objId));
  }
 
  // XXX VOTE -------------------------------------------------------------------------------------------------------------------
Index: src/main/engine/events/cooperative/npc/RegisterNpc.java
===================================================================
--- src/main/engine/events/cooperative/npc/RegisterNpc.java (revision 1121)
+++ src/main/engine/events/cooperative/npc/RegisterNpc.java (working copy)
@@ -74,7 +74,7 @@
  {
  var hb = new HtmlBuilder(HtmlType.HTML);
  hb.append(Html.START);
- hb.append(Html.head("COPERATIVE EVENTS"));
+ hb.append(Html.head("COOPERATIVE EVENTS"));
  hb.append("<center>");
  hb.append("<br><br><br><br>");
  if (EventCooperativeManager.unRegister(ph))
@@ -95,7 +95,7 @@
  {
  var hb = new HtmlBuilder(HtmlType.HTML);
  hb.append(Html.START);
- hb.append(Html.head("COPERATIVE EVENTS"));
+ hb.append(Html.head("COOPERATIVE EVENTS"));
  hb.append("<center>");
  hb.append("<br><br><br><br>");
 
@@ -132,7 +132,7 @@
  {
  var hb = new HtmlBuilder(HtmlType.HTML);
  hb.append(Html.START);
- hb.append(Html.head("COPERATIVE EVENTS"));
+ hb.append(Html.head("COOPERATIVE EVENTS"));
  hb.append("<center>");
  hb.append("<br><br><br><br>");
 
@@ -169,7 +169,7 @@
  {
  var hb = new HtmlBuilder(HtmlType.HTML);
  hb.append(Html.START);
- hb.append(Html.head("COPERATIVE EVENTS"));
+ hb.append(Html.head("COOPERATIVE EVENTS"));
  hb.append("<center>");
  hb.append("<br>");
 

bueno ya esta aca el fix, lo que si al finalizar el evento no me dio el reward, chequealo y me contas.

canonmagic

  • Jr. Member
  • **
  • Mensajes: 52
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #4 en: Julio 13, 2018, 06:20:27 pm »
Bueno ahora si lanzo bien el TP, acerca de los rewards estos solo son entregados cuando hay mas de 1 player "No tendria sentido un cooperative de 1 player  ::)", estuve probandolo y va bien hasta cierto punto, eso si... parece que el problema de el evento era por el checkafk debido a que ahora si envia al coliseo pero yo le configure 60 segs del anti-afks y me saca del evento inclusive moviendo al char en esos 60 segs, desactive el anti-afk y ya no sucedia mas ese problema "creo que es otro detalle entre los true/false". Aparte de unos detalles en los eventos como que las banderas se buguearon cuando sali del evento con ella y al deletearla en la mochila  fuera del evento causo que en el otro evento se bugueasen las banderas y dropeaba banderas cada vez que moria "Aun sin tenerla xD" pero las banderas quedaban como NPC y no pickeables ademas de que el spawn de la 2da bandera "Creo que era la red" no estaba... Yo en un rato que me desocupe reviso si puedo arreglarlo y te mando el fix

canonmagic

  • Jr. Member
  • **
  • Mensajes: 52
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #5 en: Julio 13, 2018, 07:23:50 pm »
Bueno, anduve echandole un ojo y ni idea ya que desconozco como funcionan los worlds, pero coloque un print nuevamente para que me devolviera los Location durante el inicializado del Anti-afk y antes de que teletransportara al evento y me di cuenta que al momento en que te envia al world no cambian los location al moverte "Queda la localizacion antes de teletransportarte"  :o, esta es la razon de que kickeara del evento  el anti afk aun moviendose dentro del coliseo

fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 196
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #6 en: Julio 13, 2018, 07:33:15 pm »
Buen test...revisare los temas apena este frente a mi pc

fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 196
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #7 en: Julio 14, 2018, 12:04:58 pm »
Bueno ahora si lanzo bien el TP, acerca de los rewards estos solo son entregados cuando hay mas de 1 player "No tendria sentido un cooperative de 1 player  ::)", estuve probandolo y va bien hasta cierto punto, eso si... parece que el problema de el evento era por el checkafk debido a que ahora si envia al coliseo pero yo le configure 60 segs del anti-afks y me saca del evento inclusive moviendo al char en esos 60 segs, desactive el anti-afk y ya no sucedia mas ese problema "creo que es otro detalle entre los true/false". Aparte de unos detalles en los eventos como que las banderas se buguearon cuando sali del evento con ella y al deletearla en la mochila  fuera del evento causo que en el otro evento se bugueasen las banderas y dropeaba banderas cada vez que moria "Aun sin tenerla xD" pero las banderas quedaban como NPC y no pickeables ademas de que el spawn de la 2da bandera "Creo que era la red" no estaba... Yo en un rato que me desocupe reviso si puedo arreglarlo y te mando el fix

como has salido del evento?

aca un pequeño fix para quitarte la bandera....sin test obvio xD

Código
Index: src/main/engine/events/cooperative/types/CaptureTheFlag.java
===================================================================
--- src/main/engine/events/cooperative/types/CaptureTheFlag.java (revision 1121)
+++ src/main/engine/events/cooperative/types/CaptureTheFlag.java (working copy)
@@ -22,7 +22,9 @@
 import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
 import net.sf.l2j.gameserver.model.actor.instance.enums.TeamType;
 import net.sf.l2j.gameserver.model.items.enums.ParpedollType;
+import net.sf.l2j.gameserver.model.items.enums.SlotType;
 import net.sf.l2j.gameserver.model.party.Party;
+import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
 
 /**
  * @author fissban
@@ -490,7 +492,12 @@
  var flag = ph.getInstance().getInventory().getPaperdollItem(ParpedollType.RHAND);
  if (flag != null)
  {
- ph.getInstance().getInventory().equipItem(flag);
+ SlotType slot = ph.getInstance().getInventory().getSlotFromItem(flag);
+ var items = ph.getInstance().getInventory().unEquipItemInBodySlotAndRecord(slot);
+
+ InventoryUpdate iu = new InventoryUpdate();
+ iu.addItems(items);
+ ph.getInstance().sendPacket(iu);
  }
 
  var teamType = ph.getTeam();
« Última modificación: Julio 14, 2018, 12:16:43 pm por fissban »

fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 196
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #8 en: Julio 15, 2018, 12:08:03 pm »
ya subi todos los fix que se han echo y algun que otro que no se discutio aqui.
https://sourceforge.net/p/l2jadminsc4/code/1126/

Gracias

canonmagic

  • Jr. Member
  • **
  • Mensajes: 52
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #9 en: Julio 17, 2018, 07:43:34 am »
Bueno... El problema persistio  :-\, el anti-afk sigue sacando a uno pasado el timer de 240 segundos sin importar que... Y ahora que estoy dandole a la cabeza con el CTF encontre que tiene bastante por delante. Le añadi una funcion adicional para recuperar la bandera de tu propio equipo. Si esta es tomada por un enemigo y este muere dejandola dropeada y alguien de su propio equipo interactua con ella es devuelta a su lugar original; y tambien un pequeño error que causaba que la bandera y holder roja no se spawneara. Pero aqui viene lo importante:

1.- Al tomar la bandera enemiga, la bandera se des-spawnea "Como deberia ser", pero en un par de segundos despues vuelve a aparecer.

2.- Al morir la bandera cae... Yo hize que si es interactuada por un aliado esta desaparezca, pero aun asi vuelve a aparecer al igual. "Quedando al reaparecer visualmente en el mapa, pero si intentabas targetearla o algo no sucedia nada  :o"

3.- Al entregar la bandera enemiga en tu holder la bandera es dropeada al lado del PJ y puede ser pickeada nuevamente.

4.- Hay algunos detalles, todavia no he podido chequearlos bien pero parece que visualmente la persona al entregar la bandera "Y esta ser desequipada" sigue viendose como si se llevara "Creo que incluso se mantenia en la mochila y podia ser desequipada (Quedando bugueada)"

Este evento esta dando bastantes problemas, tendremos que ir poco a poco con el.

fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 196
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #10 en: Julio 17, 2018, 01:31:08 pm »
Creo que tendre que sentarme a testearlo yo no? jeje

Aqui te dejo como lo tengo yo actualmente al ctf.

Código
package main.engine.events.cooperative.types;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import main.data.ConfigData;
import main.engine.events.cooperative.AbstractCooperative;
import main.holders.objects.CharacterHolder;
import main.holders.objects.NpcHolder;
import main.holders.objects.PlayerHolder;
import main.util.Util;
import main.util.UtilInventory;
import main.util.UtilMessage;
import main.util.builders.html.Html;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.data.ItemData;
import net.sf.l2j.gameserver.model.actor.L2Npc;
import net.sf.l2j.gameserver.model.actor.L2Playable;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.actor.instance.enums.TeamType;
import net.sf.l2j.gameserver.model.items.enums.ParpedollType;
import net.sf.l2j.gameserver.model.party.Party;
import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;

/**
 * @author fissban
 */
public class CaptureTheFlag extends AbstractCooperative
{
/** FlagItem */
private static final int FLAG_ITEM = 6718;
/** Points of blue team */
private static volatile int pointsBlue = 0;
/** Points of red team */
private static volatile int pointsRed = 0;
/** Points of each player */
private static Map<String, Integer> playerPoints = new ConcurrentHashMap<>();
/** Flags and holders instances */
private static Map<Integer, NpcHolder> flagAndHolders = new HashMap<>();

public CaptureTheFlag()
{
super();
}

@Override
public boolean canAttack(CharacterHolder attacker, CharacterHolder victim)
{
if (Util.areObjectType(L2PcInstance.class, attacker, victim))
{
// Check if the 2 players are participating in the event.
if (playerInEvent(attacker, victim))
{
// Check the team of each character.
if (attacker.getTeam() != victim.getTeam())
{
return true;
}
}
}

return false;
}

@Override
public void createParty()
{
// Leader Party Blue
PlayerHolder lpb = null;
// Leader Party Red
PlayerHolder lpr = null;

if (getPlayersInEvent().size() <= 3)
{
return;
}

for (var ph : getPlayersInEvent())
{
if (ph == null)
{
continue;
}

// Remove from old party
if (ph.getInstance().getParty() != null)
{
ph.getInstance().getParty().removePartyMember(ph.getInstance(), true);
}

PlayerHolder leader = null;

switch (ph.getTeam())
{
case BLUE:
leader = lpb;
break;
case RED:
leader = lpr;
break;
}

// If there is no leader yet, we assign one
if (leader == null)
{
leader = ph;
continue;
}

// If the party exceeds the limit of members we start the creation of a new one
if (leader != null && leader.getInstance().getParty() != null && leader.getInstance().getParty().getMemberCount() >= 7)
{
switch (ph.getTeam())
{
case BLUE:
lpb = ph;
continue;
case RED:
lpr = ph;
continue;
}
}

// Created the party
if (leader.getInstance().getParty() == null)
{
Party party = new Party(leader.getInstance());
party.addPartyMember(ph.getInstance());
}
// Added a new party member
else
{
leader.getInstance().getParty().addPartyMember(ph.getInstance());
}
}
}

@Override
public void createTeams()
{
var lastTeam = TeamType.BLUE;

for (var ph : getPlayersInEvent())
{
// Save the character's location before being sent to the event.
ph.setLastLoc(ph.getInstance().getX(), ph.getInstance().getY(), ph.getInstance().getZ());

switch (lastTeam)
{
case RED:
// Teleport
ph.getInstance().teleToLocation(ConfigData.TVT_SPAWN_TEAM_BLUE, ConfigData.TVT_RADIUS_SPAWN);
// Set team
ph.setTeam(TeamType.BLUE);
// Set last team
lastTeam = TeamType.BLUE;
break;
case BLUE:
// Teleport
ph.getInstance().teleToLocation(ConfigData.TVT_SPAWN_TEAM_RED, ConfigData.TVT_RADIUS_SPAWN);
// Set el team
ph.setTeam(TeamType.RED);
// Set last team
lastTeam = TeamType.RED;
break;
default:
// Never happens!
break;
}
}
}

@Override
public void giveRewards()
{
// Check the winning team.
var teamWinner = TeamType.NONE;

// Tied teams
if (pointsBlue == pointsRed)
{
//
}
else if (pointsBlue > pointsRed)
{
teamWinner = TeamType.BLUE;
}
else
{
teamWinner = TeamType.RED;
}

if (teamWinner == TeamType.NONE)
{
UtilMessage.sendAnnounceMsg("The event ends in a draw!", getPlayersInEvent());
}
else
{
UtilMessage.sendAnnounceMsg("The team " + teamWinner.name() + " was the winner!", getPlayersInEvent());

for (var ph : getPlayersInEvent())
{
// Prizes are awarded to the winning team.
if (ph.getTeam() == teamWinner)
{
ConfigData.TVT_REWARDS.forEach(rh -> UtilInventory.giveItems(ph, rh.getRewardId(), rh.getRewardCount(), 0));
}
}
}
}

// LISTENERS -----------------------------------------------------------------------------------------

/**
* @param ph
* @return
*/
@Override
public boolean onExitWorld(PlayerHolder ph)
{
if (ph.hasFlag())
{
unequipFlag(ph, true);
}

return super.onExitWorld(ph);
}

@Override
public void onDeath(CharacterHolder character)
{
// Check if the character is inside the event
if (!playerInEvent(character))
{
return;
}

var ph = character.getActingPlayer();

if (ph.hasFlag())
{
unequipFlag(ph, true);
}

var death = ThreadPoolManager.getInstance().schedule(() ->
{
deathTasks.remove(character.getObjectId());

// Revive
revivePlayer(ph);
// Heal
healToMax(ph);
// Buff
giveBuff(ph);

}, 10 * 1000); // 10 sec

deathTasks.put(character.getObjectId(), death);
}

@Override
public void onKill(CharacterHolder killer, CharacterHolder victim, boolean isPet)
{
if (Util.areObjectType(L2Playable.class, killer, victim))
{
var killerPc = killer.getActingPlayer();
var victimPc = victim.getActingPlayer();

if (playerInEvent(killerPc, victimPc))
{
// Increase the points of each team
if (killerPc.getTeam() == TeamType.BLUE)
{
pointsBlue += ConfigData.CTF_POINT_KILL_PLAYER;
}
else
{
pointsRed += ConfigData.CTF_POINT_KILL_PLAYER;
}

// Send all the characters of the event the amount of points.
sendPointsToAllParticipant();
// Increase the points of each player
increasePlayerPoint(killerPc, ConfigData.CTF_POINT_KILL_PLAYER);
}
}
}

@Override
public boolean onInteract(PlayerHolder ph, CharacterHolder character)
{
if (!Util.areObjectType(L2Npc.class, character))
{
return false;
}

// Check if the player participates in the event.
if (!playerInEvent(ph))
{
return false;
}

var flag = (NpcHolder) character;

if (flag.getId() == ConfigData.CTF_FLAG_ID)
{
if (ph.hasFlag())
{
return false;
}
if (ph.getTeam() != flag.getTeam())
{
equipFlag(ph, flag);
return true;
}
return false;
}

if (flag.getId() == ConfigData.CTF_HOLDER_ID)
{
if (ph.hasFlag())
{
if (ph.getTeam() == flag.getTeam())
{
unequipFlag(ph, false);

increasePlayerPoint(ph, ConfigData.CTF_POINT_DELIVER_FLAG);

switch (ph.getTeam())
{
case BLUE:
pointsBlue += ConfigData.CTF_POINT_DELIVER_FLAG;
break;
case RED:
pointsRed += ConfigData.CTF_POINT_DELIVER_FLAG;
break;
}

sendPointsToAllParticipant();
return true;
}
}
return false;
}

return true;
}

@Override
public void onUnequip(CharacterHolder player)
{
if (player instanceof PlayerHolder)
{
var ph = (PlayerHolder) player;
var flag = ph.getInstance().getInventory().getPaperdollItem(ParpedollType.RHAND);

if (flag == null && ph.hasFlag())
{
// drop flag
unequipFlag(ph, true);
}
}
}

// XXX MISC ------------------------------------------------------------------------------------------------------------

@Override
public void onStart()
{
var xRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getX();
var yRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getY();
var zRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getZ();

var xBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getX();
var yBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getY();
var zBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getZ();

// Flag spawn
addSpawnNpc(ConfigData.CTF_FLAG_ID, xBlue, yBlue, zBlue, 0, 0, 0, TeamType.BLUE);
addSpawnNpc(ConfigData.CTF_FLAG_ID, xRed, yRed, zRed, 0, 0, 0, TeamType.RED);
// Holder spawn
addSpawnNpc(ConfigData.CTF_HOLDER_ID, xBlue - 100, yBlue, zBlue, 0, 0, 0, TeamType.BLUE);// FIXME chequear el -100 si queda bien
addSpawnNpc(ConfigData.CTF_HOLDER_ID, xRed - 100, yRed, zRed, 0, 0, 0, TeamType.RED);// FIXME chequear el -100 si queda bien
}

@Override
public void onEnd()
{
// Cancel party
getPlayersInEvent().stream().filter(ph -> ph.getInstance().getParty() != null).forEach(ph -> ph.getInstance().getParty().removePartyMember(ph.getInstance(), true));

// Unspawn all flags and holders
flagAndHolders.values().stream().filter(npc -> npc.getInstance() != null).forEach(npc ->
{
// stop respawn
if (npc.getInstance().getSpawn() != null)
{
npc.getInstance().getSpawn().stopRespawn();
}
// remove from world
npc.getInstance().deleteMe();
});

// Generate ranking
var pointsOrdered = new LinkedHashMap<String, Integer>();

// Send html showing the points of each player
// order the list according to your scores
var LIMIT = 10;
playerPoints.entrySet().stream().sorted(Entry.<String, Integer> comparingByValue().reversed()).limit(LIMIT).forEach(e -> pointsOrdered.put(e.getKey(), e.getValue()));

// Generate the html of the ranking
var hb = Html.eventRanking(pointsOrdered);
// Send the html to each character in the event
sendHtml(null, hb, getPlayersInEvent());

// Clear
flagAndHolders.clear();
playerPoints.clear();
pointsBlue = 0;
pointsRed = 0;
}

/**
* Revive a character and send it to the spawn point according to his team
* @param ph
*/
private void revivePlayer(PlayerHolder ph)
{
if (!ph.getInstance().isDead())
{
return;
}

ph.getInstance().doRevive();

switch (ph.getTeam())
{
case BLUE:
ph.getInstance().teleToLocation(ConfigData.CTF_SPAWN_TEAM_BLUE, ConfigData.CTF_RADIUS_SPAWN);
break;
case RED:
ph.getInstance().teleToLocation(ConfigData.CTF_SPAWN_TEAM_RED, ConfigData.CTF_RADIUS_SPAWN);
break;
}
}

/**
* Increase by 1 the number of points of a character
* @param ph
*/
private static void increasePlayerPoint(PlayerHolder ph, int p)
{
if (!playerPoints.containsKey(ph.getName()))
{
playerPoints.put(ph.getName(), 0);
}

int points = playerPoints.get(ph.getName()) + p;
playerPoints.put(ph.getName(), points);
}

/**
* Equip a character with a flag.
* @param ph
* @param flagTeam
*/
private static void equipFlag(PlayerHolder ph, NpcHolder npc)
{
var teamType = ph.getTeam();

// get and remove flag from memory
var flag = flagAndHolders.remove(npc.getObjectId());
// stop flag respawn
if (flag.getInstance().getSpawn() != null)
{
flag.getInstance().getSpawn().stopRespawn();
}
// remove flag from world
flag.getInstance().deleteMe();

ph.setHasFlag(true);
// Equip flag
var flagItem = ItemData.getInstance().createItem("", FLAG_ITEM, 1, ph.getInstance(), null);
if (flagItem != null)
{
ph.getInstance().getInventory().equipItem(flagItem);
}
// Send Message
UtilMessage.sendAnnounceMsg("The " + teamType.name().toLowerCase() + " team has taken the flag!", getPlayersInEvent());
}

/**
* We remove the flag of a character.
* @param ph
*/
private void unequipFlag(PlayerHolder ph, boolean drop)
{
// Create new spawn
switch (ph.getTeam())
{
case BLUE:
var xRed = drop ? ph.getInstance().getX() : ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getX();
var yRed = drop ? ph.getInstance().getY() : ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getY();
var zRed = drop ? ph.getInstance().getZ() : ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getZ();
addSpawnNpc(ConfigData.CTF_FLAG_ID, xRed, yRed, zRed, 0, 0, 0, TeamType.RED);
break;
case RED:
var xBlue = drop ? ph.getInstance().getX() : ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getX();
var yBlue = drop ? ph.getInstance().getY() : ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getY();
var zBlue = drop ? ph.getInstance().getZ() : ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getZ();
addSpawnNpc(ConfigData.CTF_FLAG_ID, xBlue, yBlue, zBlue, 0, 0, 0, TeamType.BLUE);
break;
}

// Unequip flag
var flag = ph.getInstance().getInventory().getPaperdollItem(ParpedollType.RHAND);
if (flag != null)
{
var items = ph.getInstance().getInventory().unEquipItemInSlotAndRecord(ParpedollType.RHAND);

var iu = new InventoryUpdate();
iu.addItems(items);
ph.getInstance().sendPacket(iu);
}

var teamType = ph.getTeam();
if (drop)
{
UtilMessage.sendAnnounceMsg("The " + teamType.name().toLowerCase() + " has drop flag!", getPlayersInEvent());
}
else
{
UtilMessage.sendAnnounceMsg("The " + teamType.name().toLowerCase() + " team has delivered the flag!", getPlayersInEvent());
}
}

@Override
public NpcHolder addSpawnNpc(int npcId, int x, int y, int z, int heading, int randomOffset, long despawnDelay, TeamType teamType)
{
var npc = super.addSpawnNpc(npcId, x, y, z, heading, randomOffset, despawnDelay, teamType);
flagAndHolders.put(npc.getObjectId(), npc);
return npc;
}

/**
* Send all the characters a message on the screen showing the points of each team
*/
private static void sendPointsToAllParticipant()
{
UtilMessage.sendAnnounceMsg("BLUE " + pointsBlue + " | " + pointsRed + " RED", getPlayersInEvent());
}
}


Aqui habia agregado apra evitar que se desequipen la bandera.

Código
	@Override
public void onUnequip(CharacterHolder player)
{
if (player instanceof PlayerHolder)
{
var ph = (PlayerHolder) player;
var flag = ph.getInstance().getInventory().getPaperdollItem(ParpedollType.RHAND);

if (flag == null && ph.hasFlag())
{
// drop flag
unequipFlag(ph, true);
}
}
}

pero quizas herre aqui
Código
if (flag == null && ph.hasFlag())

canonmagic

  • Jr. Member
  • **
  • Mensajes: 52
  • Karma: +0/-0
    • Ver Perfil
Re:[MOD - EventCooperative] - Error
« Respuesta #11 en: Julio 18, 2018, 03:44:37 pm »
Bueno, hoy tuve un poco de tiempo libre y pude revisar mas cuidadosamente el script del evento CTF, encontre los problemas de los spawns y alguna que otra cosa y logre solucionarlo y ya esta funcional la adicion que le hize de la posibilidad de recuperar la bandera "si un enemigo la toma del spawn y este es asesinado dropea la bandera; y luego alguien del mismo equipo de la bandera dropeada podra interactuar con ella y que regrese al spawn". Aqui te dejo el diff

Código
### Eclipse Workspace Patch 1.0
#P C4_Mods
Index: src/main/engine/events/cooperative/types/CaptureTheFlag.java
===================================================================
--- src/main/engine/events/cooperative/types/CaptureTheFlag.java (revision 1100)
+++ src/main/engine/events/cooperative/types/CaptureTheFlag.java (working copy)
@@ -1,16 +1,3 @@
-/*
- * L2J_EngineMods
- * Engine developed by Fissban.
- *
- * This software is not free and you do not have permission
- * to distribute without the permission of its owner.
- *
- * This software is distributed only under the rule
- * of www.devsadmins.com.
- *
- * Contact us with any questions by the media
- * provided by our web or email marco.faccio@gmail.com
- */
 package main.engine.events.cooperative.types;
 
 import java.util.HashMap;
@@ -36,6 +23,7 @@
 import net.sf.l2j.gameserver.model.actor.instance.enums.TeamType;
 import net.sf.l2j.gameserver.model.items.enums.ParpedollType;
 import net.sf.l2j.gameserver.model.party.Party;
+import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
 
 /**
  * @author fissban
@@ -52,6 +40,9 @@
  private static Map<String, Integer> playerPoints = new ConcurrentHashMap<>();
  /** Flags and holders instances */
  private static Map<Integer, NpcHolder> flagAndHolders = new HashMap<>();
+ /** Flag position changes */
+ private static boolean FlagMovedBlue = false;
+ private static boolean FlagMovedRed = false;
 
  public CaptureTheFlag()
  {
@@ -326,8 +317,65 @@
  if (ph.getTeam() != flag.getTeam())
  {
  equipFlag(ph, flag);
+ switch (ph.getTeam())
+ {
+ case BLUE:
+ setFlagMovedRed(true);
+ break;
+ case RED:
+ setFlagMovedBlue(true);
+ break;
+ }
  return true;
  }
+ if (ph.getTeam() == flag.getTeam())
+ {
+ switch (ph.getTeam())
+ {
+ case RED:
+ if (FlagMovedRed == true)
+ {
+ flagAndHolders.remove(flag.getObjectId());
+ // stop flag respawn
+ if (flag.getInstance().getSpawn() != null)
+ {
+ flag.getInstance().getSpawn().stopRespawn();
+ }
+ // remove flag from world
+ flag.getInstance().deleteMe();
+
+ // now the red team flag its returned to his spawn
+ var xRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getX();
+ var yRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getY();
+ var zRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getZ();
+ addSpawnNpc(ConfigData.CTF_FLAG_ID, xRed, yRed, zRed, 0, 0, 0, TeamType.RED);
+ UtilMessage.sendAnnounceMsg("The red team flag has been returned!", getPlayersInEvent());
+ setFlagMovedRed(false);
+ }
+ break;
+ case BLUE:
+ if (FlagMovedBlue == true)
+ {
+ flagAndHolders.remove(flag.getObjectId());
+ // stop flag respawn
+ if (flag.getInstance().getSpawn() != null)
+ {
+ flag.getInstance().getSpawn().stopRespawn();
+ }
+ // remove flag from world
+ flag.getInstance().deleteMe();
+
+ // now the blue team flag its returned to his spawn
+ var xBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getX();
+ var yBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getY();
+ var zBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getZ();
+ addSpawnNpc(ConfigData.CTF_FLAG_ID, xBlue, yBlue, zBlue, 0, 0, 0, TeamType.BLUE);
+ UtilMessage.sendAnnounceMsg("The blue team flag has been returned!", getPlayersInEvent());
+ setFlagMovedBlue(false);
+ }
+ break;
+ }
+ }
  return false;
  }
 
@@ -339,6 +387,15 @@
  {
  unequipFlag(ph, false);
 
+ switch (ph.getTeam())
+ {
+ case BLUE:
+ setFlagMovedRed(false);
+ break;
+ case RED:
+ setFlagMovedBlue(false);
+ break;
+ }
  increasePlayerPoint(ph, ConfigData.CTF_POINT_DELIVER_FLAG);
 
  switch (ph.getTeam())
@@ -361,6 +418,22 @@
  return true;
  }
 
+ @Override
+ public void onUnequip(CharacterHolder player)
+ {
+ if (player instanceof PlayerHolder)
+ {
+ var ph = (PlayerHolder) player;
+ var flag = ph.getInstance().getInventory().getPaperdollItem(ParpedollType.RHAND);
+
+ if (flag == null && ph.hasFlag())
+ {
+ // drop flag
+ unequipFlag(ph, true);
+ }
+ }
+ }
+
  // XXX MISC ------------------------------------------------------------------------------------------------------------
 
  @Override
@@ -370,9 +443,9 @@
  var yRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getY();
  var zRed = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getZ();
 
- var xBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getX();
- var yBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getY();
- var zBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_RED.getZ();
+ var xBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getX();
+ var yBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getY();
+ var zBlue = ConfigData.CTF_FLAG_SPAWN_TEAM_BLUE.getZ();
 
  // Flag spawn
  addSpawnNpc(ConfigData.CTF_FLAG_ID, xBlue, yBlue, zBlue, 0, 0, 0, TeamType.BLUE);
@@ -389,7 +462,16 @@
  getPlayersInEvent().stream().filter(ph -> ph.getInstance().getParty() != null).forEach(ph -> ph.getInstance().getParty().removePartyMember(ph.getInstance(), true));
 
  // Unspawn all flags and holders
- flagAndHolders.values().stream().filter(npc -> npc.getInstance() != null).forEach(npc -> npc.getInstance().deleteMe());
+ flagAndHolders.values().stream().filter(npc -> npc.getInstance() != null).forEach(npc ->
+ {
+ // stop respawn
+ if (npc.getInstance().getSpawn() != null)
+ {
+ npc.getInstance().getSpawn().stopRespawn();
+ }
+ // remove from world
+ npc.getInstance().deleteMe();
+ });
 
  // Generate ranking
  var pointsOrdered = new LinkedHashMap<String, Integer>();
@@ -397,10 +479,7 @@
  // Send html showing the points of each player
  // order the list according to your scores
  var LIMIT = 10;
- playerPoints.entrySet().stream().sorted(Entry.<String, Integer> comparingByValue().reversed()).limit(LIMIT).forEach(e ->
- {
- pointsOrdered.put(e.getKey(), e.getValue());
- });
+ playerPoints.entrySet().stream().sorted(Entry.<String, Integer> comparingByValue().reversed()).limit(LIMIT).forEach(e -> pointsOrdered.put(e.getKey(), e.getValue()));
 
  // Generate the html of the ranking
  var hb = Html.eventRanking(pointsOrdered);
@@ -462,16 +541,23 @@
  {
  var teamType = ph.getTeam();
 
- flagAndHolders.get(npc.getObjectId()).getInstance().deleteMe();
- flagAndHolders.remove(npc.getObjectId());
+ // get and remove flag from memory
+ var flag = flagAndHolders.remove(npc.getObjectId());
+ // stop flag respawn
+ if (flag.getInstance().getSpawn() != null)
+ {
+ flag.getInstance().getSpawn().stopRespawn();
+ }
+ // remove flag from world
+ flag.getInstance().deleteMe();
 
- ph.setHasFlag(true);
  // Equip flag
  var flagItem = ItemData.getInstance().createItem("", FLAG_ITEM, 1, ph.getInstance(), null);
  if (flagItem != null)
  {
  ph.getInstance().getInventory().equipItem(flagItem);
  }
+ ph.setHasFlag(true);
  // Send Message
  UtilMessage.sendAnnounceMsg("The " + teamType.name().toLowerCase() + " team has taken the flag!", getPlayersInEvent());
  }
@@ -482,6 +568,7 @@
  */
  private void unequipFlag(PlayerHolder ph, boolean drop)
  {
+ ph.setHasFlag(false);
  // Create new spawn
  switch (ph.getTeam())
  {
@@ -503,13 +590,16 @@
  var flag = ph.getInstance().getInventory().getPaperdollItem(ParpedollType.RHAND);
  if (flag != null)
  {
- ph.getInstance().getInventory().equipItem(flag);
+ var items = ph.getInstance().getInventory().unEquipItemInSlotAndRecord(ParpedollType.RHAND);
+
+ var iu = new InventoryUpdate();
+ iu.addItems(items);
+ ph.getInstance().sendPacket(iu);
  }
-
  var teamType = ph.getTeam();
  if (drop)
  {
- UtilMessage.sendAnnounceMsg("The " + teamType.name().toLowerCase() + " has drop flag!", getPlayersInEvent());
+ UtilMessage.sendAnnounceMsg("The " + teamType.name().toLowerCase() + " team has drop flag!", getPlayersInEvent());
  }
  else
  {
@@ -532,4 +622,16 @@
  {
  UtilMessage.sendAnnounceMsg("BLUE " + pointsBlue + " | " + pointsRed + " RED", getPlayersInEvent());
  }
-}
+
+ private static void setFlagMovedBlue(boolean bool)
+ {
+ FlagMovedBlue = bool;
+ return;
+ }
+
+ private static void setFlagMovedRed(boolean bool)
+ {
+ FlagMovedRed = bool;
+ return;
+ }
+}
\ No newline at end of file

Lo unico que quedaria pendiente es la funcionalidad del anti-afk y su problema de la recuperacion de locations.