Beispiel #1
0
  /**
   * Pays out all players any accrued coins and records all player minutes and coin awards to this
   * game's activity log, potentially recalculating its payout factor as a result.
   */
  protected void flushAllPlayers() {
    int totalSecs = 0, totalTasks = 0, totalAward = 0;

    // pay out flow to all players, total up our coin awards and play time
    for (Player player : _players.values()) {
      final int playerSecs = player.timeAccrued + player.getPlayTime(now());
      totalSecs += playerSecs;
      totalTasks += player.tasksCompleted;
      if (player.coinsAccrued > 0) {
        final UserAction action =
            UserAction.playedGame(
                player.playerObject.getMemberId(), _content.game.name, _gameId, playerSecs);
        _gameReg.awardCoins(_gameId, action, player.coinsAccrued);
        totalAward += player.coinsAccrued;
      }
      player.reset();
    }

    // if we actually awarded coins or accrued time, update our game metrics
    if (totalAward > 0 || totalSecs > 0) {
      final int totalMins = Math.round(totalSecs / 60f);
      _gameReg.updateGameMetrics(
          _content.metrics, GameGameRegistry.MetricType.AVRG, totalMins, totalTasks, totalAward);
    }
  }
Beispiel #2
0
  /**
   * Pays accumulated coins to the supplied player and potentially recalculates our payout factor if
   * this player's payout consumes the last of our coin budget.
   */
  protected void payoutPlayer(final Player player, boolean flushing) {
    final int memberId = player.playerObject.getMemberId();
    final int playerSecs = player.timeAccrued + player.getPlayTime(now());
    final int playerMins = Math.round(playerSecs / 60f);

    if (!flushing) {
      // TODO: Get this into EventLogDelegate, or write a AVRG-specific one?
      if (player.playerObject.visitorInfo == null) {
        log.warning("No VisitorInfo for AVRG player!", "gameId", _gameId, "memberId", memberId);
      }
      _eventLog.avrgLeft(
          memberId,
          _gameId,
          playerSecs,
          _plmgr.getPlaceObject().occupantInfo.size(),
          player.playerObject.getVisitorId());
    }

    // if they accrued any coins (and are not a guest), do the actual coin awarding
    if (player.coinsAccrued > 0) {
      final UserAction action =
          UserAction.playedGame(memberId, _content.game.name, _gameId, playerSecs);
      _gameReg.awardCoins(_gameId, action, player.coinsAccrued);
    }

    // note time played and coins awarded for coin payout factor calculation purposes
    if (playerMins > 0 || player.coinsAccrued > 0) {
      _gameReg.updateGameMetrics(
          _content.metrics,
          GameGameRegistry.MetricType.AVRG,
          playerMins,
          player.tasksCompleted,
          player.coinsAccrued);
    }

    // reset their accumulated coins and whatnot
    player.reset();
  }