Skip to content

Commit

Permalink
clubset: basic workshop support
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-agon committed Aug 16, 2023
1 parent 6eeb4df commit 5453af9
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 31 deletions.
14 changes: 9 additions & 5 deletions database/migrations/V0001__base-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ CREATE TABLE account (
);

CREATE INDEX idx__account_uuid ON account (uuid);
CREATE UNIQUE INDEX idx__account_username ON account (username);
CREATE UNIQUE INDEX idx__account_nickname ON account (nickname);

CREATE TABLE achievement (
iff_id int NOT NULL PRIMARY KEY,
Expand Down Expand Up @@ -52,12 +54,14 @@ CREATE TABLE player_caddie (
CREATE UNIQUE INDEX idx_player_caddie ON player_caddie (account_uid, iff_id);

CREATE TABLE player_inventory_item (
uid serial PRIMARY KEY,
account_uid int NOT NULL
uid serial PRIMARY KEY,
account_uid int NOT NULL
CONSTRAINT fk_player_inventory_item__account REFERENCES account (uid) ON DELETE CASCADE,
iff_id int NOT NULL,
quantity int DEFAULT 0,
stats json
iff_id int NOT NULL,
quantity int DEFAULT 0,
stats json,
ucc json,
club_workshop json
);

CREATE TABLE player_equipment (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package work.fking.pangya.game.net

import work.fking.pangya.game.packet.handler.AchievementStatusRequestPacketHandler
import work.fking.pangya.game.packet.handler.ClubSetUpgradePacketHandler
import work.fking.pangya.game.packet.handler.clubworkshop.ClubSetUpgradePacketHandler
import work.fking.pangya.game.packet.handler.EquipmentUpdatePacketHandler
import work.fking.pangya.game.packet.handler.JoinLobbyPacketHandler
import work.fking.pangya.game.packet.handler.LeaveLobbyPacketHandler
Expand All @@ -15,6 +15,9 @@ import work.fking.pangya.game.packet.handler.RareShopOpenPacketHandler
import work.fking.pangya.game.packet.handler.SelectChannelPacketHandler
import work.fking.pangya.game.packet.handler.UpdateChatMacrosPacketHandler
import work.fking.pangya.game.packet.handler.UserProfileRequestPacketHandler
import work.fking.pangya.game.packet.handler.clubworkshop.ClubWorkshopAcceptTransformPacketHandler
import work.fking.pangya.game.packet.handler.clubworkshop.ClubWorkshopDeclineTransformPacketHandler
import work.fking.pangya.game.packet.handler.clubworkshop.ClubWorkshopRankUpPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchFinalStatsPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchFinishPlayerPreviewPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchHoleStartPacketHandler
Expand Down Expand Up @@ -82,6 +85,9 @@ enum class ClientPacketType(
PLAYER_RING_PROC(0x15d),
MATCH_PLAYER_TOURNEY_SHOT(0x12f, MatchTourneyShotPacketHandler()),
PAPEL_SHOP_PLAY(0x14b, PapelShopPlayPacketHandler()),
CLUB_WORKSHOP_RANK_UP(0x167, ClubWorkshopRankUpPacketHandler()),
CLUB_WORKSHOP_DECLINE_TRANSFORM(0x168, ClubWorkshopDeclineTransformPacketHandler()),
CLUB_WORKSHOP_ACCEPT_TRANSFORM(0x169, ClubWorkshopAcceptTransformPacketHandler()),
LOGIN_BONUS_INFO(0x16e, LoginBonusStatusPacketHandler()),
LOGIN_BONUS_CLAIM(0x16f, LoginBonusClaimPacketHandler());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package work.fking.pangya.game.packet.handler
package work.fking.pangya.game.packet.handler.clubworkshop

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.packet.outbound.ClubSetReplies
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.player.statById
import work.fking.pangya.game.task.ChangeClubSetStatTask
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package work.fking.pangya.game.packet.handler.clubworkshop

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player

class ClubWorkshopAcceptTransformPacketHandler : ClientPacketHandler {
override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package work.fking.pangya.game.packet.handler.clubworkshop

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player

class ClubWorkshopDeclineTransformPacketHandler : ClientPacketHandler {
override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package work.fking.pangya.game.packet.handler.clubworkshop

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.model.IFF_TYPE_CLUBSET
import work.fking.pangya.game.model.iffTypeFromId
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.packet.outbound.ClubSetReplies
import work.fking.pangya.game.player.Player

class ClubWorkshopRankUpPacketHandler : ClientPacketHandler {
override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
val cardIffId = packet.readIntLE()
val cardQuantity = packet.readShortLE()
val clubSetUid = packet.readIntLE()
println("cardIffId=$cardIffId, cardQuantity=$cardQuantity, clubSetUid=$clubSetUid")

val clubSet = player.inventory.findByUid(clubSetUid) ?: throw IllegalStateException("Player ${player.nickname} tried to rank up a clubset it does not own ($clubSetUid)")

val clubSetStats = clubSet.clubWorkshop.stats
val statBefore = clubSetStats[0]
clubSetStats[0]++
val statAfter = clubSetStats[0]
player.write(ClubSetReplies.syncClubSetItem(clubSet, statBefore, statAfter))
player.writeAndFlush(ClubSetReplies.workshopRankUpAck(clubSetUid, 0))
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
package work.fking.pangya.game.packet.outbound

import work.fking.pangya.game.player.Item
import work.fking.pangya.game.player.write
import work.fking.pangya.networking.protocol.OutboundPacket
import java.time.Instant

object ClubSetReplies {

fun upgradeAck(type: Int, stat: Int, itemUid: Int, cost: Long): OutboundPacket {
fun upgradeAck(result: UpgradeResult, stat: Int, itemUid: Int, cost: Long = 0): OutboundPacket {
return OutboundPacket { buffer ->
buffer.writeShortLE(0xa5)
buffer.writeByte(type)
buffer.writeByte(result.code)
buffer.writeByte(1) // 0 doesn't upgrade a clubset but 1 does?
buffer.writeByte(stat)
buffer.writeIntLE(itemUid)
buffer.writeLongLE(cost) // TODO: how to calculate the upgrade cost?
buffer.writeLongLE(cost)
}
}

fun workshopRankUpTransform(): OutboundPacket {
return OutboundPacket { buffer -> buffer.writeShortLE(0x241) }
}

fun workshopRankUpAck(clubSetUid: Int, leveledUpStat: Int): OutboundPacket {
return OutboundPacket { buffer ->
buffer.writeShortLE(0x240)
buffer.writeIntLE(0) // result 0 = ok, 1 = 'System error'

buffer.writeIntLE(leveledUpStat) // which stat leveled up
buffer.writeIntLE(clubSetUid)
}
}

fun syncClubSetItem(item: Item, statBefore: Int, statAfter: Int): OutboundPacket {
return OutboundPacket { buffer ->
buffer.writeShortLE(0x216)

buffer.writeIntLE(Instant.now().epochSecond.toInt())
buffer.writeIntLE(1)

buffer.writeByte(0x2) // this packet can sync multiple things, 0x2 means it's an inventory item
buffer.writeIntLE(item.iffId)
buffer.writeIntLE(item.uid)
buffer.writeIntLE(0)
buffer.writeIntLE(statBefore)
buffer.writeIntLE(statAfter)
buffer.writeIntLE(item.quantity)
buffer.writeZero(25)
buffer.write(item.clubWorkshop)
}
}

enum class UpgradeResult(val code: Int) {
UPGRADE_SUCCESS(1),
DOWNGRADE_SUCCESS(2),
INSUFFICIENT_PANG(3),
INSUFFICIENT_SLOTS(4),
CANNOT_DOWNGRADE_ANYMORE(5),
FAILED_TO_UPGRADE(6)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import work.fking.pangya.game.persistence.jooq.tables.records.PlayerInventoryIte
import work.fking.pangya.game.persistence.jooq.tables.references.PLAYER_INVENTORY_ITEM
import work.fking.pangya.game.player.Inventory
import work.fking.pangya.game.player.Item
import work.fking.pangya.game.player.nullItemClubWorkshop
import work.fking.pangya.game.player.nullItemUcc
import java.util.concurrent.atomic.AtomicInteger

interface InventoryRepository {
Expand Down Expand Up @@ -47,6 +49,8 @@ class JooqInventoryRepository : InventoryRepository {
iffId = it.iffId,
quantity = it.quantity ?: 0,
stats = it.stats ?: IntArray(0),
ucc = it.ucc ?: nullItemUcc(),
clubWorkshop = it.clubWorkshop ?: nullItemClubWorkshop()
)
}

Expand All @@ -67,10 +71,14 @@ class JooqInventoryRepository : InventoryRepository {
.set(PLAYER_INVENTORY_ITEM.IFF_ID, item.iffId)
.set(PLAYER_INVENTORY_ITEM.QUANTITY, item.quantity)
.set(PLAYER_INVENTORY_ITEM.STATS, item.stats)
.set(PLAYER_INVENTORY_ITEM.UCC, item.ucc)
.set(PLAYER_INVENTORY_ITEM.CLUB_WORKSHOP, item.clubWorkshop)
.onConflict(PLAYER_INVENTORY_ITEM_PKEY.fields)
.doUpdate()
.set(PLAYER_INVENTORY_ITEM.QUANTITY, item.quantity)
.set(PLAYER_INVENTORY_ITEM.STATS, item.stats)
.set(PLAYER_INVENTORY_ITEM.UCC, item.ucc)
.set(PLAYER_INVENTORY_ITEM.CLUB_WORKSHOP, item.clubWorkshop)
.returningResult(PLAYER_INVENTORY_ITEM.UID)
.fetchOneInto(Int::class.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import work.fking.pangya.game.persistence.jooq.tables.PlayerCharacter
// -------------------------------------------------------------------------

val FLYWAY_SCHEMA_HISTORY_S_IDX: Index = Internal.createIndex(DSL.name("flyway_schema_history_s_idx"), FlywaySchemaHistory.FLYWAY_SCHEMA_HISTORY, arrayOf(FlywaySchemaHistory.FLYWAY_SCHEMA_HISTORY.SUCCESS), false)
val IDX__ACCOUNT_NICKNAME: Index = Internal.createIndex(DSL.name("idx__account_nickname"), Account.ACCOUNT, arrayOf(Account.ACCOUNT.NICKNAME), true)
val IDX__ACCOUNT_USERNAME: Index = Internal.createIndex(DSL.name("idx__account_username"), Account.ACCOUNT, arrayOf(Account.ACCOUNT.USERNAME), true)
val IDX__ACCOUNT_UUID: Index = Internal.createIndex(DSL.name("idx__account_uuid"), Account.ACCOUNT, arrayOf(Account.ACCOUNT.UUID), false)
val IDX_PLAYER_ACHIEVEMENT: Index = Internal.createIndex(DSL.name("idx_player_achievement"), PlayerAchievement.PLAYER_ACHIEVEMENT, arrayOf(PlayerAchievement.PLAYER_ACHIEVEMENT.ACCOUNT_UID, PlayerAchievement.PLAYER_ACHIEVEMENT.IFF_ID), true)
val IDX_PLAYER_ACHIEVEMENT_MILESTONE: Index = Internal.createIndex(DSL.name("idx_player_achievement_milestone"), PlayerAchievementMilestone.PLAYER_ACHIEVEMENT_MILESTONE, arrayOf(PlayerAchievementMilestone.PLAYER_ACHIEVEMENT_MILESTONE.PLAYER_ACHIEVEMENT_UID, PlayerAchievementMilestone.PLAYER_ACHIEVEMENT_MILESTONE.IFF_ID), true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import org.jooq.impl.SQLDataType
import org.jooq.impl.TableImpl

import work.fking.pangya.game.persistence.jooq.Public
import work.fking.pangya.game.persistence.jooq.indexes.IDX__ACCOUNT_NICKNAME
import work.fking.pangya.game.persistence.jooq.indexes.IDX__ACCOUNT_USERNAME
import work.fking.pangya.game.persistence.jooq.indexes.IDX__ACCOUNT_UUID
import work.fking.pangya.game.persistence.jooq.keys.ACCOUNT_PKEY
import work.fking.pangya.game.persistence.jooq.tables.records.AccountRecord
Expand Down Expand Up @@ -127,7 +129,7 @@ open class Account(

constructor(child: Table<out Record>, key: ForeignKey<out Record, AccountRecord>): this(Internal.createPathAlias(child, key), child, key, ACCOUNT, null)
override fun getSchema(): Schema? = if (aliased()) null else Public.PUBLIC
override fun getIndexes(): List<Index> = listOf(IDX__ACCOUNT_UUID)
override fun getIndexes(): List<Index> = listOf(IDX__ACCOUNT_NICKNAME, IDX__ACCOUNT_USERNAME, IDX__ACCOUNT_UUID)
override fun getIdentity(): Identity<AccountRecord, Int?> = super.getIdentity() as Identity<AccountRecord, Int?>
override fun getPrimaryKey(): UniqueKey<AccountRecord> = ACCOUNT_PKEY
override fun `as`(alias: String): Account = Account(DSL.name(alias), this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.jooq.Identity
import org.jooq.Name
import org.jooq.Record
import org.jooq.Records
import org.jooq.Row5
import org.jooq.Row7
import org.jooq.Schema
import org.jooq.SelectField
import org.jooq.Table
Expand All @@ -31,6 +31,8 @@ import work.fking.pangya.game.persistence.jooq.Public
import work.fking.pangya.game.persistence.jooq.keys.PLAYER_INVENTORY_ITEM_PKEY
import work.fking.pangya.game.persistence.jooq.keys.PLAYER_INVENTORY_ITEM__FK_PLAYER_INVENTORY_ITEM__ACCOUNT
import work.fking.pangya.game.persistence.jooq.tables.records.PlayerInventoryItemRecord
import work.fking.pangya.game.player.ItemClubWorkshop
import work.fking.pangya.game.player.ItemUcc


/**
Expand Down Expand Up @@ -91,6 +93,16 @@ open class PlayerInventoryItem(
*/
val STATS: TableField<PlayerInventoryItemRecord, IntArray?> = createField(DSL.name("stats"), SQLDataType.JSON, this, "", JSONtoJacksonConverter<IntArray>(IntArray::class.java))

/**
* The column <code>public.player_inventory_item.ucc</code>.
*/
val UCC: TableField<PlayerInventoryItemRecord, ItemUcc?> = createField(DSL.name("ucc"), SQLDataType.JSON, this, "", JSONtoJacksonConverter<ItemUcc>(ItemUcc::class.java))

/**
* The column <code>public.player_inventory_item.club_workshop</code>.
*/
val CLUB_WORKSHOP: TableField<PlayerInventoryItemRecord, ItemClubWorkshop?> = createField(DSL.name("club_workshop"), SQLDataType.JSON, this, "", JSONtoJacksonConverter<ItemClubWorkshop>(ItemClubWorkshop::class.java))

private constructor(alias: Name, aliased: Table<PlayerInventoryItemRecord>?): this(alias, null, null, aliased, null)
private constructor(alias: Name, aliased: Table<PlayerInventoryItemRecord>?, parameters: Array<Field<*>?>?): this(alias, null, null, aliased, parameters)

Expand Down Expand Up @@ -151,18 +163,18 @@ open class PlayerInventoryItem(
override fun rename(name: Table<*>): PlayerInventoryItem = PlayerInventoryItem(name.getQualifiedName(), null)

// -------------------------------------------------------------------------
// Row5 type methods
// Row7 type methods
// -------------------------------------------------------------------------
override fun fieldsRow(): Row5<Int?, Int?, Int?, Int?, IntArray?> = super.fieldsRow() as Row5<Int?, Int?, Int?, Int?, IntArray?>
override fun fieldsRow(): Row7<Int?, Int?, Int?, Int?, IntArray?, ItemUcc?, ItemClubWorkshop?> = super.fieldsRow() as Row7<Int?, Int?, Int?, Int?, IntArray?, ItemUcc?, ItemClubWorkshop?>

/**
* Convenience mapping calling {@link SelectField#convertFrom(Function)}.
*/
fun <U> mapping(from: (Int?, Int?, Int?, Int?, IntArray?) -> U): SelectField<U> = convertFrom(Records.mapping(from))
fun <U> mapping(from: (Int?, Int?, Int?, Int?, IntArray?, ItemUcc?, ItemClubWorkshop?) -> U): SelectField<U> = convertFrom(Records.mapping(from))

/**
* Convenience mapping calling {@link SelectField#convertFrom(Class,
* Function)}.
*/
fun <U> mapping(toType: Class<U>, from: (Int?, Int?, Int?, Int?, IntArray?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
fun <U> mapping(toType: Class<U>, from: (Int?, Int?, Int?, Int?, IntArray?, ItemUcc?, ItemClubWorkshop?) -> U): SelectField<U> = convertFrom(toType, Records.mapping(from))
}
Loading

0 comments on commit 5453af9

Please sign in to comment.