Ejemplo n.º 1
0
  public void setReenterTime(InstanceWorld world) {
    if (world instanceof DPFWorld) {
      // Reenter time should be cleared every Wed and Sat at 6:30 AM, so we set next suitable
      Calendar reenter;
      Calendar now = Calendar.getInstance();
      Calendar reenterPointWed = (Calendar) now.clone();
      reenterPointWed.set(Calendar.AM_PM, Calendar.AM);
      reenterPointWed.set(Calendar.MINUTE, RESET_MIN);
      reenterPointWed.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
      reenterPointWed.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
      Calendar reenterPointSat = (Calendar) reenterPointWed.clone();
      reenterPointSat.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);

      if (now.after(reenterPointSat)) {
        reenterPointWed.add(Calendar.WEEK_OF_MONTH, 1);
        reenter = (Calendar) reenterPointWed.clone();
      } else {
        reenter = (Calendar) reenterPointSat.clone();
      }

      SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
      sm.addInstanceName(world.getTemplateId());
      // set instance reenter time for all allowed players
      for (int objectId : world.getAllowed()) {
        L2PcInstance player = L2World.getInstance().getPlayer(objectId);
        if ((player != null) && player.isOnline()) {
          InstanceManager.getInstance()
              .setInstanceTime(objectId, world.getTemplateId(), reenter.getTimeInMillis());
          player.sendPacket(sm);
        }
      }
    }
  }
Ejemplo n.º 2
0
  public static int getRecoBonus(L2PcInstance activeChar) {
    if ((activeChar != null)
        && activeChar.isOnline()
        && (activeChar.getRecomHave() != 0)
        && (activeChar.getRecomBonusTime() > 0)) {
      final int lvl = activeChar.getLevel() / 10;
      final int exp = (Math.min(100, activeChar.getRecomHave()) - 1) / 10;

      return _recoBonus[lvl][exp];
    }
    return 0;
  }
Ejemplo n.º 3
0
 @Override
 public void run() {
   if (_player != null) {
     if (_player.isOnline()) {
       final long hours = TimeUnit.MILLISECONDS.toHours(_player.getUptime());
       _player.sendPacket(
           SystemMessage.getSystemMessage(
                   SystemMessageId.YOU_HAVE_PLAYED_FOR_S1_HOUR_S_PLEASE_TAKE_A_BREAK)
               .addLong(hours));
     } else {
       _player.stopWarnUserTakeBreak();
     }
   }
 }
Ejemplo n.º 4
0
 protected void StartRace() {
   // Abort race if no players signup
   if (_players.isEmpty()) {
     Broadcast.toAllOnlinePlayers("Race aborted, nobody signup.");
     eventStop();
     return;
   }
   // Set state
   _isRaceStarted = true;
   // Announce
   Broadcast.toAllOnlinePlayers("Race started!");
   // Get random Finish
   int location = getRandom(0, _locations.length - 1);
   _randspawn = _coords[location];
   // And spawn NPC
   recordSpawn(_stop_npc, _randspawn[0], _randspawn[1], _randspawn[2], _randspawn[3], false, 0);
   // Transform players and send message
   for (L2PcInstance player : _players) {
     if ((player != null) && player.isOnline()) {
       if (player.isInsideRadius(_npc, 500, false, false)) {
         sendMessage(
             player,
             "Race started! Go find Finish NPC as fast as you can... He is located near "
                 + _locations[location]);
         transformPlayer(player);
         player.getRadar().addMarker(_randspawn[0], _randspawn[1], _randspawn[2]);
       } else {
         sendMessage(
             player,
             "I told you stay near me right? Distance was too high, you are excluded from race");
         _players.remove(player);
       }
     }
   }
   // Schedule timeup for Race
   _eventTask =
       ThreadPoolManager.getInstance().scheduleGeneral(() -> timeUp(), _time_race * 60 * 1000);
 }
