Пример #1
0
  /**
   * Method used to create one quest by receiving its information from the XML
   *
   * @param child an object of the class Element
   */
  public void createQuest(Element child) {

    // put the new quest in the hash, need to test if already has a quest
    // with this identifier, if already exists then don´t create the last

    // create the quest
    Quest quest = quests.get(child.getName());

    // test if exists, if doesn´t exists then create it
    if (quest == null) {
      // pass the element of the quest for it to be created

      // get the data for the quest
      quest = new Quest();

      // get the information
      createInformation(child.getChild("Information"), quest);

      // get the dependencies
      createDependencies(child.getChild("Dependencies"), quest);

      // get the objective
      createObjective(child.getChild("Objective"), quest);

      // get the rewards
      createReward(child.getChild("Reward"), quest);

      // put the quest in the hash
      quests.put(quest.getName(), quest);
    }
  }
Пример #2
0
 @Override
 public void write(JsonWriter out, Quest value) throws IOException {
   out.beginObject();
   out.name(NAME).value(value.getName());
   out.name(DESCRIPTION).value(value.getDescription());
   out.name(X).value(value.getGuiX());
   out.name(Y).value(value.getGuiY());
   if (value.useBigIcon()) {
     out.name(BIG_ICON).value(true);
   }
   if (value.getIcon() != null) {
     MinecraftAdapter.ITEM_STACK.write(out.name(ICON), value.getIcon());
   }
   writeQuestList(
       out, value.getRequirement(), value.getQuestSet().getQuests(), REQUIREMENTS);
   writeQuestList(out, value.getOptionLinks(), value.getQuestSet().getQuests(), OPTIONS);
   if (value.getRepeatInfo().getType() != RepeatType.NONE) {
     REPEAT_INFO_ADAPTER.write(out.name(REPEAT), value.getRepeatInfo());
   }
   if (value.getTriggerType() != TriggerType.NONE) {
     out.name(TRIGGER).value(value.getTriggerType().name());
   }
   if (value.getTriggerType().isUseTaskCount()) {
     out.name(TRIGGER_TASKS).value(value.getTriggerTasks());
   }
   if (value.getUseModifiedParentRequirement()) {
     out.name(PARENT_REQUIREMENT).value(value.getParentRequirementCount());
   }
   out.name(TASKS).beginArray();
   for (QuestTask task : value.getTasks()) {
     TASK_ADAPTER.write(out, task);
   }
   out.endArray();
   writeItemStackArray(
       out,
       (ItemStack[]) ReflectionHelper.getPrivateValue(Quest.class, value, REWARDS),
       REWARDS);
   writeItemStackArray(
       out,
       (ItemStack[]) ReflectionHelper.getPrivateValue(Quest.class, value, REWARDS_CHOICE),
       REWARDS_CHOICE);
   if (value.getReputationRewards() != null && !value.getReputationRewards().isEmpty()) {
     out.name(REWARDS_REPUTATION).beginArray();
     for (Quest.ReputationReward reward : value.getReputationRewards()) {
       REPUTATION_REWARD_ADAPTER.write(out, reward);
     }
     out.endArray();
   }
   out.endObject();
 }
