Skip to content

Implement Stop/Start trading with all - #2278

Merged
evanpelle merged 3 commits into
openfrontio:mainfrom
abdallahbahrawi1:trading-with-all-palyers
Oct 25, 2025
Merged

evanpelle merged 3 commits into
openfrontio:mainfrom
abdallahbahrawi1:trading-with-all-palyers

Conversation

@abdallahbahrawi1

@abdallahbahrawi1 abdallahbahrawi1 commented Oct 23, 2025 •

Copy link
Copy Markdown
Member

Description:

fixes #2275

Added global Start/Stop trading; use your player panel to trigger it.

Screenshot 2025-10-23 184447

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

abodcraft1

@coderabbitai

coderabbitai Bot commented Oct 23, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A new "embargo all" feature enables players to instantly stop trading with all eligible opponents via a single action, featuring UI controls, event handling, schema definitions, execution logic, and cooldown configuration. No existing embargo logic was altered.

Changes

Cohort / File(s) Summary
UI & Client Events
src/client/graphics/layers/PlayerPanel.ts, src/client/Transport.ts
Added event class SendEmbargoAllIntentEvent with start/stop action. Wired Transport listener to route events. Extended PlayerPanel with two click handlers for stop/start embargo-all and new UI button row with gated display based on canEmbargoAll.
Localization
resources/lang/en.json
Added two translation keys under player_panel: stop_trade_all and start_trade_all.
Intent & Schema
src/core/Schemas.ts
Added EmbargoAllIntent type and EmbargoAllIntentSchema to discriminated union with type embargo_all and action "start" | "stop".
Execution
src/core/execution/EmbargoAllExecution.ts, src/core/execution/ExecutionManager.ts
Created new EmbargoAllExecution class that iterates eligible players and creates or removes embargoes per action. Wired ExecutionManager to instantiate and route embargo_all intents.
Configuration
src/core/configuration/Config.ts, src/core/configuration/DefaultConfig.ts
Added embargoAllCooldown(): Tick method to Config interface and DefaultConfig (returns 10 * 10).
Game API
src/core/game/Game.ts, src/core/GameRunner.ts, src/core/game/PlayerImpl.ts
Extended Player interface with canEmbargoAll(): boolean and recordEmbargoAll(): void. PlayerImpl implements gating with team/bot exclusions and tracks lastEmbargoAllTick for cooldown. Extended PlayerActions with optional canEmbargoAll flag in GameRunner.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as PlayerPanel UI
    participant Transport
    participant ExecutionManager as ExecutionManager
    participant Execution as EmbargoAllExecution
    participant Player

    User->>UI: Click Stop/Start Trading<br/>with All
    UI->>Transport: emit SendEmbargoAllIntentEvent
    Transport->>ExecutionManager: embargo_all intent<br/>(action: start|stop)
    ExecutionManager->>Execution: new EmbargoAllExecution<br/>(player, action)
    Execution->>Execution: init(): iterate players
    Execution->>Player: createEmbargo() or<br/>removeEmbargo() for each<br/>eligible opponent
    Execution->>Player: recordEmbargoAll()
    Player->>Player: update lastEmbargoAllTick
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • PlayerImpl cooldown logic: verify canEmbargoAll() correctly gates based on team membership, bot status, cooldown state, and eligible target existence
  • EmbargoAllExecution iteration: confirm all eligible opponents are correctly identified and embargoes created/removed without side effects
  • UI gating: validate button disabled state and label updates reflect cooldown accurately
  • Schema integration: ensure new embargo_all intent integrates cleanly into discriminated union and routing

Possibly related PRs

Suggested labels

Feature - Backend

Suggested reviewers

  • scottanderson
  • evanpelle

Poem

🛑 One click to cease the trade, one press to break the flow
All rivals left in silence—their coffers move so slow
From many buttons down to one, the embargo empire grows! ✨

