/**
   * Method dropAttackable.
   *
   * @param attackable NpcInstance
   * @param killer Player
   */
  public void dropAttackable(NpcInstance attackable, Player killer) {
    if (killer.isInOlympiadMode()
        || killer.isCursedWeaponEquipped()
        || (_cursedWeapons.length == 0)
        || (killer.getReflection() != ReflectionManager.DEFAULT)) {
      return;
    }

    synchronized (_cursedWeapons) {
      CursedWeapon[] cursedWeapons = new CursedWeapon[0];

      for (CursedWeapon cw : _cursedWeapons) {
        if (cw.isActive()) {
          continue;
        }

        cursedWeapons = ArrayUtils.add(cursedWeapons, cw);
      }

      if (cursedWeapons.length > 0) {
        CursedWeapon cw = cursedWeapons[Rnd.get(cursedWeapons.length)];

        if (Rnd.get(100000000) <= cw.getDropRate()) {
          cw.create(attackable, killer);
        }
      }
    }
  }
  /**
   * Method activate.
   *
   * @param player Player
   * @param item ItemInstance
   */
  public void activate(Player player, ItemInstance item) {
    if ((player == null) || player.isInOlympiadMode()) {
      return;
    }

    CursedWeapon cw = _cursedWeaponsMap.get(item.getId());

    if (cw == null) {
      return;
    }

    if (player.isCursedWeaponEquipped()) {
      if (player.getCursedWeaponEquippedId() != item.getId()) {
        CursedWeapon cw2 = _cursedWeaponsMap.get(player.getCursedWeaponEquippedId());
        cw2.setNbKills(cw2.getStageKills() - 1);
        cw2.increaseKills();
      }

      endOfLife(cw);
      player.getInventory().destroyItem(item, 1);
    } else if (cw.getTimeLeft() > 0) {
      cw.activate(player, item);
      saveData(cw);
      announce(
          new SystemMessage(SystemMessage.THE_OWNER_OF_S2_HAS_APPEARED_IN_THE_S1_REGION)
              .addZoneName(player.getLoc())
              .addString(cw.getName()));
    } else {
      endOfLife(cw);
      player.getInventory().destroyItem(item, 1);
    }
  }
  /**
   * Method checkPlayer.
   *
   * @param player Player
   * @param item ItemInstance
   */
  public void checkPlayer(Player player, ItemInstance item) {
    if ((player == null) || (item == null) || player.isInOlympiadMode()) {
      return;
    }

    CursedWeapon cw = _cursedWeaponsMap.get(item.getId());

    if (cw == null) {
      return;
    }

    if ((player.getObjectId() == cw.getPlayerId()) || (cw.getPlayerId() == 0) || cw.isDropped()) {
      activate(player, item);
      showUsageTime(player, cw);
    } else {
      _log.warn("CursedWeaponsManager: " + player + " tried to obtain " + item + " in wrong way");
      player.getInventory().destroyItem(item, item.getCount());
    }
  }
Exemple #4
0
 /**
  * Method canDuel0.
  *
  * @param requestor Player
  * @param target Player
  * @return IStaticPacket
  */
 protected IStaticPacket canDuel0(Player requestor, Player target) {
   IStaticPacket packet = null;
   if (target.isInCombat()) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_CURRENTLY_ENGAGED_IN_BATTLE)
             .addName(target);
   } else if (target.isDead()
       || target.isAlikeDead()
       || (target.getCurrentHpPercents() < 50)
       || (target.getCurrentMpPercents() < 50)
       || (target.getCurrentCpPercents() < 50)) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1S_HP_OR_MP_IS_BELOW_50)
             .addName(target);
   } else if (target.getEvent(DuelEvent.class) != null) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_ALREADY_ENGAGED_IN_A_DUEL)
             .addName(target);
   } else if ((target.getEvent(ClanHallSiegeEvent.class) != null)
       || (target.getEvent(ClanHallNpcSiegeEvent.class) != null)) {
     packet =
         new SystemMessage2(
                 SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_PARTICIPATING_IN_A_CLAN_HALL_WAR)
             .addName(target);
   } else if (target.getEvent(SiegeEvent.class) != null) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_PARTICIPATING_IN_A_SIEGE_WAR)
             .addName(target);
   } else if (target.isInOlympiadMode()) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_PARTICIPATING_IN_THE_OLYMPIAD)
             .addName(target);
   } else if (target.isCursedWeaponEquipped()
       || (target.isChaotic())
       || (target.getPvpFlag() > 0)) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_IN_A_CHAOTIC_STATE)
             .addName(target);
   } else if (target.isInStoreMode()) {
     packet =
         new SystemMessage2(
                 SystemMsg
                     .C1_CANNOT_DUEL_BECAUSE_C1_IS_CURRENTLY_ENGAGED_IN_A_PRIVATE_STORE_OR_MANUFACTURE)
             .addName(target);
   } else if (target.isMounted() || target.isInBoat()) {
     packet =
         new SystemMessage2(
                 SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_CURRENTLY_RIDING_A_BOAT_STEED_OR_STRIDER)
             .addName(target);
   } else if (target.isFishing()) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_CURRENTLY_FISHING)
             .addName(target);
   } else if (target.isInCombatZone()
       || target.isInPeaceZone()
       || target.isInWater()
       || target.isInZone(Zone.ZoneType.no_restart)) {
     packet =
         new SystemMessage2(
                 SystemMsg
                     .C1_CANNOT_MAKE_A_CHALLENGE_TO_A_DUEL_BECAUSE_C1_IS_CURRENTLY_IN_A_DUELPROHIBITED_AREA_PEACEFUL_ZONE__SEVEN_SIGNS_ZONE__NEAR_WATER__RESTART_PROHIBITED_AREA)
             .addName(target);
   } else if (!requestor.isInRangeZ(target, 1200)) {
     packet =
         new SystemMessage2(
                 SystemMsg.C1_CANNOT_RECEIVE_A_DUEL_CHALLENGE_BECAUSE_C1_IS_TOO_FAR_AWAY)
             .addName(target);
   } else if (target.getTransformation() != 0) {
     packet =
         new SystemMessage2(SystemMsg.C1_CANNOT_DUEL_BECAUSE_C1_IS_CURRENTLY_POLYMORPHED)
             .addName(target);
   }
   return packet;
 }