mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 23:43:25 +00:00
Merge pull request #117 from ilan-schemoul/cance-attacks
feat: cancel attack
This commit is contained in:
@@ -110,6 +110,13 @@ export class SendEmbargoIntentEvent implements GameEvent {
|
||||
) {}
|
||||
}
|
||||
|
||||
export class CancelAttackIntentEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly playerID: PlayerID,
|
||||
public readonly attackID: string,
|
||||
) {}
|
||||
}
|
||||
|
||||
export class SendSetTargetTroopRatioEvent implements GameEvent {
|
||||
constructor(public readonly ratio: number) {}
|
||||
}
|
||||
@@ -179,6 +186,9 @@ export class Transport {
|
||||
this.eventBus.on(PauseGameEvent, (e) => this.onPauseGameEvent(e));
|
||||
this.eventBus.on(SendWinnerEvent, (e) => this.onSendWinnerEvent(e));
|
||||
this.eventBus.on(SendHashEvent, (e) => this.onSendHashEvent(e));
|
||||
this.eventBus.on(CancelAttackIntentEvent, (e) =>
|
||||
this.onCancelAttackIntentEvent(e),
|
||||
);
|
||||
}
|
||||
|
||||
private startPing() {
|
||||
@@ -501,6 +511,15 @@ export class Transport {
|
||||
}
|
||||
}
|
||||
|
||||
private onCancelAttackIntentEvent(event: CancelAttackIntentEvent) {
|
||||
this.sendIntent({
|
||||
type: "cancel_attack",
|
||||
clientID: this.lobbyConfig.clientID,
|
||||
playerID: event.playerID,
|
||||
attackID: event.attackID,
|
||||
});
|
||||
}
|
||||
|
||||
private sendIntent(intent: Intent) {
|
||||
if (this.isLocal || this.socket.readyState === WebSocket.OPEN) {
|
||||
const msg = ClientIntentMessageSchema.parse({
|
||||
|
||||
@@ -20,7 +20,10 @@ import { AllianceRequestUpdate } from "../../../core/game/GameUpdates";
|
||||
import { GameUpdateType } from "../../../core/game/GameUpdates";
|
||||
import { ClientID } from "../../../core/Schemas";
|
||||
import { Layer } from "./Layer";
|
||||
import { SendAllianceReplyIntentEvent } from "../../Transport";
|
||||
import {
|
||||
CancelAttackIntentEvent,
|
||||
SendAllianceReplyIntentEvent,
|
||||
} from "../../Transport";
|
||||
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
||||
import { onlyImages, sanitize } from "../../../core/Util";
|
||||
import { GameView, PlayerView } from "../../../core/game/GameView";
|
||||
@@ -298,6 +301,12 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
});
|
||||
}
|
||||
|
||||
emitCancelAttackIntent(id: string) {
|
||||
const myPlayer = this.game.playerByClientID(this.clientID);
|
||||
if (!myPlayer) return;
|
||||
this.eventBus.emit(new CancelAttackIntentEvent(myPlayer.id(), id));
|
||||
}
|
||||
|
||||
onEmojiMessageEvent(update: EmojiUpdate) {
|
||||
const myPlayer = this.game.playerByClientID(this.clientID);
|
||||
if (!myPlayer) return;
|
||||
@@ -386,6 +395,16 @@ export class EventsDisplay extends LitElement implements Layer {
|
||||
${(
|
||||
this.game.playerBySmallID(attack.targetID) as PlayerView
|
||||
)?.name()}
|
||||
${!attack.retreating
|
||||
? html`<button
|
||||
${attack.retreating ? "disabled" : ""}
|
||||
@click=${() => {
|
||||
this.emitCancelAttackIntent(attack.id);
|
||||
}}
|
||||
>
|
||||
❌
|
||||
</button>`
|
||||
: "(retreating...)"}
|
||||
</div>
|
||||
`,
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user