Пример #1
0
 public Hero getHero(String name) {
   synchronized (players) {
     for (Hero p : players.values()) {
       if (p.getName().equals(name)) return p;
     }
   }
   return null;
 }
Пример #2
0
  public void sendChatToAll(Hero from, String text) {
    List<Hero> heroesClone = null;

    synchronized (heroes) {
      heroesClone = new ArrayList<Hero>(players.values());
    }

    for (Hero h : heroesClone) {
      h.receiveChat(from, text);
    }
  }
Пример #3
0
  public void sendChatToHero(Hero from, Hero to, String text) {
    if (to == null || from == null) {
      return; // No such hero.
    }

    to.receiveChat(from, text);
  }
Пример #4
0
  /**
   * TODO: Think about how the heroes should be locked so that they can't be attacked by any other
   * hero while this is being processed.
   */
  public synchronized void heroAttacks(Hero initiator) {
    List<MapObserver> reachable = map.getNeighborsWithinAttackRange(initiator);

    // Return if there's no one to attack.
    if (reachable.isEmpty()) {
      if (initiator instanceof Player) {
        sendMessageToPlayer((Player) initiator, "There is no one to attack.", true);
      }

      return;
    }

    // Converting to list of Hero.
    List<Hero> heroes = new ArrayList<Hero>();
    for (MapObserver o : reachable) {
      heroes.add(o.getHero());
    }

    // Checking if there are to many fighters.
    int i;
    if (heroes.size() >= Fight.MAX_FIGHTERS) {
      // Sorting by distance.
      Util.sortHeroesByDistance(initiator.getLocation(), heroes);
      while ((i = heroes.size()) >= Fight.MAX_FIGHTERS) heroes.remove(i - 1);

      // Removing the most distant fighters over maxOpponents.
      /*for (int i = heroes.size() - 1; i > maxOpponents; i--) {
          heroes.remove(i);
      }*/
    }

    // Getting the appropriate fight scene.
    FightScene scene = FightScene.getFightSceneFor(initiator, heroes);

    // Adding the initiator in the list of fighters.
    heroes.add(initiator);

    // Starting the fight.
    Fight fight = new Fight(heroes, scene, this);
    fights.add(fight);

    fight.startFight();
  }
Пример #5
0
 @Override
 public void unequip(Hero hero) {
   hero.addDamage(-damage);
   hero.setAttackRange(1);
 }
Пример #6
0
 @Override
 public void equip(Hero hero) {
   hero.addDamage(damage);
   hero.setAttackRange(range);
 }