-
Notifications
You must be signed in to change notification settings - Fork 825
Cancel nukes when accepting alliance via radial menu #3155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { Execution, Game, Player, PlayerID } from "../../game/Game"; | ||
|
|
||
| export class AllianceRejectExecution implements Execution { | ||
| private active = true; | ||
|
|
||
| constructor( | ||
| private requestorID: PlayerID, | ||
| private recipient: Player, | ||
| ) {} | ||
|
|
||
| init(mg: Game, ticks: number): void { | ||
| if (!mg.hasPlayer(this.requestorID)) { | ||
| console.warn( | ||
| `AllianceRejectExecution requester ${this.requestorID} not found`, | ||
| ); | ||
| this.active = false; | ||
| return; | ||
| } | ||
| const requestor = mg.player(this.requestorID); | ||
|
|
||
| if (requestor.isFriendly(this.recipient)) { | ||
| console.warn("already allied"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here and on line 28 can you log something like: console.warn("[AllianceRejectExecution] Player ${this.requestorID} cannot reject alliance with ${this.recipient.id}, already allied" |
||
| } else { | ||
| const request = requestor | ||
| .outgoingAllianceRequests() | ||
| .find((ar) => ar.recipient() === this.recipient); | ||
| if (request === undefined) { | ||
| console.warn("no alliance request found"); | ||
| } else { | ||
| request.reject(); | ||
| } | ||
| } | ||
| this.active = false; | ||
| } | ||
|
|
||
| tick(ticks: number): void {} | ||
|
|
||
| isActive(): boolean { | ||
| return this.active; | ||
| } | ||
|
|
||
| activeDuringSpawnPhase(): boolean { | ||
| return false; | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { renderNumber } from "../../client/Utils"; | ||
| import { Config } from "../configuration/Config"; | ||
| import { cancelNukesBetweenAlliedPlayers } from "../execution/alliance/AllianceRequestExecution"; | ||
| import { | ||
| AbstractGraph, | ||
| AbstractGraphBuilder, | ||
|
|
@@ -332,12 +333,19 @@ export class GameImpl implements Game { | |
| request, | ||
| ); | ||
|
|
||
| // Update relations | ||
| requestor.updateRelation(recipient, 100); | ||
| recipient.updateRelation(requestor, 100); | ||
|
|
||
| // Automatically remove embargoes only if they were automatically created | ||
| if (requestor.hasEmbargoAgainst(recipient)) | ||
| requestor.endTemporaryEmbargo(recipient); | ||
| if (recipient.hasEmbargoAgainst(requestor)) | ||
| recipient.endTemporaryEmbargo(requestor); | ||
|
|
||
| // Cancel incoming nukes between players | ||
| cancelNukesBetweenAlliedPlayers(this, requestor, recipient); | ||
|
|
||
|
Comment on lines
+346
to
+348
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also adds a lot of logic into GameImpl, gameimpl should ideally just store & update state. Can this be removed? Same with line 337 & 338 |
||
| this.addUpdate({ | ||
| type: GameUpdateType.AllianceRequestReply, | ||
| request: request.toUpdate(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to just remove this execution? And then events display and radial menu can just send AllianceRequest? Then all alliance logic would be in a single file, and we can move cancelNukesBetweenAlliedPlayers there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I centralised acceptance logic in
AllianceRequestExecutionand created a newAllianceRejectExecutionto handle rejections, because:AllianceRequestExecutionto branch out its logic and handle rejections felt really wrong to me