[O] Make always vip configurable

pull/29/head
Azalea 2024-04-02 02:04:42 -04:00
parent 6441dfd219
commit 02e2700e96
3 changed files with 14 additions and 10 deletions

View File

@ -129,6 +129,7 @@ fun Long.toHex(len: Int = 16): Str = "0x${this.toString(len).padStart(len, '0').
fun Map<String, Any>.toUrl() = entries.joinToString("&") { (k, v) -> "$k=$v" }
fun Any.long() = when (this) {
is Boolean -> if (this) 1L else 0
is Number -> toLong()
is String -> toLong()
else -> 400 - "Invalid number: $this"

View File

@ -185,10 +185,7 @@ fun WaccaServer.init() {
val bingo = rp.bingo.findByUser(u).firstOrNull()
val go = u.card?.aquaUser?.gameOptions ?: AquaGameOptions()
// TODO: make vip configurable
// All unlock
if (go.waccaInfiniteWp) u.wp = 999999
if (go.unlockMusic && wacca.musicMapping.isNotEmpty()) {
items[MUSIC_UNLOCK()] = wacca.musicMapping.keys.map { MUSIC_UNLOCK(u, it, p1 = INFERNO.value.long()) }
}
@ -361,7 +358,7 @@ fun WaccaServer.init() {
addItems(ls(ls(MUSIC_UNLOCK(), songId.int(), diff.int())), u, items)
useItems(itemUsed as List<List<Int>>, u, items)
ls(u.wp, rp.item.findByUserAndType(u, TICKET()).map { it.ls() })
ls(u.getWp(), rp.item.findByUserAndType(u, TICKET()).map { it.ls() })
}
"user/goods/purchase" { _, (uid, pid, count, purchaseType, cost, items) ->
@ -372,7 +369,7 @@ fun WaccaServer.init() {
// WP Purchase = 2, Credit purchase = 1
if (purchaseType == 2) useItems(ls(ls(WP(), 0, cost.int())), u, itemsMap)
ls(u.wp, rp.item.findByUserAndType(u, TICKET()).map { it.ls() })
ls(u.getWp(), rp.item.findByUserAndType(u, TICKET()).map { it.ls() })
}
"user/rating/update" empty { _, (uid, newRating, songs) ->
@ -463,13 +460,13 @@ fun WaccaServer.init() {
// TODO: Test this
"user/vip/get" { _, (uid) ->
val u = user(uid) ?: (404 - "User not found")
val vipDays = (u.vipExpireTime.time - millis()) / (24 * 60 * 60 * 1000)
val vipDays = (u.getVipExpire().time - millis()) / (24 * 60 * 60 * 1000)
ls(vipDays, ls(1, 1, "presents" - empty))
}
"user/vip/start" { _, (uid, cost, days) ->
val u = user(uid) ?: (404 - "User not found")
rp.user.save(u.apply { vipExpireTime = Date(millis() + days.int() * (24 * 60 * 60 * 1000)) })
ls(u.vipExpireTime.sec, "presents" - empty)
ls(u.getVipExpire().sec, "presents" - empty)
}
}

View File

@ -34,7 +34,7 @@ class WaccaUser : BaseEntity(), IUserData {
override var playerRating = 0
override var highestRating = 0
@Temporal(TemporalType.TIMESTAMP)
var vipExpireTime: Date = "2077-01-01".isoDate().toDate()
var vipExpireTime: Date = Date(0)
var alwaysVip = false
var loginCount = 0
var loginCountDays = 0
@ -60,7 +60,13 @@ class WaccaUser : BaseEntity(), IUserData {
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, this.playerRating
userName, 1, xp, danLevel, danType, getWp(), ls(0, 0, 0), loginCount, loginCountDays,
(loginCount - 1).coerceAtLeast(0), loginCountDaysConsec, getVipExpire().sec, loginCountToday, this.playerRating
)
fun getVipExpire() =
if (card?.aquaUser?.gameOptions?.waccaAlwaysVip == true) "2077-01-01".isoDate().toDate()
else vipExpireTime
fun getWp() = if (card?.aquaUser?.gameOptions?.waccaInfiniteWp == true) 999999 else wp
}