Example #1
0
 private static final String checkConditions(L2Npc npc, L2PcInstance player) {
   final L2Party party = player.getParty();
   // player must be in party
   if (party == null) {
     player.sendPacket(SystemMessageId.YOU_ARE_NOT_CURRENTLY_IN_A_PARTY_SO_YOU_CANNOT_ENTER);
     return "32330-05.html";
   }
   // ...and be party leader
   if (party.getLeader() != player) {
     player.sendPacket(SystemMessageId.ONLY_A_PARTY_LEADER_CAN_MAKE_THE_REQUEST_TO_ENTER);
     return "32330-08.html";
   }
   boolean _kamael = false;
   // for each party member
   for (L2PcInstance partyMember : party.getMembers()) {
     // player level must be in range
     if (partyMember.getLevel() > INSTANCE_LVL_MAX) {
       final SystemMessage sm =
           SystemMessage.getSystemMessage(
               SystemMessageId.C1_S_LEVEL_DOES_NOT_CORRESPOND_TO_THE_REQUIREMENTS_FOR_ENTRY);
       sm.addPcName(partyMember);
       player.sendPacket(sm);
       return "32330-06.html";
     }
     if (partyMember.getLevel() < INSTANCE_LVL_MIN) {
       final SystemMessage sm =
           SystemMessage.getSystemMessage(
               SystemMessageId.C1_S_LEVEL_DOES_NOT_CORRESPOND_TO_THE_REQUIREMENTS_FOR_ENTRY);
       sm.addPcName(partyMember);
       player.sendPacket(sm);
       return "32330-07.html";
     }
     if (partyMember.getClassId().level() != 0) {
       final SystemMessage sm =
           SystemMessage.getSystemMessage(
               SystemMessageId.C1_S_LEVEL_DOES_NOT_CORRESPOND_TO_THE_REQUIREMENTS_FOR_ENTRY);
       sm.addPcName(partyMember);
       player.sendPacket(sm);
       return "32330-06.html";
     }
     // player must be near party leader
     if (!partyMember.isInsideRadius(player, 500, true, true)) {
       final SystemMessage sm =
           SystemMessage.getSystemMessage(
               SystemMessageId
                   .C1_IS_IN_A_LOCATION_WHICH_CANNOT_BE_ENTERED_THEREFORE_IT_CANNOT_BE_PROCESSED);
       sm.addPcName(partyMember);
       player.sendPacket(sm);
       return "32330-08.html";
     }
     if (partyMember.getRace().ordinal() == 5) {
       _kamael = true;
     }
   }
   if (!_kamael) {
     return "32330-08.html";
   }
   return "ok";
 }
Example #2
0
 private static int highestLevelPcInstanceOf(Map<Integer, L2PcInstance> players) {
   int maxLevel = Integer.MIN_VALUE, maxLevelId = -1;
   for (L2PcInstance player : players.values()) {
     if (player.getLevel() >= maxLevel) {
       maxLevel = player.getLevel();
       maxLevelId = player.getObjectId();
     }
   }
   return maxLevelId;
 }
Example #3
0
 @Override
 public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
   String htmltext = null;
   switch (event) {
     case "32972-1.html":
       {
         htmltext = event;
         break;
       }
     case "teleport_museum":
       {
         if (player.getLevel() >= MIN_LEVEL) {
           player.teleToLocation(MUSEUM);
           break;
         }
         htmltext = "32972-noteleport.html";
         break;
       }
     case "TEXT_SPAM":
       {
         if (npc != null) {
           broadcastNpcSay(
               npc,
               ChatType.NPC_GENERAL,
               NpcStringId.IS_IT_BETTER_TO_END_DESTINY_OR_START_DESTINY);
         }
         break;
       }
   }
   return htmltext;
 }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = getQuestState(player, true);
    if (st == null) {
      return htmltext;
    }

    switch (npc.getId()) {
      case ANTON:
        switch (st.getState()) {
          case State.CREATED:
            htmltext = (player.getLevel() < 75) ? "31338-0a.htm" : "31338-0b.htm";
            break;
          case State.STARTED:
            htmltext = "31338-1a.html";
            break;
          case State.COMPLETED:
            htmltext = getAlreadyCompletedMsg(player);
            break;
        }
        break;
      case MARQUEZ:
        if (st.isCond(1)) {
          htmltext = "32113-1.html";
        }
        break;
    }
    return htmltext;
  }
