Package com.deco2800.game.services
Class AchievementHandler
java.lang.Object
com.deco2800.game.services.AchievementHandler
Service for handling the loading, updating and saving of game achievements
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringEvent string for regular achievement completionstatic final StringEvent string for boss killstatic final StringEvent string for building placementstatic final StringEvent string for if crystal takes damagestatic final StringEvent string for crystal upgradestatic final StringEvent string for enemies killedstatic final StringEvent string for if the game was wonstatic final StringEvent string for when the guidebook is closed emitted by GuidebookScreenstatic final StringEvent string for structure placementstatic final StringEvent string for resources being addedstatic final StringEvent string for items bought in the shopstatic final StringEvent string for stat achievement completionstatic final intDefault stat achievement first levelstatic final intDefault stat achievement second levelstatic final intDefault stat achievement third levelstatic final intDefault stat achievement forth level -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if all achievements have been completedbooleanChecks if all achievements of a specific type are completedvoidcheckAchievementStatus(long id) Checks if an achievement has previously been completed, completes it if notvoidcheckOneNight(int dayNum) voidcheckStatAchievementMilestones(Achievement achievement) Specific to Stat achievements.voidConnects listeners for popup notification widgetgetAchievementById(int id) Returns an achievement based on its idGetter method for the achievement listGetter method for returning the events from AchievementHandlerintgetMilestoneTotal(Achievement achievement, int milestoneNumber) Gets the total to achieve for a milestonevoidincrementOneRunAchievement(int id) Increments the one run achievement totalvoidincrementTotalAchievedForStatAchievement(Achievement achievement, int increase) Correct updates the total achieved for a stat achievement.booleanisMilestoneAchieved(Achievement achievement, int milestoneNumber) Checks whether a milestone has been achieved for an achievement given a milestone number (1, 2,3,4)loadAchievements(com.badlogic.gdx.files.FileHandle fileHandle) Loads the achievement list from the achievement filevoidmarkAchievementCompletedById(long id, boolean broadcast) Marks an achievement completedvoidonTempStructurePlaced(String name) Triggered when a structure is placed on the map.voidresetOneRunAchievements(boolean won) Resets progress of achievements that need to be completed in a single run of the game.voidSaves the current state of the achievement list with the current timevoidSends popups that couldn't be shown when game screen was swapped.voidupdateStatAchievementByType(AchievementType type, int increase) Basic method to update the stat type achievements when changes are made to the game state.
-
Field Details
-
EVENT_CRYSTAL_DAMAGED
Event string for if crystal takes damage- See Also:
-
EVENT_GAME_WON
Event string for if the game was won- See Also:
-
EVENT_SHOP_ITEM_BOUGHT
Event string for items bought in the shop- See Also:
-
EVENT_BOSS_KILL
Event string for boss kill- See Also:
-
EVENT_CRYSTAL_UPGRADED
Event string for crystal upgrade- See Also:
-
EVENT_BUILDING_PLACED
Event string for building placement- See Also:
-
EVENT_ON_TEMP_STRUCTURE_PLACED
Event string for structure placement- See Also:
-
EVENT_ENEMY_KILLED
Event string for enemies killed- See Also:
-
EVENT_GUIDEBOOK_CLOSED
Event string for when the guidebook is closed emitted by GuidebookScreen- See Also:
-
EVENT_RESOURCE_ADDED
Event string for resources being added- See Also:
-
EVENT_STAT_ACHIEVEMENT_MADE
Event string for stat achievement completion- See Also:
-
EVENT_ACHIEVEMENT_MADE
Event string for regular achievement completion- See Also:
-
STAT_ACHIEVEMENT_1_MILESTONE
public static final int STAT_ACHIEVEMENT_1_MILESTONEDefault stat achievement first level- See Also:
-
STAT_ACHIEVEMENT_10_MILESTONE
public static final int STAT_ACHIEVEMENT_10_MILESTONEDefault stat achievement second level- See Also:
-
STAT_ACHIEVEMENT_25_MILESTONE
public static final int STAT_ACHIEVEMENT_25_MILESTONEDefault stat achievement third level- See Also:
-
STAT_ACHIEVEMENT_50_MILESTONE
public static final int STAT_ACHIEVEMENT_50_MILESTONEDefault stat achievement forth level- See Also:
-
-
Constructor Details
-
AchievementHandler
public AchievementHandler()Initialise the achievement handler. Uses default achievements if no achievement file already exists
-
-
Method Details
-
connectPopupListeners
public void connectPopupListeners()Connects listeners for popup notification widget -
triggerOnLoadPopups
public void triggerOnLoadPopups()Sends popups that couldn't be shown when game screen was swapped. -
getAchievements
Getter method for the achievement list- Returns:
- List
-
getEvents
Getter method for returning the events from AchievementHandler- Returns:
- EventHandler
-
saveAchievements
public void saveAchievements()Saves the current state of the achievement list with the current time -
loadAchievements
Loads the achievement list from the achievement file- Returns:
- ArrayList
-
onTempStructurePlaced
Triggered when a structure is placed on the map. When all structures that are available in the game have been placed then the achievement is complete- Parameters:
name- name of structure placed.
-
updateStatAchievementByType
Basic method to update the stat type achievements when changes are made to the game state.- Parameters:
type- AchievementType
-
incrementTotalAchievedForStatAchievement
Correct updates the total achieved for a stat achievement. checks if a milestone is reached and broadcasts message- Parameters:
achievement- the stat achievementincrease- amount to increase by
-
checkStatAchievementMilestones
Specific to Stat achievements. Check whether a new achievement milestone is reached and broadcasts it. If the last milestone is reached all achievements for that stat have been achieved.- Parameters:
achievement- the stat achievement
-
isMilestoneAchieved
Checks whether a milestone has been achieved for an achievement given a milestone number (1, 2,3,4)- Parameters:
achievement- the achievement to checkmilestoneNumber- the milestone number to check- Returns:
- true if milestone has been achieved false otherwise
-
getMilestoneTotal
Gets the total to achieve for a milestone- Parameters:
achievement- the achievement to get the total for the milestone formilestoneNumber- the milestone number- Returns:
- total for the milestone
-
checkAchievementStatus
public void checkAchievementStatus(long id) Checks if an achievement has previously been completed, completes it if not- Parameters:
id- long
-
markAchievementCompletedById
public void markAchievementCompletedById(long id, boolean broadcast) Marks an achievement completed- Parameters:
id- the id of the abroadcast- whether to broadcast a completion message true if so false otherwise
-
getAchievementById
Returns an achievement based on its id- Parameters:
id- int- Returns:
- Achievement if it exists, null otherwise
-
allCompletedOfType
Checks if all achievements of a specific type are completed- Parameters:
type- AchievementType- Returns:
- boolean
-
allCompleted
public boolean allCompleted()Checks if all achievements have been completed- Returns:
- boolean
-
resetOneRunAchievements
public void resetOneRunAchievements(boolean won) Resets progress of achievements that need to be completed in a single run of the game. -
incrementOneRunAchievement
public void incrementOneRunAchievement(int id) Increments the one run achievement total- Parameters:
id- int
-
checkOneNight
public void checkOneNight(int dayNum)
-