/**
   * this displays PledgeSkillList to the player.
   *
   * @param player
   */
  public static final void showPledgeSkillList(L2PcInstance player) {
    if (player.getClan() == null || !player.isClanLeader()) {
      NpcHtmlMessage html = new NpcHtmlMessage(1);
      html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/NotClanLeader.htm");
      player.sendPacket(html);
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    L2PledgeSkillLearn[] skills = SkillTreeTable.getInstance().getAvailablePledgeSkills(player);
    AcquireSkillList asl = new AcquireSkillList(AcquireSkillList.SkillType.Clan);
    int counts = 0;

    for (L2PledgeSkillLearn s : skills) {
      int cost = s.getRepCost();
      int itemCount = s.getItemCount();
      counts++;

      asl.addSkill(s.getId(), s.getLevel(), s.getLevel(), cost, itemCount);
    }

    if (counts == 0) {
      if (player.getClan().getLevel() < 8) {
        SystemMessage sm = new SystemMessage(SystemMessageId.DO_NOT_HAVE_FURTHER_SKILLS_TO_LEARN);
        if (player.getClan().getLevel() < 5) sm.addNumber(5);
        else sm.addNumber(player.getClan().getLevel() + 1);
        player.sendPacket(sm);
      } else {
        NpcHtmlMessage html = new NpcHtmlMessage(1);
        html.setFile(player.getHtmlPrefix(), "data/html/villagemaster/NoMoreSkills.htm");
        player.sendPacket(html);
      }
    } else player.sendPacket(asl);

    player.sendPacket(ActionFailed.STATIC_PACKET);
  }
  @Override
  public final void run() {
    final int playerObjId = super.readD();
    final int type = super.readD();

    L2PcInstance player = L2World.getInstance().getPlayer(playerObjId);
    if (player == null) return;

    switch (type) {
      case -1: // mail arrived
        player.sendPacket(ExMailArrived.STATIC_PACKET);
        break;
      case 0: // text message
        player.sendMessage(super.readS());
        break;
      case 236:
        player.sendPacket(
            SystemMessage.getSystemMessage(SystemMessageId.ONLY_THE_CLAN_LEADER_IS_ENABLED));
        break;
      case 1050:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_CB_IN_MY_CLAN));
        break;
      case 1070:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_READ_PERMISSION));
        break;
      case 1071:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_WRITE_PERMISSION));
        break;
      case 1205:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MAILBOX_FULL));
        break;
      case 1206:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MEMOBOX_FULL));
        break;
      case 1227:
        try {
          SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.S1_UNREAD_MESSAGES);
          final int number = super.readD();
          sm.addNumber(number);
          player.sendPacket(sm);
        } catch (Exception e) {
          _log.info("Incorrect packet from CBserver!");
        }
        break;
      case 1228:
        try {
          SystemMessage sm =
              SystemMessage.getSystemMessage(SystemMessageId.C1_BLOCKED_YOU_CANNOT_MAIL);
          final String name = super.readS();
          sm.addString(name);
          player.sendPacket(sm);
        } catch (Exception e) {
          _log.info("Incorrect packet from CBserver!");
        }
        break;
      case 1229:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NO_MORE_MESSAGES_TODAY));
        break;
      case 1230:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_FIVE_RECIPIENTS));
        break;
      case 1231:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SENT_MAIL));
        break;
      case 1232:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MESSAGE_NOT_SENT));
        break;
      case 1233:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NEW_MAIL));
        break;
      case 1234:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MAIL_STORED_IN_MAILBOX));
        break;
      case 1238:
        player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.TEMP_MAILBOX_FULL));
        break;
      case 1370:
        try {
          SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CANNOT_MAIL_GM_C1);
          final String name = super.readS();
          sm.addString(name);
          player.sendPacket(sm);
        } catch (Exception e) {
          _log.info("Incorrect packet from CBserver!");
        }
        break;
      default:
        _log.info("error: Unknown message request from CB server: " + type);
    }
  }
