diff --git a/src/main/java/icu/samnyan/aqua/net/games/Models.kt b/src/main/java/icu/samnyan/aqua/net/games/Models.kt index b68d5460..fbc9bbd0 100644 --- a/src/main/java/icu/samnyan/aqua/net/games/Models.kt +++ b/src/main/java/icu/samnyan/aqua/net/games/Models.kt @@ -84,7 +84,6 @@ data class GenericItemMeta( // Here are some interfaces to generalize across multiple games interface IGenericUserData { val userName: String - val iconId: Int val playerRating: Int val highestRating: Int val firstPlayDate: Any diff --git a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt index 0afedc39..14655c9a 100644 --- a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt +++ b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt @@ -120,9 +120,9 @@ fun WaccaServer.init() { u.run { ls(u.lStatus(), o[SET_TITLE_ID], o[SET_ICON_ID], "status" - if (ru == null) 1 else 0, // 0 = GOOD, 1 = Register - "version" - ls(req.appVersion.shortVer().compareTo(lastGameVer.shortVer()) + "version" - ls(req.appVersion.shortVer().compareTo(this.lastRomVersion.shortVer()) .let { if (it < 0) 1 else if (it > 0) 2 else 0 }, // 0 = Version GOOD, 1 = Game is newer, 2 = Game is older - lastGameVer.shortVer()), + this.lastRomVersion.shortVer()), o.map { (k, v) -> ls(k, v) } ) } } @@ -132,7 +132,7 @@ fun WaccaServer.init() { val u = rp.user.save(WaccaUser().apply { card = cardRepo.findByExtId(uid.long())() ?: (404 - "Card not found") - username = name.toString() + userName = name.toString() }) // Starter items @@ -160,13 +160,13 @@ fun WaccaServer.init() { loginCountDays++ loginCountToday = 0 lastConsecDate = Date() - if (millis() - lastLoginDate.time < 2 * 24 * 60 * 60 * 1000) loginCountDaysConsec++ + if (millis() - this.lastPlayDate.time < 2 * 24 * 60 * 60 * 1000) loginCountDaysConsec++ } loginCountToday++ - lastLoginDate = Date() + this.lastPlayDate = Date() }) - "[[], [], [], 0, [2077, 1, 1, 1, [], []], ${u.lastLoginDate.time / 1000}, []]" + "[[], [], [], 0, [2077, 1, 1, 1, [], []], ${u.lastPlayDate.time / 1000}, []]" } "user/status/GetDetail" api@ { _, (uid) -> @@ -176,7 +176,7 @@ fun WaccaServer.init() { val scores = rp.bestScore.findByUser(u) val gates = rp.gate.findByUser(u) val bingo = rp.bingo.findByUser(u).firstOrNull() - val go = u.card.aquaUser?.gameOptions + val go = u.card?.aquaUser?.gameOptions // TODO: make this and vip configurable // u.wp = 999999 @@ -195,12 +195,12 @@ fun WaccaServer.init() { }, "4 scores" - scores.map { it.ls() }, "5 songPlayStatus" - ls(lastSongInfo[0], 1), - "6 seasonInfo" - ls(xp, wpTotal, wpSpent, scores.sumOf { it.score }, + "6 seasonInfo" - ls(xp, wpTotal, wpSpent, u.totalScore, items[TITLE()]?.size ?: 0, items[ICON()]?.size ?: 0, 0, items[NOTE_COLOR()]?.size ?: 0, items[NOTE_SOUND()]?.size ?: 0, items[USER_PLATE()]?.size ?: 0, gates.sumOf { it.totalPoints }), "7 playAreaList" - "[[0],[0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0],[0,0,0,0],[0,0,0,0,0,0,0],[0]]".jsonArray(), - "8 songUpdateTime" - lastLoginDate.time / 1000, + "8 songUpdateTime" - this.lastPlayDate.time / 1000, "9 favorites" - u.favoriteSongs, "10 stoppedSongIds" - empty, "11 events" - empty, @@ -306,6 +306,9 @@ fun WaccaServer.init() { rating = waccaRating(score, song.level) }) + // Re-calculate user total score + rp.user.save(u.apply { totalScore = rp.bestScore.sumScoreByUser(u) }) + ls(best.lsMusicUpdate(), ls(song.songId, best.clears[0]), "seasonalInfo" - (1..11).map { 0 }, "ranking" - empty) } "user/music/UpdateCoop" redirect "user/music/update" @@ -335,7 +338,6 @@ fun WaccaServer.init() { "user/rating/update" empty { _, (uid, newRating, songs) -> val u = user(uid) ?: (404 - "User not found") - rp.user.save(u.apply { rating = newRating.int() }) // Update best record (songs as List>).forEach { (songId, diff, newRating) -> @@ -343,6 +345,12 @@ fun WaccaServer.init() { best.rating = newRating.int() rp.bestScore.save(best) } + + rp.user.save(u.apply { + playerRating = newRating.int() + highestRating = max(highestRating, newRating.int()) + totalScore = rp.bestScore.sumScoreByUser(u) + }) } fun incrUses(u: WaccaUser, opts: Map) { @@ -356,7 +364,7 @@ fun WaccaServer.init() { rp.user.save(u.apply { playCounts[playType.int() - 1]++ addItems(items, u, itmGrp(u)) - lastGameVer = version + lastRomVersion = version incrUses(u, options(u)) }) } diff --git a/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/Repos.kt b/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/Repos.kt index 43b953c8..744fceae 100644 --- a/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/Repos.kt +++ b/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/Repos.kt @@ -2,6 +2,7 @@ package icu.samnyan.aqua.sega.wacca.model.db import jakarta.transaction.Transactional import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import org.springframework.data.repository.NoRepositoryBean import org.springframework.stereotype.Component @@ -31,6 +32,8 @@ interface WcUserItemRepo : IWaccaUserLinked { } interface WcUserBestScoreRepo : IWaccaUserLinked { fun findByUserAndSongIdAndDifficulty(user: WaccaUser, songId: Int, difficulty: Int): WcUserScore? + @Query("SELECT SUM(score) FROM WcUserScore WHERE user = :user") + fun sumScoreByUser(user: WaccaUser): Long } interface WcUserPlayLogRepo : IWaccaUserLinked interface WcUserStageUpRepo : IWaccaUserLinked diff --git a/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/WaccaUser.kt b/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/WaccaUser.kt index 65e067c3..0f3c95ba 100644 --- a/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/WaccaUser.kt +++ b/src/main/java/icu/samnyan/aqua/sega/wacca/model/db/WaccaUser.kt @@ -5,6 +5,7 @@ import ext.ls import ext.sec import ext.toDate import icu.samnyan.aqua.net.games.BaseEntity +import icu.samnyan.aqua.net.games.IGenericUserData import icu.samnyan.aqua.sega.general.IntegerListConverter import icu.samnyan.aqua.sega.general.model.Card import jakarta.persistence.* @@ -14,13 +15,13 @@ import java.util.* * General user information */ @Entity @Table(name = "wacca_user") -class WaccaUser : BaseEntity() { +class WaccaUser : BaseEntity(), IGenericUserData { @OneToOne @JoinColumn(name = "aime_card_id", unique = true) - var card: Card = Card() + override var card: Card? = Card() @Column(length = 8) - var username = "" + override var userName = "" var xp = 0 var wp = 500 @@ -30,7 +31,8 @@ class WaccaUser : BaseEntity() { var danLevel = 0 @Convert(converter = IntegerListConverter::class) var titles: MutableList = mutableListOf(0, 0, 0) - var rating = 0 + override var playerRating = 0 + override var highestRating = 0 @Temporal(TemporalType.TIMESTAMP) var vipExpireTime: Date = "2077-01-01".isoDate().toDate() var alwaysVip = false @@ -43,17 +45,22 @@ class WaccaUser : BaseEntity() { @Convert(converter = IntegerListConverter::class) var friendViews: MutableList = mutableListOf(0, 0, 0) @Column(length = 50) - var lastGameVer = "1.0.0" + override var lastRomVersion = "1.0.0" @Convert(converter = IntegerListConverter::class) var lastSongInfo: MutableList = mutableListOf(0, 0, 0, 0, 0) @Temporal(TemporalType.TIMESTAMP) var lastConsecDate: Date = Date(0) @Temporal(TemporalType.TIMESTAMP) - var lastLoginDate: Date = Date() + override var lastPlayDate: Date = Date() + @Temporal(TemporalType.TIMESTAMP) + override var firstPlayDate: Date = Date() var gateTutorialFlags: String = "[[1, 0], [2, 0], [3, 0], [4, 0], [5, 0]]" @Convert(converter = IntegerListConverter::class) var favoriteSongs: MutableList = mutableListOf() + override var totalScore = 0L - fun lStatus() = ls(card.extId, username, 1, xp, danLevel, danType, wp, ls(0, 0, 0), loginCount, loginCountDays, - (loginCount - 1).coerceAtLeast(0), loginCountDaysConsec, vipExpireTime.sec, loginCountToday, rating) + fun lStatus() = ls(card?.extId, + userName, 1, xp, danLevel, danType, wp, ls(0, 0, 0), loginCount, loginCountDays, + (loginCount - 1).coerceAtLeast(0), loginCountDaysConsec, vipExpireTime.sec, loginCountToday, this.playerRating + ) } \ No newline at end of file diff --git a/src/main/resources/db/migration/mariadb/V1000_12__wacca_reinit.sql b/src/main/resources/db/migration/mariadb/V1000_12__wacca_reinit.sql index 166ff706..223eb29a 100644 --- a/src/main/resources/db/migration/mariadb/V1000_12__wacca_reinit.sql +++ b/src/main/resources/db/migration/mariadb/V1000_12__wacca_reinit.sql @@ -7,7 +7,7 @@ create table wacca_user id bigint auto_increment primary key, aime_card_id bigint not null, - username varchar(8) not null, + user_name varchar(8) not null, xp int not null, wp int not null, wp_total int not null, @@ -15,7 +15,8 @@ create table wacca_user dan_type int not null, dan_level int not null, titles varchar(255) not null, - rating int not null, + player_rating int not null, + highest_rating int not null, always_vip bit not null, login_count int not null, login_count_days int not null, @@ -23,13 +24,15 @@ create table wacca_user login_count_today int not null, play_counts varchar(255) not null, friend_views varchar(255) not null, - last_game_ver varchar(50) not null, + last_rom_version varchar(50) not null, last_song_info varchar(255) not null, gate_tutorial_flags varchar(255) not null, - last_login_date datetime not null, + last_play_date datetime not null, + first_play_date datetime not null, vip_expire_time datetime not null, last_consec_date datetime not null, favorite_songs TEXT not null, + total_score bigint not null, constraint wacca_user_detail_unique unique (aime_card_id), constraint wacca_user_detail_fk