Beispiel #1
0
  @Override
  public String onSpawn(L2Npc npc) {
    for (L2PcInstance target : npc.getKnownList().getKnownType(L2PcInstance.class)) {
      if (!target.isDead()
          && GeoData.getInstance().canSeeTarget(npc, target)
          && Util.checkIfInRange(npc.getAggroRange(), npc, target, true)) {
        if (target.getActiveWeaponInstance() != null
            && !npc.isInCombat()
            && npc.getTarget() == null) {
          npc.setTarget(target);
          npc.broadcastNpcSay(
              ((target.getAppearance().getSex()) ? "Sister " : "Brother ")
                  + target.getName()
                  + ", move your weapon away!");

          switch (npc.getNpcId()) {
            case 22124:
            case 22126:
            case 22127:
              npc.doCast(SkillTable.getInstance().getInfo(4589, 8));
              break;

            default:
              attack(((L2Attackable) npc), target);
              break;
          }
        }
      }
    }
    return super.onSpawn(npc);
  }
Beispiel #2
0
  @Override
  public void useSkill(L2Character caster, L2Object[] targets) {
    try {
      for (L2Object target : targets) {
        if (target instanceof L2PcInstance) {
          L2PcInstance targetPlayer = (L2PcInstance) target;
          if (_faceId >= 0) targetPlayer.getAppearance().setFace(_faceId);
          if (_hairColorId >= 0) targetPlayer.getAppearance().setHairColor(_hairColorId);
          if (_hairStyleId >= 0) targetPlayer.getAppearance().setHairStyle(_hairStyleId);

          targetPlayer.broadcastUserInfo();
        }
      }
    } catch (Exception e) {
      _log.log(Level.SEVERE, "", e);
    }
  }
Beispiel #3
0
  /**
   * Return the number of players in a defined radius.<br>
   * Dead players aren't counted, invisible ones is the boolean parameter.
   *
   * @param range : the radius.
   * @param npc : the object to make the test on.
   * @param invisible : true counts invisible characters.
   * @return the number of targets found.
   */
  public static int getPlayersCountInRadius(int range, L2Character npc, boolean invisible) {
    int count = 0;
    for (L2PcInstance player : npc.getKnownList().getKnownType(L2PcInstance.class)) {
      if (player.isDead()) continue;

      if (!invisible && player.getAppearance().getInvisible()) continue;

      if (Util.checkIfInRange(range, npc, player, true)) count++;
    }
    return count;
  }
Beispiel #4
0
  /**
   * This method selects a random player.<br>
   * Player can't be dead and isn't an hidden GM aswell.
   *
   * @param npc to check.
   * @return the random player.
   */
  public static L2PcInstance getRandomPlayer(L2Npc npc) {
    List<L2PcInstance> result = new ArrayList<>();

    for (L2PcInstance player : npc.getKnownList().getKnownType(L2PcInstance.class)) {
      if (player.isDead()) continue;

      if (player.isGM() && player.getAppearance().getInvisible()) continue;

      result.add(player);
    }

    return (result.isEmpty()) ? null : result.get(Rnd.get(result.size()));
  }
Beispiel #5
0
 @Override
 public String onSkillSee(
     L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet) {
   if (skill.getSkillType() == L2SkillType.AGGDAMAGE && targets.length != 0) {
     for (L2Object obj : targets) {
       if (obj.equals(npc)) {
         npc.broadcastNpcSay(
             ((caster.getAppearance().getSex()) ? "Sister " : "Brother ")
                 + caster.getName()
                 + ", move your weapon away!");
         attack(((L2Attackable) npc), caster);
         break;
       }
     }
   }
   return super.onSkillSee(npc, caster, skill, targets, isPet);
 }
Beispiel #6
0
  /**
   * Under that barbarian name, return the number of players in front, back and sides of the npc.
   * <br>
   * Dead players aren't counted, invisible ones is the boolean parameter.
   *
   * @param range : the radius.
   * @param npc : the object to make the test on.
   * @param invisible : true counts invisible characters.
   * @return an array composed of front, back and side targets number.
   */
  public static int[] getPlayersCountInPositions(int range, L2Character npc, boolean invisible) {
    int frontCount = 0;
    int backCount = 0;
    int sideCount = 0;

    for (L2PcInstance player : npc.getKnownList().getKnownType(L2PcInstance.class)) {
      if (player.isDead()) continue;

      if (!invisible && player.getAppearance().getInvisible()) continue;

      if (!Util.checkIfInRange(range, npc, player, true)) continue;

      if (player.isInFrontOf(npc)) frontCount++;
      else if (player.isBehind(npc)) backCount++;
      else sideCount++;
    }

    int[] array = {frontCount, backCount, sideCount};
    return array;
  }