Example #5
0
 /**
  * @param player
  * @param target
  */
 public MyTargetSelected(L2PcInstance player, L2Character target) {
   _objectId =
       (target instanceof L2ControllableAirShipInstance)
           ? ((L2ControllableAirShipInstance) target).getHelmObjectId()
           : target.getObjectId();
   _color = target.isAutoAttackable(player) ? (player.getLevel() - target.getLevel()) : 0;
 }
  @Override
  public boolean useBypass(String command, L2PcInstance player, L2Character bypassOrigin) {
    final QuestState qs = getQuestState(player, false);
    if ((qs != null)
        || (player.getLevel() < MIN_LEVEL)
        || (player.getLevel() > MAX_LEVEL)
        || (player.getRace() == Race.ERTHEIA)) {
      return false;
    }

    if (player.isInParty()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in party.", 5000));
    } else if (player.isInCombat()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in combat.", 5000));
    } else if (player.isInDuel()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in a duel.", 5000));
    } else if (player.isInOlympiadMode()) {
      player.sendPacket(
          new ExShowScreenMessage("You cannot teleport when you are in Olympiad.", 5000));
    } else if (player.isInVehicle()) {
      player.sendPacket(
          new ExShowScreenMessage(
              "You cannot teleport when you are in any vehicle or mount.", 5000));
    } else {
      player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
      player.teleToLocation(TELE_LOCATION);
    }
    return true;
  }
 @Override
 public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
   final QuestState st = getQuestState(player, false);
   if ((st != null) && (player.getLevel() >= MIN_LEVEL) && event.equals("32612-04.html")) {
     st.startQuest();
     return event;
   }
   return null;
 }
 @RegisterEvent(EventType.ON_PLAYER_LEVEL_CHANGED)
 @RegisterType(ListenerRegisterType.GLOBAL)
 public void OnPlayerLevelChanged(OnPlayerLevelChanged event) {
   final L2PcInstance player = event.getActiveChar();
   if ((player.getLevel() >= MIN_LEVEL)
       && (player.getLevel() <= MAX_LEVEL)
       && (player.getRace() != Race.ERTHEIA)) {
     final QuestState qs = getQuestState(player, false);
     if (qs == null) {
       final NpcHtmlMessage html = new NpcHtmlMessage(0, 0);
       html.setHtml(
           HtmCache.getInstance()
               .getHtm(
                   player.getHtmlPrefix(),
                   "scripts/quests/Q10404_KekropusLetter_AHiddenMeaning/Announce.html"));
       player.sendPacket(html);
     }
   }
 }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = getQuestState(player, true);
   final QuestState st2 = player.getQuestState(Q00115_TheOtherSideOfTruth.class.getSimpleName());
   String htmltext = getNoQuestMsg(player);
   switch (npc.getId()) {
     case RAFFORTY:
       {
         if (st.isCreated()) {
           if (player.getLevel() < MIN_LVL) {
             htmltext = "32020-01.htm";
           } else {
             htmltext = ((st2 != null) && (st2.isCompleted())) ? "32020-02.htm" : "32020-03.htm";
           }
         } else if (st.isStarted()) {
           final long hasQuestItems =
               getQuestItemsCount(player, SILVER_ICE_CRYSTAL, BLACK_ICE_CRYSTAL);
           if ((st2 != null) && st2.isCompleted()) {
             htmltext = (hasQuestItems > 0) ? "32020-13.html" : "32020-11.html";
             if (st.isCond(1)) {
               st.setCond(2, true);
             }
           } else {
             htmltext = (hasQuestItems > 0) ? "32020-12.html" : "32020-10.html";
           }
         }
         break;
       }
     case ICE_SHELF:
       {
         // TODO: In High Five this quest have an updated reward system.
         if (st.isStarted()) {
           if (hasQuestItems(player, SILVER_ICE_CRYSTAL)) {
             final int val = st.getInt("ex") % 10;
             if (val == 0) {
               htmltext = "32023-03.html";
               st.set("ex", 0);
             } else {
               htmltext = "32023-09.html";
             }
           } else {
             htmltext = "32023-02.html";
           }
         } else {
           htmltext = "32023-01.html";
         }
         break;
       }
   }
   return htmltext;
 }
 @Override
 public String onAdvEvent(String event, L2Npc npc, L2PcInstance player) {
   final QuestState st = getQuestState(player, false);
   if (st == null) {
     return getNoQuestMsg(player);
   }
   switch (event) {
     case "30070-02.htm":
       st.startQuest();
       st.giveItems(TEMPLE_MANIFESTO, 1);
       break;
     case "30070-05.html":
       st.giveAdena(84593, true);
       if ((player.getLevel() < 42)) {
         st.addExpAndSp(187062, 11307);
       }
       st.exitQuest(false, true);
       break;
     case "30070-03.html":
       st.setCond(2, true);
       break;
     case "30118-06.html":
       st.setCond(3, true);
       break;
     case "30118-09.html":
       st.setCond(6, true);
       st.giveItems(PUPINAS_RECOMMENDATION, 1);
       break;
     case "30474-02.html":
       st.setCond(4, true);
       break;
     case "30666-02.html":
       if (st.hasQuestItems(PUPINAS_RECOMMENDATION)) {
         st.set("talk", "1");
         st.takeItems(PUPINAS_RECOMMENDATION, -1);
       }
       break;
     case "30666-03.html":
       if (st.hasQuestItems(TEMPLE_MANIFESTO)) {
         st.set("talk", "2");
         st.takeItems(TEMPLE_MANIFESTO, -1);
       }
       break;
     case "30666-08.html":
       st.setCond(7, true);
       st.unset("talk");
       break;
   }
   return event;
 }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    final QuestState st = getQuestState(player, true);
    String htmltext = getNoQuestMsg(player);
    if (st == null) {
      return htmltext;
    }

    switch (st.getState()) {
      case State.COMPLETED:
        {
          if (npc.getId() == NAMELESS_SPIRIT) {
            htmltext = "31453-06.html";
          }
          break;
        }
      case State.CREATED:
        {
          htmltext =
              ((player.getLevel() >= MIN_LEVEL) && st.hasQuestItems(ANTIQUE_BROOCH))
                  ? "31453-01.htm"
                  : "31453-05.html";
          break;
        }
      case State.STARTED:
        {
          if (npc.getId() == NAMELESS_SPIRIT) {
            if (st.isCond(1)) {
              if (st.hasQuestItems(ANTIQUE_BROOCH)) {
                htmltext = "31453-07.html";
              } else {
                htmltext = "31453-08.html";
                st.exitQuest(true);
              }
            } else if (st.isCond(2)) {
              htmltext = "31453-09.html";
            }
          } else if (npc.getId() == DEVORIN) {
            if (st.isCond(1)) {
              htmltext = "32009-01.html";
            } else if (st.isCond(2)) {
              htmltext = "32009-05.html";
            }
          }
          break;
        }
    }
    return htmltext;
  }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   final QuestState st = getQuestState(player, true);
   String htmltext = getNoQuestMsg(player);
   switch (st.getState()) {
     case State.CREATED:
       {
         htmltext = (player.getLevel() < MIN_LEVEL) ? "32612-02.html" : "32612-01.htm";
         break;
       }
     case State.STARTED:
       {
         switch (st.getCond()) {
           case 1:
             {
               htmltext = "32612-05.html";
               break;
             }
           case 2:
             {
               if (getQuestItemsCount(player, ZAKENS_SOUL_FRAGMENT) >= FRAGMENT_COUNT) {
                 giveItems(player, SOUL_CLOAK_OF_ZAKEN, 1);
                 playSound(player, QuestSound.ITEMSOUND_QUEST_ITEMGET);
                 st.exitQuest(false, true);
                 htmltext = "32612-06.html";
               }
               break;
             }
         }
         break;
       }
     case State.COMPLETED:
       {
         htmltext = "32612-03.html";
         break;
       }
   }
   return htmltext;
 }