예제 #3
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());
        }
      }
    }
  }
  @Override
  public void onBypassFeedback(L2PcInstance player, String command) {
    if (command.startsWith("Chat")) {
      int val = 0;
      try {
        val = Integer.parseInt(command.substring(5));
      } catch (IndexOutOfBoundsException ioobe) {
      } catch (NumberFormatException nfe) {
      }
      showChatWindow(player, val);
      return;
    } else if (command.startsWith("ExchangeKE")) {
      String filename = null;
      int item;
      int i0 = Rnd.get(100);
      if (i0 < 5) {
        int i1 = Rnd.get(100);
        if (i1 < 5) item = 9931; // Red Talisman of Meditation
        else if (i1 <= 50) item = 9932; // Blue Talisman - Divine Protection
        else if (i1 <= 75) item = 10416; // Blue Talisman - Explosion
        else item = 10417; // Blue Talisman - Magic Explosion
      } else if (i0 <= 15) {
        switch (Rnd.get(5)) {
          case 1: // Red Talisman of Minimum Clarity
            item = 9917;
            break;
          case 2: // Red Talisman of Maximum Clarity
            item = 9918;
            break;
          case 3: // Red Talisman of Mental Regeneration
            item = 9928;
            break;
          case 4: // Blue Talisman of Protection
            item = 9929;
            break;
          default: // Blue Talisman of Invisibility
            item = 9920;
        }
      } else if (i0 <= 30) {
        switch (Rnd.get(8)) {
          case 1: // Blue Talisman of Defense
            item = 9916;
            break;
          case 2: // Blue Talisman of Defense
            item = 9916;
            break;
          case 3: // Blue Talisman of Healing
            item = 9924;
            break;
          case 4: // Red Talisman of Recovery
            item = 9925;
            break;
          case 5: // Blue Talisman of Defense
            item = 9926;
            break;
          case 6: // Blue Talisman of Magic Defense
            item = 9927;
            break;
          case 7: // Red Talisman - Life Force
            item = 10518;
            break;
          default: // Blue Talisman - Greater Healing
            item = 10424;
        }
      } else {
        switch (Rnd.get(46)) {
          case 0: // Blue Talisman of Power
            item = 9914;
            break;
          case 1: // Blue Talisman of Wild Magic
            item = 9915;
            break;
          case 2: // Blue Talisman of Invisibility
            item = 9920;
            break;
          case 3: // Blue Talisman of Invisibility
            item = 9920;
            break;
          case 4: // Blue Talisman - Shield Protection
            item = 9921;
            break;
          case 5: // Black Talisman - Mending
            item = 9922;
            break;
          case 6: // Yellow Talisman of Power
            item = 9933;
            break;
          case 7: // Yellow Talisman of Violent Haste
            item = 9934;
            break;
          case 8: // Yellow Talisman of Arcane Defense
            item = 9935;
            break;
          case 9: // Yellow Talisman of Arcane Power
            item = 9936;
            break;
          case 10: // Yellow Talisman of Arcane Haste
            item = 9937;
            break;
          case 11: // Yellow Talisman of Accuracy
            item = 9938;
            break;
          case 12: // Yellow Talisman of Defense
            item = 9939;
            break;
          case 13: // Yellow Talisman of Alacrity
            item = 9940;
            break;
          case 14: // Yellow Talisman of Speed
            item = 9941;
            break;
          case 15: // Yellow Talisman of Critical Reduction
            item = 9942;
            break;
          case 16: // Yellow Talisman of Critical Damage
            item = 9943;
            break;
          case 17: // Yellow Talisman of Critical Dodging
            item = 9944;
            break;
          case 18: // Yellow Talisman of Evasion
            item = 9945;
            break;
          case 19: // Yellow Talisman of Healing
            item = 9946;
            break;
          case 20: // Yellow Talisman of CP Regeneration
            item = 9947;
            break;
          case 21: // Yellow Talisman of Physical Regeneration
            item = 9948;
            break;
          case 22: // Yellow Talisman of Mental Regeneration
            item = 9949;
            break;
          case 23: // Grey Talisman of Weight Training
            item = 9950;
            break;
          case 24: // White Talisman of Protection
            item = 9965;
            break;
          case 25: // Orange Talisman - Hot Springs CP Potion
            item = 9952;
            break;
          case 26: // Orange Talisman - Elixir of Life
            item = 9953;
            break;
          case 27: // Orange Talisman - Elixir of Mental Strength
            item = 9954;
            break;
          case 28: // Black Talisman - Vocalization
            item = 9955;
            break;
          case 29: // Black Talisman - Arcane Freedom
            item = 9956;
            break;
          case 30: // Black Talisman - Physical Freedom
            item = 9957;
            break;
          case 31: // Black Talisman - Rescue
            item = 9958;
            break;
          case 32: // Black Talisman - Free Speech
            item = 9959;
            break;
          case 33: // White Talisman of Bravery
            item = 9960;
            break;
          case 34: // White Talisman of Motion
            item = 9961;
            break;
          case 35: // White Talisman of Grounding
            item = 9962;
            break;
          case 36: // White Talisman of Attention
            item = 9963;
            break;
          case 37: // White Talisman of Bandages
            item = 9964;
            break;
          case 38: // White Talisman - Storm
            item = 10418;
            break;
          case 39: // White Talisman - Water
            item = 10420;
            break;
          case 40: // White Talisman -  Earth
            item = 10519;
            break;
          case 41: // White Talisman - Light
            item = 10422;
            break;
          case 42: // Blue Talisman - Self-Destruction
            item = 10423;
            break;
          case 43: // White Talisman - Darkness
            item = 10419;
            break;
          default: // White Talisman - Fire
            item = 10421;
        }
      }

      if (player.destroyItemByItemId("ExchangeKE", 9912, 10, this, false)) {
        SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.S2_S1_DISAPPEARED);
        msg.addItemName(9912);
        msg.addNumber(10);
        player.sendPacket(msg);

        player.addItem("ExchangeKE", item, 1, player, true);

        filename = "data/html/castlemagician/magician-KE-Exchange.htm";
      } else filename = "data/html/castlemagician/magician-no-KE.htm";

      showChatWindow(player, filename);
      return;
    } else if (command.equals("gotoleader")) {
      if (player.getClan() != null) {
        L2PcInstance clanLeader = player.getClan().getLeader().getPlayerInstance();
        if (clanLeader == null) return;

        if (clanLeader.getFirstEffect(L2EffectType.CLAN_GATE) != null) {
          if (!validateGateCondition(clanLeader, player)) return;

          player.teleToLocation(clanLeader.getX(), clanLeader.getY(), clanLeader.getZ(), false);
          return;
        }
        String filename = "data/html/castlemagician/magician-nogate.htm";
        showChatWindow(player, filename);
      }
      return;
    } else if (command.equals("subskills")) {
      if (player.getClan() != null) {
        if (player.isClanLeader()) {
          AcquireSkillList skilllist = new AcquireSkillList(SkillType.SubClass);
          FastList<L2SkillLearn> list =
              SkillTreesData.getInstance().getAvailableSubPledgeSkills(player.getClan());
          if (list.isEmpty()) {
            player.sendPacket(SystemMessageId.NO_MORE_SKILLS_TO_LEARN);
            return;
          }
          for (L2SkillLearn skillLearn : list) {
            skilllist.addSkill(
                skillLearn.getSkillId(),
                skillLearn.getSkillLevel(),
                skillLearn.getSkillLevel(),
                skillLearn.getLevelUpSp(),
                0);
          }
          player.sendPacket(skilllist);
        } else {
          String filename = "data/html/castlemagician/magician-nosquad.htm";
          showChatWindow(player, filename);
        }
      }
    } else super.onBypassFeedback(player, command);
  }