예제 #1
0
  public Monster getMostAggroInPanel(Point p) {
    Monster monster = null;
    Monster mostAggroMonster = null;

    double mostAggro = 0;

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (!monster.getName().equals("Pig")
            && !monster.getName().equals("BlueThorn")
            && !monster.getName().equals("VineThorn")) {
          if (monster.getIsInPanel()) {
            double distance = p.distance(monster.getCenterPoint());
            if (monster.getPlayerDamage() > mostAggro) {
              mostAggroMonster = monster;
              mostAggro = monster.getPlayerDamage();
            }
          }
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }

    return mostAggroMonster;
  }
예제 #2
0
  public void removeAllMonsters() {
    Monster monster = null;

    ArrayList deadMonsters = new ArrayList();

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (!monster.getName().equals("Pig")
            && !monster.getName().equals("BlueThorn")
            && !monster.getName().equals("VineThorn")) {
          deadMonsters.add(key);
          if (gameController.multiplayerMode == gameController.multiplayerMode.SERVER
              && registry.getNetworkThread() != null) {
            if (registry.getNetworkThread().readyForUpdates()) {
              UpdateMonster um = new UpdateMonster(monster.getId());
              um.mapX = monster.getMapX();
              um.mapY = monster.getMapY();
              um.action = "Die";
              registry.getNetworkThread().sendData(um);
            }
          }
        }
      }

      if (deadMonsters.size() > 0) {
        for (int i = 0; i < deadMonsters.size(); i++) {
          monsters.remove((String) deadMonsters.get(i));
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }
  }
예제 #3
0
  public Monster getClosestWithinMax(Point p, int r) {
    Monster monster = null;
    Monster closestMonster = null;

    double closestDistance = 0;

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (!monster.getName().equals("Pig")
            && !monster.getName().equals("BlueThorn")
            && !monster.getName().equals("VineThorn")) {
          if (monster.getIsInPanel()) {
            double distance = p.distance(monster.getCenterPoint());
            if ((distance < closestDistance || closestDistance == 0) && distance <= r) {
              closestMonster = monster;
              closestDistance = distance;
            }
          }
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }

    return closestMonster;
  }
예제 #4
0
  private void removeMonster(String monsterType) {
    Monster monster = null;

    ArrayList deadMonsters = new ArrayList();

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (monster.getName().equals(monsterType)) {
          deadMonsters.add(key);
          break;
        }
      }

      if (deadMonsters.size() > 0) {
        for (int i = 0; i < deadMonsters.size(); i++) {
          // EIError.debugMsg((String) deadMonsters.get(i));
          monsters.remove((String) deadMonsters.get(i));
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }
  }
예제 #5
0
  public ArrayList<String> attackDamageAndKnockBack(
      Actor source,
      Arc2D.Double arc,
      Point mapPoint,
      int damage,
      int knockBackX,
      int knockBackY,
      int maxHits,
      String weaponType) {
    int dmg = 0;
    int hits = 0;
    Monster monster = null;
    ArrayList<String> monstersHit = new ArrayList<String>();

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);

        if (weaponType != null) {
          if (weaponType.equals("Net")) {
            damage = 1;
          }
        }

        dmg =
            monster.attackDamageAndKnockBack(
                source, arc, mapPoint, damage, knockBackX, knockBackY, weaponType);
        if (dmg > 0) {
          if (weaponType != null) {
            if (weaponType.equals("FangClaw")) {
              monster.poison(10);
            }
          }
          monstersHit.add(monster.getName());
          hits++;
        }
        if (hits >= maxHits) {
          break;
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }

    if (hits == 0) {
      if (source != null) {
        SoundClip cl = new SoundClip(registry, "Weapon/Miss", source.getCenterPoint());
      } else {
        SoundClip cl = new SoundClip("Weapon/Miss");
      }
    }

    return monstersHit;
  }
예제 #6
0
  private int getCountByType(String type) {
    int count = 0;
    Monster monster = null;

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (monster.getName().equals(type)) {
          count++;
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }

    return count;
  }
예제 #7
0
  public int getAnimalCount(Rectangle r) {
    int count = 0;
    Monster monster = null;

    try {
      for (String key : monsters.keySet()) {
        monster = (Monster) monsters.get(key);
        if (monster.getName().equals("Pig")) {
          if (monster.getSpriteRect().intersects(r)) {
            count++;
          }
        }
      }
    } catch (ConcurrentModificationException concEx) {
      // another thread was trying to modify monsters while iterating
      // we'll continue and the new item can be grabbed on the next update
    }

    return count;
  }
