diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/packet/handler/ClubSetUpgradePacketHandler.kt b/game-server/src/main/kotlin/work/fking/pangya/game/packet/handler/ClubSetUpgradePacketHandler.kt index a15f54a..7e8a9e3 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/packet/handler/ClubSetUpgradePacketHandler.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/packet/handler/ClubSetUpgradePacketHandler.kt @@ -3,7 +3,6 @@ package work.fking.pangya.game.packet.handler 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 diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ClubSetReplies.kt b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ClubSetReplies.kt deleted file mode 100644 index c4844c7..0000000 --- a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ClubSetReplies.kt +++ /dev/null @@ -1,17 +0,0 @@ -package work.fking.pangya.game.packet.outbound - -import work.fking.pangya.networking.protocol.OutboundPacket - -object ClubSetReplies { - - fun upgradeAck(type: Int, stat: Int, itemUid: Int, cost: Long): OutboundPacket { - return OutboundPacket { buffer -> - buffer.writeShortLE(0xa5) - buffer.writeByte(type) - 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? - } - } -} \ No newline at end of file diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ClubSetUpgradeReplies.kt b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ClubSetUpgradeReplies.kt new file mode 100644 index 0000000..6e81f8e --- /dev/null +++ b/game-server/src/main/kotlin/work/fking/pangya/game/packet/outbound/ClubSetUpgradeReplies.kt @@ -0,0 +1,26 @@ +package work.fking.pangya.game.packet.outbound + +import work.fking.pangya.networking.protocol.OutboundPacket + +object ClubSetUpgradeReplies { + + fun upgradeAck(result: UpgradeResult, stat: Int, itemUid: Int, cost: Long = 0): OutboundPacket { + return OutboundPacket { buffer -> + buffer.writeShortLE(0xa5) + 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) + } + } + + 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) + } +} \ No newline at end of file diff --git a/game-server/src/main/kotlin/work/fking/pangya/game/task/ChangeClubSetStatTask.kt b/game-server/src/main/kotlin/work/fking/pangya/game/task/ChangeClubSetStatTask.kt index 8168e23..86ce683 100644 --- a/game-server/src/main/kotlin/work/fking/pangya/game/task/ChangeClubSetStatTask.kt +++ b/game-server/src/main/kotlin/work/fking/pangya/game/task/ChangeClubSetStatTask.kt @@ -2,7 +2,12 @@ package work.fking.pangya.game.task import work.fking.pangya.game.model.IFF_TYPE_CLUBSET import work.fking.pangya.game.model.iffTypeFromId -import work.fking.pangya.game.packet.outbound.ClubSetReplies +import work.fking.pangya.game.packet.outbound.ClubSetUpgradeReplies +import work.fking.pangya.game.packet.outbound.ClubSetUpgradeReplies.UpgradeResult.CANNOT_DOWNGRADE_ANYMORE +import work.fking.pangya.game.packet.outbound.ClubSetUpgradeReplies.UpgradeResult.DOWNGRADE_SUCCESS +import work.fking.pangya.game.packet.outbound.ClubSetUpgradeReplies.UpgradeResult.INSUFFICIENT_PANG +import work.fking.pangya.game.packet.outbound.ClubSetUpgradeReplies.UpgradeResult.INSUFFICIENT_SLOTS +import work.fking.pangya.game.packet.outbound.ClubSetUpgradeReplies.UpgradeResult.UPGRADE_SUCCESS import work.fking.pangya.game.persistence.PersistenceContext import work.fking.pangya.game.player.Item import work.fking.pangya.game.player.Player @@ -45,7 +50,10 @@ class ChangeClubSetStatTask( SPIN, CURVE -> 1900 } val wallet = player.wallet - require(wallet.pangBalance >= cost) { "Player ${player.nickname} tried to upgrade an item but doesn't have enough pang" } + + if (wallet.pangBalance < cost) { + player.writeAndFlush(ClubSetUpgradeReplies.upgradeAck(result = INSUFFICIENT_PANG, stat = stat.ordinal, itemUid = itemUid)) + } // TODO: verify clubset upgrade limits persistenceCtx.transactional { tx -> @@ -54,15 +62,18 @@ 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)) + player.writeAndFlush(ClubSetUpgradeReplies.upgradeAck(result = UPGRADE_SUCCESS, stat = stat.ordinal, itemUid = itemUid, cost = cost)) } private fun downgrade(clubSet: Item) { - require(clubSet.stats[stat.ordinal] > 0) { "Player ${player.nickname} tried to downgrade an item but the stat is already at 0" } + if (clubSet.stats[stat.ordinal] <= 0) { + player.writeAndFlush(ClubSetUpgradeReplies.upgradeAck(result = CANNOT_DOWNGRADE_ANYMORE, stat = stat.ordinal, itemUid = itemUid)) + return + } clubSet.stats[stat.ordinal]-- persistenceCtx.inventoryRepository.saveItem(persistenceCtx.noTxContext(), player.uid, clubSet) - player.writeAndFlush(ClubSetReplies.upgradeAck(type, stat.ordinal, itemUid, 0)) + player.writeAndFlush(ClubSetUpgradeReplies.upgradeAck(result = DOWNGRADE_SUCCESS, stat = stat.ordinal, itemUid = itemUid)) } }