Example #13
0
  private final synchronized String enterInstance(L2Npc npc, L2PcInstance player) {
    InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
    if (world != null) {
      if (!(world instanceof NornilsWorld) || (world.getTemplateId() != TEMPLATE_ID)) {
        player.sendPacket(
            SystemMessageId
                .YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON);
        return null;
      }
      // check for level difference again on reenter
      if ((player.getLevel() > INSTANCE_LVL_MAX) || (player.getLevel() < INSTANCE_LVL_MIN)) {
        final SystemMessage sm =
            SystemMessage.getSystemMessage(
                SystemMessageId.C1_S_LEVEL_DOES_NOT_CORRESPOND_TO_THE_REQUIREMENTS_FOR_ENTRY);
        sm.addPcName(player);
        player.sendPacket(sm);
        return null;
      }
      // check what instance still exist
      final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
      if (inst != null) {
        teleportPlayer(player, SPAWN_PPL, world.getInstanceId());
      }
      return null;
    }
    // Creating new instance
    final String result = checkConditions(npc, player);
    if (!(result.equalsIgnoreCase("ok"))) {
      return result;
    }

    final int instanceId = InstanceManager.getInstance().createDynamicInstance("NornilsGarden.xml");
    final Instance inst = InstanceManager.getInstance().getInstance(instanceId);

    inst.setName(InstanceManager.getInstance().getInstanceIdName(TEMPLATE_ID));
    inst.setExitLoc(new Location(player));
    inst.setAllowSummon(false);
    inst.setDuration(DURATION_TIME * 60000);
    inst.setEmptyDestroyTime(EMPTY_DESTROY_TIME * 60000);
    world = new NornilsWorld();
    world.setInstanceId(instanceId);
    world.setTemplateId(TEMPLATE_ID);
    InstanceManager.getInstance().addWorld(world);
    _log.info(
        "Nornils Garden: started, Instance: "
            + instanceId
            + " created by player: "
            + player.getName());

    prepareInstance((NornilsWorld) world);

    // and finally teleport party into instance
    final L2Party party = player.getParty();
    if (party != null) {
      for (L2PcInstance partyMember : party.getMembers()) {
        world.addAllowed(partyMember.getObjectId());
        teleportPlayer(partyMember, SPAWN_PPL, instanceId);
      }
    }
    return null;
  }
 @Override
 public String onTalk(L2Npc npc, L2PcInstance player) {
   String htmltext = getNoQuestMsg(player);
   final QuestState st = getQuestState(player, true);
   if (st == null) {
     return htmltext;
   }
   switch (npc.getId()) {
     case SYLVAIN:
       switch (st.getCond()) {
         case 1:
           htmltext = "30070-02.htm";
           break;
         case 2:
         case 3:
         case 4:
         case 5:
         case 6:
           htmltext = "30070-03.html";
           break;
         case 7:
           htmltext = "30070-04.html";
           break;
         default:
           if (st.isCompleted()) {
             return getAlreadyCompletedMsg(player);
           }
           final QuestState qs =
               player.getQuestState(Q00137_TempleChampionPart1.class.getSimpleName());
           htmltext =
               (player.getLevel() >= 36)
                   ? ((qs != null) && qs.isCompleted()) ? "30070-01.htm" : "30070-00a.htm"
                   : "30070-00.htm";
           break;
       }
       break;
     case PUPINA:
       switch (st.getCond()) {
         case 2:
           htmltext = "30118-01.html";
           break;
         case 3:
         case 4:
           htmltext = "30118-07.html";
           break;
         case 5:
           htmltext = "30118-08.html";
           if (st.hasQuestItems(ANGUS_RECOMMENDATION)) {
             st.takeItems(ANGUS_RECOMMENDATION, -1);
           }
           break;
         case 6:
           htmltext = "30118-10.html";
           break;
       }
       break;
     case ANGUS:
       switch (st.getCond()) {
         case 3:
           htmltext = "30474-01.html";
           break;
         case 4:
           if (st.getQuestItemsCount(RELICS_OF_THE_DARK_ELF_TRAINEE) >= 10) {
             st.takeItems(RELICS_OF_THE_DARK_ELF_TRAINEE, -1);
             st.giveItems(ANGUS_RECOMMENDATION, 1);
             st.setCond(5, true);
             htmltext = "30474-04.html";
           } else {
             htmltext = "30474-03.html";
           }
           break;
         case 5:
           htmltext = "30474-05.html";
           break;
       }
       break;
     case SLA:
       switch (st.getCond()) {
         case 6:
           switch (st.getInt("talk")) {
             case 1:
               htmltext = "30666-02.html";
               break;
             case 2:
               htmltext = "30666-03.html";
               break;
             default:
               htmltext = "30666-01.html";
               break;
           }
           break;
         case 7:
           htmltext = "30666-09.html";
           break;
       }
       break;
   }
   return htmltext;
 }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance talker) {
    final QuestState qs = getQuestState(talker, true);
    String htmltext = getNoQuestMsg(talker);

    switch (npc.getId()) {
      case CRONOS:
        {
          switch (qs.getState()) {
            case State.CREATED:
              {
                final long fluteCount =
                    getQuestItemsCount(
                        talker, DRAGONFLUTE_OF_WIND, DRAGONFLUTE_OF_STAR, DRAGONFLUTE_OF_TWILIGHT);
                if (fluteCount == 0) {
                  break; // this quest does not show up if no flute in inventory
                }

                if (talker.getLevel() < MIN_PLAYER_LVL) {
                  htmltext = "30610-01.htm";
                } else if (fluteCount > 1) {
                  htmltext = "30610-02.htm";
                } else if (getFlute(talker).getEnchantLevel() < MIN_HACHLING_LVL) {
                  htmltext = "30610-03.html";
                } else {
                  htmltext = "30610-04.htm";
                }
                break;
              }
            case State.STARTED:
              {
                htmltext = "30610-07.html";
                break;
              }
            case State.COMPLETED:
              {
                htmltext = getAlreadyCompletedMsg(talker);
                break;
              }
          }
          break;
        }
      case MIMYU:
        {
          switch (qs.getMemoState()) {
            case 100:
              {
                qs.setMemoState(200);
                htmltext = "30747-01.html";
                break;
              }
            case 200:
              {
                final L2Summon summon = talker.getPet();

                if (summon == null) {
                  htmltext = "30747-02.html";
                } else if (summon.getControlObjectId() != qs.getInt("fluteObjectId")) {
                  htmltext = "30747-03.html";
                } else {
                  htmltext = "30747-04.html";
                }
                break;
              }
            case 0:
              {
                htmltext = "30747-07.html";
                break;
              }
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
              {
                if (hasQuestItems(talker, FAIRY_LEAF)) {
                  htmltext = "30747-11.html";
                }
                break;
              }
            case 15:
              {
                if (!hasQuestItems(talker, FAIRY_LEAF)) {
                  final L2Summon summon = talker.getPet();

                  if (summon == null) {
                    htmltext = "30747-12.html";
                  } else if (summon.getControlObjectId() == qs.getInt("fluteObjectId")) {
                    qs.setMemoState(16);
                    htmltext = "30747-13.html";
                  } else {
                    htmltext = "30747-14.html";
                  }
                }
                break;
              }
            case 16:
              {
                if (!hasQuestItems(talker, FAIRY_LEAF)) {
                  if (talker.hasSummon()) {
                    htmltext = "30747-15.html";
                  } else {
                    final long fluteCount =
                        getQuestItemsCount(
                            talker,
                            DRAGONFLUTE_OF_WIND,
                            DRAGONFLUTE_OF_STAR,
                            DRAGONFLUTE_OF_TWILIGHT);

                    if (fluteCount > 1) {
                      htmltext = "30747-17.html";
                    } else if (fluteCount == 1) {
                      final L2ItemInstance flute = getFlute(talker);

                      if (flute.getObjectId() == qs.getInt("fluteObjectId")) {
                        // TODO what if the hatchling has items in his inventory?
                        // Should they be transfered to the strider or given to the player?
                        switch (flute.getId()) {
                          case DRAGONFLUTE_OF_WIND:
                            takeItems(talker, DRAGONFLUTE_OF_WIND, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_WIND, 1);
                            break;
                          case DRAGONFLUTE_OF_STAR:
                            takeItems(talker, DRAGONFLUTE_OF_STAR, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_STAR, 1);
                            break;
                          case DRAGONFLUTE_OF_TWILIGHT:
                            takeItems(talker, DRAGONFLUTE_OF_TWILIGHT, -1);
                            giveItems(talker, DRAGON_BUGLE_OF_TWILIGHT, 1);
                            break;
                        }

                        qs.exitQuest(true, true);
                        htmltext = "30747-16.html";
                      } else {
                        npc.setTarget(talker);
                        npc.doCast(CURSE_OF_MIMYU.getSkill());
                        htmltext = "30747-18.html";
                      }
                    }
                  }
                }
                break;
              }
          }
          break;
        }
    }
    return htmltext;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = getQuestState(player, true);
    if (st == null) {
      return htmltext;
    }

    switch (npc.getId()) {
      case NATOOLS:
        switch (st.getState()) {
          case State.STARTED:
            switch (st.getCond()) {
              case 1:
                htmltext = "30894-01.html";
                break;
              default:
                htmltext = "30894-04.html";
                break;
            }
            break;
          case State.COMPLETED:
            htmltext = getAlreadyCompletedMsg(player);
            break;
        }
        break;
      case TOBIAS:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 1:
              htmltext = "30297-01.html";
              break;
            case 2:
              htmltext = (st.isSet("talk")) ? "30297-04.html" : "30297-02.html";
              break;
            case 3:
            case 4:
              htmltext = "30297-06.html";
              break;
            case 5:
              st.giveAdena(89046, true);
              if (player.getLevel() <= MAX_REWARD_LEVEL) {
                st.addExpAndSp(223036, 13901);
              }
              st.exitQuest(false, true);
              htmltext = "30297-07.html";
              break;
          }
        }
        break;
      case CASIAN:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 1:
            case 2:
              htmltext = "30612-01.html";
              break;
            case 3:
              htmltext = (st.isSet("talk")) ? "30612-04.html" : "30612-02.html";
              break;
            default:
              htmltext = "30612-10.html";
              break;
          }
        }
        break;
      case ROCK:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 1:
            case 2:
            case 3:
              htmltext = "32368-01.html";
              break;
            case 4:
              htmltext = "32368-02.html";
              break;
            case 5:
              htmltext = "32368-05.html";
              break;
          }
        }
        break;
      case ANGEL:
        if (st.isStarted()) {
          switch (st.getCond()) {
            case 1:
            case 2:
            case 3:
              htmltext = "32369-01.html";
              break;
            case 4:
              if (st.getInt("talk") == 1) {
                htmltext = "32369-04.html";
              } else if (st.getInt("talk") == 2) {
                htmltext = "32369-07.html";
              } else {
                htmltext = "32369-02.html";
              }
              break;
          }
        }
        break;
    }
    return htmltext;
  }
