Esempio n. 1
0
 /**
  * @see com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager#parsewrite(java.lang.String,
  *     java.lang.String, java.lang.String, java.lang.String, java.lang.String,
  *     com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  */
 @Override
 public void parsewrite(
     String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar) {
   if (!activeChar.isGM()) {
     return;
   }
 }
Esempio n. 2
0
 @Override
 public boolean useAdminCommand(String command, L2PcInstance activeChar) {
   if (command.equals("admin_gm") && activeChar.isGM()) {
     AdminData.getInstance().deleteGm(activeChar);
     activeChar.setAccessLevel(0, true);
     activeChar.sendMessage("You no longer have GM status.");
     _log.info(
         "GM: "
             + activeChar.getName()
             + "("
             + activeChar.getObjectId()
             + ") turned his GM status off");
   }
   return true;
 }
 public void handleCheat(L2PcInstance player, L2Npc npc) {
   showHtmlFile(player, "data/html/seven_signs/rift/Cheater.htm", npc);
   if (!player.isGM()) {
     _log.warning(
         "Player "
             + player.getName()
             + "("
             + player.getObjectId()
             + ") was cheating in dimension rift area!");
     Util.handleIllegalPlayerAction(
         player,
         "Warning!! Character " + player.getName() + " tried to cheat in dimensional rift.",
         Config.DEFAULT_PUNISH);
   }
 }
Esempio n. 4
0
  @Override
  protected void runImpl() {
    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    String command = "admin_" + _command.split(" ")[0];

    IAdminCommandHandler ach = AdminCommandHandler.getInstance().getHandler(command);

    if (ach == null) {
      if (activeChar.isGM()) {
        activeChar.sendMessage("指令「" + command.substring(6) + "」不存在!");
      }

      _log.warning("No handler registered for admin command '" + command + "'");
      return;
    }

    if (!AdminData.getInstance().hasAccess(command, activeChar.getAccessLevel())) {
      activeChar.sendMessage("没有相关权限");
      _log.warning(
          "Character "
              + activeChar.getName()
              + " tryed to use admin command "
              + command
              + ", but have no access to it!");
      return;
    }

    if (Config.GMAUDIT) {
      GMAudit.auditGMAction(
          activeChar.getName() + " [" + activeChar.getObjectId() + "]",
          _command,
          (activeChar.getTarget() != null ? activeChar.getTarget().getName() : "no-target"));
    }

    ach.useAdminCommand("admin_" + _command, activeChar);
  }
Esempio n. 5
0
  /**
   * @see com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String,
   *     com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
   */
  @Override
  public void parsecmd(String command, L2PcInstance activeChar) {
    if (!activeChar.isGM()) {
      return;
    }
    if (command.startsWith("admin_bbs")) {
      separateAndSend(
          "<html><body><br><br><center>This Page is only an exemple :)<br><br>command="
              + command
              + "</center></body></html>",
          activeChar);
    } else {

      ShowBoard sb =
          new ShowBoard(
              "<html><body><br><br><center>the command: "
                  + command
                  + " is not implemented yet</center><br><br></body></html>",
              "101");
      activeChar.sendPacket(sb);
      activeChar.sendPacket(new ShowBoard(null, "102"));
      activeChar.sendPacket(new ShowBoard(null, "103"));
    }
  }
