示例#1
0
  @Override
  protected void runImpl() {
    L2PcInstance player = getClient().getActiveChar();
    if (player == null) {
      return;
    }
    if (player.getClan() == null) {
      player.sendPacket(SystemMessageId.YOU_ARE_NOT_A_CLAN_MEMBER);
      return;
    }
    if (!player.isClanLeader()) {
      player.sendPacket(SystemMessageId.ONLY_CLAN_LEADER_WITHDRAW_ALLY);
      return;
    }
    L2Clan clan = player.getClan();
    if (clan.getAllyId() == 0) {
      player.sendPacket(SystemMessageId.NO_CURRENT_ALLIANCES);
      return;
    }
    if (clan.getClanId() == clan.getAllyId()) {
      player.sendPacket(SystemMessageId.ALLIANCE_LEADER_CANT_WITHDRAW);
      return;
    }

    long currentTime = System.currentTimeMillis();
    clan.setAllyId(0);
    clan.setAllyName(null);
    clan.changeAllyCrest(0, true);
    clan.setAllyPenaltyExpiryTime(
        currentTime + Config.ALT_ALLY_JOIN_DAYS_WHEN_LEAVED * 86400000L,
        L2Clan.PENALTY_TYPE_CLAN_LEAVED); // 24*60*60*1000 = 86400000
    clan.updateClanInDB();

    player.sendPacket(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_ALLIANCE);
  }
  @Override
  public String onTalk(L2Npc npc, QuestState st) {
    L2PcInstance player = st.getPlayer();

    L2Clan clan = player.getClan();

    switch (st.getState()) {
      case CREATED:
        return clan == null || !player.isClanLeader() || clan.getLevel() < 6
            ? "31331-0a.htm"
            : "31331-0b.htm";
      case STARTED:
        if (clan == null || !player.isClanLeader()) {
          st.exitQuest(QuestType.REPEATABLE);
          return "31331-6.html";
        }

        int raid = st.getInt("raid");

        if (REWARD_POINTS.containsKey(raid)) {
          if (st.hasQuestItems(REWARD_POINTS.get(raid)[1])) {
            st.playSound(QuestSound.ITEMSOUND_QUEST_FANFARE_1);
            st.takeItems(REWARD_POINTS.get(raid)[1], -1);
            clan.addReputationScore(REWARD_POINTS.get(raid)[2], true);
            player.sendPacket(
                SystemMessage.getSystemMessage(
                        SystemMessageId.CLAN_QUEST_COMPLETED_AND_S1_POINTS_GAINED)
                    .addNumber(REWARD_POINTS.get(raid)[2]));
            clan.broadcastToOnlineMembers(new PledgeShowInfoUpdate(clan));
            return "31331-" + raid + "b.html";
          } else {
            return "31331-" + raid + "a.html";
          }
        } else {
          return "31331-0.html";
        }
    }
    return null;
  }