예제 #8
0
  private void spawnPlants() {
    if (gameController.multiplayerMode != gameController.multiplayerMode.CLIENT) {
      // Blue Thorns
      int blueThornCount = this.getCountByType("BlueThorn");
      if (blueThornCount < 200) {
        for (int i = 0; i < 200 - blueThornCount; i++) {
          boolean canSpawn = true;
          int level = Rand.getRange(1, 3);
          Point vinePosition = new Point();
          vinePosition.x = Rand.getRange(1, gameController.getMapWidth());
          vinePosition.y =
              Rand.getRange(
                  registry.getBlockManager().getLevelBottom(level),
                  registry.getBlockManager().getLevelTop(level));

          vinePosition.y = this.findNextFloor(vinePosition.x, vinePosition.y, 60);

          if (this.doesRectContainBlocks(vinePosition.x, vinePosition.y + 100, 17, 16)) {
            Monster monster = null;
            try {
              for (String key : monsters.keySet()) {
                monster = (Monster) monsters.get(key);
                if (monster.getName().equals("BlueThorn")
                    || monster.getName().equals("VineThorn")) {
                  double distance = vinePosition.distance(monster.getCenterPoint());
                  if (distance < 750) {
                    canSpawn = false;
                    break;
                  }
                }
              }
            } catch (ConcurrentModificationException concEx) {
              // another thread was trying to modify monsters while iterating
              // we'll continue and the new item can be grabbed on the next update
            }
            if (canSpawn) {
              spawn("BlueThorn", "Roaming", vinePosition.x, vinePosition.y);
            }
          }
        }
      }

      // Vine Thorns
      int vineThornCount = this.getCountByType("VineThorn");
      if (vineThornCount < 200) {
        for (int i = 0; i < 200 - vineThornCount; i++) {
          boolean canSpawn = true;
          int level = Rand.getRange(1, 3);
          Point vinePosition = new Point();
          vinePosition.x = Rand.getRange(1, gameController.getMapWidth());
          vinePosition.y =
              Rand.getRange(
                  registry.getBlockManager().getLevelBottom(level),
                  registry.getBlockManager().getLevelTop(level));

          vinePosition.y = this.findNextFloor(vinePosition.x, vinePosition.y, 60);

          if (this.doesRectContainBlocks(vinePosition.x, vinePosition.y + 100, 17, 16)) {
            Monster monster = null;
            try {
              for (String key : monsters.keySet()) {
                monster = (Monster) monsters.get(key);
                if (monster.getName().equals("BlueThorn")
                    || monster.getName().equals("VineThorn")) {
                  double distance = vinePosition.distance(monster.getCenterPoint());
                  if (distance < 750) {
                    canSpawn = false;
                    break;
                  }
                }
              }
            } catch (ConcurrentModificationException concEx) {
              // another thread was trying to modify monsters while iterating
              // we'll continue and the new item can be grabbed on the next update
            }
            if (canSpawn) {
              spawn("VineThorn", "Roaming", vinePosition.x, vinePosition.y);
            }
          }
        }
      }
    }
  }
예제 #9
0
  public void spawnNearPlayers() {
    Monster monster = null;
    float prob, rand;
    int count;
    HashMap<String, Player> players = registry.getPlayerManager().getPlayers();
    Player player = null;
    Integer spawnCoolDown = null;
    for (String key : players.keySet()) {
      player = (Player) players.get(key);

      // check for spawning Melvin
      if (registry.currentTime >= nextBossOrcSpawn && nextBossOrcSpawn != 0) {
        // to spawn melvin, player must have 40 AP, be within a range on the map and be on the
        // surface
        if (player.getMapX() >= 2000
            && player.getMapX() <= 5000
            && player.getLevel() >= 10
            && player.getMapY() == this.findFloor(player.getMapX())) {
          spawnBossOrc(player);
        }
      }

      if (spawnCoolDowns.containsKey(key)) {
        spawnCoolDown = spawnCoolDowns.get(key);
      } else {
        spawnCoolDown = new Integer(0);
        spawnCoolDowns.put(key, spawnCoolDown);
      }
      spawnCoolDown--;
      if (spawnCoolDown < 0) {
        int x = player.getMapX();
        int y = player.getMapY();
        int groundLevel = registry.getBlockManager().getLevelByY(y);
        count = -groundLevel;
        try {
          for (String key2 : monsters.keySet()) {
            monster = (Monster) monsters.get(key2);
            if (monster.getCenterPoint().distance(player.getCenterPoint())
                < MonsterManager.mobSpawnRangeMax * 3 / 2) {
              if (monster.getTouchDamage() > 0
                  && !monster.getName().equals("BlueThorn")
                  && !monster.getName().equals("VineThorn")) {
                count++;
              }
            }
          }
        } catch (ConcurrentModificationException concEx) {
          // another thread was trying to modify monsters while iterating
          // we'll continue and the new item can be grabbed on the next update
        }
        if (count < 4) {
          for (MonsterType monsterType : MonsterType.values()) {
            if (count < 4) {
              rand = Rand.getFloat();
              prob = getShouldSpawn(monsterType, groundLevel);
              if (prob > 0.0f) {
                if ((prob - count * spawnRatioDiff) > 0.005f) {
                  prob += -count * spawnRatioDiff;
                } else {
                  prob = 0.005f;
                }
              }
              if (rand <= prob) {
                // System.out.println("spawn near player " + monsterType.name());
                spawn(monsterType.name(), "Roaming", x, y);
                count++;
              }
            }
          }
        } else {
          // EIError.debugMsg("too many to spawn");
          spawnCoolDown = 20;
        }
      }
    }
  }