Combat Precision Fix and Health UI Enhancement - #141
Conversation
- Refactored Enemy, Stall, and Projectile models to use Float for health and damage. - Updated MainViewModel and StallUpgradeManager to maintain float precision in combat calculations. - Improved rendering z-sorting in GameBoard.kt to keep overhead effects above ground entities. - Added percentage health text display to enemy health bars. - Updated unit tests and documentation (AGENTS.md, fixes.md). Co-authored-by: candour <4670475+candour@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR refactors health and damage from Int to Float across models, gameplay logic, UI rendering, and tests; updates GameBoard z-order grouping/sorting and refactors enemy health-bar drawing to use a Float-based ratio. ChangesFloat Health/Damage Precision & Z-Order Rendering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/com/messark/hawker/MainViewModel.kt (1)
814-855:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winInconsistent death threshold causes kill-credit inflation across stalls.
In
hits.forEachthe early-exit at line 822 usescurrentHealth <= 0, but the per-projectile kill check at line 843 (and the final death check at line 856) usescurrentHealth < 1.0f. WithFloathealth, a projectile that drops health to e.g.0.5does not trip the<= 0early exit, so a later projectile in the same tick will also satisfy< 1.0fand awardkills += 1to its source stall — double-counting kills (which feeds into the legendary-suffix Level-10 unlock heuristics indirectly through stats and any leaderboard surfaces).Suggest aligning the early exit with the kill threshold:
🛠 Proposed fix to align death thresholds
hits.forEach { proj -> - if (currentHealth <= 0) return@forEach + if (currentHealth < 1.0f) return@forEach
🧹 Nitpick comments (2)
app/src/main/java/com/messark/hawker/MainViewModel.kt (1)
817-817: 💤 Low valueRedundant
.toFloat()after Float migration.
enemy.healthandproj.damageare alreadyFloatper the updatedGameModels.kt, so.toFloat()here is a no-op and slightly misleading.♻️ Proposed cleanup
- var currentHealth = enemy.health.toFloat() + var currentHealth = enemy.health @@ - var damage = proj.damage.toFloat() + var damage = proj.damageAlso applies to: 824-824
app/src/main/java/com/messark/hawker/ui/components/GameBoard.kt (1)
670-678: ⚡ Quick winUse theme-driven colors for health text rendering.
The new percentage text paint hardcodes white/black at
Line 674andLine 677. Please source these from theme colors to preserve light/dark behavior consistency.As per coding guidelines "Avoid hardcoding colors in UI components; always prefer MaterialTheme.colorScheme (e.g., onSurface, surface, primary) for light and dark theme support".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 87f58376-1cc0-4045-ad2f-c8e54da24ffa
📒 Files selected for processing (13)
AGENTS.mdapp/src/main/java/com/messark/hawker/MainViewModel.ktapp/src/main/java/com/messark/hawker/model/GameModels.ktapp/src/main/java/com/messark/hawker/registry/Registry.ktapp/src/main/java/com/messark/hawker/ui/components/GameBoard.ktapp/src/main/java/com/messark/hawker/ui/components/StallConsole.ktapp/src/main/java/com/messark/hawker/utils/StallUpgradeManager.ktapp/src/test/java/com/messark/hawker/KitchelinBonusTest.ktapp/src/test/java/com/messark/hawker/MilestoneBoostTest.ktapp/src/test/java/com/messark/hawker/StallStatsTest.ktapp/src/test/java/com/messark/hawker/UncleDoubleGrabTest.ktapp/src/test/java/com/messark/hawker/UndeadEnemyTest.ktfixes.md
|
If enemy.maxHealth <= 0f, Line 647 can produce NaN/Inf, which then propagates into filledHeight and draw calls (Line 662-667), risking unstable rendering. |
Good catch! I've added a check for |
- Added guard in GameBoard.kt to prevent NaN/Inf in healthRatio calculation. - Verified that all unit tests still pass. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
|
app/src/main/java/com/messark/hawker/MainViewModel.kt line 817 Redundant .toFloat() after Float migration. enemy.health and proj.damage are already Float per the updated GameModels.kt, so .toFloat() here is a no-op and slightly misleading. app/src/main/java/com/messark/hawker/MainViewModel.kt lines 814-855 Inconsistent death threshold causes kill-credit inflation across stalls. In hits.forEach the early-exit at line 822 uses currentHealth <= 0, but the per-projectile kill check at line 843 (and the final death check at line 856) uses currentHealth < 1.0f. With Float health, a projectile that drops health to e.g. 0.5 does not trip the <= 0 early exit, so a later projectile in the same tick will also satisfy < 1.0f and award kills += 1 to its source stall — double-counting kills (which feeds into the legendary-suffix Level-10 unlock heuristics indirectly through stats and any leaderboard surfaces). Suggest aligning the early exit with the kill threshold |
Excellent points. I've removed the redundant |
- Refactored combat stats to Float to resolve rounding bugs. - Implemented percentage health display for enemies. - Optimized rendering z-sorting to keep projectiles/VFX above world entities. - Cleaned up redundant casts and unified death thresholds in game engine. - Added safety guards for potential division by zero in UI. - Updated documentation and test suite. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
|
In MainViewModel.kt (around the combat loop), lines like enemy.health.toFloat() and proj.damage.toFloat() are now no-ops. |
Acknowledged. I have removed the redundant |
- Removed redundant .toFloat() calls on health and damage. - Aligned hit-loop early exit with the < 1.0f death threshold to prevent kill double-counting. - Verified all tests pass. Co-authored-by: candour <4670475+candour@users.noreply.github.com>
Build Successful! 🚀Note: This link will be removed when the PR is closed. |
This PR addresses a core combat logic bug where precision loss occurred during health and damage calculations due to the use of integers. By refactoring these fields to
Float, we ensure that damage modifiers and armor buffs are applied accurately.Additionally, this PR includes:
StallConsolefor cleaner integer-based display of stats and verified the entire fix with the existing test suite.PR created automatically by Jules for task 5785280520036751080 started by @candour
Summary by CodeRabbit
New Features
Bug Fixes
Visual
Documentation