Skip to content

Commit

Permalink
修复强行指定符卡功能的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Jan 15, 2024
1 parent e4a1dff commit 452ad8c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/Spell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/SpellConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object SpellConfig {
if (md5sum != null && config.md5sum != null && md5sum == config.md5sum)
return config.allSpells
val allSpells = HashMap<Int, HashMap<Boolean, HashMap<String, ArrayList<Spell>>>>()
val spellsById = HashMap<Int, Spell>()
val spellsByIndex = HashMap<Int, Spell>()
for (file in files) {
XSSFWorkbook(OPCPackage.open(file, PackageAccess.READ)).use { wb ->
val sheet = wb.getSheetAt(0)
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -188,7 +190,7 @@ object SpellConfig {
/** star => ( isEx => ( game => spellList ) ) */
var allSpells: Map<Int, Map<Boolean, Map<String, List<Spell>>>> = mapOf()

var spellsById: Map<Int, Spell> = mapOf()
var spellsByIndex: Map<Int, Spell> = mapOf()
}

private val isWindows = System.getProperty("os.name").lowercase().contains("windows")
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/message/SetDebugSpellsCs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/message/StartGameCs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
}
Expand Down

0 comments on commit 452ad8c

Please sign in to comment.