@Override
 public boolean onDialogEvent(QuestCookie env) {
   if (env.getPlayer().getTribe().equals("PC_DARK")) {
     final Player player = env.getPlayer();
     int targetId = 0;
     if (env.getVisibleObject() instanceof Npc)
       targetId = ((Npc) env.getVisibleObject()).getNpcId();
     QuestTemplate template = DataManager.QUEST_DATA.getQuestById(questId);
     QuestState qs = player.getQuestStateList().getQuestState(questId);
     if (targetId == 730330) {
       PlayerClass playerClass = player.getCommonData().getPlayerClass();
       if (playerClass == PlayerClass.RANGER
           || playerClass == PlayerClass.ASSASSIN
           || playerClass == PlayerClass.MAGE
           || playerClass == PlayerClass.PRIEST
           || playerClass == PlayerClass.GLADIATOR
           || playerClass == PlayerClass.WARRIOR
           || playerClass == PlayerClass.SCOUT) {
         if (qs == null
             || qs.getStatus() == QuestStatus.NONE
             || (qs.getStatus() == QuestStatus.COMPLETE
                 && (qs.getCompleteCount() <= template.getMaxRepeatCount()))) {
           if (env.getDialogId() == -1) return sendQuestDialog(env, 1011);
           else return defaultQuestStartDialog(env);
         } else if (qs != null
             && qs.getStatus() == QuestStatus.START
             && qs.getQuestVarById(0) == 0) {
           if (env.getDialogId() == -1) return sendQuestDialog(env, 2375);
           else if (env.getDialogId() == 34) {
             if (player.getInventory().getItemCountByItemId(185000102) >= 1) {
               player.getInventory().removeFromBagByItemId(185000102, 1);
               qs.setStatus(QuestStatus.REWARD);
               qs.setQuestVar(1);
               qs.setCompliteCount(0);
               updateQuestStatus(env);
               return sendQuestDialog(env, 5);
             } else return sendQuestDialog(env, 2716);
           }
         } else if (qs != null && qs.getStatus() == QuestStatus.REWARD) {
           int var = qs.getQuestVarById(0);
           switch (env.getDialogId()) {
             case -1:
               if (var == 1) return sendQuestDialog(env, 5);
             case 17:
               QuestService.questFinish(env, qs.getQuestVars().getQuestVars() - 1);
               PacketSendUtility.sendPacket(
                   player, new SM_DIALOG_WINDOW(env.getVisibleObject().getObjectId(), 10));
               return true;
           }
         }
       }
       return false;
     }
     return false;
   } else {
     return false;
   }
 }
