Ejemplo n.º 1
0
 @Override
 public EbRegistration getMyRegistration(Game p_game) {
   EbRegistration registration = p_game.getRegistration(getRegistrationId());
   if (registration != null) {
     return registration;
   }
   return super.getMyRegistration(p_game);
 }
Ejemplo n.º 2
0
 /* (non-Javadoc)
  * @see com.fullmetalgalaxy.model.persist.AnAction#exec()
  */
 @Override
 public void exec(Game p_game) throws RpcFmpException {
   super.exec(p_game);
   EbRegistration registration = getMyRegistration(p_game);
   if (registration != null) {
     registration.setPtAction(registration.getPtAction() - getCost());
     // registration.setLastUpdate( getLastUpdate() );
     if (p_game.isParallel()) {
       registration.getTeam(p_game).setLockedPosition(getLockedPosition());
       registration
           .getTeam(p_game)
           .setEndTurnDate(
               new Date(
                   SharedMethods.currentTimeMillis()
                       + p_game.getEbConfigGameTime().getLockGameInMillis()));
     }
   }
 }
Ejemplo n.º 3
0
 /**
  * @param p_game game to apply event
  * @return the tokenDestroyer2
  */
 public EbToken getTokenDestroyer2(Game p_game) {
   if (m_tokenDestroyer2 == null && getPackedTokenDestroyer2() != null) {
     m_tokenDestroyer2 = p_game.getToken(getPackedTokenDestroyer2().getId());
   }
   return m_tokenDestroyer2;
 }
Ejemplo n.º 4
0
 /**
  * @param p_game game to apply event
  * @return the newTokenCarrier
  */
 public EbToken getNewTokenCarrier(Game p_game) {
   if (m_newTokenCarrier == null && getPackedNewTokenCarrier() != null) {
     m_newTokenCarrier = p_game.getToken(getPackedNewTokenCarrier().getId());
   }
   return m_newTokenCarrier;
 }
Ejemplo n.º 5
0
 /**
  * @param p_game game to apply event
  * @return the token
  */
 public EbToken getToken(Game p_game) {
   if (m_token == null && getPackedToken() != null) {
     m_token = p_game.getToken(getPackedToken().getId());
   }
   return m_token;
 }
Ejemplo n.º 6
0
  /* (non-Javadoc)
   * @see com.fullmetalgalaxy.model.persist.AnAction#check()
   */
  @Override
  public void check(Game p_game) throws RpcFmpException {
    super.check(p_game);
    if (isAuto()) {
      // if event is auto generated, assume everything are correct
      return;
    }
    EbRegistration myRegistration = getMyRegistration(p_game);
    if (myRegistration == null) {
      // no i18n ?
      throw new RpcFmpException("you didn't join this game.", this);
    }
    if (myRegistration.getPtAction() < getCost() && p_game.getGameType() != GameType.Practice) {
      throw new RpcFmpException(errMsg().NotEnouthActionPt(), this);
    }
    if ((!p_game.isParallel() || (p_game.getCurrentTimeStep() <= 1))
        && (!p_game.getCurrentPlayerIds().contains(myRegistration.getId()))
        && p_game.getGameType() != GameType.Practice) {
      throw new RpcFmpException(errMsg().NotYourTurn(), this);
    }
    if ((p_game.getStatus() == GameStatus.Open || p_game.getStatus() == GameStatus.Pause)
        && p_game.getGameType() != GameType.Practice) {
      throw new RpcFmpException(errMsg().gameNotStarted(), this);
    }

    if (p_game.isParallel()
        && p_game.getCurrentTimeStep() > p_game.getEbConfigGameTime().getDeploymentTimeStep()) {
      EbTeam team =
          p_game.getOtherTeamBoardLocked(
              myRegistration, getLockedPosition(), SharedMethods.currentTimeMillis());
      if (team != null) {
        throw new RpcFmpException(errMsg().boardLocked(), this);
      }
    }
  }
Ejemplo n.º 7
0
  @Override
  public ModelFmpInit loadGame(InputStream p_input) {
    Game game = new Game();
    game.setName("upload");
    game.setPlanetType(PlanetType.Desert);
    game.setConfigGameTime(ConfigGameTime.Standard);
    game.setMaxNumberOfPlayer(4);

    String str = readln(p_input);
    if (str == null || !str.startsWith("<FMP Format=4 Version=\"2.3.7")) {
      LOG.error("Bad format");
      return null;
    }
    // lecture de la carte
    str = readln(p_input);
    if (str == null || !str.startsWith("<CARTE Lignes=")) {
      LOG.error("<CARTE Lignes= not found");
      return null;
    }
    int height = Integer.parseInt(str.substring(14, 16));
    int width = Integer.parseInt(str.substring(26, 28));
    game.setLandSize(width, height);
    for (int iy = 0; iy < height; iy++) {
      str = readln(p_input);
      for (int ix = 0; ix < width; ix++) {
        switch (str.charAt(ix)) {
          case '.':
            game.setLand(ix, iy, LandType.Sea);
            break;
          case '*':
            game.setLand(ix, iy, LandType.Reef);
            break;
          case '%':
            game.setLand(ix, iy, LandType.Marsh);
            break;
          case '$':
            game.setLand(ix, iy, LandType.Plain);
            break;
          case '#':
            game.setLand(ix, iy, LandType.Montain);
            break;
          case '?':
          default:
            game.setLand(ix, iy, LandType.None);
            break;
        }
      }
    }
    str = readln(p_input);
    if (str == null || !str.startsWith("</CARTE>")) {
      LOG.error("</CARTE> not found");
    }
    // lecture des minerais
    str = readln(p_input);
    if (str != null && str.startsWith("<REPARTITION Lignes=")) {
      height = Integer.parseInt(str.substring(20, 22));
      width = Integer.parseInt(str.substring(32, 34));
      for (int iy = 0; iy < height; iy++) {
        str = readln(p_input);
        for (int ix = 0; ix < width; ix++) {
          if (str.charAt(ix) != '.') {
            EbToken token = new EbToken(TokenType.Ore);
            game.addToken(token);
            game.moveToken(token, new AnBoardPosition(ix, iy));
          }
        }
      }
      str = readln(p_input);
      if (str == null || !str.startsWith("</REPARTITION>")) {
        LOG.error("</REPARTITION> not found");
      }
    }

    try {
      p_input.close();
    } catch (IOException e) {
      LOG.error(e);
    }

    return game2Model(game);
  }