Pre-merge checks

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Implement Stop/Start trading with all" clearly and accurately summarizes the main change in the pull request. It is specific, concise, and directly conveys what is being implemented without vague language or noise. The changeset demonstrates exactly what the title claims: new UI controls in the player panel, event handling, schema definitions, and execution logic to enable starting and stopping trade with all non-allied players. The title is neither overly broad nor misleading, and effectively communicates the primary objective to a developer reviewing the repository history.
Linked Issues Check ✅ Passed The code changes fully implement the primary objective from issue #2275: providing a single-button action to instantly cease all trade with enemies. The PlayerPanel.ts adds UI buttons for "Stop Trading with All" and "Start Trading with All," triggering SendEmbargoAllIntentEvent events that route to EmbargoAllExecution, which applies embargoes to all eligible non-allied players. The implementation includes proper cooldown configuration via DefaultConfig.embargoAllCooldown(), eligibility gating through PlayerImpl.canEmbargoAll(), and team/bot exclusions in the execution logic. The changeset supports both "start" and "stop" actions, enabling rapid economic countermeasures as required by the issue, while avoiding unnecessary team-level controls that were deferred to future work per the PR author's decision.
Out of Scope Changes Check ✅ Passed All changes in the pull request remain within scope of implementing the stop/start trading with all feature described in issue #2275. The modifications—including UI components, translation keys, event classes, schema definitions, cooldown configuration, execution logic, and player interface extensions—directly support the core objective of enabling a single action to cease or resume trade with all non-allied players. No extraneous features, refactoring, or unrelated improvements are present. The PR author appropriately deferred team-level trading controls (referenced in PR comments regarding issue #808) to a subsequent PR to maintain focused scope.
Description Check ✅ Passed The pull request description is directly related to the changeset. It explicitly states the feature adds "global Start/Stop trading" via the "player panel," which aligns precisely with the modifications across PlayerPanel.ts, the new UI buttons with translation keys, and the underlying event handling infrastructure. The description references issue #2275, provides context about the feature's purpose, includes evidence of completion (screenshot, checklist items), and confirms translations were processed through translateText() and added to en.json, all of which correspond to the code changes present in the PR.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1bbb09 and 7af8ff7.

📒 Files selected for processing (1)
  • src/core/execution/EmbargoAllExecution.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/execution/EmbargoAllExecution.ts

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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 23, 2025
@evanpelle evanpelle added this to the v27 milestone Oct 23, 2025
Comment thread src/core/game/PlayerImpl.ts Resolved
Comment thread src/core/game/PlayerImpl.ts Resolved
Comment thread src/client/Transport.ts Resolved
Comment thread src/core/Schemas.ts Resolved
coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 23, 2025
@TheGiraffe3 TheGiraffe3 added Feature - Frontend UI/UX UI/UX changes including assets, menus, QoL, etc. labels Oct 24, 2025
@TheGiraffe3

Copy link
Copy Markdown
Member

Related issue: #808; that should probably also be fixed in this PR. In FFA I think your current buttons are good, but in teams mode it would be better to have "Stop trading with all other teams" and "Stop trading with dropdown team"

@abdallahbahrawi1

Copy link
Copy Markdown
Member Author

Related issue: #808; that should probably also be fixed in this PR. In FFA I think your current buttons are good, but in teams mode it would be better to have "Stop trading with all other teams" and "Stop trading with dropdown team"

Right now, teammates are already excluded in team mode. Let’s keep this PR focused and add team-level controls in a subsequent one. If you’ve got a design idea for the team trading UX, please share it here or on Discord.

@evanpelle

Copy link
Copy Markdown
Collaborator

Related issue: #808; that should probably also be fixed in this PR. In FFA I think your current buttons are good, but in teams mode it would be better to have "Stop trading with all other teams" and "Stop trading with dropdown team"

Right now, teammates are already excluded in team mode. Let’s keep this PR focused and add team-level controls in a subsequent one. If you’ve got a design idea for the team trading UX, please share it here or on Discord.

+1 for small PRs, makes my life much easier.

Removed checks for player status before processing.

@evanpelle evanpelle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@evanpelle
evanpelle added this pull request to the merge queue Oct 25, 2025
Merged via the queue into openfrontio:main with commit 380eab5 Oct 25, 2025
2 checks passed
Lavodan pushed a commit to Lavodan/OpenFrontIO_changes that referenced this pull request Oct 26, 2025
## Description:
fixes openfrontio#2275 

Added global Start/Stop trading; use your **player panel** to trigger
it.

<img width="370" height="540" alt="Screenshot 2025-10-23 184447"
src="https://github.com/user-attachments/assets/c3b7967e-ffdd-4f37-ba67-b60a602278ce"
/>

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

abodcraft1
evanpelle pushed a commit that referenced this pull request Oct 26, 2025
fixes #2275

Added global Start/Stop trading; use your **player panel** to trigger
it.

<img width="370" height="540" alt="Screenshot 2025-10-23 184447"
src="https://github.com/user-attachments/assets/c3b7967e-ffdd-4f37-ba67-b60a602278ce"
/>

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
regression is found:

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

Labels

UI/UX UI/UX changes including assets, menus, QoL, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Easy Stop Trade with other Teams

3 participants