feat(game): handle npc dialog replies and send correct dialog actions (#63)
This commit is contained in:
1 parent
35a7966a97
commit
e89ae6e6df
10 files changed
+97
-74
No files matched your search
@@ -6,6 +6,7 @@ import de.fiereu.network.c2s
|
|||||||
import de.fiereu.network.s2c
|
import de.fiereu.network.s2c
|
||||||
import de.fiereu.openmmo.net.game.packets.*
|
import de.fiereu.openmmo.net.game.packets.*
|
||||||
import de.fiereu.openmmo.net.game.packets.battle.*
|
import de.fiereu.openmmo.net.game.packets.battle.*
|
||||||
|
import de.fiereu.openmmo.net.game.packets.dialog.*
|
||||||
import de.fiereu.openmmo.net.game.packets.guild.*
|
import de.fiereu.openmmo.net.game.packets.guild.*
|
||||||
|
|
||||||
object GameProtocol : Protocol() {
|
object GameProtocol : Protocol() {
|
||||||
@@ -97,7 +98,7 @@ object GameProtocol : Protocol() {
|
|||||||
c2s<NullPacket>(0x20u, NullPacketCodec)
|
c2s<NullPacket>(0x20u, NullPacketCodec)
|
||||||
s2c<TokenPayloadPacket>(0x20u, TokenPayloadPacketCodec)
|
s2c<TokenPayloadPacket>(0x20u, TokenPayloadPacketCodec)
|
||||||
|
|
||||||
c2s<WarpTileInteractPacket>(0x21u, WarpTileInteractPacketCodec)
|
c2s<DialogActionResponsePacket>(0x21u, DialogActionResponsePacketCodec)
|
||||||
s2c<DialogActionPacket>(0x21u, DialogActionPacketCodec)
|
s2c<DialogActionPacket>(0x21u, DialogActionPacketCodec)
|
||||||
|
|
||||||
bidi<EntityInteractPacket>(0x22u, EntityInteractPacketCodec)
|
bidi<EntityInteractPacket>(0x22u, EntityInteractPacketCodec)
|
||||||
|
|||||||
-26
@@ -1,26 +0,0 @@
|
|||||||
package de.fiereu.openmmo.net.game.packets
|
|
||||||
|
|
||||||
import de.fiereu.bytecodec.*
|
|
||||||
|
|
||||||
data class InteractivePacket(
|
|
||||||
val id: Int,
|
|
||||||
val type: Int,
|
|
||||||
val unk1: Int,
|
|
||||||
val unk2: Int,
|
|
||||||
val targetEntityId: Long,
|
|
||||||
val unk3: Int,
|
|
||||||
val unk4: Int,
|
|
||||||
)
|
|
||||||
|
|
||||||
object InteractivePacketCodec : PacketCodec<InteractivePacket>() {
|
|
||||||
override fun CodecScope<InteractivePacket>.body(): InteractivePacket {
|
|
||||||
val id = field(U8) { it.id }
|
|
||||||
val type = field(U8) { it.type }
|
|
||||||
val unk1 = field(S32LE) { it.unk1 }
|
|
||||||
val unk2 = field(S32LE) { it.unk2 }
|
|
||||||
val targetEntityId = field(S64LE) { it.targetEntityId }
|
|
||||||
val unk3 = field(U16LE) { it.unk3 }
|
|
||||||
val unk4 = field(U16LE) { it.unk4 }
|
|
||||||
return InteractivePacket(id, type, unk1, unk2, targetEntityId, unk3, unk4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
package de.fiereu.openmmo.net.game.packets
|
|
||||||
|
|
||||||
import de.fiereu.bytecodec.CodecScope
|
|
||||||
import de.fiereu.bytecodec.PacketCodec
|
|
||||||
import de.fiereu.bytecodec.U8
|
|
||||||
|
|
||||||
data class InteractiveResponsePacket(val id: Int, val unk: Int)
|
|
||||||
|
|
||||||
object InteractiveResponsePacketCodec : PacketCodec<InteractiveResponsePacket>() {
|
|
||||||
override fun CodecScope<InteractiveResponsePacket>.body(): InteractiveResponsePacket {
|
|
||||||
val id = field(U8) { it.id }
|
|
||||||
val unk = field(U8) { it.unk }
|
|
||||||
return InteractiveResponsePacket(id, unk)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
package de.fiereu.openmmo.net.game.packets
|
|
||||||
|
|
||||||
import de.fiereu.bytecodec.CodecScope
|
|
||||||
import de.fiereu.bytecodec.PacketCodec
|
|
||||||
import de.fiereu.bytecodec.S8
|
|
||||||
|
|
||||||
data class WarpTileInteractPacket(
|
|
||||||
val floorId: Byte,
|
|
||||||
val warpMode: Byte,
|
|
||||||
)
|
|
||||||
|
|
||||||
object WarpTileInteractPacketCodec : PacketCodec<WarpTileInteractPacket>() {
|
|
||||||
override fun CodecScope<WarpTileInteractPacket>.body(): WarpTileInteractPacket {
|
|
||||||
val floorId = field(S8) { it.floorId }
|
|
||||||
val warpMode = field(S8) { it.warpMode }
|
|
||||||
return WarpTileInteractPacket(floorId, warpMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package de.fiereu.openmmo.net.game.packets
|
package de.fiereu.openmmo.net.game.packets.dialog
|
||||||
|
|
||||||
import de.fiereu.bytecodec.*
|
import de.fiereu.bytecodec.*
|
||||||
|
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package de.fiereu.openmmo.net.game.packets.dialog
|
||||||
|
|
||||||
|
import de.fiereu.bytecodec.CodecScope
|
||||||
|
import de.fiereu.bytecodec.PacketCodec
|
||||||
|
import de.fiereu.bytecodec.U8
|
||||||
|
|
||||||
|
data class DialogActionResponsePacket(val id: Int, val unk: Int)
|
||||||
|
|
||||||
|
object DialogActionResponsePacketCodec : PacketCodec<DialogActionResponsePacket>() {
|
||||||
|
override fun CodecScope<DialogActionResponsePacket>.body(): DialogActionResponsePacket {
|
||||||
|
val id = field(U8) { it.id }
|
||||||
|
val unk = field(U8) { it.unk }
|
||||||
|
return DialogActionResponsePacket(id, unk)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package de.fiereu.openmmo.net.game
|
||||||
|
|
||||||
|
import de.fiereu.bytecodec.test.decodeBytes
|
||||||
|
import de.fiereu.bytecodec.test.encodeToBytes
|
||||||
|
import de.fiereu.openmmo.net.game.packets.dialog.CreatureDataArg
|
||||||
|
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionPacketCodec
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
|
||||||
|
private fun bytes(hex: String): ByteArray =
|
||||||
|
hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||||
|
|
||||||
|
private fun ByteArray.hex(): String = joinToString("") { "%02x".format(it) }
|
||||||
|
|
||||||
|
class DialogActionPacketTest :
|
||||||
|
FunSpec({
|
||||||
|
// Every case is a real 0x21 dialog action from the NPC interaction capture.
|
||||||
|
val captures =
|
||||||
|
listOf(
|
||||||
|
"0c2e0d00b52903e008bf86c4c01ab004000000",
|
||||||
|
"006400000000ffffffffffffffff0000000000",
|
||||||
|
"0e04f90600010ae008bf86c4c01ab004000000",
|
||||||
|
"0d04f80600010ae008bf86c4c01ab004000001000992d00300",
|
||||||
|
)
|
||||||
|
|
||||||
|
test("round-trips every captured dialog action byte for byte") {
|
||||||
|
captures.forEach { hex ->
|
||||||
|
val packet = DialogActionPacketCodec.decodeBytes(bytes(hex))
|
||||||
|
DialogActionPacketCodec.encodeToBytes(packet).hex() shouldBe hex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test("decodes the fields of a dialog action carrying a creature arg") {
|
||||||
|
val packet =
|
||||||
|
DialogActionPacketCodec.decodeBytes(
|
||||||
|
bytes("0d04f80600010ae008bf86c4c01ab004000001000992d00300"))
|
||||||
|
packet.flags shouldBe 0x0d.toByte()
|
||||||
|
packet.actionType shouldBe 0x04.toByte()
|
||||||
|
packet.textId shouldBe 0x010006f8
|
||||||
|
packet.entityId shouldBe 0x1ac0c486bf08e00aL
|
||||||
|
packet.contextValue shouldBe 0x04b0
|
||||||
|
packet.messageArgs shouldBe listOf(CreatureDataArg(0x03d09209, emptyList()))
|
||||||
|
}
|
||||||
|
})
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package de.fiereu.openmmo.net.game
|
||||||
|
|
||||||
|
import de.fiereu.bytecodec.test.decodeBytes
|
||||||
|
import de.fiereu.bytecodec.test.encodeToBytes
|
||||||
|
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacketCodec
|
||||||
|
import io.kotest.core.spec.style.FunSpec
|
||||||
|
import io.kotest.matchers.shouldBe
|
||||||
|
|
||||||
|
class DialogActionResponsePacketTest :
|
||||||
|
FunSpec({
|
||||||
|
// The client replies to a 0x21 dialog action with the action id and a response byte. This is
|
||||||
|
// the "0c 00" the capture sends back after the "0c" dialog action.
|
||||||
|
test("round-trips the captured dialog reply") {
|
||||||
|
val bytes = byteArrayOf(0x0c, 0x00)
|
||||||
|
val packet = DialogActionResponsePacketCodec.decodeBytes(bytes)
|
||||||
|
packet shouldBe DialogActionResponsePacket(id = 0x0c, unk = 0)
|
||||||
|
DialogActionResponsePacketCodec.encodeToBytes(packet) shouldBe bytes
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -16,7 +16,6 @@ import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
|||||||
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
|
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket
|
import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.InteractiveResponsePacket
|
|
||||||
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
import de.fiereu.openmmo.net.game.packets.JoinPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
import de.fiereu.openmmo.net.game.packets.KeepAlivePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
import de.fiereu.openmmo.net.game.packets.MovementPacket
|
||||||
@@ -48,6 +47,7 @@ import de.fiereu.openmmo.net.game.packets.battle.BattleTeamPreviewConfirmPacket
|
|||||||
import de.fiereu.openmmo.net.game.packets.battle.BattleTierSelectPacket
|
import de.fiereu.openmmo.net.game.packets.battle.BattleTierSelectPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.battle.BattleTransitionReadyPacket
|
import de.fiereu.openmmo.net.game.packets.battle.BattleTransitionReadyPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.battle.BattleUseItemPacket
|
import de.fiereu.openmmo.net.game.packets.battle.BattleUseItemPacket
|
||||||
|
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.guild.GuildActivityLogPageRequestPacket
|
import de.fiereu.openmmo.net.game.packets.guild.GuildActivityLogPageRequestPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.guild.GuildCreatePacket
|
import de.fiereu.openmmo.net.game.packets.guild.GuildCreatePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.guild.GuildDisbandPacket
|
import de.fiereu.openmmo.net.game.packets.guild.GuildDisbandPacket
|
||||||
@@ -104,7 +104,7 @@ constructor(
|
|||||||
onSuspend<FaceDirectionPacket> { event -> movementService.onFaceDirection(event) }
|
onSuspend<FaceDirectionPacket> { event -> movementService.onFaceDirection(event) }
|
||||||
|
|
||||||
onSuspend<EntityInteractPacket> { event -> interactionService.onEntityInteract(event) }
|
onSuspend<EntityInteractPacket> { event -> interactionService.onEntityInteract(event) }
|
||||||
onSuspend<InteractiveResponsePacket> { event -> dialogService.onInteractive(event) }
|
onSuspend<DialogActionResponsePacket> { event -> dialogService.onInteractive(event) }
|
||||||
onSuspend<DialogChoicePacket> { event -> dialogService.onDialogChoice(event) }
|
onSuspend<DialogChoicePacket> { event -> dialogService.onDialogChoice(event) }
|
||||||
|
|
||||||
on<AddFriendPacket> { event -> socialService.onAddFriend(event) }
|
on<AddFriendPacket> { event -> socialService.onAddFriend(event) }
|
||||||
|
|||||||
+13
-11
@@ -4,8 +4,8 @@ import de.fiereu.network.PacketEvent
|
|||||||
import de.fiereu.network.SessionContext
|
import de.fiereu.network.SessionContext
|
||||||
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.DialogStatePacket
|
import de.fiereu.openmmo.net.game.packets.DialogStatePacket
|
||||||
import de.fiereu.openmmo.net.game.packets.InteractivePacket
|
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionPacket
|
||||||
import de.fiereu.openmmo.net.game.packets.InteractiveResponsePacket
|
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket
|
||||||
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
|
||||||
import de.fiereu.openmmo.server.game.session.ScriptPage
|
import de.fiereu.openmmo.server.game.session.ScriptPage
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
@@ -52,18 +52,20 @@ class DialogService @Inject constructor() {
|
|||||||
unk3: Int = 0x0708,
|
unk3: Int = 0x0708,
|
||||||
) {
|
) {
|
||||||
ctx.send(
|
ctx.send(
|
||||||
InteractivePacket(
|
DialogActionPacket(
|
||||||
id = id,
|
flags = id.toByte(),
|
||||||
type = type,
|
actionType = type.toByte(),
|
||||||
unk1 = unk1,
|
// The client reads the text id as one little endian int whose two halves the scripts
|
||||||
unk2 = unk2,
|
// carry as unk1 (low) and unk2 (high).
|
||||||
targetEntityId = entityId,
|
textId = unk1 or (unk2 shl 16),
|
||||||
unk3 = unk3,
|
entityId = entityId,
|
||||||
unk4 = 0,
|
contextValue = unk3,
|
||||||
|
messageArgs = emptyList(),
|
||||||
|
detail = ByteArray(0),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onInteractive(event: PacketEvent<InteractiveResponsePacket>) {
|
fun onInteractive(event: PacketEvent<DialogActionResponsePacket>) {
|
||||||
val ctx = event.session
|
val ctx = event.session
|
||||||
val state = ctx.attributes[PLAYER_STATE] ?: return
|
val state = ctx.attributes[PLAYER_STATE] ?: return
|
||||||
val charId = state.characterId ?: return
|
val charId = state.characterId ?: return
|
||||||
|
|||||||
Reference in new issue
Block a user