Skip to content

Commit

Permalink
persistence: promote pang/cookie balance to long
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-agon committed Aug 11, 2023
1 parent 723d024 commit f7c8f08
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions database/migrations/V0001__base-schema.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CREATE TABLE account (
uid serial PRIMARY KEY,
uuid uuid NOT NULL,
username text NOT NULL,
uuid uuid NOT NULL,
username text NOT NULL,
nickname text,
password bytea NOT NULL,
pang_balance int NOT NULL,
cookie_balance int NOT NULL,
password bytea NOT NULL,
pang_balance bigint NOT NULL,
cookie_balance bigint NOT NULL,
created_at timestamptz DEFAULT NOW()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import work.fking.pangya.game.player.Player
import work.fking.pangya.networking.protocol.OutboundPacket

class CookieBalancePacket(
private val balance: Int
private val balance: Long
) : OutboundPacket {

constructor(player: Player) : this(player.wallet.cookieBalance)

override fun encode(buffer: ByteBuf) {
buffer.writeShortLE(0x96)
buffer.writeLongLE(balance.toLong())
buffer.writeLongLE(balance)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ object MatchReplies {
buffer.writeByte(player.currentHole) // hole
buffer.writeByte(3) // total strokes?
buffer.writeIntLE(-1) // score
buffer.writeLongLE(player.pang.toLong()) // pang
buffer.writeLongLE(player.bonusPang.toLong()) // bonus pang
buffer.writeLongLE(player.pang) // pang
buffer.writeLongLE(player.bonusPang) // bonus pang
buffer.writeByte(1) // finished the hole, 1 or 0 not
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import work.fking.pangya.game.player.Player
import work.fking.pangya.networking.protocol.OutboundPacket

class PangBalancePacket(
private val balance: Int
private val balance: Long
) : OutboundPacket {

constructor(player: Player) : this(player.wallet.pangBalance)

override fun encode(buffer: ByteBuf) {
buffer.writeShortLE(0xc8)
buffer.writeLongLE(balance.toLong())
buffer.writeLongLE(balance)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class JooqPlayerRepository : PlayerRepository {
.where(ACCOUNT.UID.eq(playerUid))
.fetchOne {
PlayerWallet(
pangBalance = it[ACCOUNT.PANG_BALANCE] as Int,
cookieBalance = it[ACCOUNT.COOKIE_BALANCE] as Int
pangBalance = it[ACCOUNT.PANG_BALANCE] as Long,
cookieBalance = it[ACCOUNT.COOKIE_BALANCE] as Long
)
}
return wallet ?: throw IllegalStateException("could not load player wallet for playerUid=$playerUid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ open class Account(
/**
* The column <code>public.account.pang_balance</code>.
*/
val PANG_BALANCE: TableField<AccountRecord, Int?> = createField(DSL.name("pang_balance"), SQLDataType.INTEGER.nullable(false), this, "")
val PANG_BALANCE: TableField<AccountRecord, Long?> = createField(DSL.name("pang_balance"), SQLDataType.BIGINT.nullable(false), this, "")

/**
* The column <code>public.account.cookie_balance</code>.
*/
val COOKIE_BALANCE: TableField<AccountRecord, Int?> = createField(DSL.name("cookie_balance"), SQLDataType.INTEGER.nullable(false), this, "")
val COOKIE_BALANCE: TableField<AccountRecord, Long?> = createField(DSL.name("cookie_balance"), SQLDataType.BIGINT.nullable(false), this, "")

/**
* The column <code>public.account.created_at</code>.
Expand Down Expand Up @@ -152,16 +152,16 @@ open class Account(
// -------------------------------------------------------------------------
// Row8 type methods
// -------------------------------------------------------------------------
override fun fieldsRow(): Row8<Int?, java.util.UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?> = super.fieldsRow() as Row8<Int?, java.util.UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?>
override fun fieldsRow(): Row8<Int?, java.util.UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?> = super.fieldsRow() as Row8<Int?, java.util.UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?>

/**
* Convenience mapping calling {@link SelectField#convertFrom(Function)}.
*/
fun <U> mapping(from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?) -> U): SelectField<U> = convertFrom(Records.mapping(from))
fun <U> mapping(from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?) -> U): SelectField<U> = convertFrom(Records.mapping(from))

/**
* Convenience mapping calling {@link SelectField#convertFrom(Class,
* Function)}.
*/
fun <U> mapping(toType: Class<U>, from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
fun <U> mapping(toType: Class<U>, from: (Int?, java.util.UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import work.fking.pangya.game.persistence.jooq.tables.Account
* This class is generated by jOOQ.
*/
@Suppress("UNCHECKED_CAST")
open class AccountRecord private constructor() : UpdatableRecordImpl<AccountRecord>(Account.ACCOUNT), Record8<Int?, UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?> {
open class AccountRecord private constructor() : UpdatableRecordImpl<AccountRecord>(Account.ACCOUNT), Record8<Int?, UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?> {

open var uid: Int?
set(value): Unit = set(0, value)
Expand All @@ -42,13 +42,13 @@ open class AccountRecord private constructor() : UpdatableRecordImpl<AccountReco
set(value): Unit = set(4, value)
get(): ByteArray = get(4) as ByteArray

open var pangBalance: Int
open var pangBalance: Long
set(value): Unit = set(5, value)
get(): Int = get(5) as Int
get(): Long = get(5) as Long

open var cookieBalance: Int
open var cookieBalance: Long
set(value): Unit = set(6, value)
get(): Int = get(6) as Int
get(): Long = get(6) as Long

open var createdAt: OffsetDateTime?
set(value): Unit = set(7, value)
Expand All @@ -64,31 +64,31 @@ open class AccountRecord private constructor() : UpdatableRecordImpl<AccountReco
// Record8 type implementation
// -------------------------------------------------------------------------

override fun fieldsRow(): Row8<Int?, UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?> = super.fieldsRow() as Row8<Int?, UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?>
override fun valuesRow(): Row8<Int?, UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?> = super.valuesRow() as Row8<Int?, UUID?, String?, String?, ByteArray?, Int?, Int?, OffsetDateTime?>
override fun fieldsRow(): Row8<Int?, UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?> = super.fieldsRow() as Row8<Int?, UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?>
override fun valuesRow(): Row8<Int?, UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?> = super.valuesRow() as Row8<Int?, UUID?, String?, String?, ByteArray?, Long?, Long?, OffsetDateTime?>
override fun field1(): Field<Int?> = Account.ACCOUNT.UID
override fun field2(): Field<UUID?> = Account.ACCOUNT.UUID
override fun field3(): Field<String?> = Account.ACCOUNT.USERNAME
override fun field4(): Field<String?> = Account.ACCOUNT.NICKNAME
override fun field5(): Field<ByteArray?> = Account.ACCOUNT.PASSWORD
override fun field6(): Field<Int?> = Account.ACCOUNT.PANG_BALANCE
override fun field7(): Field<Int?> = Account.ACCOUNT.COOKIE_BALANCE
override fun field6(): Field<Long?> = Account.ACCOUNT.PANG_BALANCE
override fun field7(): Field<Long?> = Account.ACCOUNT.COOKIE_BALANCE
override fun field8(): Field<OffsetDateTime?> = Account.ACCOUNT.CREATED_AT
override fun component1(): Int? = uid
override fun component2(): UUID = uuid
override fun component3(): String = username
override fun component4(): String? = nickname
override fun component5(): ByteArray = password
override fun component6(): Int = pangBalance
override fun component7(): Int = cookieBalance
override fun component6(): Long = pangBalance
override fun component7(): Long = cookieBalance
override fun component8(): OffsetDateTime? = createdAt
override fun value1(): Int? = uid
override fun value2(): UUID = uuid
override fun value3(): String = username
override fun value4(): String? = nickname
override fun value5(): ByteArray = password
override fun value6(): Int = pangBalance
override fun value7(): Int = cookieBalance
override fun value6(): Long = pangBalance
override fun value7(): Long = cookieBalance
override fun value8(): OffsetDateTime? = createdAt

override fun value1(value: Int?): AccountRecord {
Expand Down Expand Up @@ -116,12 +116,12 @@ open class AccountRecord private constructor() : UpdatableRecordImpl<AccountReco
return this
}

override fun value6(value: Int?): AccountRecord {
override fun value6(value: Long?): AccountRecord {
set(5, value)
return this
}

override fun value7(value: Int?): AccountRecord {
override fun value7(value: Long?): AccountRecord {
set(6, value)
return this
}
Expand All @@ -131,7 +131,7 @@ open class AccountRecord private constructor() : UpdatableRecordImpl<AccountReco
return this
}

override fun values(value1: Int?, value2: UUID?, value3: String?, value4: String?, value5: ByteArray?, value6: Int?, value7: Int?, value8: OffsetDateTime?): AccountRecord {
override fun values(value1: Int?, value2: UUID?, value3: String?, value4: String?, value5: ByteArray?, value6: Long?, value7: Long?, value8: OffsetDateTime?): AccountRecord {
this.value1(value1)
this.value2(value2)
this.value3(value3)
Expand All @@ -146,7 +146,7 @@ open class AccountRecord private constructor() : UpdatableRecordImpl<AccountReco
/**
* Create a detached, initialised AccountRecord
*/
constructor(uid: Int? = null, uuid: UUID, username: String, nickname: String? = null, password: ByteArray, pangBalance: Int, cookieBalance: Int, createdAt: OffsetDateTime? = null): this() {
constructor(uid: Int? = null, uuid: UUID, username: String, nickname: String? = null, password: ByteArray, pangBalance: Long, cookieBalance: Long, createdAt: OffsetDateTime? = null): this() {
this.uid = uid
this.uuid = uuid
this.username = username
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package work.fking.pangya.game.player
import kotlin.math.max

class PlayerWallet(
pangBalance: Int = 10000,
cookieBalance: Int = 0
pangBalance: Long = 10000,
cookieBalance: Long = 0
) {
var pangBalance = pangBalance
set(value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class RoomPlayer(
// in game state
var currentHole: Int = 1
var finishedHole: Boolean = false
var pang: Int = 0
var bonusPang: Int = 0
var pang: Long = 0
var bonusPang: Long = 0
var statistics: PlayerStatistics = PlayerStatistics()

fun write(message: Any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class PracticeMatchDirector : MatchDirector {

private fun handleShotSync(room: Room, event: PlayerShotSyncEvent) {
val player = event.player
player.pang = event.pang
player.bonusPang = event.bonusPang
player.pang = event.pang.toLong()
player.bonusPang = event.bonusPang.toLong()
room.broadcast(
MatchReplies.tourneyShotGhost(
player = player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ChangeClubSetStatTask(

private fun upgrade(clubSet: Item) {
val level = clubSet.stats[stat.ordinal]
val cost = (level + 1) * when (stat) {
val cost = (level + 1L) * when (stat) {
POWER -> 2100
CONTROL -> 1700
ACCURACY -> 2400
Expand All @@ -54,7 +54,7 @@ class ChangeClubSetStatTask(
persistenceCtx.playerRepository.saveWallet(tx, player.uid, wallet)
persistenceCtx.inventoryRepository.saveItem(tx, player.uid, clubSet)
}
player.writeAndFlush(ClubSetReplies.upgradeAck(type, stat.ordinal, itemUid, cost.toLong()))
player.writeAndFlush(ClubSetReplies.upgradeAck(type, stat.ordinal, itemUid, cost))
}

private fun downgrade(clubSet: Item) {
Expand Down

0 comments on commit f7c8f08

Please sign in to comment.