From 452ad8cd9977c11e6028c3d68deb79939dc317c6 Mon Sep 17 00:00:00 2001 From: CuteReimu <415551921@qq.com> Date: Mon, 15 Jan 2024 11:39:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=BA=E8=A1=8C=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E7=AC=A6=E5=8D=A1=E5=8A=9F=E8=83=BD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/Spell.kt | 1 + src/main/kotlin/SpellConfig.kt | 12 +++++++----- src/main/kotlin/message/SetDebugSpellsCs.kt | 8 ++++++++ src/main/kotlin/message/StartGameCs.kt | 8 ++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/Spell.kt b/src/main/kotlin/Spell.kt index 7964e77..83a8464 100644 --- a/src/main/kotlin/Spell.kt +++ b/src/main/kotlin/Spell.kt @@ -3,6 +3,7 @@ package org.tfcc.bingo import java.io.Serializable data class Spell( + val index: Int, val game: String, val name: String, var rank: String, diff --git a/src/main/kotlin/SpellConfig.kt b/src/main/kotlin/SpellConfig.kt index fe9bded..04ff2bd 100644 --- a/src/main/kotlin/SpellConfig.kt +++ b/src/main/kotlin/SpellConfig.kt @@ -114,7 +114,7 @@ object SpellConfig { if (md5sum != null && config.md5sum != null && md5sum == config.md5sum) return config.allSpells val allSpells = HashMap>>>() - val spellsById = HashMap() + val spellsByIndex = HashMap() for (file in files) { XSSFWorkbook(OPCPackage.open(file, PackageAccess.READ)).use { wb -> val sheet = wb.getSheetAt(0) @@ -125,22 +125,23 @@ object SpellConfig { .getOrPut(spell.rank != "L") { hashMapOf() } .getOrPut(spell.game) { arrayListOf() } .add(spell) - spellsById[spell.id] = spell + spellsByIndex[spell.index] = spell } } } config.md5sum = md5sum config.allSpells = allSpells - config.spellsById = spellsById + config.spellsByIndex = spellsByIndex SpellLog.createLogFile() // 重读时重新载入log return allSpells } - fun getSpellById(type: Int, id: Int): Spell? = cache[type]?.spellsById?.get(id) + fun getSpellById(type: Int, id: Int): Spell? = cache[type]?.spellsByIndex?.get(id) private fun buildNormalSpell(row: XSSFRow): Spell? { if (row.lastCellNum < 6) return null return Spell( + index = row.getCell(0).numericCellValue.toInt(), game = row.getCell(1).numericCellValue.toInt().toString(), name = row.getCell(3).stringCellValue.trim(), rank = row.getCell(5).stringCellValue.trim(), @@ -154,6 +155,7 @@ object SpellConfig { private fun buildBPSpell(row: XSSFRow): Spell? { if (row.lastCellNum < 7) return null return Spell( + index = row.getCell(0).numericCellValue.toInt(), game = row.getCell(1).numericCellValue.toInt().toString(), name = row.getCell(3).stringCellValue.trim(), rank = row.getCell(5).stringCellValue.trim(), @@ -188,7 +190,7 @@ object SpellConfig { /** star => ( isEx => ( game => spellList ) ) */ var allSpells: Map>>> = mapOf() - var spellsById: Map = mapOf() + var spellsByIndex: Map = mapOf() } private val isWindows = System.getProperty("os.name").lowercase().contains("windows") diff --git a/src/main/kotlin/message/SetDebugSpellsCs.kt b/src/main/kotlin/message/SetDebugSpellsCs.kt index 941a413..b4bf7cc 100644 --- a/src/main/kotlin/message/SetDebugSpellsCs.kt +++ b/src/main/kotlin/message/SetDebugSpellsCs.kt @@ -13,6 +13,14 @@ class SetDebugSpellsCs(val spells: IntArray?) : Handler { val room = Store.getRoom(player.roomId) ?: throw HandlerException("找不到房间") if (!room.isHost(token)) throw HandlerException("没有权限") room.debugSpells = spells + if (spells != null) { + val roomType = if (room.roomType == 2) SpellConfig.BPGame else SpellConfig.NormalGame + room.spells!!.forEachIndexed { i, _ -> + if (spells[i] != 0) { + SpellConfig.getSpellById(roomType, spells[i])?.also { room.spells!![i] = it } + } + } + } Store.putRoom(room) ctx.writeMessage(Message(name = "set_debug_spells_sc", reply = protoName)) } diff --git a/src/main/kotlin/message/StartGameCs.kt b/src/main/kotlin/message/StartGameCs.kt index f7e96c7..bc26a1b 100644 --- a/src/main/kotlin/message/StartGameCs.kt +++ b/src/main/kotlin/message/StartGameCs.kt @@ -27,10 +27,10 @@ class StartGameCs : Handler { val now = System.currentTimeMillis() logger.debug("随符卡耗时:${now - start}") room.debugSpells?.also { debugSpells -> - room.spells!!.forEachIndexed { index, spell -> - if (debugSpells[index] != 0) { - val roomType = if (room.roomType == 2) SpellConfig.BPGame else SpellConfig.NormalGame - SpellConfig.getSpellById(roomType, spell.id)?.also { room.spells!![index] = it } + val roomType = if (room.roomType == 2) SpellConfig.BPGame else SpellConfig.NormalGame + room.spells!!.forEachIndexed { i, _ -> + if (debugSpells[i] != 0) { + SpellConfig.getSpellById(roomType, debugSpells[i])?.also { room.spells!![i] = it } } } }