Ejemplo n.º 1
0
  /**
   * Stops the TvTEvent fight<br>
   * 1. Set state EventState.INACTIVATING<br>
   * 2. Remove tvt npc from world<br>
   * 3. Open doors specified in configs<br>
   * 4. Teleport all participants back to participation npc location<br>
   * 5. Teams cleaning<br>
   * 6. Set state EventState.INACTIVE<br>
   */
  public static void stopFight() {
    // Set state INACTIVATING
    setState(EventState.INACTIVATING);
    // Unspawn event npc
    unSpawnNpc();
    // Opens all doors specified in configs for tvt
    openDoors(Config.TVT_DOORS_IDS_TO_CLOSE);
    // Closes all doors specified in Configs for tvt
    closeDoors(Config.TVT_DOORS_IDS_TO_OPEN);

    // Iterate over all teams
    for (TvTEventTeam team : _teams) {
      for (L2PcInstance playerInstance : team.getParticipatedPlayers().values()) {
        // Check for nullpointer
        if (playerInstance != null) {
          // Enable player revival.
          playerInstance.setCanRevive(true);
          // Teleport back.
          new TvTEventTeleporter(
              playerInstance, Config.TVT_EVENT_PARTICIPATION_NPC_COORDINATES, false, false);
        }
      }
    }

    // Cleanup of teams
    _teams[0].cleanMe();
    _teams[1].cleanMe();
    // Set state INACTIVE
    setState(EventState.INACTIVE);
    AntiFeedManager.getInstance().clear(AntiFeedManager.TVT_ID);
  }
Ejemplo n.º 2
0
 /** Teams initializing<br> */
 public static void init() {
   AntiFeedManager.getInstance().registerEvent(AntiFeedManager.TVT_ID);
   _teams[0] = new TvTEventTeam(Config.TVT_EVENT_TEAM_1_NAME, Config.TVT_EVENT_TEAM_1_COORDINATES);
   _teams[1] = new TvTEventTeam(Config.TVT_EVENT_TEAM_2_NAME, Config.TVT_EVENT_TEAM_2_COORDINATES);
 }
Ejemplo n.º 3
0
  /**
   * Starts the TvTEvent fight<br>
   * 1. Set state EventState.STARTING<br>
   * 2. Close doors specified in configs<br>
   * 3. Abort if not enough participants(return false)<br>
   * 4. Set state EventState.STARTED<br>
   * 5. Teleport all participants to team spot<br>
   * <br>
   *
   * @return boolean: true if success, otherwise false<br>
   */
  public static boolean startFight() {
    // Set state to STARTING
    setState(EventState.STARTING);

    // Randomize and balance team distribution
    final Map<Integer, L2PcInstance> allParticipants = new HashMap<>();
    allParticipants.putAll(_teams[0].getParticipatedPlayers());
    allParticipants.putAll(_teams[1].getParticipatedPlayers());
    _teams[0].cleanMe();
    _teams[1].cleanMe();

    L2PcInstance player;
    Iterator<L2PcInstance> iter;
    if (needParticipationFee()) {
      iter = allParticipants.values().iterator();
      while (iter.hasNext()) {
        player = iter.next();
        if (!hasParticipationFee(player)) {
          iter.remove();
        }
      }
    }

    final int balance[] = {0, 0};
    int priority = 0, highestLevelPlayerId;
    L2PcInstance highestLevelPlayer;
    // TODO: allParticipants should be sorted by level instead of using highestLevelPcInstanceOf for
    // every fetch
    while (!allParticipants.isEmpty()) {
      // Priority team gets one player
      highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants);
      highestLevelPlayer = allParticipants.get(highestLevelPlayerId);
      allParticipants.remove(highestLevelPlayerId);
      _teams[priority].addPlayer(highestLevelPlayer);
      balance[priority] += highestLevelPlayer.getLevel();
      // Exiting if no more players
      if (allParticipants.isEmpty()) {
        break;
      }
      // The other team gets one player
      // TODO: Code not dry
      priority = 1 - priority;
      highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants);
      highestLevelPlayer = allParticipants.get(highestLevelPlayerId);
      allParticipants.remove(highestLevelPlayerId);
      _teams[priority].addPlayer(highestLevelPlayer);
      balance[priority] += highestLevelPlayer.getLevel();
      // Recalculating priority
      priority = balance[0] > balance[1] ? 1 : 0;
    }

    // Check for enought participants
    if ((_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)
        || (_teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)) {
      // Set state INACTIVE
      setState(EventState.INACTIVE);
      // Cleanup of teams
      _teams[0].cleanMe();
      _teams[1].cleanMe();
      // Unspawn the event NPC
      unSpawnNpc();
      AntiFeedManager.getInstance().clear(AntiFeedManager.TVT_ID);
      return false;
    }

    if (needParticipationFee()) {
      iter = _teams[0].getParticipatedPlayers().values().iterator();
      while (iter.hasNext()) {
        player = iter.next();
        if (!payParticipationFee(player)) {
          iter.remove();
        }
      }
      iter = _teams[1].getParticipatedPlayers().values().iterator();
      while (iter.hasNext()) {
        player = iter.next();
        if (!payParticipationFee(player)) {
          iter.remove();
        }
      }
    }

    if (Config.TVT_EVENT_IN_INSTANCE) {
      try {
        _TvTEventInstance =
            InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_FILE);
        InstanceManager.getInstance().getInstance(_TvTEventInstance).setAllowSummon(false);
        InstanceManager.getInstance().getInstance(_TvTEventInstance).setPvPInstance(true);
        InstanceManager.getInstance()
            .getInstance(_TvTEventInstance)
            .setEmptyDestroyTime((Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY * 1000) + 60000L);
      } catch (Exception e) {
        _TvTEventInstance = 0;
        _log.log(
            Level.WARNING,
            "TvTEventEngine[TvTEvent.createDynamicInstance]: exception: " + e.getMessage(),
            e);
      }
    }

    // Opens all doors specified in configs for tvt
    openDoors(Config.TVT_DOORS_IDS_TO_OPEN);
    // Closes all doors specified in configs for tvt
    closeDoors(Config.TVT_DOORS_IDS_TO_CLOSE);
    // Set state STARTED
    setState(EventState.STARTED);

    // Iterate over all teams
    for (TvTEventTeam team : _teams) {
      // Iterate over all participated player instances in this team
      for (L2PcInstance playerInstance : team.getParticipatedPlayers().values()) {
        if (playerInstance != null) {
          // Disable player revival.
          playerInstance.setCanRevive(false);
          // Teleporter implements Runnable and starts itself
          new TvTEventTeleporter(playerInstance, team.getCoordinates(), false, false);
        }
      }
    }

    // Notify to scripts.
    EventDispatcher.getInstance().notifyEventAsync(new OnTvTEventStart());
    return true;
  }