Ejemplo n.º 5
0
  /**
   * Sets reenter time for every player in the instance.
   *
   * @param world the instance
   * @param time the time in milliseconds
   */
  protected void setReenterTime(InstanceWorld world, long time) {
    for (int objectId : world.getAllowed()) {
      InstanceManager.getInstance().setInstanceTime(objectId, world.getTemplateId(), time);
      final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
      if ((player != null) && player.isOnline()) {
        player.sendPacket(
            SystemMessage.getSystemMessage(
                    SystemMessageId
                        .INSTANT_ZONE_S1_S_ENTRY_HAS_BEEN_RESTRICTED_YOU_CAN_CHECK_THE_NEXT_POSSIBLE_ENTRY_TIME_BY_USING_THE_COMMAND_INSTANCEZONE)
                .addString(
                    InstanceManager.getInstance().getInstance(world.getInstanceId()).getName()));
      }
    }

    if (Config.DEBUG_INSTANCES) {
      _log.info(
          "Time restrictions has been set for player in instance ID: "
              + world.getInstanceId()
              + " ("
              + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(time)
              + ")");
    }
  }
Ejemplo n.º 6
0
  @Override
  public boolean eventStop() {
    // Don't stop inactive event
    if (!_isactive) {
      return false;
    }

    // Set inactive
    _isactive = false;
    _isRaceStarted = false;

    // Cancel task if any
    if (_eventTask != null) {
      _eventTask.cancel(true);
      _eventTask = null;
    }
    // Untransform players
    // Teleport to event start point
    for (L2PcInstance player : _players) {
      if ((player != null) && player.isOnline()) {
        player.untransform();
        player.teleToLocation(_npc.getX(), _npc.getY(), _npc.getZ(), true);
      }
    }
    // Despawn NPCs
    for (L2Npc _npc : _npclist) {
      if (_npc != null) {
        _npc.deleteMe();
      }
    }
    _npclist.clear();
    _players.clear();
    // Announce event end
    Broadcast.toAllOnlinePlayers("* Race Event finished *");

    return true;
  }
  protected static final Participant[][] createListOfParticipants(List<List<Integer>> list) {
    if ((list == null) || list.isEmpty() || (list.size() < 2)) {
      return null;
    }

    List<Integer> teamOne = null;
    List<Integer> teamTwo = null;
    L2PcInstance player;
    List<L2PcInstance> teamOnePlayers = new ArrayList<>(MAX_TEAM_SIZE);
    List<L2PcInstance> teamTwoPlayers = new ArrayList<>(MAX_TEAM_SIZE);

    while (list.size() > 1) {
      teamOne = list.remove(Rnd.nextInt(list.size()));

      if (((teamOne == null) || teamOne.isEmpty())) {
        continue;
      }

      for (int objectId : teamOne) {
        player = L2World.getInstance().getPlayer(objectId);
        if ((player == null) || !player.isOnline()) {
          teamOnePlayers.clear();
          break;
        }
        teamOnePlayers.add(player);
      }
      if (teamOnePlayers.isEmpty()) {
        continue;
      }

      teamTwo = list.remove(Rnd.nextInt(list.size()));
      if ((teamTwo == null) || teamTwo.isEmpty()) {
        list.add(teamOne);
        teamOnePlayers.clear();
        continue;
      }

      for (int objectId : teamTwo) {
        player = L2World.getInstance().getPlayer(objectId);
        if ((player == null) || !player.isOnline()) {
          teamTwoPlayers.clear();
          break;
        }
        teamTwoPlayers.add(player);
      }
      if (teamTwoPlayers.isEmpty()) {
        list.add(teamOne);
        teamOnePlayers.clear();
        continue;
      }

      Participant[] t1 = new Participant[teamOnePlayers.size()];
      Participant[] t2 = new Participant[teamTwoPlayers.size()];
      Participant[][] result = new Participant[2][];

      for (int i = 0; i < t1.length; i++) {
        t1[i] = new Participant(teamOnePlayers.get(i), 1);
      }

      for (int i = 0; i < t2.length; i++) {
        t2[i] = new Participant(teamTwoPlayers.get(i), 2);
      }

      result[0] = t1;
      result[1] = t2;
      return result;
    }

    return null;
  }