Ejemplo n.º 1
0
 public void run() {
   try {
     if (_isFree) return;
     L2Clan Clan = getOwnerClan();
     if (getOwnerClan().getWarehouse().getAdena() >= getLease()) {
       if (_paidUntil != 0) {
         while (_paidUntil < System.currentTimeMillis()) _paidUntil += _chRate;
       } else _paidUntil = System.currentTimeMillis() + _chRate;
       _paidDayTime = _paidUntil;
       getOwnerClan()
           .getWarehouse()
           .destroyItemByItemId("CH_rental_fee", 57, getLease(), null, null);
       if (_log.isDebugEnabled() || Config.DEBUG)
         _log.warn(
             "deducted "
                 + getLease()
                 + " adena from "
                 + getName()
                 + " owner's cwh for ClanHall _paidUntil"
                 + _paidUntil);
       ThreadPoolManager.getInstance()
           .scheduleGeneral(new FeeTask(), _paidUntil - System.currentTimeMillis());
       _paid = true;
       updateDb();
     } else {
       _paid = false;
       if (System.currentTimeMillis() > _paidUntil + _chRate) {
         if (ClanHallManager.loaded()) {
           AuctionManager.getInstance().initNPC(getId());
           ClanHallManager.getInstance().setFree(getId());
           Clan.broadcastToOnlineMembers(
               new SystemMessage(
                   SystemMessageId
                       .THE_CLAN_HALL_FEE_IS_ONE_WEEK_OVERDUE_THEREFORE_THE_CLAN_HALL_OWNERSHIP_HAS_BEEN_REVOKED));
           _log.info(
               "ClanHall: "
                   + getName()
                   + " set to FREE. Old Clan owner : "
                   + Clan.getName()
                   + ". Adena count in CWH : "
                   + Clan.getWarehouse().getAdena());
         } else ThreadPoolManager.getInstance().scheduleGeneral(new FeeTask(), 3000);
       } else {
         SystemMessage sm =
             new SystemMessage(
                 SystemMessageId
                     .PAYMENT_FOR_YOUR_CLAN_HALL_HAS_NOT_BEEN_MADE_PLEASE_MAKE_PAYMENT_TO_YOUR_CLAN_WAREHOUSE_BY_TOMORROW);
         Clan.broadcastToOnlineMembers(sm);
         if (System.currentTimeMillis() + (1000 * 60 * 60 * 24) <= _paidUntil + _chRate)
           _paidDayTime = System.currentTimeMillis() + (1000 * 60 * 60 * 24);
         else _paidDayTime = _paidUntil + _chRate;
         ThreadPoolManager.getInstance()
             .scheduleGeneral(new FeeTask(), _paidDayTime - System.currentTimeMillis());
         updateDb();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 2
0
 private void initializeFunctionTask(boolean cwh) {
   if (_isFree) return;
   long currentTime = System.currentTimeMillis();
   if (_endDate > currentTime)
     ThreadPoolManager.getInstance()
         .scheduleGeneral(new FunctionTask(cwh), _endDate - currentTime);
   else ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(cwh), 0);
 }
Ejemplo n.º 3
0
 /** Initialyze Fee Task */
 private void initializeTask(boolean forced) {
   long currentTime = System.currentTimeMillis();
   if (_paidUntil > currentTime)
     ThreadPoolManager.getInstance().scheduleGeneral(new FeeTask(), _paidUntil - currentTime);
   else if (!_paid && !forced) {
     if (_paidDayTime > currentTime)
       ThreadPoolManager.getInstance().scheduleGeneral(new FeeTask(), _paidDayTime - currentTime);
     else ThreadPoolManager.getInstance().scheduleGeneral(new FeeTask(), 0);
   } else ThreadPoolManager.getInstance().scheduleGeneral(new FeeTask(), 0);
 }
Ejemplo n.º 4
0
 public void run() {
   try {
     if (_isFree) return;
     if (getOwnerClan().getWarehouse().getAdena() >= _fee || !_cwh) {
       int fee = _fee;
       boolean newfc = true;
       if (getEndTime() == 0 || getEndTime() == -1) {
         if (getEndTime() == -1) {
           newfc = false;
           fee = _tempFee;
         }
       } else newfc = false;
       setEndTime(System.currentTimeMillis() + getRate());
       dbSave(newfc);
       if (_cwh) {
         getOwnerClan()
             .getWarehouse()
             .destroyItemByItemId("CH_function_fee", 57, fee, null, null);
         if (_log.isDebugEnabled() || Config.DEBUG)
           _log.warn(
               "deducted "
                   + fee
                   + " adena from "
                   + getName()
                   + " owner's cwh for function id : "
                   + getType());
       }
       ThreadPoolManager.getInstance().scheduleGeneral(new FunctionTask(true), getRate());
     } else removeFunction(getType());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 5
0
  private synchronized void startEffectTask(int duration) {
    stopEffectTask();
    _currentTask = new EffectTask(duration, -1);
    _currentFuture = ThreadPoolManager.getInstance().scheduleEffect(_currentTask, duration);

    if (_state == EffectState.ACTING) _effected.addEffect(this);
  }
Ejemplo n.º 6
0
  private synchronized void startEffectTaskAtFixedRate(int delay, int rate) {
    stopEffectTask();
    _currentTask = new EffectTask(delay, rate);
    _currentFuture =
        ThreadPoolManager.getInstance().scheduleEffectAtFixedRate(_currentTask, delay, rate);

    if (_state == EffectState.ACTING) _effected.addEffect(this);
  }
Ejemplo n.º 7
0
  private void updateOwnerInDB() {
    L2Clan clan = getOwnerClan();
    int clanId = 0;

    if (clan != null) {
      clanId = clan.getClanId();
      _lastOwnedTime = System.currentTimeMillis();
    } else _lastOwnedTime = 0;

    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection(con);
      PreparedStatement statement;

      statement =
          con.prepareStatement(
              "UPDATE fort SET owner=?, lastOwnedTime=?, state=?, castleId=? WHERE id = ?");
      statement.setInt(1, clanId);
      statement.setLong(2, _lastOwnedTime);
      statement.setInt(3, 0);
      statement.setInt(4, 0);
      statement.setInt(5, getFortId());
      statement.execute();
      statement.close();

      // ============================================================================
      // Announce to clan memebers
      if (clan != null) {
        clan.setHasFort(getFortId()); // Set has fort flag for new owner
        SystemMessage sm;
        sm = new SystemMessage(SystemMessageId.S1);
        sm.addString(clan.getName() + " победил в битве за форт " + getName());
        Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
        for (L2PcInstance player : pls) player.sendPacket(sm);

        clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
        clan.broadcastToOnlineMembers(new PlaySound(1, "Siege_Victory", 0, 0, 0, 0, 0));
        ThreadPoolManager.getInstance()
            .scheduleGeneral(
                new FortUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
      }
    } catch (Exception e) {
      _log.warn("Exception: updateOwnerInDB(L2Clan clan): " + e.getMessage());
      e.printStackTrace();
    } finally {
      try {
        con.close();
      } catch (Exception e) {
        _log.warn("" + e.getMessage());
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 8
0
  private void load() {
    Connection con = null;
    try {
      PreparedStatement statement;
      ResultSet rs;

      con = L2DatabaseFactory.getInstance().getConnection(con);

      statement = con.prepareStatement("SELECT * FROM fort WHERE id = ?");
      statement.setInt(1, getFortId());
      rs = statement.executeQuery();

      while (rs.next()) {
        _name = rs.getString("name");
        _siegeDate = Calendar.getInstance();
        _siegeDate.setTimeInMillis(rs.getLong("siegeDate"));
        _lastOwnedTime = rs.getLong("lastOwnedTime");
        _ownerId = rs.getInt("owner");
        _fortType = rs.getInt("fortType");
        _state = rs.getInt("state");
        _castleId = rs.getInt("castleId");
      }

      rs.close();
      statement.close();

      if (_ownerId > 0) {
        L2Clan clan = ClanTable.getInstance().getClan(_ownerId); // Try to find clan instance
        if (clan != null) {
          setOwnerClan(clan);
          clan.setHasFort(getFortId());
          ThreadPoolManager.getInstance()
              .scheduleGeneral(
                  new FortUpdater(clan, 1), 3600000); // Schedule owner tasks to start running
        } else setOwnerClan(null);
      } else setOwnerClan(null);

      if (_state == 2 && _castleId != 0) {
        Castle castle = CastleManager.getInstance().getCastleById(_castleId);
        if (castle != null) castle.addContractFort(getFortId());
      }
    } catch (Exception e) {
      _log.warn("Exception: loadFortData(): " + e.getMessage(), e);
    } finally {
      try {
        if (con != null) con.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 9
0
 public void setFirstTime(int newfirsttime) {
   if (_currentFuture != null) {
     _periodStartTicks =
         GameTimeController.getGameTicks() - newfirsttime * GameTimeController.TICKS_PER_SECOND;
     _currentFuture.cancel(false);
     _currentFuture = null;
     _currentTask = null;
     _periodfirsttime = newfirsttime;
     int duration = _period - _periodfirsttime;
     _currentTask = new EffectTask(duration * 1000, -1);
     _currentFuture =
         ThreadPoolManager.getInstance().scheduleEffect(_currentTask, duration * 1000);
   }
 }
Ejemplo n.º 10
0
  /**
   * This method will set owner for Fort
   *
   * @param clan
   * @param updateClanPoints
   */
  public boolean setOwner(L2Clan clan, boolean updateClansReputation) {
    ClanHall hall = ClanHallManager.getInstance().getClanHallByOwner(clan);
    if (hall != null) {
      clan.broadcastToOnlineMembers(
          new SystemMessage(SystemMessageId.S1)
              .addString("Вы потеряли ваш кланхолл " + hall.getName()));
      ClanHallManager.getInstance().setFree(hall.getId());
      AuctionManager.getInstance().initNPC(hall.getId());
    }
    if (clan.getAuctionBiddedAt() > 0) {
      Auction a = AuctionManager.getInstance().getAuction(clan.getAuctionBiddedAt());
      if (a != null) {
        a.cancelAuction();
        clan.broadcastToOnlineMembers(
            new SystemMessage(SystemMessageId.S1).addString("Ваше участие в аукционе отменено"));
      }
    }

    if (updateClansReputation) updateClansReputation(clan, false); // update reputation first

    for (L2PcInstance member : clan.getOnlineMembers(0)) {
      giveResidentialSkills(member);
      member.sendSkillList();
    }

    // Remove old owner
    if (getOwnerClan() != null && (clan != null && clan != getOwnerClan())) {
      updateClansReputation(clan, true);
      L2PcInstance oldLord = getOwnerClan().getLeader().getPlayerInstance();
      if (oldLord != null && oldLord.getMountType() == 2) oldLord.dismount();
      removeOwner(true);
    }
    setFortState(0, 0); // initialize fort state
    //	if clan already have castle, don't store him in fortress
    if (clan.getHasCastle() > 0) {
      getSiege()
          .announceToPlayer(
              new SystemMessage(SystemMessageId.S1).addString("Форт снова пренадлежит NPC"),
              0,
              false);
      return false;
    } else {
      getSpawnManager().spawnSpecialEnvoys();
      ThreadPoolManager.getInstance()
          .scheduleGeneral(
              new ScheduleSpecialEnvoysDeSpawn(this),
              1 * 60 * 60 * 1000); // Prepare 1hr task for special envoys despawn
      // if clan have already fortress, remove it
      if (clan.getHasFort() > 0) FortManager.getInstance().getFortByOwner(clan).removeOwner(true);

      setOwnerClan(clan);
      _ownerId = clan.getClanId();
      updateOwnerInDB(); // Update in database

      if (getSiege().getIsInProgress()) { // If siege in progress
        if (Config.FORTSIEGE_REWARD_ID > 0) {
          clan.getWarehouse()
              .addItem(
                  "Siege", Config.FORTSIEGE_REWARD_ID, Config.FORTSIEGE_REWARD_COUNT, null, null);
          if (clan.getLeader().getPlayerInstance() != null)
            clan.getLeader()
                .getPlayerInstance()
                .sendMessage(
                    "Your clan obtain "
                        + Config.FORTSIEGE_REWARD_COUNT
                        + " "
                        + ItemTable.getInstance().getItemName(Config.FORTSIEGE_REWARD_ID));
        }

        getSiege().endSiege();
      }
      return true;
    }
  }
Ejemplo n.º 11
0
 public void endOfSiege(L2Clan clan) {
   ThreadPoolManager.getInstance().scheduleGeneral(new endFortressSiege(this, clan), 1000);
 }