Fixed HP desync with battle.

This commit is contained in:
lightheel 2025-10-19 13:09:14 -04:00
parent 61daad459b
commit 0875b114d5

View File

@ -1649,10 +1649,24 @@ fun BattlesScreen() {
// Format as "dim" + cardId + "_mon" + (charaIndex + 1)
val formattedCardId = String.format("dim%03d_mon%02d", cardId, charaIndex + 1)
// Create APIBattleCharacter from database character
val playerCharacter = APIBattleCharacter(
name = "Player Digimon", // We could get this from the database if needed
namekey = "player_digimon", // Name key for the character
charaId = formattedCardId, // Use the formatted card ID for sprite loading
stage = characterData.stage,
attribute = characterData.attribute.ordinal, // Convert enum to int
baseHp = 1000, // Default values - API will provide correct values
currentHp = 1000,
baseBp = 1000.0f,
baseAp = 1000.0f
)
// Update UI state on main thread
withContext(Dispatchers.Main) {
activeUserCharacter = activeChar
activeCardId = formattedCardId
activeCharacter = playerCharacter // Set the active character for battle
}
println("BATTLESCREEN: Loaded active character from database:")
@ -2076,6 +2090,11 @@ fun BattlesScreen() {
// Randomly select background set (0, 1, or 2)
selectedBackgroundSet = kotlin.random.Random.nextInt(3)
RetrofitHelper().getPVPWinner(context, 0, 2, cardId, 0, 0, opponent.charaId, 0) { apiResult ->
// Update player character HP from API response
activeCharacter = activeCharacter?.copy(
baseHp = apiResult.playerHP,
currentHp = apiResult.playerHP
)
currentView = "battle-main"
}
} ?: run {
@ -2132,6 +2151,11 @@ fun BattlesScreen() {
// Randomly select background set (0, 1, or 2)
selectedBackgroundSet = kotlin.random.Random.nextInt(3)
RetrofitHelper().getPVPWinner(context, 0, 2, cardId, 1, 0, opponent.charaId, 1) { apiResult ->
// Update player character HP from API response
activeCharacter = activeCharacter?.copy(
baseHp = apiResult.playerHP,
currentHp = apiResult.playerHP
)
currentView = "battle-main"
}
} ?: run {
@ -2188,6 +2212,11 @@ fun BattlesScreen() {
// Randomly select background set (0, 1, or 2)
selectedBackgroundSet = kotlin.random.Random.nextInt(3)
RetrofitHelper().getPVPWinner(context, 0, 2, cardId, 2, 0, opponent.charaId, 2) { apiResult ->
// Update player character HP from API response
activeCharacter = activeCharacter?.copy(
baseHp = apiResult.playerHP,
currentHp = apiResult.playerHP
)
currentView = "battle-main"
}
} ?: run {
@ -2244,6 +2273,11 @@ fun BattlesScreen() {
// Randomly select background set (0, 1, or 2)
selectedBackgroundSet = kotlin.random.Random.nextInt(3)
RetrofitHelper().getPVPWinner(context, 0, 2, cardId, 3, 0, opponent.charaId, 3) { apiResult ->
// Update player character HP from API response
activeCharacter = activeCharacter?.copy(
baseHp = apiResult.playerHP,
currentHp = apiResult.playerHP
)
currentView = "battle-main"
}
} ?: run {