feat(game): keep the appearance the client picks at character creation (#145)
This commit is contained in:
1 parent
0dab4b16fa
commit
0200858be9
14 files changed
+234
-18
No files matched your search
@@ -1,12 +1,22 @@
|
||||
package de.fiereu.openmmo.net.game.codecs
|
||||
|
||||
import de.fiereu.bytecodec.*
|
||||
import de.fiereu.openmmo.common.Skin
|
||||
import de.fiereu.openmmo.common.enums.SkinSlot
|
||||
import java.util.*
|
||||
|
||||
data class Skin(val slot: SkinSlot, val type: UShort?, val color: UByte?)
|
||||
// Type and color share one 16 bit word.
|
||||
private const val TYPE_MASK = 0x3FF
|
||||
private const val COLOR_SHIFT = 10
|
||||
private const val COLOR_MASK = 0x3F
|
||||
|
||||
class SkinSet(var regionSelectionIndex: Int = 0, skins: Map<SkinSlot, Skin> = emptyMap()) :
|
||||
EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||
|
||||
init {
|
||||
putAll(skins)
|
||||
}
|
||||
|
||||
class SkinSet(var regionSelectionIndex: Int = 0) : EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||
fun put(skin: Skin) {
|
||||
this[skin.slot] = skin
|
||||
}
|
||||
@@ -33,14 +43,14 @@ class SkinSetCodec(
|
||||
val compressed =
|
||||
field(U16LE) {
|
||||
val skin = it[slot] ?: Skin(slot, 0u, 0u)
|
||||
val type = skin.type ?: 0x3FFFu
|
||||
val color = skin.color ?: 0x3Fu
|
||||
require(type <= 0x3FFFu) { "Skin type too large: ${skin.type}" }
|
||||
require(color <= 0x3Fu) { "Skin color too large: ${skin.color}" }
|
||||
(type and 0x3FFFu).toInt() or ((color and 0x3Fu).toInt() shl 10)
|
||||
val type = (skin.type ?: TYPE_MASK.toUShort()).toInt()
|
||||
val color = (skin.color ?: COLOR_MASK.toUByte()).toInt()
|
||||
require(type <= TYPE_MASK) { "Skin type too large: ${skin.type}" }
|
||||
require(color <= COLOR_MASK) { "Skin color too large: ${skin.color}" }
|
||||
type or (color shl COLOR_SHIFT)
|
||||
}
|
||||
val type = (compressed and 0x3FFF).toUShort()
|
||||
val color = ((compressed shr 10) and 0x3F).toUByte()
|
||||
val type = (compressed and TYPE_MASK).toUShort()
|
||||
val color = ((compressed shr COLOR_SHIFT) and COLOR_MASK).toUByte()
|
||||
skins.put(Skin(slot, type, color))
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -8,6 +8,8 @@ import de.fiereu.openmmo.net.game.codecs.*
|
||||
data class CharacterEntry(
|
||||
val characterInfo: CharacterInfo,
|
||||
val skinSet: SkinSet,
|
||||
/** A second set of the same shape, empty in every capture and still unidentified. */
|
||||
val secondarySkinSet: SkinSet = SkinSet(),
|
||||
val guildId: Int? = null,
|
||||
val pokemon: List<Pokemon>,
|
||||
) {
|
||||
@@ -31,7 +33,7 @@ private object CharacterEntryCodec : PacketCodec<CharacterEntry>() {
|
||||
override fun CodecScope<CharacterEntry>.body(): CharacterEntry {
|
||||
val info = field(CharacterInfoAsymmetric, CharacterEntry::characterInfo)
|
||||
val skin = field(DefaultSkinSetCodec, CharacterEntry::skinSet)
|
||||
field(SkinSetCodecNoLeading, CharacterEntry::skinSet)
|
||||
val secondarySkin = field(SkinSetCodecNoLeading, CharacterEntry::secondarySkinSet)
|
||||
val hasGuild = field(Bool) { it.guildId != null }
|
||||
val guildId =
|
||||
if (hasGuild) {
|
||||
@@ -42,7 +44,7 @@ private object CharacterEntryCodec : PacketCodec<CharacterEntry>() {
|
||||
}
|
||||
val partySize = field(U8) { it.pokemon.size }
|
||||
val party = List(partySize) { field(PokemonCodec) { entry -> entry.pokemon[it] } }
|
||||
return CharacterEntry(info, skin, guildId, party)
|
||||
return CharacterEntry(info, skin, secondarySkin, guildId, party)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -7,6 +7,7 @@ import de.fiereu.openmmo.net.game.codecs.DefaultSkinSetCodec
|
||||
import de.fiereu.openmmo.net.game.codecs.PokemonCodec
|
||||
import de.fiereu.openmmo.net.game.codecs.SkinSetCodecNoLeading
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.maps.shouldBeEmpty
|
||||
import io.kotest.matchers.shouldBe
|
||||
|
||||
class CharactersListPacketTest :
|
||||
@@ -15,10 +16,11 @@ class CharactersListPacketTest :
|
||||
val buf = fixtureBuffer("game/s2c/02/character_list_32710.bin")
|
||||
val names = mutableListOf<String>()
|
||||
val parties = mutableListOf<Int>()
|
||||
val skinSlotCounts = mutableListOf<Int>()
|
||||
repeat(U8.read(buf)) {
|
||||
names += CharacterInfoCodecShort.read(buf).name
|
||||
DefaultSkinSetCodec.read(buf)
|
||||
SkinSetCodecNoLeading.read(buf)
|
||||
skinSlotCounts += DefaultSkinSetCodec.read(buf).size
|
||||
SkinSetCodecNoLeading.read(buf).shouldBeEmpty()
|
||||
val hasGuild = buf.readByte().toInt() != 0
|
||||
hasGuild shouldBe false
|
||||
val party = U8.read(buf)
|
||||
@@ -28,6 +30,7 @@ class CharactersListPacketTest :
|
||||
|
||||
names shouldBe listOf("MacherRin", "astridefour", "MacherDer")
|
||||
parties shouldBe listOf(0, 1, 0)
|
||||
skinSlotCounts shouldBe listOf(5, 5, 5)
|
||||
buf.remaining() shouldBe 0
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -30,6 +30,19 @@ class CreateCharacterPacketTest :
|
||||
CreateCharacterPacketCodec.encodeToBytes(packet).toHex() shouldBe bytes.toHex()
|
||||
}
|
||||
|
||||
test("splits a packed slot into a ten bit type and a six bit color") {
|
||||
val bytes = fixture("game/c2s/03/female_hoenn.bin")
|
||||
|
||||
val packet = CreateCharacterPacketCodec.decodeBytes(bytes)
|
||||
|
||||
val hair = packet.appearance[SkinSlot.HAIR]!!
|
||||
hair.type shouldBe 4.toUShort()
|
||||
hair.color shouldBe 24.toUByte()
|
||||
val leggings = packet.appearance[SkinSlot.LEGGINGS]!!
|
||||
leggings.type shouldBe 0.toUShort()
|
||||
leggings.color shouldBe 33.toUByte()
|
||||
}
|
||||
|
||||
test("roundtrips the new male Hoenn character creation capture") {
|
||||
val bytes = fixture("game/c2s/03/male_hoenn_32710.bin")
|
||||
|
||||
|
||||
Reference in new issue
Block a user