Beispiel #7
0
  @Override
  public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isPet) {
    if (!npc.isInCombat()) {
      if (player.getActiveWeaponInstance() != null) {
        npc.setTarget(player);
        npc.broadcastNpcSay(
            ((player.getAppearance().getSex()) ? "Sister " : "Brother ")
                + player.getName()
                + ", move your weapon away!");

        switch (npc.getNpcId()) {
          case 22124:
          case 22126:
            npc.doCast(SkillTable.getInstance().getInfo(4589, 8));
            break;

          default:
            attack(((L2Attackable) npc), player);
            break;
        }
      } else if (((L2Attackable) npc).getMostHated() == null) return null;
    }
    return super.onAggroRangeEnter(npc, player, isPet);
  }
  public boolean useAdminCommand(String command, L2PcInstance activeChar) {
    if (command.equals("admin_current_player")) {
      showCharacterInfo(activeChar, null);
    } else if ((command.startsWith("admin_character_list"))
        || (command.startsWith("admin_character_info"))) {
      try {
        String val = command.substring(21);
        L2PcInstance target = L2World.getInstance().getPlayer(val);
        if (target != null) showCharacterInfo(activeChar, target);
        else activeChar.sendPacket(new SystemMessage(SystemMessageId.CHARACTER_DOES_NOT_EXIST));
      } catch (StringIndexOutOfBoundsException e) {
        activeChar.sendMessage(385);
      }
    } else if (command.startsWith("admin_show_characters")) {
      try {
        String val = command.substring(22);
        int page = Integer.parseInt(val);
        listCharacters(activeChar, page);
      } catch (StringIndexOutOfBoundsException e) {
        // Case of empty page number
        activeChar.sendMessage(421);
      }
    } else if (command.startsWith("admin_find_character")) {
      try {
        String val = command.substring(21);
        findCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(392);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_ip")) {
      try {
        String val = command.substring(14);
        findCharactersPerIp(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed IP number
        activeChar.sendMessage(393);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_find_account")) {
      try {
        String val = command.substring(19);
        findCharactersPerAccount(activeChar, val);
      } catch (Exception e) { // Case of empty or malformed player name
        activeChar.sendMessage(391);
        listCharacters(activeChar, 0);
      }
    } else if (command.equals("admin_edit_character")) editCharacter(activeChar);
    // Karma control commands
    else if (command.equals("admin_nokarma")) setTargetKarma(activeChar, 0);
    else if (command.startsWith("admin_setkarma")) {
      try {
        String val = command.substring(15);
        int karma = Integer.parseInt(val);
        setTargetKarma(activeChar, karma);
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set karma error: " + e);
        activeChar.sendMessage(419);
      }
    } else if (command.startsWith("admin_setfame")) {
      try {
        String val = command.substring(14);
        int fame = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        if (target instanceof L2PcInstance) {
          L2PcInstance player = (L2PcInstance) target;
          player.setFame(fame);
          player.sendPacket(new UserInfo(player));
          player.sendPacket(new ExBrExtraUserInfo(player));
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[261]);
          cm.addNumber(fame);
          cm.sendMessage(player);
        } else {
          activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
        }
      } catch (Exception e) {
        if (Config.DEVELOPER) _log.warning("Set Fame error: " + e);
        activeChar.sendMessage(316);
      }
    } else if (command.startsWith("admin_save_modifications")) {
      try {
        String val = command.substring(24);
        adminModifyCharacter(activeChar, val);
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(113);
        listCharacters(activeChar, 0);
      }
    } else if (command.startsWith("admin_rec")) {
      try {
        String val = command.substring(10);
        int recVal = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setRecomHave(recVal);
        player.sendMessage(528);
        player.broadcastUserInfo();
      } catch (Exception e) {
        activeChar.sendMessage(414);
      }
    } else if (command.startsWith("admin_setclass")) {
      try {
        String val = command.substring(15);
        int classidval = Integer.parseInt(val);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) player = (L2PcInstance) target;
        else return false;
        boolean valid = false;
        for (ClassId classid : ClassId.values()) if (classidval == classid.getId()) valid = true;
        if (valid && (player.getClassId().getId() != classidval)) {
          player.setClassId(classidval);
          if (!player.isSubClassActive()) player.setBaseClass(classidval);
          String newclass = player.getTemplate().className;
          player.store();
          L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[14]);
          cm.addString(newclass);
          cm.sendMessage(player);
          player.broadcastUserInfo();
          cm = new L2CoreMessage(MessageTable.Messages[670]);
          cm.addString(player.getName());
          cm.addString(newclass);
          cm.sendMessage(activeChar);
        }
        activeChar.sendMessage(418);
      } catch (StringIndexOutOfBoundsException e) {
        AdminHelpPage.showHelpPage(activeChar, "charclasses.htm");
      }
    } else if (command.startsWith("admin_settitle")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.setTitle(val);
        player.sendMessage(644);
        player.broadcastTitleInfo();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character title
        activeChar.sendMessage(584);
      }
    } else if (command.startsWith("admin_changename")) {
      try {
        String val = command.substring(17);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        L2World.getInstance().removeFromAllPlayers(player);
        player.setName(val);
        player.store();
        L2World.getInstance().addToAllPlayers(player);

        player.sendMessage(623);
        player.broadcastUserInfo();

        if (player.isInParty()) {
          // Delete party window for other party members
          player.getParty().broadcastToPartyMembers(player, new PartySmallWindowDeleteAll());
          for (L2PcInstance member : player.getParty().getPartyMembers()) {
            // And re-add
            if (member != player)
              member.sendPacket(new PartySmallWindowAll(member, player.getParty()));
          }
        }
        if (player.getClan() != null) {
          player.getClan().broadcastClanStatus();
        }

        RegionBBSManager.getInstance().changeCommunityBoard();
      } catch (StringIndexOutOfBoundsException e) { // Case of empty character name
        activeChar.sendMessage(420);
      }
    } else if (command.startsWith("admin_setsex")) {
      L2Object target = activeChar.getTarget();
      L2PcInstance player = null;
      if (target instanceof L2PcInstance) {
        player = (L2PcInstance) target;
      } else {
        return false;
      }
      player.getAppearance().setSex(player.getAppearance().getSex() ? false : true);
      player.sendMessage(621);
      player.broadcastUserInfo();
      player.decayMe();
      player.spawnMe(player.getX(), player.getY(), player.getZ());
    } else if (command.startsWith("admin_setcolor")) {
      try {
        String val = command.substring(15);
        L2Object target = activeChar.getTarget();
        L2PcInstance player = null;
        if (target instanceof L2PcInstance) {
          player = (L2PcInstance) target;
        } else {
          return false;
        }
        player.getAppearance().setNameColor(Integer.decode("0x" + val));
        player.sendMessage(622);
        player.broadcastUserInfo();
      } catch (Exception e) { // Case of empty color or invalid hex string
        activeChar.sendMessage(583);
      }
    } else if (command.startsWith("admin_fullfood")) {
      L2Object target = activeChar.getTarget();
      if (target instanceof L2PetInstance) {
        L2PetInstance targetPet = (L2PetInstance) target;
        targetPet.setCurrentFed(targetPet.getMaxFed());
        targetPet
            .getOwner()
            .sendPacket(new SetSummonRemainTime(targetPet.getMaxFed(), targetPet.getCurrentFed()));
      } else activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
    } else if (command.startsWith("admin_unpenalty")) {
      try {
        StringTokenizer st = new StringTokenizer(command, " ");
        if (st.countTokens() != 3) {
          activeChar.sendMessage(364);
          return false;
        }

        st.nextToken();

        boolean changeCreateExpiryTime = st.nextToken().equalsIgnoreCase("create");

        String playerName = st.nextToken();
        L2PcInstance player = null;
        player = L2World.getInstance().getPlayer(playerName);

        if (player == null) {
          Connection con = L2DatabaseFactory.getInstance().getConnection();
          PreparedStatement ps =
              con.prepareStatement(
                  "UPDATE characters SET "
                      + (changeCreateExpiryTime
                          ? "clan_create_expiry_time"
                          : "clan_join_expiry_time")
                      + " WHERE char_name=? LIMIT 1");

          ps.setString(1, playerName);
          ps.execute();
        } else {
          // removing penalty
          if (changeCreateExpiryTime) player.setClanCreateExpiryTime(0);
          else player.setClanJoinExpiryTime(0);
        }

        L2CoreMessage cm = new L2CoreMessage(MessageTable.Messages[470]);
        cm.addString(playerName);
        cm.sendMessage(activeChar);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (command.startsWith("admin_find_dualbox")) {
      int multibox = 2;
      try {
        String val = command.substring(19);
        multibox = Integer.parseInt(val);
        if (multibox < 1) {
          activeChar.sendMessage(97);
          return false;
        }
      } catch (Exception e) {
      }
      findDualbox(activeChar, multibox);
    }

    return true;
  }