Example #1
0
  @Override
  public HashMap<Integer, Point> getVoisins(int refRMI) throws RemoteException {
    HashMap<Integer, Point> res = new HashMap<Integer, Point>();

    VuePersonnage courant = personnages.get(refRMI);
    VuePersonnage tempPers;

    // personnages
    for (int refVoisin : personnages.keySet()) {
      tempPers = personnages.get(refVoisin);

      if (estVoisin(courant, tempPers)) {
        res.put(refVoisin, tempPers.getPosition());
      }
    }

    VuePotion tempPot;

    // potions
    for (int refVoisin : potions.keySet()) {
      tempPot = potions.get(refVoisin);

      if (estVoisin(courant, tempPot)) {
        res.put(refVoisin, tempPot.getPosition());
      }
    }

    return res;
  }
Example #2
0
  @Override
  public boolean ramassePotion(int refRMI, int refPotion) throws RemoteException {
    boolean res = false;

    VuePersonnage vuePersonnage = personnages.get(refRMI);
    VuePotion vuePotion = potions.get(refPotion);

    if (vuePersonnage.isActionExecutee()) {
      // si une action a deja ete executee
      logActionDejaExecutee(refRMI);

    } else {
      // sinon, on tente de jouer l'interaction
      int distance =
          Calculs.distanceChebyshev(vuePersonnage.getPosition(), vuePotion.getPosition());

      // on teste la distance entre le personnage et la potion
      if (distance <= Constantes.DISTANCE_MIN_INTERACTION) {
        new Ramassage(this, vuePersonnage, vuePotion).interagit();
        personnages.get(refRMI).executeAction();

        res = true;
      } else {
        logger.warning(
            Constantes.nomClasse(this),
            nomRaccourciClient(refRMI)
                + " a tente d'interagir avec "
                + vuePotion.getElement().getNom()
                + ", alors qu'il est trop eloigne !\nDistance = "
                + distance);
      }
    }

    return res;
  }
 @Override
 public int compareTo(VuePotion vp2) {
   return vp2.getRefRMI() - this.getRefRMI();
 }