Example #17
0
  /**
   * Starts the TvTEvent fight<br>
   * 1. Set state EventState.STARTING<br>
   * 2. Close doors specified in configs<br>
   * 3. Abort if not enough participants(return false)<br>
   * 4. Set state EventState.STARTED<br>
   * 5. Teleport all participants to team spot<br>
   * <br>
   *
   * @return boolean: true if success, otherwise false<br>
   */
  public static boolean startFight() {
    // Set state to STARTING
    setState(EventState.STARTING);

    // Randomize and balance team distribution
    final Map<Integer, L2PcInstance> allParticipants = new HashMap<>();
    allParticipants.putAll(_teams[0].getParticipatedPlayers());
    allParticipants.putAll(_teams[1].getParticipatedPlayers());
    _teams[0].cleanMe();
    _teams[1].cleanMe();

    L2PcInstance player;
    Iterator<L2PcInstance> iter;
    if (needParticipationFee()) {
      iter = allParticipants.values().iterator();
      while (iter.hasNext()) {
        player = iter.next();
        if (!hasParticipationFee(player)) {
          iter.remove();
        }
      }
    }

    final int balance[] = {0, 0};
    int priority = 0, highestLevelPlayerId;
    L2PcInstance highestLevelPlayer;
    // TODO: allParticipants should be sorted by level instead of using highestLevelPcInstanceOf for
    // every fetch
    while (!allParticipants.isEmpty()) {
      // Priority team gets one player
      highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants);
      highestLevelPlayer = allParticipants.get(highestLevelPlayerId);
      allParticipants.remove(highestLevelPlayerId);
      _teams[priority].addPlayer(highestLevelPlayer);
      balance[priority] += highestLevelPlayer.getLevel();
      // Exiting if no more players
      if (allParticipants.isEmpty()) {
        break;
      }
      // The other team gets one player
      // TODO: Code not dry
      priority = 1 - priority;
      highestLevelPlayerId = highestLevelPcInstanceOf(allParticipants);
      highestLevelPlayer = allParticipants.get(highestLevelPlayerId);
      allParticipants.remove(highestLevelPlayerId);
      _teams[priority].addPlayer(highestLevelPlayer);
      balance[priority] += highestLevelPlayer.getLevel();
      // Recalculating priority
      priority = balance[0] > balance[1] ? 1 : 0;
    }

    // Check for enought participants
    if ((_teams[0].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)
        || (_teams[1].getParticipatedPlayerCount() < Config.TVT_EVENT_MIN_PLAYERS_IN_TEAMS)) {
      // Set state INACTIVE
      setState(EventState.INACTIVE);
      // Cleanup of teams
      _teams[0].cleanMe();
      _teams[1].cleanMe();
      // Unspawn the event NPC
      unSpawnNpc();
      AntiFeedManager.getInstance().clear(AntiFeedManager.TVT_ID);
      return false;
    }

    if (needParticipationFee()) {
      iter = _teams[0].getParticipatedPlayers().values().iterator();
      while (iter.hasNext()) {
        player = iter.next();
        if (!payParticipationFee(player)) {
          iter.remove();
        }
      }
      iter = _teams[1].getParticipatedPlayers().values().iterator();
      while (iter.hasNext()) {
        player = iter.next();
        if (!payParticipationFee(player)) {
          iter.remove();
        }
      }
    }

    if (Config.TVT_EVENT_IN_INSTANCE) {
      try {
        _TvTEventInstance =
            InstanceManager.getInstance().createDynamicInstance(Config.TVT_EVENT_INSTANCE_FILE);
        InstanceManager.getInstance().getInstance(_TvTEventInstance).setAllowSummon(false);
        InstanceManager.getInstance().getInstance(_TvTEventInstance).setPvPInstance(true);
        InstanceManager.getInstance()
            .getInstance(_TvTEventInstance)
            .setEmptyDestroyTime((Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY * 1000) + 60000L);
      } catch (Exception e) {
        _TvTEventInstance = 0;
        _log.log(
            Level.WARNING,
            "TvTEventEngine[TvTEvent.createDynamicInstance]: exception: " + e.getMessage(),
            e);
      }
    }

    // Opens all doors specified in configs for tvt
    openDoors(Config.TVT_DOORS_IDS_TO_OPEN);
    // Closes all doors specified in configs for tvt
    closeDoors(Config.TVT_DOORS_IDS_TO_CLOSE);
    // Set state STARTED
    setState(EventState.STARTED);

    // Iterate over all teams
    for (TvTEventTeam team : _teams) {
      // Iterate over all participated player instances in this team
      for (L2PcInstance playerInstance : team.getParticipatedPlayers().values()) {
        if (playerInstance != null) {
          // Disable player revival.
          playerInstance.setCanRevive(false);
          // Teleporter implements Runnable and starts itself
          new TvTEventTeleporter(playerInstance, team.getCoordinates(), false, false);
        }
      }
    }

    // Notify to scripts.
    EventDispatcher.getInstance().notifyEventAsync(new OnTvTEventStart());
    return true;
  }
  @Override
  public String onTalk(L2Npc npc, L2PcInstance player) {
    String htmltext = getNoQuestMsg(player);
    final QuestState st = getQuestState(player, true);

    if (st == null) {
      return htmltext;
    }

    if (npc.getId() == KANEMIKA) {
      switch (st.getState()) {
        case State.COMPLETED:
          if (!st.isNowAvailable()) {
            htmltext = "32650-03.html";
            break;
          }
          st.setState(State.CREATED);
        case State.CREATED:
          htmltext = (player.getLevel() >= MIN_LEVEL) ? "32650-01.htm" : "32650-02.htm";
          break;
        case State.STARTED:
          if (st.isCond(1)) {
            htmltext =
                (!st.hasQuestItems(EVIDENCE_OF_MIGRATION)) ? "32650-08.html" : "32650-09.html";
          } else {
            st.giveAdena(
                65000, true); // Glory days reward: 6 886 980 exp, 8 116 410 sp, 371 400 Adena
            st.exitQuest(QuestType.DAILY, true);
            htmltext = "32650-10.html";
          }
          break;
      }
    } else if (st.isCond(1)) {
      if (npc.isBusy()) {
        return null;
      }

      if (getRandom(100) < 66) {
        st.giveItems(EVIDENCE_OF_MIGRATION, 1);
        st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
        npc.getAI()
            .setIntention(
                CtrlIntention.AI_INTENTION_MOVE_TO,
                new Location(npc.getX() + 100, npc.getY() + 100, npc.getZ(), 0));
        npc.setBusy(true);

        startQuestTimer("despawn", 3000, npc, player);

        if (st.getQuestItemsCount(EVIDENCE_OF_MIGRATION) == 10) {
          st.setCond(2, true);
        }
        htmltext = "32651-01.html";
      } else {
        if (getRandom(100) < 50) {
          npc.broadcastPacket(
              new NpcSay(
                  npc.getObjectId(), ChatType.NPC_GENERAL, npc.getId(), NpcStringId.GRUNT_OH));
        } else {
          npc.broadcastPacket(
              new NpcSay(
                  npc.getObjectId(),
                  ChatType.NPC_GENERAL,
                  npc.getId(),
                  NpcStringId.GRUNT_WHAT_S_WRONG_WITH_ME));
        }
        npc.deleteMe();
        htmltext = null;

        final L2Attackable monster =
            (L2Attackable)
                addSpawn(
                    WARRIOR_MON,
                    npc.getX(),
                    npc.getY(),
                    npc.getZ(),
                    npc.getHeading(),
                    true,
                    600000);
        monster.setRunning();
        monster.addDamageHate(player, 0, 999);
        monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
        showOnScreenMsg(
            player,
            NpcStringId
                .THE_GRAVE_ROBBER_WARRIOR_HAS_BEEN_FILLED_WITH_DARK_ENERGY_AND_IS_ATTACKING_YOU,
            5,
            5000);
      }
    }

    return htmltext;
  }