예제 #2
0
파일: Reload.java 프로젝트: osiris087/aionj
  @Override
  public void executeCommand(Player admin, String[] params) {
    if (admin.getAccessLevel() < AdminConfig.COMMAND_RELOAD) {
      PacketSendUtility.sendMessage(admin, "You dont have enough rights to execute this command");
      return;
    }

    if (params == null || params.length != 1) {
      sendSyntax(admin);
      return;
    }

    ReloadType reloadType = ReloadType.UNKNOWN;
    try {
      reloadType = ReloadType.valueOf(params[0].toUpperCase());
    } catch (Exception e) {
    }

    switch (reloadType) {
      case COMMAND:
        try {
          ChatHandlers.getInstance().reloadChatHandlers();
          PacketSendUtility.sendMessage(admin, "Admin/user commands reloaded successfully!");
        } catch (GameServerError e) {
          PacketSendUtility.sendMessage(
              admin, "Admin/user commands failed to reload! Keeping last version ...");
        }
        break;
      case NPC:
        File npcXml = new File("./data/static_data/npcs/npc_templates.xml");
        List<NpcTemplate> npcTemplates = new ArrayList<NpcTemplate>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          NpcData data = (NpcData) un.unmarshal(npcXml);
          if (data != null && data.getTemplates() != null) npcTemplates.addAll(data.getTemplates());
        } catch (Exception e) {
          PacketSendUtility.sendMessage(
              admin, "NPC templates reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (npcTemplates.size() > 0) {
          DataManager.NPC_DATA.setTemplates(npcTemplates);

          PacketSendUtility.sendMessage(
              admin,
              "NPC templates reloaded successfuly, now updating World to reflect changes ...!");

          World.getInstance()
              .doOnAllNpcs(
                  new Executor<Npc>() {

                    @Override
                    public boolean run(Npc object) {
                      NpcTemplate newTemplate =
                          DataManager.NPC_DATA.getNpcTemplate(object.getNpcId());
                      if (newTemplate != null) {
                        object.setObjectTemplate(newTemplate);
                      }
                      return true;
                    }
                  },
                  true);

          PacketSendUtility.sendMessage(admin, "Complete !");

        } else
          PacketSendUtility.sendMessage(
              admin, "NPC templates reload failed! Keeping last version ...");

        break;
      case PORTAL:
        File portalDir = new File("./data/static_data/portals");
        List<PortalTemplate> portalTemplates = new ArrayList<PortalTemplate>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          for (File file : listFiles(portalDir, true)) {
            PortalData data = (PortalData) un.unmarshal(file);
            if (data != null && data.getPortals() != null)
              portalTemplates.addAll(data.getPortals());
          }

        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Portals reload failed! Keeping last version ...");
          log.error(e);
          return;
        }
        if (portalTemplates.size() > 0) {
          DataManager.PORTAL_DATA.setPortals(portalTemplates);
          PacketSendUtility.sendMessage(admin, "Portals reloaded successfuly!");
        } else
          PacketSendUtility.sendMessage(admin, "Portals reload failed! Keeping last version ...");
        break;
      case QUEST:
        File questXml = new File("./data/static_data/quest_data/quest_data.xml");
        File questDir = new File("./data/static_data/quest_script_data");

        QuestsData newQuestData;
        ArrayList<QuestScriptsData> newScriptData = new ArrayList<QuestScriptsData>();

        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));
          newQuestData = (QuestsData) un.unmarshal(questXml);
          for (File file : listFiles(questDir, true)) {
            QuestScriptsData data = ((QuestScriptsData) un.unmarshal(file));
            if (data != null) if (data.getData() != null) newScriptData.add(data);
          }
        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Quests reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (newQuestData != null) {
          try {
            DataManager.QUEST_DATA.setQuestsData(newQuestData.getQuestsData());
            QuestScriptsData questScriptsData = DataManager.QUEST_SCRIPTS_DATA;
            questScriptsData.getData().clear();
            for (QuestScriptsData qsd : newScriptData) {
              questScriptsData.getData().addAll(qsd.getData());
            }
            QuestEngine.getInstance().load(true);
            PacketSendUtility.sendMessage(admin, "Quests reloaded successfuly!");
          } catch (GameServerError e) {
            PacketSendUtility.sendMessage(admin, "Quests reload failed! Keeping last version ...");
            log.error(e);
            return;
          }
        }
        break;
      case SKILL:
        File skillDir = new File("./data/static_data/skills");
        List<SkillTemplate> skillTemplates = new ArrayList<SkillTemplate>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          for (File file : listFiles(skillDir, true)) {
            SkillData data = (SkillData) un.unmarshal(file);
            if (data != null) skillTemplates.addAll(data.getSkillTemplates());
          }
        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Skills reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (skillTemplates.size() > 0) {
          DataManager.SKILL_DATA.setSkillTemplates(skillTemplates);
          PacketSendUtility.sendMessage(admin, "Skills reloaded successfuly!");
        } else
          PacketSendUtility.sendMessage(admin, "Skills reload failed! Keeping last version ...");
        break;
      case SPAWN:
        File spawnDir = new File("./data/static_data/spawns");
        List<SpawnGroup> spawnTemplates = new ArrayList<SpawnGroup>();
        try {
          JAXBContext jc = JAXBContext.newInstance(StaticData.class);
          Unmarshaller un = jc.createUnmarshaller();
          un.setSchema(getSchema("./data/static_data/static_data.xsd"));

          for (File file : listFiles(spawnDir, true)) {
            SpawnsData data = (SpawnsData) un.unmarshal(file);
            if (data != null && data.getSpawnGroups() != null)
              spawnTemplates.addAll(data.getSpawnGroups());
          }
        } catch (Exception e) {
          PacketSendUtility.sendMessage(admin, "Spawns reload failed! Keeping last version ...");
          log.error(e);
          return;
        }

        if (spawnTemplates.size() > 0) {
          DataManager.SPAWNS_DATA.setSpawns(spawnTemplates);
          PacketSendUtility.sendMessage(admin, "Spawns reloaded successfuly!");
        } else
          PacketSendUtility.sendMessage(
              admin, "Spawns reload failed with empty object! Keeping last version ...");
        break;
      default:
        sendSyntax(admin);
        return;
    }
  }