Esempio n. 6
0
  @Override
  protected void runImpl() {
    if (Config.DEBUG) _log.info("Say2: Msg Type = '" + _type + "' Text = '" + _text + "'.");

    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) return;

    if (_type < 0 || _type >= CHAT_NAMES.length) {
      _log.warning(
          "Say2: Invalid type: "
              + _type
              + " Player : "
              + activeChar.getName()
              + " text: "
              + String.valueOf(_text));
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      activeChar.logout();
      return;
    }

    if (_text.isEmpty()) {
      _log.warning(activeChar.getName() + ": sending empty text. Possible packet hack!");
      activeChar.sendPacket(ActionFailed.STATIC_PACKET);
      activeChar.logout();
      return;
    }

    // Even though the client can handle more characters than it's current limit allows, an overflow
    // (critical error) happens if you pass a huge (1000+) message.
    // July 11, 2011 - Verified on High Five 4 official client as 105.
    // Allow higher limit if player shift some item (text is longer then).
    if (!activeChar.isGM()
        && ((_text.indexOf(8) >= 0 && _text.length() > 500)
            || (_text.indexOf(8) < 0 && _text.length() > 105))) {
      activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.DONT_SPAM));
      return;
    }

    if (Config.L2WALKER_PROTECTION && _type == TELL && checkBot(_text)) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "Client Emulator Detect: Player " + activeChar.getName() + " using l2walker.",
          Config.DEFAULT_PUNISH);
      return;
    }

    if (activeChar.isCursedWeaponEquipped() && (_type == TRADE || _type == SHOUT)) {
      activeChar.sendPacket(
          SystemMessage.getSystemMessage(
              SystemMessageId.SHOUT_AND_TRADE_CHAT_CANNOT_BE_USED_WHILE_POSSESSING_CURSED_WEAPON));
      return;
    }

    if (activeChar.isChatBanned() && !_text.startsWith(".")) {
      for (int chatId : Config.BAN_CHAT_CHANNELS) {
        if (_type == chatId) {
          activeChar.sendPacket(
              SystemMessage.getSystemMessage(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED));
          return;
        }
      }
    }

    if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT) {
      if (_type == TELL || _type == SHOUT || _type == TRADE || _type == HERO_VOICE) {
        activeChar.sendMessage("You can not chat with players outside of the jail.");
        return;
      }
    }

    if (_type == PETITION_PLAYER && activeChar.isGM()) _type = PETITION_GM;

    if (Config.LOG_CHAT) {
      LogRecord record = new LogRecord(Level.INFO, _text);
      record.setLoggerName("chat");

      if (_type == TELL)
        record.setParameters(
            new Object[] {CHAT_NAMES[_type], "[" + activeChar.getName() + " to " + _target + "]"});
      else record.setParameters(new Object[] {CHAT_NAMES[_type], "[" + activeChar.getName() + "]"});

      _logChat.log(record);
    }

    if (_text.indexOf(8) >= 0) if (!parseAndPublishItem(activeChar)) return;

    // Say Filter implementation
    if (Config.USE_SAY_FILTER) checkText();

    IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
    if (handler != null) handler.handleChat(_type, activeChar, _target, _text);
    else _log.info("No handler registered for ChatType: " + _type + " Player: " + getClient());
  }
