Exemplo n.º 1
0
 public void handleHeroAttackRequest(HeroAttackRequest request) {
   int slot = request.getSlotIndex();
   for (Iterator it = team2.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     player.getCom().write(request);
   }
   for (Iterator it = team1.iterator(); it.hasNext(); ) {
     Player player = (Player) it.next();
     // if(player.getSlotIndex()!=request.getSlotIndex())
     player.getCom().write(request);
   }
 }
Exemplo n.º 2
0
  @Override
  public void mouseClicked(MouseEvent e) {

    // To change body of implemented methods use File | Settings | File Templates.
    GameMap temp = panel;
    temp.setStatus("selected");
    Cell selectCell = new Cell();
    Point curPos = e.getPoint();
    int x = (curPos.x + panel.getScrollX()) / Utilizer.TILE_SIZE;
    selectCell.setColPos(x);
    x = x * Utilizer.TILE_SIZE;
    selectCell.setX(x);
    int y = (curPos.y + panel.getScrollY()) / Utilizer.TILE_SIZE;
    selectCell.setRowPos(y);
    y = y * Utilizer.TILE_SIZE;
    selectCell.setY(y);
    temp.setSelectedCell(selectCell);
    panel.requestFocus();
    if (e.isMetaDown()) {
      panel.getFacade().getMainHero().setIsChosen(false);
    }
    model.Character clickedCharacter =
        panel.getFacade().getCharacterByCord(selectCell.getRowPos(), selectCell.getColPos());
    mainHero = panel.getFacade().getMainHero();
    if (clickedCharacter != null && !mainHero.getStatus().equals(HeroStatus.attacking)) {
      if (mainHero.getStatus().equals(HeroStatus.standing))
        controlPanel.setCharacter(clickedCharacter);
      // panel.getFacade().setCurrentHero(clickedHero);
      if (clickedCharacter instanceof Hero) {
        Hero clickedHero = (Hero) clickedCharacter;
        if (clickedHero.equals(mainHero)) {
          mainHero.setIsChosen(true);
          mainHero.resetPath();
          mainHero.calculateRange(
              mainHero.getRow(), mainHero.getCol(), ((int) mainHero.getAP() / 2) + 1);
          if ((mainHero.getCurrentSkill()) != null) {
            if (mainHero.getCurrentSkill() instanceof AOESkill)
              ((AOESkill) mainHero.getCurrentSkill()).clearRangeCell();
          }
        }
      }
      if (panel.getFacade().getIsLocked()) {
        panel.repaint();
        return;
      }
    }
    // To set Hero
    /*if(selectCell.getRowPos()==panel.getHero().getRow() && selectCell.getColPos()==panel.getHero().getCol()){
        panel.getHero().setIsChosen(true);
        panel.getHero().setStatus(HeroStatus.standing);
        panel.getHero().resetPath();
        panel.getHero().calculateRange(panel.getHero().getRow(), panel.getHero().getCol(), ((int) panel.getHero().getAP() / 2) + 1);
        if(( panel.getHero().getCurrentSkill())!=null){
            if( panel.getHero().getCurrentSkill() instanceof AOESkill) ((AOESkill) panel.getHero().getCurrentSkill()).clearRangeCell();
        }
    }*/
    else if (panel.getFacade().getIsLocked()) {
      panel.repaint();
      return;
    } else if (mainHero.getIsChosen()
        && mainHero.getStatus().equals(HeroStatus.standing)
        && Utilizer.inRange(selectCell, mainHero.getRange())) {
      // send moving request
      int gameIndex = panel.getFacade().getGameIndex();
      int heroSlot = panel.getFacade().getHeroSlot();
      mainHero.setShortestPathSelect(mainHero.getShortestpathHover());

      HeroMoveRequest moveRequest = null;
      try {
        moveRequest = new HeroMoveRequest(gameIndex, heroSlot, mainHero.clone());
        moveRequest.setSelectedCell(selectCell.clone());
        com.write(moveRequest);
      } catch (CloneNotSupportedException e1) {
        e1.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }

      // HeroAnimation.move(mainHero,panel);
      if ((mainHero.getCurrentSkill()) != null) {
        if (mainHero.getCurrentSkill() instanceof AOESkill)
          ((AOESkill) mainHero.getCurrentSkill()).clearRangeCell();
      }
    }
    // cast AOE skill
    else if (mainHero.getIsChosen()
        && mainHero.getStatus().equals(HeroStatus.attacking)
        && mainHero.getCurrentSkill().getStatus().equals(SkillStatus.before)
        && mainHero.getCurrentSkill().getPath().contains(selectCell)
        && (mainHero.getAP() - mainHero.getCurrentSkill().getAP()) >= 0
        && mainHero.getCurrentSkill() != null
        && Utilizer.inRange(selectCell, mainHero.getCurrentSkill().getRangeCell())) {
      // send attack request
      int gameIndex = panel.getFacade().getGameIndex();
      int heroSlot = panel.getFacade().getHeroSlot();
      if (selectCell.getColPos() < mainHero.getCol()) mainHero.setCurrentSprite(16);
      else mainHero.setCurrentSprite(20);

      HeroAttackRequest attackReq = null;
      if (mainHero.getCurrentSkill() instanceof NormalSkill)
        mainHero.getCurrentSkill().getDmgCell().clear();
      mainHero.getCurrentSkill().getDmgCell().add(selectCell);
      try {
        Hero cloneHero = mainHero.clone();

        // cloneHero.getCurrentSkill().clonePath(mainHero.getCurrentSkill().getPath());
        attackReq = new HeroAttackRequest(gameIndex, heroSlot, cloneHero);
        attackReq.setSelectedCell(selectCell.clone());
        attackReq.setPath(mainHero.getCurrentSkill().getPath());
        attackReq.setDmgCell(mainHero.getCurrentSkill().getDmgCell());
        com.write(attackReq);
      } catch (CloneNotSupportedException e1) {
        e1.printStackTrace(); // To change body of catch statement use File | Settings | File
        // Templates.
      }

      /*if(mainHero.getCurrentSkill() instanceof NormalSkill) mainHero.getCurrentSkill().getDmgCell().clear();
      mainHero.getCurrentSkill().getDmgCell().add(selectCell);
      if(Utilizer.inRange(new Cell(panel.getMonster().getCol(),panel.getMonster().getRow()),
              mainHero.getCurrentSkill().getDmgCell()) ){
          panel.getMonster().setHP(panel.getMonster().getHP()-panel.getHero().getCurrentSkill().getDamage(mainHero));
          panel.setDamage(mainHero.getCurrentSkill().getDamage(panel.getHero()));
      }else panel.setDamage(0);*/
    }

    /*//cast cleave skill
    else if(panel.getHero().getIsChosen() && panel.getHero().getStatus().equals(HeroStatus.attacking)
            && panel.getHero().getCurrentSkill().getStatus().equals(SkillStatus.before)
            && panel.getHero().getCurrentSkill().getPath().contains(selectCell)
            && (panel.getHero().getAP()-panel.getHero().getCurrentSkill().getAP())>=0
            && ! (panel.getHero().getCurrentSkill() instanceof AOESkill)
            && ! (panel.getHero().getCurrentSkill() instanceof NormalSkill)){
        HeroAnimation.attack(panel.getHero(),panel);
        if(Utilizer.inRange(new Cell(panel.getMonster().getCol(),panel.getMonster().getRow()),
                panel.getHero().getCurrentSkill().getPath())){
            panel.getMonster().setHP(panel.getMonster().getHP()-panel.getHero().getCurrentSkill().getDamage());
        }
    }*/

    // cast normal skill
    /* else if(panel.getHero().getIsChosen() && panel.getHero().getStatus().equals(HeroStatus.attacking)
            && panel.getHero().getCurrentSkill().getStatus().equals(SkillStatus.before)
            && panel.getHero().getCurrentSkill().getPath().contains(selectCell)
            && (panel.getHero().getAP()-panel.getHero().getCurrentSkill().getAP())>=0
            && (panel.getHero().getCurrentSkill() instanceof NormalSkill)){
        HeroAnimation.attack(panel.getHero(),panel);
        Cell c = new Cell(panel.getMonster().getCol(),panel.getMonster().getRow());
        if(selectCell.equals(c)){
            panel.getMonster().setHP(panel.getMonster().getHP()-panel.getHero().getCurrentSkill().getDamage());
        }
    }*/
    // System.out.println(panel.getHero().getStatus());
    panel.repaint();
  }