Пример #3
0
  /**
   * Destroy element used by quest when quest is exited
   *
   * @param repeatable
   * @return QuestState
   */
  public QuestState exitCurrentQuest(boolean repeatable) {
    Player player = getPlayer();
    if (player == null) {
      return this;
    }

    removePlayerOnKillListener();
    // Clean drops
    for (int itemId : _quest.getItems()) {
      // Get [item from] / [presence of the item in] the inventory of the player
      ItemInstance item = player.getInventory().getItemByItemId(itemId);
      if ((item == null) || (itemId == 57)) {
        continue;
      }
      long count = item.getCount();
      // If player has the item in inventory, destroy it (if not gold)
      player.getInventory().destroyItemByItemId(itemId, count);
      player.getWarehouse().destroyItemByItemId(itemId, count); // TODO [G1ta0] analyze this
    }

    // If quest is repeatable, delete quest from list of quest of the player and from database
    // (quest CAN be created again => repeatable)
    if (repeatable) {
      player.removeQuestState(_quest.getName());
      Quest.deleteQuestInDb(this);
      _vars.clear();
    } else { // Otherwise, delete variables for quest and update database (quest CANNOT be created
             // again => not repeatable)
      for (String var : _vars.keySet()) {
        if (var != null) {
          unset(var);
        }
      }
      setState(Quest.COMPLETED);
      Quest.updateQuestInDb(this); // FIXME: оно вроде не нужно?
    }
    if (isCompleted()) {
      // WorldStatisticsManager.getInstance().updateStat(player, CategoryType.QUESTS_COMPLETED,0,
      // 1);
    }
    player.sendPacket(new QuestList(player));
    return this;
  }
Пример #4
0
 @Override
 public Quest read(JsonReader in) throws IOException {
   int ID_OFFSET = Quest.size();
   QUEST = new Quest(ID_OFFSET, "", "", 0, 0, false);
   List<Integer> requirement = new ArrayList<>(), options = new ArrayList<>();
   in.beginObject();
   while (in.hasNext()) {
     switch (in.nextName()) {
       case NAME:
         QUEST.setName(in.nextString());
         break;
       case DESCRIPTION:
         QUEST.setDescription(in.nextString());
         break;
       case X:
         ReflectionHelper.setPrivateValue(Quest.class, QUEST, in.nextInt(), X);
         break;
       case Y:
         ReflectionHelper.setPrivateValue(Quest.class, QUEST, in.nextInt(), Y);
         break;
       case TRIGGER_TASKS:
         QUEST.setTriggerTasks(in.nextInt());
         break;
       case PARENT_REQUIREMENT:
         QUEST.setParentRequirementCount(in.nextInt());
         break;
       case BIG_ICON:
         QUEST.setBigIcon(in.nextBoolean());
         break;
       case ICON:
         QUEST.setIcon(MinecraftAdapter.ITEM_STACK.read(in));
         break;
       case REQUIREMENTS:
         in.beginArray();
         while (in.hasNext()) {
           requirement.add(in.nextInt() + QUEST_ID);
         }
         in.endArray();
         break;
       case OPTIONS:
         in.beginArray();
         while (in.hasNext()) {
           options.add(in.nextInt() + QUEST_ID);
         }
         in.endArray();
         break;
       case REPEAT:
         QUEST.setRepeatInfo(REPEAT_INFO_ADAPTER.read(in));
         break;
       case TRIGGER:
         QUEST.setTriggerType(TriggerType.valueOf(in.nextString()));
         break;
       case TASKS:
         in.beginArray();
         while (in.hasNext()) {
           QuestTask task = TASK_ADAPTER.read(in);
           if (task != null) {
             QUEST.getTasks().add(task);
           }
         }
         in.endArray();
         break;
       case REWARDS:
         ReflectionHelper.setPrivateValue(
             Quest.class, QUEST, readItemStackArray(in), REWARDS);
         break;
       case REWARDS_CHOICE:
         ReflectionHelper.setPrivateValue(
             Quest.class, QUEST, readItemStackArray(in), REWARDS_CHOICE);
         break;
       case REWARDS_REPUTATION:
         in.beginArray();
         List<Quest.ReputationReward> reputationRewards = new ArrayList<>();
         while (in.hasNext()) {
           Quest.ReputationReward reward = REPUTATION_REWARD_ADAPTER.read(in);
           if (reward != null) reputationRewards.add(reward);
         }
         QUEST.setReputationRewards(reputationRewards);
         in.endArray();
         break;
     }
   }
   in.endObject();
   if (!QUEST.getName().isEmpty()) {
     requirementMapping.put(QUEST, requirement);
     optionMapping.put(QUEST, options);
     return QUEST;
   }
   QuestLine.getActiveQuestLine().quests.remove(QUEST.getId());
   return null;
 }