Class AchievementHandler

java.lang.Object
com.deco2800.game.services.AchievementHandler

public class AchievementHandler extends Object
Service for handling the loading, updating and saving of game achievements
  • Field Details

    • EVENT_CRYSTAL_DAMAGED

      public static final String EVENT_CRYSTAL_DAMAGED
      Event string for if crystal takes damage
      See Also:
    • EVENT_GAME_WON

      public static final String EVENT_GAME_WON
      Event string for if the game was won
      See Also:
    • EVENT_SHOP_ITEM_BOUGHT

      public static final String EVENT_SHOP_ITEM_BOUGHT
      Event string for items bought in the shop
      See Also:
    • EVENT_BOSS_KILL

      public static final String EVENT_BOSS_KILL
      Event string for boss kill
      See Also:
    • EVENT_CRYSTAL_UPGRADED

      public static final String EVENT_CRYSTAL_UPGRADED
      Event string for crystal upgrade
      See Also:
    • EVENT_BUILDING_PLACED

      public static final String EVENT_BUILDING_PLACED
      Event string for building placement
      See Also:
    • EVENT_ON_TEMP_STRUCTURE_PLACED

      public static final String EVENT_ON_TEMP_STRUCTURE_PLACED
      Event string for structure placement
      See Also:
    • EVENT_ENEMY_KILLED

      public static final String EVENT_ENEMY_KILLED
      Event string for enemies killed
      See Also:
    • EVENT_GUIDEBOOK_CLOSED

      public static final String EVENT_GUIDEBOOK_CLOSED
      Event string for when the guidebook is closed emitted by GuidebookScreen
      See Also:
    • EVENT_RESOURCE_ADDED

      public static final String EVENT_RESOURCE_ADDED
      Event string for resources being added
      See Also:
    • EVENT_STAT_ACHIEVEMENT_MADE

      public static final String EVENT_STAT_ACHIEVEMENT_MADE
      Event string for stat achievement completion
      See Also:
    • EVENT_ACHIEVEMENT_MADE

      public static final String EVENT_ACHIEVEMENT_MADE
      Event string for regular achievement completion
      See Also:
    • STAT_ACHIEVEMENT_1_MILESTONE

      public static final int STAT_ACHIEVEMENT_1_MILESTONE
      Default stat achievement first level
      See Also:
    • STAT_ACHIEVEMENT_10_MILESTONE

      public static final int STAT_ACHIEVEMENT_10_MILESTONE
      Default stat achievement second level
      See Also:
    • STAT_ACHIEVEMENT_25_MILESTONE

      public static final int STAT_ACHIEVEMENT_25_MILESTONE
      Default stat achievement third level
      See Also:
    • STAT_ACHIEVEMENT_50_MILESTONE

      public static final int STAT_ACHIEVEMENT_50_MILESTONE
      Default 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

      public List<Achievement> getAchievements()
      Getter method for the achievement list
      Returns:
      List
    • getEvents

      public EventHandler 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

      public List<Achievement> loadAchievements(com.badlogic.gdx.files.FileHandle fileHandle)
      Loads the achievement list from the achievement file
      Returns:
      ArrayList
    • onTempStructurePlaced

      public void onTempStructurePlaced(String name)
      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

      public void updateStatAchievementByType(AchievementType type, int increase)
      Basic method to update the stat type achievements when changes are made to the game state.
      Parameters:
      type - AchievementType
    • incrementTotalAchievedForStatAchievement

      public void incrementTotalAchievedForStatAchievement(Achievement achievement, int increase)
      Correct updates the total achieved for a stat achievement. checks if a milestone is reached and broadcasts message
      Parameters:
      achievement - the stat achievement
      increase - amount to increase by
    • checkStatAchievementMilestones

      public void checkStatAchievementMilestones(Achievement achievement)
      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

      public boolean isMilestoneAchieved(Achievement achievement, int milestoneNumber)
      Checks whether a milestone has been achieved for an achievement given a milestone number (1, 2,3,4)
      Parameters:
      achievement - the achievement to check
      milestoneNumber - the milestone number to check
      Returns:
      true if milestone has been achieved false otherwise
    • getMilestoneTotal

      public int getMilestoneTotal(Achievement achievement, int milestoneNumber)
      Gets the total to achieve for a milestone
      Parameters:
      achievement - the achievement to get the total for the milestone for
      milestoneNumber - 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 a
      broadcast - whether to broadcast a completion message true if so false otherwise
    • getAchievementById

      public Achievement getAchievementById(int id)
      Returns an achievement based on its id
      Parameters:
      id - int
      Returns:
      Achievement if it exists, null otherwise
    • allCompletedOfType

      public boolean allCompletedOfType(AchievementType type)
      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)