Skip to content

Commit

Permalink
Achievements Pull Request (#10)
Browse files Browse the repository at this point in the history
* Changes from ~2 days ago:
- Began working on structuring the API for achievements.

* Changes from ~2 days ago:
- Began working on structuring the API for achievements.

* - Added socket route
- Created sealed class for Agent params
- Updated other methods and classes

* Changes:
- ID of an Achievement is now generated by the API rather than passed via the payload.
- The socket route has been reimplemented in SocketRouter.kt rather than AchievementRoutes.kt.
- I believe the reimplemented socket route no longer sends a reply to the socket handler (intended), and Redis should be updated properly.

* Changes:
- Created @SerialNames for AgentParam classes and successfully tested the POST and GET methods.
- Changed the achievements variable in Player.kt from a HashSet to a MutableList, because that just felt like the right decision.
- Began creating a deleteAchievement route to allow for deleting achievements; this is currently still a WIP.

* Changes:
- Fixed the deleteAchievement route by changing the "id" field in the Achievement data class to "_id" (mongo-supported variable name)
- Changed "params" in Agent data class to a nullable type, since some achievements will not require parameters (example: GlovesOff- kill a player with your fist while wearing no armor)
- Changed the AgentParams structure to a 1:1 mapping of AgentParams to an AgentType; this will allow for more descriptive variable names.
- Added an AgentParam called CompositeAgentParams. This is intended to combine agents, requiring emissions from multiple Agents in order for the achievement to be marked complete.

* Minor Update:
- Added a route for getting an individual achievement by id.
- Added corresponding AchievementMissingException for when an individual achievement is not found by id.

* Latest Version:
- Posting my latest code for reference.

* More Achievements:
- Added a couple of achievements.

* Reply to server on player profile update

* Menu Refactor
- Refactored the achievement menu.

* Achievements First Release
- This is the first release of the achievements system. Everything functionality-wise has been tested and implemented.
- 20+ achievement parents.
- ~80+ achievements are being added in this release.

* Minor Patch
- Removed an unnecessary "test" variable from PlayerStats and other relevant classes.

* Another Minor Patch
- Fixed a copy-paste issue.

* Validation Patch
- Fixed missing validations for achievement routes.

* Validation Patch (v2)
- Fixed missing validations for achievement routes.

* Remove comment

* PR Fixes:

- Changed the API to store the date/time each achievement was reached (as requested)
- Combined the routes into one function (as requested)
- Refactored the AchievementParent class into AchievementCategory
- Changed achievements variable in PlayerStats to be of type MutableMap<String, AchievementStatistic>, where the String key is the id of the achievement, and AchievementStatistic is an object containing additional data such as completionTime.

* Fix

- Removed redundant data classes.

* Fix #3

- Reduced LoC in PlayerContext file
- Removed Misc.kt file
- Removed unused PlayerLevelUpData class

* PR Fix

- Changed "achievement" field in PlayerAchievementData to "achievementId" for clarity sake.

* PR Fix

- Moved "reply" method from PlayerUpdateListener to PlayerContext and renamed it "update".

* Optimize Imports

- Ran IntelliJ's "optimize imports" function on the entire codebase.

---------

Co-authored-by: chatt <[email protected]>
Co-authored-by: Daniel <[email protected]>
  • Loading branch information
3 people authored Mar 24, 2024
1 parent 5ab8656 commit 16eda72
Show file tree
Hide file tree
Showing 15 changed files with 750 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import io.ktor.websocket.*
import network.warzone.api.database.Database
import network.warzone.api.http.ApiException
import network.warzone.api.http.InternalServerErrorException
import network.warzone.api.http.achievements.achievementRoutes
import network.warzone.api.http.broadcast.broadcastRoutes
import network.warzone.api.http.leaderboard.leaderboardRoutes
import network.warzone.api.http.level.levelRoutes
Expand All @@ -49,8 +50,6 @@ import network.warzone.api.http.tag.tagRoutes
import network.warzone.api.socket.initSocketHandler
import java.util.*

//import com.koriit.kotlin

fun main() {
embeddedServer(Netty, host = Config.listenHost, port = Config.listenPort) {
Server().apply { main() }
Expand Down Expand Up @@ -114,6 +113,7 @@ class Server {

initSocketHandler()

achievementRoutes()
statusRoutes()
playerRoutes()
matchRoutes()
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/database/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object Database {
val matches: CoroutineCollection<Match>
val deaths: CoroutineCollection<Death>
val punishments: CoroutineCollection<Punishment>
val achievements: CoroutineCollection<Achievement>

init {
val client = KMongo.createClient(Config.mongoUrl).coroutine
Expand All @@ -34,6 +35,7 @@ object Database {
matches = database.getCollection()
deaths = database.getCollection()
punishments = database.getCollection()
achievements = database.getCollection()

runBlocking {
// remove if indexes are problematic later...
Expand Down
Loading

0 comments on commit 16eda72

Please sign in to comment.