Skip to content

Commit

Permalink
quit pratice mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-agon committed Jul 10, 2023
1 parent 2ed20ad commit 172c67f
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ 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.match.MatchPlayerHoleFinishPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchFinishPlayerPreviewPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchHoleStartPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerHoleFinishPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerQuitPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerRotateAimPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerShotCommitPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerTurnEndPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerShotStartPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerShotSyncPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerTurnEndPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchPlayerUseItemPacketHandler
import work.fking.pangya.game.packet.handler.match.MatchTourneyShotPacketHandler
import work.fking.pangya.game.packet.handler.match.StartGamePacketHandler
Expand Down Expand Up @@ -67,6 +68,7 @@ enum class ClientPacketType(
UNKNOWN_9C(0x9c),
UNKNOWN_C1(0xC1),
LOCKER_INVENTORY_REQUEST(0xd3, LockerInventoryRequestPacketHandler()),
MATCH_PLAYER_QUIT(0x130, MatchPlayerQuitPacketHandler()),
UNKNOWN_140(0x140),
ACHIEVEMENT_STATUS_REQUEST(0x157),
MATCH_PLAYER_TOURNEY_SHOT(0x12f, MatchTourneyShotPacketHandler()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ class JoinLobbyPacketHandler : ClientPacketHandler {
artifactIffId = 0,
naturalWind = false
)
player.writeAndFlush(RoomReplies.list(listOf(
roomVersus,
roomTournament,
roomLounge
)))
player.writeAndFlush(
RoomReplies.list(
listOf(
roomVersus,
roomTournament,
roomLounge
)
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class MatchHoleStartPacketHandler : ClientPacketHandler {
val holeCoord = Coord2D(packet.readFloatLE(), packet.readFloatLE())


room.handleMatchEvent(PlayerHoleStartEvent(
player = roomPlayer,
hole = hole.toInt(),
par = par.toInt(),
teeCoord = teeCoord,
holeCoord = holeCoord
))
room.handleMatchEvent(
PlayerHoleStartEvent(
player = roomPlayer,
hole = hole.toInt(),
par = par.toInt(),
teeCoord = teeCoord,
holeCoord = holeCoord
)
)
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package work.fking.pangya.game.packet.handler.match

import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufUtil
import work.fking.pangya.game.GameServer
import work.fking.pangya.game.net.ClientPacketHandler
import work.fking.pangya.game.player.Player
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package work.fking.pangya.game.packet.handler.match

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
import work.fking.pangya.game.room.match.PlayerQuitEvent

class MatchPlayerQuitPacketHandler : ClientPacketHandler {
override fun handle(server: GameServer, player: Player, packet: ByteBuf) {
val room = player.currentRoom ?: throw IllegalStateException("Player ${player.nickname} finished a hole but is not in a room")
val roomPlayer = room.findSelf(player)
room.handleMatchEvent(PlayerQuitEvent(roomPlayer))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class MatchPlayerShotSyncPacketHandler : ClientPacketHandler {
val shotFrames = packet.readShortLE().toInt() // i think this is the travel time in frames?
val grandPrixPenalties = packet.readByte().toInt()

room.handleMatchEvent(PlayerShotSyncEvent(
player = roomPlayer,
x = x,
z = z,
shotFlags = shotFlags,
frames = shotFrames
))
room.handleMatchEvent(
PlayerShotSyncEvent(
player = roomPlayer,
x = x,
z = z,
shotFlags = shotFlags,
frames = shotFrames
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import work.fking.pangya.game.room.RoomNaturalWindChange
import work.fking.pangya.game.room.RoomPasswordChange
import work.fking.pangya.game.room.RoomPlayerCountChange
import work.fking.pangya.game.room.RoomShotTimeChange
import work.fking.pangya.game.room.RoomType
import work.fking.pangya.game.room.RoomTypeChange
import work.fking.pangya.game.room.RoomUpdate
import work.fking.pangya.game.room.courseById
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package work.fking.pangya.game.packet.outbound

import io.netty.buffer.ByteBufUtil
import work.fking.pangya.game.model.CourseStatistics
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.player.PlayerBasicInfo
import work.fking.pangya.game.player.PlayerStatistic
import work.fking.pangya.game.player.PlayerTrophies
import work.fking.pangya.game.player.write
import work.fking.pangya.game.room.Course
import work.fking.pangya.game.room.CourseStatistics
import work.fking.pangya.networking.protocol.OutboundPacket
import work.fking.pangya.networking.protocol.writeFixedSizeString
import work.fking.pangya.networking.protocol.writeLocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package work.fking.pangya.game.packet.outbound

import work.fking.pangya.common.Rand
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.room.Room
import work.fking.pangya.game.room.RoomPlayer
Expand Down Expand Up @@ -164,4 +163,48 @@ object MatchReplies {
tourneyShotData.serialize(buffer)
}
}

fun gameTourneyEndingScore(): OutboundPacket {
return OutboundPacket { buffer ->
buffer.writeShortLE(0x79)
buffer.writeIntLE(100) // experience
buffer.writeIntLE(738197504) // trophy IffId
buffer.writeByte(0) // trophy again?
buffer.writeByte(0) // which team won? 0 red 1 blue 2 neither

repeat(12) { // medals
buffer.writeIntLE(0) // uniqueId
buffer.writeIntLE(0) // iffId
}
}
}

fun gameTourneyWinnings(): OutboundPacket {
return OutboundPacket { buffer ->
buffer.writeShortLE(0xce)
buffer.writeByte(0)
buffer.writeShortLE(1) // count

repeat(1) {
buffer.writeIntLE(402653195) // item iffIds
}
}
}

fun gameTourneyTimeout(): OutboundPacket {
return OutboundPacket { buffer -> buffer.writeShortLE(0x8c) }
}

fun gameTourneyUpdatePlayerProgress(player: RoomPlayer): OutboundPacket {
return OutboundPacket { buffer ->
buffer.writeShortLE(0x6d)
buffer.writeIntLE(player.connectionId)
buffer.writeByte(player.currentHole) // hole
buffer.writeByte(3) // total strokes?
buffer.writeIntLE(-1) // score
buffer.writeLongLE(30) // pang
buffer.writeLongLE(1) // bonus pang
buffer.writeByte(1) // finished the hole 1 or 0 not
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package work.fking.pangya.game.packet.outbound

import io.netty.buffer.ByteBuf
import work.fking.pangya.networking.protocol.OutboundPacket

object PapelShopReplies {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package work.fking.pangya.game.packet.outbound

import work.fking.pangya.game.room.Course
import work.fking.pangya.game.model.CourseStatistics
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.player.PlayerBasicInfo
import work.fking.pangya.game.player.PlayerStatistic
import work.fking.pangya.game.player.PlayerTrophies
import work.fking.pangya.game.player.Player
import work.fking.pangya.game.player.write
import work.fking.pangya.game.room.Course
import work.fking.pangya.game.room.CourseStatistics
import work.fking.pangya.networking.protocol.OutboundPacket

object UserStatisticsReplies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package work.fking.pangya.game.player

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.model.IffObject
import java.time.Instant
import java.time.temporal.ChronoField
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalUnit

@JvmRecord
data class Caddie(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package work.fking.pangya.game.player

import work.fking.pangya.common.Rand
import work.fking.pangya.game.model.IffContainer
import work.fking.pangya.game.model.IFF_TYPE_CADDIE
import work.fking.pangya.game.model.IffContainer
import work.fking.pangya.game.model.iffTypeFromId

class CaddieRoster(override val entries: MutableList<Caddie> = ArrayList()) : IffContainer<Caddie> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package work.fking.pangya.game.player

import io.netty.buffer.ByteBuf
import work.fking.pangya.common.Rand
import work.fking.pangya.game.model.IFF_TYPE_CLUBSET
import work.fking.pangya.game.model.IFF_TYPE_BALL
import work.fking.pangya.game.model.IFF_TYPE_ITEM
import work.fking.pangya.game.model.IffObject
import work.fking.pangya.game.model.iffTypeFromId
Expand All @@ -26,7 +26,7 @@ class Item(
buffer.writeIntLE(iffId)
buffer.writeIntLE(0)
// if the item is not quantifiable, this is the item current stats
if (iffTypeFromId(iffId) == IFF_TYPE_ITEM) {
if (iffTypeFromId(iffId) in intArrayOf(IFF_TYPE_ITEM, IFF_TYPE_BALL)) {
buffer.writeIntLE(quantity)
buffer.writeZero(180)
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package work.fking.pangya.game.player

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.player.Player
import work.fking.pangya.networking.protocol.writeFixedSizeString

class PlayerBasicInfo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package work.fking.pangya.game.model
package work.fking.pangya.game.room

import io.netty.buffer.ByteBuf
import work.fking.pangya.game.room.Course

class CourseStatistics(
private val course: Course
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class RoomCourseChange(val course: Course) : RoomUpdate
data class RoomHoleCountChange(val count: Int) : RoomUpdate
data class RoomHoleModeChange(val holeMode: HoleMode) : RoomUpdate
data class RoomShotTimeChange(val shotTime: Int) : RoomUpdate
data class RoomPlayerCountChange(val playerCount : Int) : RoomUpdate
data class RoomPlayerCountChange(val playerCount: Int) : RoomUpdate
data class RoomGameTimeChange(val gameTime: Int) : RoomUpdate
data class RoomArtifactChange(val artifactIffId: Int) : RoomUpdate
data class RoomNaturalWindChange(val naturalWind: Boolean) : RoomUpdate
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ data class PlayerShotStartEvent(val player: RoomPlayer) : MatchEvent
data class PlayerTurnEndEvent(val player: RoomPlayer) : MatchEvent
data class PlayerTourneyShotEvent(val player: RoomPlayer, val tourneyShotData: TourneyShotData) : MatchEvent
data class PlayerShotSyncEvent(val player: RoomPlayer, val x: Float, val z: Float, val shotFlags: Int, val frames: Int) : MatchEvent
data class PlayerUseItemEvent(val player: RoomPlayer, val itemIffId: Int): MatchEvent
data class PlayerUseItemEvent(val player: RoomPlayer, val itemIffId: Int) : MatchEvent
data class PlayerQuitEvent(val player: RoomPlayer) : MatchEvent
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class PracticeMatchDirector : MatchDirector {
is PlayerTourneyShotEvent -> handleTourneyShot(room, event)
is PlayerShotSyncEvent -> handleShotSync(room, event)
is PlayerUseItemEvent -> handleUseItem(room, event)
is PlayerQuitEvent -> handlePlayerQuit(room, event)
else -> return
}
}
Expand Down Expand Up @@ -56,4 +57,13 @@ class PracticeMatchDirector : MatchDirector {
val randSeed = Rand.nextInt()
room.broadcast(MatchReplies.gamePlayerUseItem(event.player, event.itemIffId, randSeed))
}

private fun handlePlayerQuit(room: Room, event: PlayerQuitEvent) {
with(event.player) {
write(MatchReplies.gameTourneyEndingScore())
write(MatchReplies.gameTourneyWinnings())
write(MatchReplies.gameTourneyTimeout())
}
room.broadcast(MatchReplies.gameTourneyUpdatePlayerProgress(event.player))
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package work.fking.pangya.networking.protocol

import dev.pangya.lzo.MiniLZO
import io.netty.buffer.ByteBuf
import io.netty.buffer.Unpooled
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.MessageToByteEncoder
import org.apache.logging.log4j.LogManager
import work.fking.pangya.networking.crypt.PangCrypt
import dev.pangya.lzo.MiniLZO

class ProtocolEncoder(
private val cryptKey: Int
Expand Down

0 comments on commit 172c67f

Please sign in to comment.