feat(game): let the player replace a move on level up (#90)

This commit is contained in:
Fiereu authored and GitHub committed 2026-08-05 23:10:59 +02:00
1 parent 1ecfabaed5
commit 4470cbda37
11 files changed
+281 -66

No files matched your search

@@ -6,6 +6,7 @@ import de.fiereu.network.c2s
import de.fiereu.network.s2c
import de.fiereu.openmmo.net.game.packets.*
import de.fiereu.openmmo.net.game.packets.battle.*
import de.fiereu.openmmo.net.game.packets.battle.moves.*
import de.fiereu.openmmo.net.game.packets.dialog.*
import de.fiereu.openmmo.net.game.packets.guild.*
@@ -38,7 +39,7 @@ object GameProtocol : Protocol() {
bidi<ChatMessagePacket>(0x09u, ChatMessagePacketCodec)
c2s<BattleMoveUsePacket>(0x0Au, BattleMoveUsePacketCodec)
c2s<MoveLearnReplyPacket>(0x0Au, MoveLearnReplyPacketCodec)
s2c<WorldFlagTableResetPacket>(0x0Au, WorldFlagTableResetPacketCodec)
c2s<EvolutionPromptResponsePacket>(0x0Bu, EvolutionPromptResponsePacketCodec)
@@ -73,7 +74,7 @@ object GameProtocol : Protocol() {
s2c<BattleEntityDeltaPacket>(0x16u, BattleEntityDeltaPacketCodec)
c2s<StorageBoxClosePacket>(0x17u, StorageBoxClosePacketCodec)
s2c<SocialEntryFlagSetPacket>(0x17u, SocialEntryFlagSetPacketCodec)
s2c<MoveLearnPromptPacket>(0x17u, MoveLearnPromptPacketCodec)
c2s<MonsterStatusConditionPacket>(0x18u, MonsterStatusConditionPacketCodec)
s2c<SocialEntryPresencePacket>(0x18u, SocialEntryPresencePacketCodec)
@@ -1,18 +0,0 @@
package de.fiereu.openmmo.net.game.packets
import de.fiereu.bytecodec.*
data class SocialEntryFlagSetPacket(
val playerId: Long,
val flag: Byte,
val value: Short,
)
object SocialEntryFlagSetPacketCodec : PacketCodec<SocialEntryFlagSetPacket>() {
override fun CodecScope<SocialEntryFlagSetPacket>.body(): SocialEntryFlagSetPacket {
val playerId = field(S64LE) { it.playerId }
val flag = field(S8) { it.flag }
val value = field(S16LE) { it.value }
return SocialEntryFlagSetPacket(playerId, flag, value)
}
}
@@ -1,18 +0,0 @@
package de.fiereu.openmmo.net.game.packets.battle
import de.fiereu.bytecodec.*
data class BattleMoveUsePacket(
val targetEntityId: Long,
val moveSlotIndex: Byte,
val moveId: Short,
)
object BattleMoveUsePacketCodec : PacketCodec<BattleMoveUsePacket>() {
override fun CodecScope<BattleMoveUsePacket>.body(): BattleMoveUsePacket {
val targetEntityId = field(S64LE) { it.targetEntityId }
val moveSlotIndex = field(S8) { it.moveSlotIndex }
val moveId = field(S16LE) { it.moveId }
return BattleMoveUsePacket(targetEntityId, moveSlotIndex, moveId)
}
}
@@ -0,0 +1,17 @@
package de.fiereu.openmmo.net.game.packets.battle.moves
import de.fiereu.bytecodec.*
/** Asks the player which move to drop for a new one. */
data class MoveLearnPromptPacket(
val entityId: Long,
val offered: List<Short>,
)
object MoveLearnPromptPacketCodec : PacketCodec<MoveLearnPromptPacket>() {
override fun CodecScope<MoveLearnPromptPacket>.body(): MoveLearnPromptPacket {
val entityId = field(S64LE) { it.entityId }
val offered = field(S16LE.listPrefixed(U8)) { it.offered }
return MoveLearnPromptPacket(entityId, offered)
}
}
@@ -0,0 +1,19 @@
package de.fiereu.openmmo.net.game.packets.battle.moves
import de.fiereu.bytecodec.*
/** The moveset the player picked. A new move sits in the slot it takes over. */
data class MoveLearnReplyPacket(
val entityId: Long,
val moveIds: List<Short>,
val offered: List<Short>,
)
object MoveLearnReplyPacketCodec : PacketCodec<MoveLearnReplyPacket>() {
override fun CodecScope<MoveLearnReplyPacket>.body(): MoveLearnReplyPacket {
val entityId = field(S64LE) { it.entityId }
val moveIds = field(S16LE.listPrefixed(U8)) { it.moveIds }
val offered = field(S16LE.listPrefixed(U8)) { it.offered }
return MoveLearnReplyPacket(entityId, moveIds, offered)
}
}
@@ -0,0 +1,81 @@
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.battle.moves.MoveLearnPromptPacket
import de.fiereu.openmmo.net.game.packets.battle.moves.MoveLearnPromptPacketCodec
import de.fiereu.openmmo.net.game.packets.battle.moves.MoveLearnReplyPacket
import de.fiereu.openmmo.net.game.packets.battle.moves.MoveLearnReplyPacketCodec
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
private const val ENTITY_ID = 0x1ACEADEF2AC8C000L
private const val FURY_SWIPES: Short = 154
private const val LICK: Short = 122
private const val WATER_GUN: Short = 55
private const val LEER: Short = 43
private const val UNOVA_MOVE: Short = 526
private fun entityIdBytes() =
byteArrayOf(
0x00, 0xC0.toByte(), 0xC8.toByte(), 0x2A, 0xEF.toByte(), 0xAD.toByte(), 0xCE.toByte(), 0x1A)
class MoveLearnPacketsTest :
FunSpec({
test("decodes a captured prompt for one move") {
val bytes = entityIdBytes() + byteArrayOf(0x01, 0x9A.toByte(), 0x00)
val decoded = MoveLearnPromptPacketCodec.decodeBytes(bytes)
decoded shouldBe MoveLearnPromptPacket(ENTITY_ID, listOf(FURY_SWIPES))
MoveLearnPromptPacketCodec.encodeToBytes(decoded) shouldBe bytes
}
test("decodes a captured prompt for two moves") {
val bytes = entityIdBytes() + byteArrayOf(0x02, 0x18, 0x02, 0x59, 0x01)
val decoded = MoveLearnPromptPacketCodec.decodeBytes(bytes)
decoded shouldBe MoveLearnPromptPacket(ENTITY_ID, listOf(536, 345))
MoveLearnPromptPacketCodec.encodeToBytes(decoded) shouldBe bytes
}
// Fury Swipes took the slot Leer held.
test("decodes a captured reply that swapped a move in") {
val bytes =
entityIdBytes() +
byteArrayOf(
0x04,
0x0E,
0x02,
0x9A.toByte(),
0x00,
0x7A,
0x00,
0x37,
0x00,
0x01,
0x9A.toByte(),
0x00)
val decoded = MoveLearnReplyPacketCodec.decodeBytes(bytes)
decoded shouldBe
MoveLearnReplyPacket(
entityId = ENTITY_ID,
moveIds = listOf(UNOVA_MOVE, FURY_SWIPES, LICK, WATER_GUN),
offered = listOf(FURY_SWIPES),
)
MoveLearnReplyPacketCodec.encodeToBytes(decoded) shouldBe bytes
}
// The moveset comes back as it was, so the player kept Leer.
test("decodes a captured reply that declined") {
val bytes =
entityIdBytes() +
byteArrayOf(
0x04, 0x0E, 0x02, 0x2B, 0x00, 0x7A, 0x00, 0x37, 0x00, 0x01, 0x9A.toByte(), 0x00)
val decoded = MoveLearnReplyPacketCodec.decodeBytes(bytes)
decoded shouldBe
MoveLearnReplyPacket(
entityId = ENTITY_ID,
moveIds = listOf(UNOVA_MOVE, LEER, LICK, WATER_GUN),
offered = listOf(FURY_SWIPES),
)
MoveLearnReplyPacketCodec.encodeToBytes(decoded) shouldBe bytes
}
})