Example #19
0
 @Override
 public String onTalk(L2Npc npc, L2PcInstance talker) {
   final QuestState qs = getQuestState(talker, true);
   String htmltext = getNoQuestMsg(talker);
   switch (npc.getId()) {
     case IRIS:
       {
         switch (qs.getCond()) {
           case 3:
             {
               htmltext = "30034-01.html";
               break;
             }
           case 4:
             {
               htmltext = "30034-04.html";
               break;
             }
           case 5:
             {
               htmltext = "30034-05.html";
               break;
             }
           case 6:
             {
               htmltext = "30034-09.html";
               break;
             }
           case 7:
             {
               if (hasItem(talker, TOTEM_TOOTH_2ND)) {
                 htmltext = "30034-08.html";
               }
               break;
             }
         }
         break;
       }
     case MAGISTER_ROHMER:
       {
         if (qs.isCond(4)) {
           htmltext = "30344-01.html";
         } else if (qs.isCond(5)) {
           htmltext = "30344-04.html";
         }
         break;
       }
     case GUARD_LUIS:
       {
         if (qs.isCreated()) {
           htmltext = (talker.getLevel() >= MIN_LVL) ? "30386-01.htm" : "30386-02.htm";
         } else if (qs.isStarted()) {
           switch (qs.getCond()) {
             case 1:
               {
                 htmltext = "30386-05.html";
                 break;
               }
             case 2:
               {
                 if (hasItem(talker, FEATHER)) {
                   htmltext = "30386-04.html";
                 }
                 break;
               }
             case 3:
               {
                 htmltext = "30386-08.html";
                 break;
               }
           }
         } else if (qs.isCompleted()) {
           htmltext = getAlreadyCompletedMsg(talker);
         }
         break;
       }
   }
   return htmltext;
 }