Esempio n. 7
0
  @Override
  public void runImpl() {
    final L2PcInstance player = getClient().getActiveChar();
    if (player == null) {
      return;
    }

    if (!getClient().getFloodProtectors().getMultiSell().tryPerformAction("multisell choose")) {
      player.setMultiSell(null);
      return;
    }

    if ((_amount < 1) || (_amount > 5000)) {
      player.setMultiSell(null);
      return;
    }

    PreparedListContainer list = player.getMultiSell();
    if ((list == null) || (list.getListId() != _listId)) {
      player.setMultiSell(null);
      return;
    }

    final L2Npc npc = player.getLastFolkNPC();
    if (((npc != null) && !list.isNpcAllowed(npc.getId())) || ((npc == null) && list.isNpcOnly())) {
      player.setMultiSell(null);
      return;
    }

    if (!player.isGM() && (npc != null)) {
      if (!player.isInsideRadius(npc, INTERACTION_DISTANCE, true, false)
          || (player.getInstanceId() != npc.getInstanceId())) {
        player.setMultiSell(null);
        return;
      }
    }

    for (Entry entry : list.getEntries()) {
      if (entry.getEntryId() == _entryId) {
        if (!entry.isStackable() && (_amount > 1)) {
          _log.severe(
              "Character: "
                  + player.getName()
                  + " is trying to set amount > 1 on non-stackable multisell, id:"
                  + _listId
                  + ":"
                  + _entryId);
          player.setMultiSell(null);
          return;
        }

        final PcInventory inv = player.getInventory();

        int slots = 0;
        int weight = 0;
        for (Ingredient e : entry.getProducts()) {
          if (e.getItemId() < 0) {
            continue;
          }

          if (!e.isStackable()) {
            slots += e.getItemCount() * _amount;
          } else if (player.getInventory().getItemByItemId(e.getItemId()) == null) {
            slots++;
          }
          weight += e.getItemCount() * _amount * e.getWeight();
        }

        if (!inv.validateWeight(weight)) {
          player.sendPacket(SystemMessageId.WEIGHT_LIMIT_EXCEEDED);
          return;
        }

        if (!inv.validateCapacity(slots)) {
          player.sendPacket(SystemMessageId.SLOTS_FULL);
          return;
        }

        ArrayList<Ingredient> ingredientsList = new ArrayList<>(entry.getIngredients().size());
        // Generate a list of distinct ingredients and counts in order to check if the correct
        // item-counts
        // are possessed by the player
        boolean newIng;
        for (Ingredient e : entry.getIngredients()) {
          newIng = true;
          // at this point, the template has already been modified so that enchantments are properly
          // included
          // whenever they need to be applied. Uniqueness of items is thus judged by item id AND
          // enchantment level
          for (int i = ingredientsList.size(); --i >= 0; ) {
            Ingredient ex = ingredientsList.get(i);
            // if the item was already added in the list, merely increment the count
            // this happens if 1 list entry has the same ingredient twice (example 2 swords = 1
            // dual)
            if ((ex.getItemId() == e.getItemId())
                && (ex.getEnchantLevel() == e.getEnchantLevel())) {
              if ((ex.getItemCount() + e.getItemCount()) > Integer.MAX_VALUE) {
                player.sendPacket(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
                return;
              }
              // two same ingredients, merge into one and replace old
              final Ingredient ing = ex.getCopy();
              ing.setItemCount(ex.getItemCount() + e.getItemCount());
              ingredientsList.set(i, ing);
              newIng = false;
              break;
            }
          }
          if (newIng) {
            // if it's a new ingredient, just store its info directly (item id, count, enchantment)
            ingredientsList.add(e);
          }
        }

        // now check if the player has sufficient items in the inventory to cover the ingredients'
        // expences
        for (Ingredient e : ingredientsList) {
          if ((e.getItemCount() * _amount) > Integer.MAX_VALUE) {
            player.sendPacket(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED);
            return;
          }
          if (e.getItemId() < 0) {
            if (!MultisellData.hasSpecialIngredient(
                e.getItemId(), e.getItemCount() * _amount, player)) {
              return;
            }
          } else {
            // if this is not a list that maintains enchantment, check the count of all items that
            // have the given id.
            // otherwise, check only the count of items with exactly the needed enchantment level
            final long required =
                ((Config.ALT_BLACKSMITH_USE_RECIPES || !e.getMaintainIngredient())
                    ? (e.getItemCount() * _amount)
                    : e.getItemCount());
            if (inv.getInventoryItemCount(
                    e.getItemId(), list.getMaintainEnchantment() ? e.getEnchantLevel() : -1, false)
                < required) {
              SystemMessage sm =
                  SystemMessage.getSystemMessage(SystemMessageId.S2_UNIT_OF_THE_ITEM_S1_REQUIRED);
              sm.addItemName(e.getTemplate());
              sm.addLong(required);
              player.sendPacket(sm);
              return;
            }
          }
        }

        List<L2Augmentation> augmentation = new ArrayList<>();
        Elementals[] elemental = null;
        /** All ok, remove items and add final product */
        for (Ingredient e : entry.getIngredients()) {
          if (e.getItemId() < 0) {
            if (!MultisellData.takeSpecialIngredient(
                e.getItemId(), e.getItemCount() * _amount, player)) {
              return;
            }
          } else {
            L2ItemInstance itemToTake =
                inv.getItemByItemId(
                    e.getItemId()); // initialize and initial guess for the item to take.
            if (itemToTake
                == null) { // this is a cheat, transaction will be aborted and if any items already
                           // taken will not be returned back to inventory!
              _log.severe(
                  "Character: "
                      + player.getName()
                      + " is trying to cheat in multisell, id:"
                      + _listId
                      + ":"
                      + _entryId);
              player.setMultiSell(null);
              return;
            }

            // if (itemToTake.isEquipped())
            // {
            // this is a cheat, transaction will be aborted and if any items already taken will not
            // be returned back to inventory!
            // _log.severe("Character: " + player.getName() + " is trying to cheat in multisell,
            // exchanging equipped item, merchatnt id:" + merchant.getNpcId());
            // player.setMultiSell(null);
            // return;
            // }

            if (Config.ALT_BLACKSMITH_USE_RECIPES || !e.getMaintainIngredient()) {
              // if it's a stackable item, just reduce the amount from the first (only) instance
              // that is found in the inventory
              if (itemToTake.isStackable()) {
                if (!player.destroyItem(
                    "Multisell",
                    itemToTake.getObjectId(),
                    (e.getItemCount() * _amount),
                    player.getTarget(),
                    true)) {
                  player.setMultiSell(null);
                  return;
                }
              } else {
                // for non-stackable items, one of two scenaria are possible:
                // a) list maintains enchantment: get the instances that exactly match the requested
                // enchantment level
                // b) list does not maintain enchantment: get the instances with the LOWEST
                // enchantment level

                // a) if enchantment is maintained, then get a list of items that exactly match this
                // enchantment
                if (list.getMaintainEnchantment()) {
                  // loop through this list and remove (one by one) each item until the required
                  // amount is taken.
                  L2ItemInstance[] inventoryContents =
                      inv.getAllItemsByItemId(e.getItemId(), e.getEnchantLevel(), false);
                  for (int i = 0; i < (e.getItemCount() * _amount); i++) {
                    if (inventoryContents[i].isAugmented()) {
                      augmentation.add(inventoryContents[i].getAugmentation());
                    }
                    if (inventoryContents[i].getElementals() != null) {
                      elemental = inventoryContents[i].getElementals();
                    }
                    if (!player.destroyItem(
                        "Multisell",
                        inventoryContents[i].getObjectId(),
                        1,
                        player.getTarget(),
                        true)) {
                      player.setMultiSell(null);
                      return;
                    }
                  }
                } else
                // b) enchantment is not maintained. Get the instances with the LOWEST enchantment
                // level
                {
                  // NOTE: There are 2 ways to achieve the above goal.
                  // 1) Get all items that have the correct itemId, loop through them until the
                  // lowest enchantment
                  // level is found. Repeat all this for the next item until proper count of items
                  // is reached.
                  // 2) Get all items that have the correct itemId, sort them once based on
                  // enchantment level,
                  // and get the range of items that is necessary.
                  // Method 1 is faster for a small number of items to be exchanged.
                  // Method 2 is faster for large amounts.
                  //
                  // EXPLANATION:
                  // Worst case scenario for algorithm 1 will make it run in a number of cycles
                  // given by:
                  // m*(2n-m+1)/2 where m is the number of items to be exchanged and n is the total
                  // number of inventory items that have a matching id.
                  // With algorithm 2 (sort), sorting takes n*log(n) time and the choice is done in
                  // a single cycle
                  // for case b (just grab the m first items) or in linear time for case a (find the
                  // beginning of items
                  // with correct enchantment, index x, and take all items from x to x+m).
                  // Basically, whenever m > log(n) we have: m*(2n-m+1)/2 = (2nm-m*m+m)/2 >
                  // (2nlogn-logn*logn+logn)/2 = nlog(n) - log(n*n) + log(n) = nlog(n) + log(n/n*n)
                  // =
                  // nlog(n) + log(1/n) = nlog(n) - log(n) = (n-1)log(n)
                  // So for m < log(n) then m*(2n-m+1)/2 > (n-1)log(n) and m*(2n-m+1)/2 > nlog(n)
                  //
                  // IDEALLY:
                  // In order to best optimize the performance, choose which algorithm to run, based
                  // on whether 2^m > n
                  // if ( (2<<(e.getItemCount()// _amount)) < inventoryContents.length )
                  // // do Algorithm 1, no sorting
                  // else
                  // // do Algorithm 2, sorting
                  //
                  // CURRENT IMPLEMENTATION:
                  // In general, it is going to be very rare for a person to do a massive exchange
                  // of non-stackable items
                  // For this reason, we assume that algorithm 1 will always suffice and we keep
                  // things simple.
                  // If, in the future, it becomes necessary that we optimize, the above discussion
                  // should make it clear
                  // what optimization exactly is necessary (based on the comments under "IDEALLY").
                  //

                  // choice 1. Small number of items exchanged. No sorting.
                  for (int i = 1; i <= (e.getItemCount() * _amount); i++) {
                    L2ItemInstance[] inventoryContents =
                        inv.getAllItemsByItemId(e.getItemId(), false);

                    itemToTake = inventoryContents[0];
                    // get item with the LOWEST enchantment level from the inventory...
                    // +0 is lowest by default...
                    if (itemToTake.getEnchantLevel() > 0) {
                      for (L2ItemInstance item : inventoryContents) {
                        if (item.getEnchantLevel() < itemToTake.getEnchantLevel()) {
                          itemToTake = item;
                          // nothing will have enchantment less than 0. If a zero-enchanted
                          // item is found, just take it
                          if (itemToTake.getEnchantLevel() == 0) {
                            break;
                          }
                        }
                      }
                    }
                    if (!player.destroyItem(
                        "Multisell", itemToTake.getObjectId(), 1, player.getTarget(), true)) {
                      player.setMultiSell(null);
                      return;
                    }
                  }
                }
              }
            }
          }
        }

        // Generate the appropriate items
        for (Ingredient e : entry.getProducts()) {
          if (e.getItemId() < 0) {
            MultisellData.giveSpecialProduct(e.getItemId(), e.getItemCount() * _amount, player);
          } else {
            if (e.isStackable()) {
              inv.addItem(
                  "Multisell",
                  e.getItemId(),
                  e.getItemCount() * _amount,
                  player,
                  player.getTarget());
            } else {
              L2ItemInstance product = null;
              for (int i = 0; i < (e.getItemCount() * _amount); i++) {
                product = inv.addItem("Multisell", e.getItemId(), 1, player, player.getTarget());
                if ((product != null) && list.getMaintainEnchantment()) {
                  if (i < augmentation.size()) {
                    product.setAugmentation(
                        new L2Augmentation(augmentation.get(i).getAugmentationId()));
                  }
                  if (elemental != null) {
                    for (Elementals elm : elemental) {
                      product.setElementAttr(elm.getElement(), elm.getValue());
                    }
                  }
                  product.setEnchantLevel(e.getEnchantLevel());
                  product.updateDatabase();
                }
              }
            }
            // msg part
            SystemMessage sm;

            if ((e.getItemCount() * _amount) > 1) {
              sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
              sm.addItemName(e.getItemId());
              sm.addLong(e.getItemCount() * _amount);
              player.sendPacket(sm);
            } else {
              if (list.getMaintainEnchantment() && (e.getEnchantLevel() > 0)) {
                sm = SystemMessage.getSystemMessage(SystemMessageId.ACQUIRED_S1_S2);
                sm.addLong(e.getEnchantLevel());
                sm.addItemName(e.getItemId());
              } else {
                sm = SystemMessage.getSystemMessage(SystemMessageId.EARNED_ITEM_S1);
                sm.addItemName(e.getItemId());
              }
              player.sendPacket(sm);
            }
          }
        }
        player.sendPacket(new ItemList(player, false));

        StatusUpdate su = new StatusUpdate(player);
        su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
        player.sendPacket(su);

        // finally, give the tax to the castle...
        if ((npc != null) && (entry.getTaxAmount() > 0)) {
          npc.getCastle().addToTreasury(entry.getTaxAmount() * _amount);
        }
        break;
      }
    }
  }
Esempio n. 8
0
  public final void reduceHp(
      double value,
      L2Character attacker,
      boolean awake,
      boolean isDOT,
      boolean isHPConsumption,
      boolean ignoreCP) {
    if (getActiveChar().isDead()) {
      return;
    }

    // If OFFLINE_MODE_NO_DAMAGE is enabled and player is offline and he is in store/craft mode, no
    // damage is taken.
    if (Config.OFFLINE_MODE_NO_DAMAGE
        && (getActiveChar().getClient() != null)
        && getActiveChar().getClient().isDetached()
        && ((Config.OFFLINE_TRADE_ENABLE
                && ((getActiveChar().getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_SELL)
                    || (getActiveChar().getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_BUY)))
            || (Config.OFFLINE_CRAFT_ENABLE
                && (getActiveChar().isInCraftMode()
                    || (getActiveChar().getPrivateStoreType()
                        == L2PcInstance.STORE_PRIVATE_MANUFACTURE))))) {
      return;
    }

    if (getActiveChar().isInvul() && !(isDOT || isHPConsumption)) {
      return;
    }

    if (!isHPConsumption) {
      getActiveChar().stopEffectsOnDamage(awake);
      // Attacked players in craft/shops stand up.
      if (getActiveChar().isInCraftMode() || getActiveChar().isInStoreMode()) {
        getActiveChar().setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
        getActiveChar().standUp();
        getActiveChar().broadcastUserInfo();
      } else if (getActiveChar().isSitting()) {
        getActiveChar().standUp();
      }

      if (!isDOT) {
        if (getActiveChar().isStunned() && (Rnd.get(10) == 0)) {
          getActiveChar().stopStunning(true);
        }
      }
    }

    int fullValue = (int) value;
    int tDmg = 0;
    int mpDam = 0;

    if ((attacker != null) && (attacker != getActiveChar())) {
      final L2PcInstance attackerPlayer = attacker.getActingPlayer();

      if (attackerPlayer != null) {
        if (attackerPlayer.isGM() && !attackerPlayer.getAccessLevel().canGiveDamage()) {
          return;
        }

        if (getActiveChar().isInDuel()) {
          if (getActiveChar().getDuelState() == Duel.DUELSTATE_DEAD) {
            return;
          } else if (getActiveChar().getDuelState() == Duel.DUELSTATE_WINNER) {
            return;
          }

          // cancel duel if player got hit by another player, that is not part of the duel
          if (attackerPlayer.getDuelId() != getActiveChar().getDuelId()) {
            getActiveChar().setDuelState(Duel.DUELSTATE_INTERRUPTED);
          }
        }
      }

      // Check and calculate transfered damage
      final L2Summon summon = getActiveChar().getSummon();
      if (getActiveChar().hasSummon()
          && summon.isServitor()
          && Util.checkIfInRange(1000, getActiveChar(), summon, true)) {
        tDmg =
            ((int) value
                    * (int)
                        getActiveChar()
                            .getStat()
                            .calcStat(Stats.TRANSFER_DAMAGE_PERCENT, 0, null, null))
                / 100;

        // Only transfer dmg up to current HP, it should not be killed
        tDmg = Math.min((int) summon.getCurrentHp() - 1, tDmg);
        if (tDmg > 0) {
          summon.reduceCurrentHp(tDmg, attacker, null);
          value -= tDmg;
          fullValue =
              (int)
                  value; // reduce the announced value here as player will get a message about
                         // summon damage
        }
      }

      mpDam =
          ((int) value
                  * (int)
                      getActiveChar().getStat().calcStat(Stats.MANA_SHIELD_PERCENT, 0, null, null))
              / 100;

      if (mpDam > 0) {
        mpDam = (int) (value - mpDam);
        if (mpDam > getActiveChar().getCurrentMp()) {
          getActiveChar().sendPacket(SystemMessageId.MP_BECAME_0_ARCANE_SHIELD_DISAPPEARING);
          getActiveChar().getFirstEffect(1556).stopEffectTask();
          value = mpDam - getActiveChar().getCurrentMp();
          getActiveChar().setCurrentMp(0);
        } else {
          getActiveChar().reduceCurrentMp(mpDam);
          SystemMessage smsg =
              SystemMessage.getSystemMessage(
                  SystemMessageId.ARCANE_SHIELD_DECREASED_YOUR_MP_BY_S1_INSTEAD_OF_HP);
          smsg.addNumber(mpDam);
          getActiveChar().sendPacket(smsg);
          return;
        }
      }

      final L2PcInstance caster = getActiveChar().getTransferingDamageTo();
      if ((caster != null)
          && (getActiveChar().getParty() != null)
          && Util.checkIfInRange(1000, getActiveChar(), caster, true)
          && !caster.isDead()
          && (getActiveChar() != caster)
          && getActiveChar().getParty().getMembers().contains(caster)) {
        int transferDmg = 0;

        transferDmg =
            ((int) value
                    * (int)
                        getActiveChar()
                            .getStat()
                            .calcStat(Stats.TRANSFER_DAMAGE_TO_PLAYER, 0, null, null))
                / 100;
        transferDmg = Math.min((int) caster.getCurrentHp() - 1, transferDmg);
        if ((transferDmg > 0) && (attacker instanceof L2Playable)) {
          int membersInRange = 0;
          for (L2PcInstance member : caster.getParty().getMembers()) {
            if (Util.checkIfInRange(1000, member, caster, false) && (member != caster)) {
              membersInRange++;
            }
          }

          if (caster.getCurrentCp() > 0) {
            if (caster.getCurrentCp() > transferDmg) {
              reduceCp(transferDmg);
            } else {
              transferDmg = (int) (transferDmg - caster.getCurrentCp());
              reduceCp((int) caster.getCurrentCp());
            }
          }

          caster.reduceCurrentHp(transferDmg / membersInRange, attacker, null);
          value -= transferDmg;
          fullValue = (int) value;
        }
      }

      if (!ignoreCP && (attacker instanceof L2Playable)) {
        if (getCurrentCp() >= value) {
          setCurrentCp(getCurrentCp() - value); // Set Cp to diff of Cp vs value
          value = 0; // No need to subtract anything from Hp
        } else {
          value -= getCurrentCp(); // Get diff from value vs Cp; will apply diff to Hp
          setCurrentCp(0, false); // Set Cp to 0
        }
      }

      if ((fullValue > 0) && !isDOT) {
        SystemMessage smsg;
        // Send a System Message to the L2PcInstance
        smsg = SystemMessage.getSystemMessage(SystemMessageId.C1_RECEIVED_DAMAGE_OF_S3_FROM_C2);
        smsg.addString(getActiveChar().getName());
        smsg.addCharName(attacker);
        smsg.addNumber(fullValue);
        getActiveChar().sendPacket(smsg);

        if (tDmg > 0) {
          smsg = SystemMessage.getSystemMessage(SystemMessageId.C1_RECEIVED_DAMAGE_OF_S3_FROM_C2);
          smsg.addString(getActiveChar().getSummon().getName());
          smsg.addCharName(attacker);
          smsg.addNumber(tDmg);
          getActiveChar().sendPacket(smsg);

          if (attackerPlayer != null) {
            smsg =
                SystemMessage.getSystemMessage(
                    SystemMessageId.GIVEN_S1_DAMAGE_TO_YOUR_TARGET_AND_S2_DAMAGE_TO_SERVITOR);
            smsg.addNumber(fullValue);
            smsg.addNumber(tDmg);
            attackerPlayer.sendPacket(smsg);
          }
        }
      }
    }

    if (value > 0) {
      value = getCurrentHp() - value;
      if (value <= 0) {
        if (getActiveChar().isInDuel()) {
          getActiveChar().disableAllSkills();
          stopHpMpRegeneration();
          if (attacker != null) {
            attacker.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
            attacker.sendPacket(ActionFailed.STATIC_PACKET);
          }
          // let the DuelManager know of his defeat
          DuelManager.getInstance().onPlayerDefeat(getActiveChar());
          value = 1;
        } else {
          value = 0;
        }
      }
      setCurrentHp(value);
    }

    if (getActiveChar().getCurrentHp() < 0.5) {
      getActiveChar().abortAttack();
      getActiveChar().abortCast();

      if (getActiveChar().isInOlympiadMode()) {
        stopHpMpRegeneration();
        getActiveChar().setIsDead(true);
        getActiveChar().setIsPendingRevive(true);
        if (getActiveChar().hasSummon()) {
          getActiveChar().getSummon().getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
        }
        return;
      }

      getActiveChar().doDie(attacker);
      if (!Config.DISABLE_TUTORIAL) {
        QuestState qs = getActiveChar().getQuestState("255_Tutorial");
        if (qs != null) {
          qs.getQuest().notifyEvent("CE30", null, getActiveChar());
        }
      }
    }
  }
Esempio n. 9
0
  @Override
  protected void runImpl() {
    if (_items == null) {
      return;
    }

    // Get the current player and return if null
    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null) {
      return;
    }

    if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy")) {
      activeChar.sendMessage("You are buying too fast.");
      return;
    }

    // If Alternate rule Karma punishment is set to true, forbid Wear to player with Karma
    if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (activeChar.getKarma() > 0)) {
      return;
    }

    // Check current target of the player and the INTERACTION_DISTANCE
    L2Object target = activeChar.getTarget();
    if (!activeChar.isGM()
        && ((target == null // No target (i.e. GM Shop)
            )
            || !((target instanceof L2MerchantInstance)) // Target not a merchant
            || !activeChar.isInsideRadius(
                target, L2Npc.INTERACTION_DISTANCE, false, false) // Distance is too far
        )) {
      return;
    }

    if ((_count < 1) || (_listId >= 4000000)) {
      sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    // Get the current merchant targeted by the player
    final L2MerchantInstance merchant =
        (target instanceof L2MerchantInstance) ? (L2MerchantInstance) target : null;
    if (merchant == null) {
      _log.warning(getClass().getName() + " Null merchant!");
      return;
    }

    final L2BuyList buyList = BuyListData.getInstance().getBuyList(_listId);
    if (buyList == null) {
      Util.handleIllegalPlayerAction(
          activeChar,
          "Warning!! Character "
              + activeChar.getName()
              + " of account "
              + activeChar.getAccountName()
              + " sent a false BuyList list_id "
              + _listId,
          Config.DEFAULT_PUNISH);
      return;
    }

    long totalPrice = 0;
    Map<Integer, Integer> itemList = new HashMap<>();

    for (int i = 0; i < _count; i++) {
      int itemId = _items[i];

      final Product product = buyList.getProductByItemId(itemId);
      if (product == null) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Warning!! Character "
                + activeChar.getName()
                + " of account "
                + activeChar.getAccountName()
                + " sent a false BuyList list_id "
                + _listId
                + " and item_id "
                + itemId,
            Config.DEFAULT_PUNISH);
        return;
      }

      L2Item template = product.getItem();
      if (template == null) {
        continue;
      }

      int slot = Inventory.getPaperdollIndex(template.getBodyPart());
      if (slot < 0) {
        continue;
      }

      if (template instanceof L2Weapon) {
        if (activeChar.getRace().ordinal() == 5) {
          if (template.getItemType() == WeaponType.NONE) {
            continue;
          } else if ((template.getItemType() == WeaponType.RAPIER)
              || (template.getItemType() == WeaponType.CROSSBOW)
              || (template.getItemType() == WeaponType.ANCIENTSWORD)) {
            continue;
          }
        }
      } else if (template instanceof L2Armor) {
        if (activeChar.getRace().ordinal() == 5) {
          if ((template.getItemType() == ArmorType.HEAVY)
              || (template.getItemType() == ArmorType.MAGIC)) {
            continue;
          }
        }
      }

      if (itemList.containsKey(slot)) {
        activeChar.sendPacket(SystemMessageId.YOU_CAN_NOT_TRY_THOSE_ITEMS_ON_AT_THE_SAME_TIME);
        return;
      }

      itemList.put(slot, itemId);
      totalPrice += Config.WEAR_PRICE;
      if (totalPrice > Inventory.MAX_ADENA) {
        Util.handleIllegalPlayerAction(
            activeChar,
            "Warning!! Character "
                + activeChar.getName()
                + " of account "
                + activeChar.getAccountName()
                + " tried to purchase over "
                + Inventory.MAX_ADENA
                + " adena worth of goods.",
            Config.DEFAULT_PUNISH);
        return;
      }
    }

    // Charge buyer and add tax to castle treasury if not owned by npc clan because a Try On is not
    // Free
    if ((totalPrice < 0)
        || !activeChar.reduceAdena("Wear", totalPrice, activeChar.getLastFolkNPC(), true)) {
      activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
      return;
    }

    if (!itemList.isEmpty()) {
      activeChar.sendPacket(new ShopPreviewInfo(itemList));
      // Schedule task
      ThreadPoolManager.getInstance()
          .scheduleGeneral(new RemoveWearItemsTask(activeChar), Config.WEAR_DELAY * 1000);
    }
  }