Example #1
0
  /**
   * 获取用户当前阵型
   *
   * @param player
   */
  public void getForm(Player player) {
    // 获取用户当前对应的阵型配置,找不到配置直接返回错误
    Human human = player.getHuman();
    FormTemplate template = getFormTemplate(human.getVocationType(), human.getLevel());
    if (template == null) {
      player.sendErrorPromptMessage(SkillLangConstants_80000.TEMPLATE_NOT_FOUND);
      return;
    }

    // 获取用户当前阵法,找不到则初始化阵法
    BattleForm form = human.getBattleForm();
    if (form == null) {
      form = initBattleForm(human, template);
    }
    String[] positions = form.getPositions();

    // 根据当前阵法和阵法配置构造返回消息
    List<FormPosition> list = new ArrayList<FormPosition>();
    for (int open : template.getOpenPositions()) {
      if (open > 0 && open <= positions.length && StringUtils.isNotEmpty(positions[open - 1])) {
        list.add(new FormPosition(open, positions[open - 1]));
      } else {
        list.add(new FormPosition(open, "-1"));
      }
    }

    // 返回初始化消息
    GCForm msg = new GCForm();
    msg.setFormPositions(list.toArray(new FormPosition[0]));
    msg.setMaxPos(template.getMaxPos());
    player.sendMessage(msg);
  }
Example #2
0
  /**
   * 角色初始化阵型,将自身放入阵法中
   *
   * @param human
   * @param temp
   * @return
   */
  private BattleForm initBattleForm(Human human, FormTemplate temp) {
    // 初始化时将玩家放入阵型配置的第一个开启位置中
    String[] positions = new String[BattleForm.TotalPositions];
    int initPos = temp.getOpenPositions().get(0);
    positions[initPos - 1] = human.getUUID();

    // 构造阵型对象并保存到数据库中
    BattleForm form = new BattleForm(human);
    form.setFormSn(temp.getId());
    form.setOwner(human);
    form.setPositions(positions);
    FormEntity entity = form.toEntity();
    Globals.getDaoService().getFormDao().save(entity);
    form.setDbId(entity.getId());
    form.setInDb(true);

    // 设置角色阵型
    human.setBattleForm(form);
    return form;
  }
Example #3
0
  /**
   * 根据客户端提供的阵型位置修改用户阵型
   *
   * @param player
   * @param message
   */
  public void modifyFormOrder(Player player, CGFormPosition message) {
    // 获取用户当前对应的阵型配置,找不到配置直接返回错误
    Human human = player.getHuman();
    FormTemplate template = getFormTemplate(human.getVocationType(), human.getLevel());
    if (template == null) {
      player.sendErrorPromptMessage(SkillLangConstants_80000.TEMPLATE_NOT_FOUND);
      return;
    }

    // 获取用户当前阵法,找不到返回错误
    BattleForm form = human.getBattleForm();
    if (form == null) {
      player.sendErrorPromptMessage(SkillLangConstants_80000.TEMPLATE_NOT_FOUND);
      return;
    }

    // 获取用户提供的阵型站位信息,判断是否都站在有效位置上,是否有玩家,是否存在重复id
    String[] positions = new String[BattleForm.TotalPositions];
    int totalPos = 0;
    boolean hasHuman = false;
    Map<String, String> allPets = new HashMap<String, String>();
    for (FormPosition position : message.getPetPositions()) {
      // 初步判断信息有效,即位置上的id不为空,并且位置在阵法规定的范围内
      String petSn = position.getPetSn();
      int formPos = position.getPosition();
      if (StringUtils.isNotEmpty(petSn) && formPos > 0 && formPos <= positions.length) {
        // 判断是否存在重复id或重复位置
        if (allPets.containsKey(petSn) || StringUtils.isNotEmpty(positions[formPos - 1])) {
          player.sendErrorPromptMessage(SkillLangConstants_80000.DUPLICATE_PET);
          return;
        }

        // 判断是否为玩家本身
        if (!hasHuman) {
          hasHuman = petSn.equals(human.getUUID());
        }

        // 判断是否为玩家所属角色,如果是则放入阵法信息中
        if (human.getRole(petSn) != null) {
          positions[formPos - 1] = petSn;
          allPets.put(petSn, petSn);
          totalPos++;
        }
      }
    }

    // 判断阵型中总人数是否超过阵法最大人数限制
    if (totalPos > template.getMaxPos()) {
      player.sendErrorPromptMessage(SkillLangConstants_80000.OUT_OF_MAX_POSITIONS);
      return;
    }

    // 如果玩家不在阵型中返回错误
    if (!hasHuman) {
      player.sendErrorPromptMessage(SkillLangConstants_80000.NO_PLAYER_IN_FORM);
      return;
    }

    // 保存阵法信息
    form.setPositions(positions);
    form.setModified();

    // 更新玩家武将是否在阵型的状态
    for (Pet pet : human.getPetManager().getPets()) {
      if (form.isBattle(pet.getUUID())) {
        pet.getPropertyManager().setIsInBattle(true);
        pet.snapChangedProperty(true);
      } else {
        pet.getPropertyManager().setIsInBattle(false);
        pet.snapChangedProperty(true);
      }
    }
  }