Skip to content

Fix enemy collision bug in undoSell#165

Merged
candour merged 2 commits into
mainfrom
fix/undo-sell-enemy-collision-12364030995966921869
May 18, 2026
Merged

Fix enemy collision bug in undoSell#165
candour merged 2 commits into
mainfrom
fix/undo-sell-enemy-collision-12364030995966921869

Conversation

@candour

@candour candour commented May 18, 2026

Copy link
Copy Markdown
Owner

I identified and fixed a bug in the undoSell mechanic where players could restore a previously sold stall on top of an active enemy or on a tile that an enemy was about to enter. This bypassed the collision checks implemented for regular stall placement.

Key changes:

  • Added isEnemyNear check to MainViewModel.undoSell to match the logic in onCellClick.
  • Created a new test file UndoStallOnEnemyTest.kt to verify that undoSell correctly rejects restoration when an enemy is present or approaching.
  • Updated fixes.md to document this fix as FIX-013.

PR created automatically by Jules for task 12364030995966921869 started by @candour

Summary by CodeRabbit

  • Bug Fixes

    • Prevented undoing stall sales when enemies occupy or are moving toward the target tile.
  • Tests

    • Added tests verifying stalls are not restored if an enemy is on or en route to the same tile.
  • Documentation

    • Updated fix log documenting the resolved undo/restore issue.

Review Change Stack

Prevent stalls from being restored via undoSell on tiles occupied or targeted by enemies, ensuring consistency with the standard placement logic.

Co-authored-by: candour <4670475+candour@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 66fe7d92-ee0a-4f90-b69f-a2c28882fb2d

📥 Commits

Reviewing files that changed from the base of the PR and between e649140 and b3a9313.

📒 Files selected for processing (1)
  • fixes.md

📝 Walkthrough

Walkthrough

This PR fixes a bug in MainViewModel.undoSell() where stalls could be restored onto hexes currently occupied by or targeted by moving enemies. The fix adds an early-exit guard, and comprehensive tests validate both the on-tile and in-path enemy blocking scenarios.

Changes

Enemy-on-hex undo prevention

Layer / File(s) Summary
Undo stall prevention logic
app/src/main/java/com/messark/hawker/MainViewModel.kt, fixes.md
Modified undoSell() to return early if an active enemy is at the target coord or on its next path step toward that coord. Added FIX-013 documentation entry.
Test suite for undo-on-enemy scenarios
app/src/test/java/com/messark/hawker/UndoStallOnEnemyTest.kt
New test class with coroutine dispatcher lifecycle and two test methods: one blocking undo when an enemy is on the stall tile, and one when an enemy is moving toward the stall along its path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • candour/towerpower#165: Both PRs modify MainViewModel.undoSell() to early-return when an enemy is on the target hex or is next in its path, and they add the same UndoStallOnEnemyTest plus a FIX-013 fixes.md entry.
  • candour/towerpower#154: Both PRs adjust MainViewModel’s undo/sale restore behavior to prevent incorrect enemy interactions on undo (main PR adds undoSell() early-return when an enemy is on/approaching the target hex, while the other clears heldEnemyId/releaseTimeMs in sellStall() when saving lastSoldStall).
  • candour/towerpower#163: Both PRs update MainViewModel to prevent stall state changes when enemies are on the target hex or its next-step target—one in onCellClick (stall placement/lastSoldStall clearing) and the other in undoSell (stall restoration/lastSoldStall preservation).
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing a bug related to enemy collisions in the undoSell mechanic, which is the primary purpose of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/undo-sell-enemy-collision-12364030995966921869

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/src/test/java/com/messark/hawker/UndoStallOnEnemyTest.kt (1)

88-135: 💤 Low value

Consider adding lastSoldStall assertion for consistency.

The first test verifies that lastSoldStall is not cleared when undoSell fails (line 85), but this test only checks that the stall is not restored (line 134). For consistency and completeness, consider adding an assertion after line 134:

assertNotNull("lastSoldStall should NOT be cleared because undo failed", viewModel.gameState.value.lastSoldStall)

This would align with the first test's validation pattern and confirm the function's early-return behavior preserves state correctly.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 22fa1cd5-9cec-4abb-ba4e-1f8aba684156

📥 Commits

Reviewing files that changed from the base of the PR and between 6803d1f and e649140.

📒 Files selected for processing (3)
  • app/src/main/java/com/messark/hawker/MainViewModel.kt
  • app/src/test/java/com/messark/hawker/UndoStallOnEnemyTest.kt
  • fixes.md

Comment thread fixes.md Outdated
@candour
candour enabled auto-merge (squash) May 18, 2026 05:45
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@candour
candour merged commit bfe5c7f into main May 18, 2026
3 checks passed
@candour
candour deleted the fix/undo-sell-enemy-collision-12364030995966921869 branch May 18, 2026 05:45
@github-actions

Copy link
Copy Markdown

Build Successful! 🚀

Download APK

Note: This link will be removed when the PR is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant