Пример #1
0
  public static void loadPlayer(Registry registry) {
    Player p = (Player) getPlayers().get(player);
    if (p != null) {
      p.setTransient(registry);
    }

    GameController gc = registry.getGameController();
    registry.getPlayerManager().clearPlayers();
    registry.getPlayerManager().registerPlayer(p);
    BlockManager bm = (BlockManager) blockManagers.get(player);
    bm.name = "Saved";
    bm = (BlockManager) bm.clone();
    bm.name = "Clone";
    bm.setTransient(registry);
    gc.setBlockManager(bm);
    PlaceableManager pm = (PlaceableManager) placeableManagers.get(player).clone();
    gc.setPlaceableManager(pm);
    MonsterManager mm = (MonsterManager) monsterManagers.get(player).clone();
    mm.setTransient(registry);
    gc.setMonsterManager(mm);

    if (p != null) {
      p.resetPlayer();
    }

    // unloadUnused();
  }
Пример #2
0
 public boolean spawnSnailRider(Player player) {
   if (getSpawnCount("SnailRider") < 1) {
     registry.showMessage("Success", "Suddenly, a wild Snail Rider appears!");
     spawn("SnailRider", "Roaming", player.getMapX(), player.getMapY());
     return true;
   }
   return false;
 }
Пример #3
0
 public boolean spawnBossOrc(Player player) {
   if (getSpawnCount("BossOrc") < 1) {
     registry.showMessage("Success", "Beware, Melvin lurks nearby...");
     spawn("BossOrc", "Roaming", player.getMapX(), player.getMapY());
     return true;
   }
   return false;
 }
Пример #4
0
  //    public static void unloadUnused() {
  //        if (player > -1) {
  //            for (int i = 0; i < NUMBER_OF_PLAYER_SLOTS; i++) {
  //                if (i != player) {
  //                    players.set(i, null);
  //                    blockManagers.set(i, null);
  //                    placeableManagers.set(i, null);
  //                    monsterManagers.set(i, null);
  //                }
  //            }
  //        }
  //    }
  public static ArrayList getPlayerList() {
    ArrayList names = new ArrayList();

    for (int i = 0; i < players.size(); i++) {
      Player p = players.get(i);
      if (p != null) {
        names.add(p.getName());
      } else {
        names.add("");
      }
    }
    return names;
  }
Пример #5
0
  public void spawnNearPlaceable() {
    float prob, rand;
    Placeable placeable = registry.getPlaceableManager().getRandomPlacable();
    if (placeable != null
        && !placeable.getType().equals("TownHall")
        && !placeable.getType().equals("Cabin")
        && !placeable.getType().equals("Chest")) {

      Point p = placeable.getCenterPoint();
      HashMap<String, Player> players = registry.getPlayerManager().getPlayers();
      Player player = null;
      boolean playerNear = false;
      for (String key : players.keySet()) {
        player = (Player) players.get(key);
        Point p2 = new Point(player.getMapX(), player.getMapY());
        if (p.distance(p2) < mobSpawnRangeMin * 2) {
          playerNear = true;
        }
      }
      if (!playerNear) {
        for (MonsterType monsterType : MonsterType.values()) {
          if (monsterType.toString().equals("Porcupine")
              || monsterType.toString().equals("Snail")
              || monsterType.toString().equals("Snake")
              || monsterType.toString().equals("ZombieWalrus")) {
            rand = Rand.getFloat();
            prob = getShouldSpawn(monsterType, 0);
            if (rand <= prob / 3.0f) {
              // System.out.println("spawn near placeable " + monsterType.name());
              spawn(monsterType.name(), "Roaming", p.x, p.y);
            }
          }
        }
      }
    }
  }
Пример #6
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;
        }
      }
    }
  }