Commit a56353bf authored by Drahomír Karchňák's avatar Drahomír Karchňák

#493 New game label in game menu pages for newly addded games. Also refactored...

#493 New game label in game menu pages for newly addded games. Also refactored RankProcessingScripts...
parent 1a90e24d
......@@ -52,6 +52,8 @@ victoryscreen_button_changegame=Jinou hru
victoryscreen_text_tutorial=Gratuluji! A teď to zkus sám…
victoryscreen_new_trophy=Získáváš trofej!
game_status_new=Nová hra
game_score=Počet bodů:
game_score_error=Počet chyb:
game_score_duration=Trvání hry:
......
......@@ -52,6 +52,8 @@ victoryscreen_button_changegame=Anderes Spiel
victoryscreen_text_tutorial=Gratulation! Und nun versuch es selbst…
victoryscreen_new_trophy=Du erhältst eine Trophäe!
game_status_new=Neues Spiel
game_score=Punktezahl:
game_score_error=Fehlerzahl:
game_score_duration=Spieldauer:
......
......@@ -54,6 +54,8 @@ victoryscreen_button_changegame=Inú hru
victoryscreen_text_tutorial=Gratulujem! A teraz to skús sám…
victoryscreen_new_trophy=Získavaš trofej!
game_status_new=Nová hra
game_score=Počet bodov\:
game_score_error=Počet chýb\:
game_score_duration=Trvanie hry\:
......
......@@ -17,7 +17,9 @@
package cz.nic.tablexia.game.ranksystem;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
......@@ -32,47 +34,40 @@ import cz.nic.tablexia.shared.model.User;
* Created by drahomir on 8/11/16.
*/
public enum RankProcessingScript {
BEFORE_3_3(
Game.BACK_COMPATIBILITY_321_RANK_SYSTEM_VERSION_CODE, //RankProcessingScript Version
new GameDefinition[] { //Games in this version
GameDefinition.ROBBERY,
GameDefinition.PURSUIT,
GameDefinition.KIDNAPPING,
GameDefinition.NIGHT_WATCH,
GameDefinition.SHOOTING_RANGE,
GameDefinition.IN_THE_DARKNESS
}
),
V3_3(2) { //RankProcessingScript Version - DO NOT CHANGE THIS!
@Override
protected void beforeRankCompute(User user, UserRankManager.RankComputeData rankComputeData, List<Game> games) {
UserRankManager.UserRank prevRank = UserRankManager.UserRank.getPreviousRank(rankComputeData.getCurrentRank());
UserRankManager.UserRank nextRank = rankComputeData.getNextRank();
rankComputeData.getRankProgress(GameDefinition.RUNES.getGameNumber()).setMinXP(prevRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(GameDefinition.RUNES.getGameNumber()).setCurrXP(prevRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(GameDefinition.RUNES.getGameNumber()).setNextXP(nextRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(GameDefinition.CRIME_SCENE.getGameNumber()).setMinXP(prevRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(GameDefinition.CRIME_SCENE.getGameNumber()).setCurrXP(prevRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(GameDefinition.CRIME_SCENE.getGameNumber()).setNextXP(nextRank.getExperiencePointsNeeded());
BEFORE_3_3(Game.BACK_COMPATIBILITY_321_RANK_SYSTEM_VERSION_CODE),
V3_3(
2,
new GameDefinition[] { //New games for V3.3
GameDefinition.RUNES,
GameDefinition.CRIME_SCENE
}
}; //All versions
);
/**
* Games that were part of the game before additionally added games
*/
private static final GameDefinition[] ORIGINAL_GAMES = {
GameDefinition.ROBBERY,
GameDefinition.PURSUIT,
GameDefinition.KIDNAPPING,
GameDefinition.NIGHT_WATCH,
GameDefinition.SHOOTING_RANGE,
GameDefinition.IN_THE_DARKNESS
};
private final int scriptVersion;
private final GameDefinition[] games;
//Games that are already in the game. Need to fill progress to 100 percent for each of these to rank up.
private GameDefinition[] includedGames;
private GameDefinition[] newGames;
RankProcessingScript(int scriptVersion) {
this(scriptVersion, GameDefinition.values());
this(scriptVersion, null);
}
RankProcessingScript(int scriptVersion, GameDefinition[] games) {
RankProcessingScript(int scriptVersion, GameDefinition[] newGames) {
this.scriptVersion = scriptVersion;
this.games = games;
}
public interface RankGamesRetriever {
List<Game> getGames(User user, RankProcessingScript rankProcessingScript);
this.newGames = newGames;
}
public static RankProcessingScript getCurrentRankProcessingScript() {
......@@ -87,6 +82,27 @@ public enum RankProcessingScript {
return result;
}
/**
* Included games include Original games + new games of this script + new games of every older script.
*/
private void prepareIncludedGames() {
List<GameDefinition> includedGamesList = new ArrayList<GameDefinition>();
Collections.addAll(includedGamesList, ORIGINAL_GAMES);
if(hasNewGames()) Collections.addAll(includedGamesList, newGames);
for(RankProcessingScript script : values()) {
if(this.getScriptVersion() > script.getScriptVersion() && script.hasNewGames()) {
Collections.addAll(includedGamesList, script.getNewGames());
}
}
includedGames = includedGamesList.toArray(new GameDefinition[includedGamesList.size()]);
}
public interface RankGamesRetriever {
List<Game> getGames(User user, RankProcessingScript rankProcessingScript);
}
/**
* Basically iterates through all the games and calculates users rank using defined enum values above.
* The result of this method is instance of RankComputeData class, which stores all the necessary stuff
......@@ -118,29 +134,55 @@ public enum RankProcessingScript {
return scriptVersion;
}
public boolean hasNewGames() {
return newGames != null && newGames.length > 0;
}
public GameDefinition[] getNewGames() {
return newGames;
}
private static int getExperiencePoints(int cupsCount, GameDifficulty difficulty) {
return cupsCount * difficulty.getExperiencePointsMultiplier();
}
protected void runRankProcessingScript(User user, RankGamesRetriever gamesRetriever, UserRankManager.RankComputeData rankComputeData) {
private void runRankProcessingScript(User user, RankGamesRetriever gamesRetriever, UserRankManager.RankComputeData rankComputeData) {
if(includedGames == null) prepareIncludedGames();
List<Game> games = prepareGames(user, gamesRetriever);
beforeRankCompute(user, rankComputeData, games);
beforeRankCompute(rankComputeData, games);
for(Game game : games) {
forEachGame(user, rankComputeData, game);
forEachGame(rankComputeData, game);
}
afterRankCompute(user, rankComputeData);
afterRankCompute(rankComputeData);
}
protected List<Game> prepareGames(User user, RankGamesRetriever gamesRetriever) {
private List<Game> prepareGames(User user, RankGamesRetriever gamesRetriever) {
return gamesRetriever.getGames(user, this);
}
protected void beforeRankCompute(User user, UserRankManager.RankComputeData rankComputeData, List<Game> games) {}
private void beforeRankCompute(UserRankManager.RankComputeData rankComputeData, List<Game> games) {
//Has user played any previous versions of the game ?
if(this != getCurrentRankProcessingScript() && games.size() > 0) rankComputeData.setNewUser(false);
UserRankManager.UserRank prevRank = UserRankManager.UserRank.getPreviousRank(rankComputeData.getCurrentRank());
UserRankManager.UserRank nextRank = rankComputeData.getNextRank();
if(hasNewGames()) {
for(GameDefinition game : getNewGames()) {
rankComputeData.getRankProgress(game.getGameNumber()).setMinXP(prevRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(game.getGameNumber()).setCurrXP(prevRank.getExperiencePointsNeeded());
rankComputeData.getRankProgress(game.getGameNumber()).setNextXP(nextRank.getExperiencePointsNeeded());
rankComputeData.setNewGame(game, true);
}
}
}
protected void forEachGame(User user, UserRankManager.RankComputeData rankComputeData, Game game) {
private void forEachGame(UserRankManager.RankComputeData rankComputeData, Game game) {
if(!game.isFinished()) return;
if(game.getGameDifficulty() == GameDifficulty.TUTORIAL.getDifficultyNumber()) return;
......@@ -155,18 +197,18 @@ public enum RankProcessingScript {
rankComputeData.getRankProgress(gameNumber).capRankProgress();
//Checking if user ranked up after this game
if(checkUserRankUp(user, rankComputeData, game))
onRankUp(user, rankComputeData, game);
if(checkUserRankUp(rankComputeData))
onRankUp(rankComputeData, game);
}
protected boolean checkUserRankUp(User user, UserRankManager.RankComputeData rankComputeData, Game game) {
for(GameDefinition gameDefinition : games) {
private boolean checkUserRankUp(UserRankManager.RankComputeData rankComputeData) {
for(GameDefinition gameDefinition : includedGames) {
if(!rankComputeData.getRankProgress(gameDefinition.getGameNumber()).isComplete()) return false;
}
return true;
}
protected void onRankUp(User user, UserRankManager.RankComputeData rankComputeData, Game game) {
private void onRankUp(UserRankManager.RankComputeData rankComputeData, Game game) {
rankComputeData.setCurrentRank(rankComputeData.getNextRank());
rankComputeData.setNextRank(UserRankManager.UserRank.getNextRank(rankComputeData.getCurrentRank()));
rankComputeData.setLastRankUp(game.getEndTime());
......@@ -175,9 +217,12 @@ public enum RankProcessingScript {
rankProgresses.minXP = rankComputeData.getCurrentRank().getExperiencePointsNeeded();
rankProgresses.nextXP = rankComputeData.getNextRank().getExperiencePointsNeeded();
}
rankComputeData.clearNewGames();
}
protected void afterRankCompute(User user, UserRankManager.RankComputeData rankComputeData) {
private void afterRankCompute(UserRankManager.RankComputeData rankComputeData) {
//If user is at last rank
if(rankComputeData.getCurrentRank() == rankComputeData.getNextRank()) {
for(UserRankManager.RankProgress rankProgress : rankComputeData.getRankProgresses()) {
rankProgress.setCurrXP(rankProgress.getNextXP());
......
......@@ -177,12 +177,16 @@ public class UserRankManager {
private RankProgress[] rankProgresses;
private Long lastRankUp;
private boolean newUser = true;
private boolean[] newGames;
public RankComputeData() {
currentRank = UserRankManager.UserRank.RANK_NONE;
nextRank = UserRankManager.UserRank.getNextRank(currentRank);
lastRankUp = 0L;
initializeRankProgresses();
initializeNewGames();
}
private void initializeRankProgresses() {
......@@ -194,6 +198,33 @@ public class UserRankManager {
}
}
private void initializeNewGames() {
this.newGames = new boolean[GameDefinition.values().length];
clearNewGames();
}
public void clearNewGames() {
for(int i = 0; i < newGames.length; i++) {
newGames[i] = false;
}
}
public void setNewGame(GameDefinition gameDefinition, boolean value) {
this.newGames[gameDefinition.getGameNumber() - 1] = value;
}
public void setNewUser(boolean newUser) {
this.newUser = newUser;
}
public boolean isNewGame(GameDefinition gameDefinition) {
return !isNewUser() && newGames[gameDefinition.getGameNumber() - 1];
}
public boolean isNewUser() {
return newUser;
}
public Long getLastRankUp() {
return lastRankUp;
}
......@@ -303,6 +334,10 @@ public class UserRankManager {
return rankComputeDataMap.get(user.getId()).lastRankUp;
}
public boolean isNewGameForUser(User user, GameDefinition gameDefinition) {
return rankComputeDataMap.get(user.getId()).isNewGame(gameDefinition);
}
public synchronized void forceRefreshUserRank(User user) {
setRankRefreshNeeded(user, true);
refreshUserRank(user);
......
......@@ -100,6 +100,8 @@ public class ApplicationTextManager extends TablexiaDataManager<I18NBundle> impl
public static final String GAME_AVERAGE_SCORE_DURATION = "game_averagescore_duration";
public static final String GAME_QUIT_QUESTION = "game_quit_question";
public static final String GAME_STATUS_NEW = "game_status_new";
public static final String SOUND_MUTED_QUESTION = "sound_muted_question";
public static final String SOUND_MUTED_GAME_QUESTION = "sound_muted_game_question";
......
......@@ -27,6 +27,7 @@ import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.ranksystem.UserRankManager;
import cz.nic.tablexia.loader.application.ApplicationFontManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.UserDifficultySettingsDAO;
import cz.nic.tablexia.screen.gamemenu.GameMenuAssets;
import cz.nic.tablexia.screen.gamemenu.GameMenuScreen;
......@@ -98,6 +99,9 @@ public class GameMenuPage extends MenuPage {
//Progress status font
private static final ApplicationFontManager.FontType_NEW PROGRESS_STATUS_FONT = ApplicationFontManager.FontType_NEW.BOLD_18;
//Progress status font
private static final ApplicationFontManager.FontType_NEW NEW_GAME_STATUS_FONT = ApplicationFontManager.FontType_NEW.BOLD_18;
private GameDefinition game;
private GameMenuScreen.GameMenuPageDefinition gameMenuPageDefinition;
......@@ -477,6 +481,13 @@ public class GameMenuPage extends MenuPage {
addActor(gameMenuPageProgress);
addActor(progressLabel);
//New Game
if(UserRankManager.getInstance().isNewGameForUser(TablexiaSettings.getInstance().getSelectedUser(), game)) {
TablexiaLabel newGameLabel = new TablexiaLabel(ApplicationTextManager.getInstance().getText(ApplicationTextManager.ApplicationTextsAssets.GAME_STATUS_NEW), new TablexiaLabel.TablexiaLabelStyle(NEW_GAME_STATUS_FONT, Color.BLACK));
newGameLabel.setPosition(progressLabel.getX() + progressLabel.getWidth(), progressLabel.getY());
addActor(newGameLabel);
}
}
public void updateGameProgress() {
......
......@@ -51,7 +51,8 @@ public class AverageScoreTest {
1,
TablexiaSettings.BuildType.DEBUG.getId(),
TablexiaSettings.Platform.DESKTOP.getId(),
"Serial");
"Serial",
Game.BACK_COMPATIBILITY_321_RANK_SYSTEM_VERSION_CODE);
game.setGameScoreMap(scores);
games.add(game);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment