Skip to content

Commit

Permalink
兼容配置表错误的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed Nov 12, 2024
1 parent f485b6a commit 3afbe45
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/main/kotlin/SpellConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package org.tfcc.bingo
import org.apache.logging.log4j.kotlin.logger
import org.apache.poi.openxml4j.opc.OPCPackage
import org.apache.poi.openxml4j.opc.PackageAccess
import org.apache.poi.ss.usermodel.CellType.*
import org.apache.poi.xssf.usermodel.XSSFCell
import org.apache.poi.xssf.usermodel.XSSFRow
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.tfcc.bingo.message.HandlerException
Expand Down Expand Up @@ -138,6 +140,13 @@ object SpellConfig {

fun getSpellById(type: Int, id: Int): Spell? = cache[type]?.spellsByIndex?.get(id)

private fun XSSFCell?.getFloatValue(): Float {
if (this == null) return 0f
if (cellType == STRING)
return stringCellValue.ifBlank { return 0f }.toFloat()
return numericCellValue.toFloat()
}

private fun buildNormalSpell(row: XSSFRow): Spell? {
if (row.lastCellNum < 15) return null
return Spell(
Expand All @@ -147,13 +156,13 @@ object SpellConfig {
rank = row.getCell(5).stringCellValue.trim(),
star = row.getCell(6).numericCellValue.toInt(),
desc = row.getCell(4)?.stringCellValue?.trim() ?: "",
id = row.getCell(8).numericCellValue.toInt(),
fastest = row.getCell(9).numericCellValue.toFloat(),
one = row.getCell(10).numericCellValue.toFloat(),
two = row.getCell(11).numericCellValue.toFloat(),
three = row.getCell(12).numericCellValue.toFloat(),
final = row.getCell(13).numericCellValue.toFloat(),
bonusRate = row.getCell(14).numericCellValue.toFloat(),
id = row.getCell(8)?.numericCellValue?.toInt() ?: 0,
fastest = row.getCell(9).getFloatValue(),
one = row.getCell(10).getFloatValue(),
two = row.getCell(11).getFloatValue(),
three = row.getCell(12).getFloatValue(),
final = row.getCell(13).getFloatValue(),
bonusRate = row.getCell(14).getFloatValue(),
)
}

Expand All @@ -167,12 +176,12 @@ object SpellConfig {
star = row.getCell(7).numericCellValue.toInt(),
desc = row.getCell(4)?.stringCellValue?.trim() ?: "",
id = row.getCell(8).numericCellValue.toInt(),
fastest = row.getCell(9).numericCellValue.toFloat(),
one = row.getCell(10).numericCellValue.toFloat(),
two = row.getCell(11).numericCellValue.toFloat(),
three = row.getCell(12).numericCellValue.toFloat(),
final = row.getCell(13).numericCellValue.toFloat(),
bonusRate = row.getCell(14).numericCellValue.toFloat(),
fastest = row.getCell(9).getFloatValue(),
one = row.getCell(10).getFloatValue(),
two = row.getCell(11).getFloatValue(),
three = row.getCell(12).getFloatValue(),
final = row.getCell(13).getFloatValue(),
bonusRate = row.getCell(14).getFloatValue(),
)
}

Expand Down

0 comments on commit 3afbe45

Please sign in to comment.