Exemplo n.º 1
0
  public void createSubPledge(
      L2PcInstance player, String clanName, String leaderName, int pledgeType, int minClanLvl) {
    if (Config.DEBUG) {
      _log.info(
          player.getObjectId()
              + "("
              + player.getName()
              + ") requested sub clan creation from "
              + getObjectId()
              + "("
              + getName()
              + ")");
    }

    if (!player.isClanLeader()) {
      player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
      return;
    }

    L2Clan clan = player.getClan();
    if (clan.getLevel() < minClanLvl) {
      if (pledgeType == L2Clan.SUBUNIT_ACADEMY) {
        player.sendPacket(
            new SystemMessage(
                SystemMessageId.YOU_DO_NOT_MEET_CRITERIA_IN_ORDER_TO_CREATE_A_CLAN_ACADEMY));
      } else {
        player.sendPacket(
            new SystemMessage(
                SystemMessageId.YOU_DO_NOT_MEET_CRITERIA_IN_ORDER_TO_CREATE_A_MILITARY_UNIT));
      }
      return;
    }

    if (!Util.isAlphaNumeric(clanName) || 2 > clanName.length()) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_INCORRECT));
      return;
    }

    if (clanName.length() > 16) {
      player.sendPacket(new SystemMessage(SystemMessageId.CLAN_NAME_TOO_LONG));
      return;
    }
    for (L2Clan tempClan : ClanTable.getInstance().getClans()) {
      if (tempClan.getSubPledge(clanName) != null) {
        if (pledgeType == L2Clan.SUBUNIT_ACADEMY) {
          SystemMessage sm = new SystemMessage(SystemMessageId.S1_ALREADY_EXISTS);
          sm.addString(clanName);
          player.sendPacket(sm);
          sm = null;
        } else {
          player.sendPacket(
              new SystemMessage(SystemMessageId.ANOTHER_MILITARY_UNIT_IS_ALREADY_USING_THAT_NAME));
        }
        return;
      }
    }

    if (pledgeType != L2Clan.SUBUNIT_ACADEMY)
      if (clan.getClanMember(leaderName) == null
          || clan.getClanMember(leaderName).getPledgeType() != 0) {
        if (pledgeType >= L2Clan.SUBUNIT_KNIGHT1) {
          player.sendPacket(
              new SystemMessage(SystemMessageId.CAPTAIN_OF_ORDER_OF_KNIGHTS_CANNOT_BE_APPOINTED));
        } else if (pledgeType >= L2Clan.SUBUNIT_ROYAL1) {
          player.sendPacket(
              new SystemMessage(SystemMessageId.CAPTAIN_OF_ROYAL_GUARD_CANNOT_BE_APPOINTED));
        }
        return;
      }

    int leaderId =
        clan.getClanMember(leaderName) != null ? clan.getClanMember(leaderName).getObjectId() : 0;

    if (clan.createSubPledge(player, pledgeType, leaderId, clanName) == null) return;

    SystemMessage sm;
    if (pledgeType == L2Clan.SUBUNIT_ACADEMY) {
      sm = new SystemMessage(SystemMessageId.THE_S1S_CLAN_ACADEMY_HAS_BEEN_CREATED);
      sm.addString(player.getClan().getName());
    } else if (pledgeType >= L2Clan.SUBUNIT_KNIGHT1) {
      sm = new SystemMessage(SystemMessageId.THE_KNIGHTS_OF_S1_HAVE_BEEN_CREATED);
      sm.addString(player.getClan().getName());
    } else if (pledgeType >= L2Clan.SUBUNIT_ROYAL1) {
      sm = new SystemMessage(SystemMessageId.THE_ROYAL_GUARD_OF_S1_HAVE_BEEN_CREATED);
      sm.addString(player.getClan().getName());
    } else {
      sm = new SystemMessage(SystemMessageId.CLAN_CREATED);
    }

    player.sendPacket(sm);
    if (pledgeType != L2Clan.SUBUNIT_ACADEMY) {
      L2ClanMember leaderSubPledge = clan.getClanMember(leaderName);
      if (leaderSubPledge.getPlayerInstance() == null) return;

      leaderSubPledge
          .getPlayerInstance()
          .setPledgeClass(
              leaderSubPledge.calculatePledgeClass(leaderSubPledge.getPlayerInstance()));
      leaderSubPledge
          .getPlayerInstance()
          .sendPacket(new UserInfo(leaderSubPledge.getPlayerInstance()));
    }
    clan = null;
    sm = null;
  }
  @Override
  protected void runImpl() {
    L2PcInstance player = getClient().getActiveChar();
    if (player == null) return;

    ItemContainer warehouse = player.getActiveWarehouse();
    if (warehouse == null) return;

    L2FolkInstance manager = player.getLastFolkNPC();
    if ((manager == null
            || !player.isInsideRadius(manager, L2NpcInstance.INTERACTION_DISTANCE, false, false))
        && !player.isGM()) return;

    if (warehouse instanceof ClanWarehouse && !player.getAccessLevel().allowTransaction()) {
      player.sendMessage("Unsufficient privileges.");
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    if (!FloodProtector.getInstance()
        .tryPerformAction(player.getObjectId(), FloodProtector.PROTECTED_WEREHOUSE)) {
      _log.warn("Player " + player.getName() + " has performed a werehouse action too fast");
      return;
    }

    // Alt game - Karma punishment
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_USE_WAREHOUSE && player.getKarma() > 0) return;

    if (Config.ALT_MEMBERS_CAN_WITHDRAW_FROM_CLANWH) {
      if (warehouse instanceof ClanWarehouse
          && (player.getClanPrivileges() & L2Clan.CP_CL_VIEW_WAREHOUSE)
              != L2Clan.CP_CL_VIEW_WAREHOUSE) return;
    } else {
      if (warehouse instanceof ClanWarehouse && !player.isClanLeader()) {
        // this msg is for depositing but maybe good to send some msg?
        player.sendPacket(
            new SystemMessage(
                SystemMessageId.ONLY_CLAN_LEADER_CAN_RETRIEVE_ITEMS_FROM_CLAN_WAREHOUSE));
        return;
      }
    }

    int weight = 0;
    int slots = 0;

    for (int i = 0; i < _count; i++) {
      int objectId = _items[i * 2 + 0];
      int count = _items[i * 2 + 1];

      // Calculate needed slots
      L2ItemInstance item = warehouse.getItemByObjectId(objectId);
      if (item == null) {
        continue;
      }
      weight += count * item.getItem().getWeight();
      if (!item.isStackable()) {
        slots += count;
      } else if (player.getInventory().getItemByItemId(item.getItemId()) == null) {
        slots++;
      }
    }

    // Item Max Limit Check
    if (!player.getInventory().validateCapacity(slots)) {
      sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    if (player.getActiveEnchantItem() != null) {
      Util.handleIllegalPlayerAction(
          player,
          "Player " + player.getName() + " tried to use enchant exploit!",
          Config.DEFAULT_PUNISH);
      return;
    }

    // Weight limit Check
    if (!player.getInventory().validateWeight(weight)) {
      sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    // Proceed to the transfer
    InventoryUpdate playerIU = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
    for (int i = 0; i < _count; i++) {
      int objectId = _items[i * 2 + 0];
      int count = _items[i * 2 + 1];

      L2ItemInstance oldItem = warehouse.getItemByObjectId(objectId);
      if (oldItem == null || oldItem.getCount() < count) {
        player.sendMessage("Can't withdraw requested item" + (count > 1 ? "s" : ""));
      }
      L2ItemInstance newItem =
          warehouse.transferItem(
              "Warehouse", objectId, count, player.getInventory(), player, player.getLastFolkNPC());
      if (newItem == null) {
        _log.warn("Error withdrawing a warehouse object for char " + player.getName());
        continue;
      }

      if (playerIU != null) {
        if (newItem.getCount() > count) {
          playerIU.addModifiedItem(newItem);
        } else {
          playerIU.addNewItem(newItem);
        }
      }
    }

    // Send updated item list to the player
    if (playerIU != null) {
      player.sendPacket(playerIU);
    } else {
      player.sendPacket(new ItemList(player, false));
    }

    // Update current load status on player
    StatusUpdate su = new StatusUpdate(player.getObjectId());
    su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    player.sendPacket(su);
  }
Exemplo n.º 3
0
  @Override
  protected void runImpl() {
    L2PcInstance player = getClient().getActiveChar();
    if (player == null || !(player.getPet().isPet)) return;

    // Alt game - Karma punishment
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TRADE && player.getKarma() > 0) return;

    if (player.getPrivateStoreType() != 0) {
      player.sendMessage("Cannot exchange items while trading");
      return;
    }

    if (player.isCastingNow()) {
      return;
    }

    if (player.getActiveEnchantItem() != null) {
      Util.handleIllegalPlayerAction(
          player,
          "Player " + player.getName() + " Tried To Use Enchant Exploit! Ban This Player",
          Config.DEFAULT_PUNISH);
      return;
    }

    if (player.InventoryMoreLimit()) {
      return;
    }

    // Exploit Fix for Hero weapons Uses pet Inventory to buy New One.
    // [L2Scoria]
    L2ItemInstance item = player.getInventory().getItemByObjectId(_objectId);

    if (item == null) return;

    if (item.isAugmented()) return;

    if (!item.isDropable() || !item.isDestroyable() || !item.isTradeable()) {
      sendPacket(new SystemMessage(SystemMessageId.ITEM_NOT_FOR_PETS));
      return;
    }

    if (item.isTimeLimitedItem()) {
      sendPacket(new SystemMessage(SystemMessageId.ITEM_NOT_FOR_PETS));
      return;
    }

    L2PetInstance pet = (L2PetInstance) player.getPet();

    if (pet.isDead()) {
      sendPacket(new SystemMessage(SystemMessageId.CANNOT_GIVE_ITEMS_TO_DEAD_PET));
      return;
    }

    if (_amount < 0) return;

    if (player.transferItem("Transfer", _objectId, _amount, pet.getInventory(), pet) == null) {
      _log.warn(
          "Invalid item transfer request: " + pet.getName() + "(pet) --> " + player.getName());
    }
  }