Пример #1
0
  @Override
  public void gather(Player player, NPC npc) {
    // 根据npc判断采集物品
    Q_npcBean bean = ManagerPool.dataManager.q_npcContainer.getMap().get(npc.getModelId());
    if (bean == null) {
      return;
    }
    String itemModelIds = bean.getQ_acquisition_item();
    if (StringUtil.isBlank(itemModelIds)) {
      // player停止采集
      ManagerPool.npcManager.playerStopGather(player);
      return;
    }
    Map<Integer, Integer> gatherMap = new HashMap<Integer, Integer>();
    String[] split = itemModelIds.split(Symbol.FENHAO_REG);
    for (String str : split) {
      String[] split2 = str.split(Symbol.XIAHUAXIAN_REG);
      int id = Integer.parseInt(split2[0]);
      int num = 1;
      if (split2.length > 1) num = Integer.parseInt(split2[1]);
      String jobLimit = null;
      if (split2.length > 2) jobLimit = split2[2];
      if (PlayerManager.checkJob(player.getJob(), jobLimit)) gatherMap.put(id, num);
    }
    if (gatherMap.size() == 0) {
      log.error("没有物品可以采集了:" + bean.getQ_id());
      ManagerPool.npcManager.playerStopGather(player);
      return;
    }
    // 判断包裹是否能够放下此物品
    int num = ManagerPool.backpackManager.getEmptyGridNum(player);
    if (num < gatherMap.size()) {
      // 提示包裹空间不足
      MessageUtil.notify_player(
          player, Notifys.ERROR, ResManager.getInstance().getString("背包空间不足"));
      // player停止采集
      ManagerPool.npcManager.playerStopGather(player);
      return;
    }

    // 根据npc判断采集物品
    String taskModelId = bean.getQ_acquisition_task();
    if (StringUtil.isNotBlank(taskModelId)) {
      MainTask mainTask = null;
      for (MainTask task : player.getCurrentMainTasks()) {
        if (taskModelId.contains(String.valueOf(task.getModelid()))) {
          mainTask = task;
          break;
        }
      }
      if (mainTask == null) {
        return;
      }
      Q_task_mainBean taskModel =
          DataManager.getInstance().q_task_mainContainer.getMap().get(mainTask.getModelid());
      if (player.getLevel() < taskModel.getQ_accept_needmingrade()) {
        // 等级不足
        MessageUtil.notify_player(
            player, Notifys.ERROR, ResManager.getInstance().getString("采集需要的等级不足"));
        return;
      }
      // 增加player物品
      List<Item> item = new ArrayList<Item>();
      Iterator<Entry<Integer, Integer>> iterator = gatherMap.entrySet().iterator();
      while (iterator.hasNext()) {
        Entry<Integer, Integer> next = iterator.next();
        List<Item> item2 = Item.createItems(next.getKey(), next.getValue(), true, 0);
        if (CollectionUtil.isNotBlank(item2)) item.addAll(item2);
      }

      if (BackpackManager.getInstance().hasAddSpace(player, item)) {
        log.error("玩家(" + player.getId() + ")完成任务(" + mainTask.getModelid() + ")检查物品有地儿放!");
      } else {
        log.error("玩家(" + player.getId() + ")完成任务(" + mainTask.getModelid() + ")检查物品没地儿放!");
      }
      if (ManagerPool.backpackManager.addItems(player, item, Reasons.TAKEUP, Config.getId())) {
        log.error("玩家(" + player.getId() + ")完成任务(" + mainTask.getModelid() + ")获得物品成功!");
        ;
      } else {
        log.error("玩家(" + player.getId() + ")完成任务(" + mainTask.getModelid() + ")获得物品失败!");
        ;
      }
      log.error("玩家(" + player.getId() + ")采集成功准备完成任务(" + mainTask.getModelid() + ")!");
      // 触发完成任务
      //			mainTask.changeTask();
      if (mainTask.checkFinsh(false, player)) {
        mainTask.finshTask(player);
        log.error("玩家(" + player.getId() + ")采集成功完成任务(" + taskModelId + ")了!");
      } else {

        log.error("玩家(" + player.getId() + ")采集成功未完成任务(" + taskModelId + ")了!");
      }
      //			ManagerPool.taskManager.finishMainTask(player, taskModelId);
    }

    // player停止采集
    ManagerPool.npcManager.playerStopGather(player);
  }
Пример #2
0
 public void addItems(
     Player player, List<Item> items, String title, String notice, Reasons reasons, long action) {
   List<Item> tmp = new ArrayList<Item>();
   List<Item> special = new ArrayList<Item>();
   tmp.addAll(items);
   while (tmp.iterator().hasNext()) {
     Item item = (Item) tmp.iterator().next();
     if (item.getItemModelId() < 0) {
       tmp.iterator().remove();
       special.add(item);
     }
   }
   boolean tag = true;
   for (Item item : special) {
     // -1金币,-2钻石,-3经验,-4真气  -5绑定钻石
     switch (item.getItemModelId()) {
       case -1:
         if (player.getMoney() + item.getNum() > Global.BAG_MAX_COPPER) tag = false;
         break;
         //			case -2:
         //				if(player.getGold()!=null&&player.getGold().getGold()+item.getNum() >
         // Global.BAG_MAX_GOLD)tag=false;
         //				break;
       case -3:
         if (PlayerManager.getInstance().isTopLevel(player)) tag = false;
         break;
       case -4:
         if (PlayerManager.getInstance().isFullZq(player)) tag = false;
         break;
       case -5:
         if (player.getBindGold() + item.getNum() > Global.BAG_MAX_GOLD) tag = false;
         break;
     }
   }
   if (!BackpackManager.getInstance().hasAddSpace(player, tmp)) {
     tag = false;
   }
   if (tag) {
     for (Item item : special) {
       // -1金币,-2钻石,-3经验,-4真气  -5绑定钻石
       switch (item.getItemModelId()) {
         case -1:
           BackpackManager.getInstance().changeMoney(player, item.getNum(), reasons, action);
           break;
           //				case -2:
           //					BackpackManager.getInstance().addGold(player, item.getNum(), reasons, action);
           //					break;
         case -3:
           PlayerManager.getInstance().addExp(player, item.getNum(), AttributeChangeReason.MAIL);
           break;
         case -4:
           PlayerManager.getInstance()
               .addZhenqi(player, item.getNum(), AttributeChangeReason.MAIL);
           break;
         case -5:
           BackpackManager.getInstance().changeBindGold(player, item.getNum(), reasons, action);
           break;
       }
     }
   } else {
     MailServerManager.getInstance()
         .sendSystemMail(player.getId(), player.getName(), title, notice, (byte) 0, 0, items);
   }
 }