diff --git a/src/client/graphics/layers/EventsDisplay.ts b/src/client/graphics/layers/EventsDisplay.ts index 1178ddda4..407658016 100644 --- a/src/client/graphics/layers/EventsDisplay.ts +++ b/src/client/graphics/layers/EventsDisplay.ts @@ -80,6 +80,17 @@ export class EventsDisplay extends LitElement implements Layer { this.events = remainingEvents; this.requestUpdate(); } + + const myPlayer = this.game.myPlayer(); + if (!myPlayer) { + return; + } + myPlayer.incomingAttacks().forEach((a) => { + // console.log(`got incoming attack: ${JSON.stringify(a)}`); + }); + myPlayer.outgoingAttacks().forEach((a) => { + // console.log(`got outgoing attack: ${JSON.stringify(a)}`); + }); } private addEvent(event: Event) { @@ -125,10 +136,10 @@ export class EventsDisplay extends LitElement implements Layer { } const requestor = this.game.playerBySmallID( - update.requestorID, + update.requestorID ) as PlayerView; const recipient = this.game.playerBySmallID( - update.recipientID, + update.recipientID ) as PlayerView; this.addEvent({ @@ -139,7 +150,7 @@ export class EventsDisplay extends LitElement implements Layer { className: "btn", action: () => this.eventBus.emit( - new SendAllianceReplyIntentEvent(requestor, recipient, true), + new SendAllianceReplyIntentEvent(requestor, recipient, true) ), }, { @@ -147,7 +158,7 @@ export class EventsDisplay extends LitElement implements Layer { className: "btn-info", action: () => this.eventBus.emit( - new SendAllianceReplyIntentEvent(requestor, recipient, false), + new SendAllianceReplyIntentEvent(requestor, recipient, false) ), }, ], @@ -156,7 +167,7 @@ export class EventsDisplay extends LitElement implements Layer { createdAt: this.game.ticks(), onDelete: () => this.eventBus.emit( - new SendAllianceReplyIntentEvent(requestor, recipient, false), + new SendAllianceReplyIntentEvent(requestor, recipient, false) ), }); } @@ -168,7 +179,7 @@ export class EventsDisplay extends LitElement implements Layer { } const recipient = this.game.playerBySmallID( - update.request.recipientID, + update.request.recipientID ) as PlayerView; this.addEvent({ @@ -213,8 +224,8 @@ export class EventsDisplay extends LitElement implements Layer { update.player1ID === myPlayer.smallID() ? update.player2ID : update.player2ID === myPlayer.smallID() - ? update.player1ID - : null; + ? update.player1ID + : null; const other = this.game.playerBySmallID(otherID) as PlayerView; if (!other || !myPlayer.isAlive() || !other.isAlive()) return; @@ -250,7 +261,7 @@ export class EventsDisplay extends LitElement implements Layer { ? AllPlayers : this.game.playerBySmallID(update.emoji.recipientID); const sender = this.game.playerBySmallID( - update.emoji.senderID, + update.emoji.senderID ) as PlayerView; if (recipient == myPlayer) { @@ -306,7 +317,7 @@ export class EventsDisplay extends LitElement implements Layer { (event, index) => html` @@ -331,14 +342,14 @@ export class EventsDisplay extends LitElement implements Layer { > ${btn.text} - `, + ` )} ` : ""} - `, + ` )} diff --git a/src/core/game/GameUpdates.ts b/src/core/game/GameUpdates.ts index 7bd89182a..166297260 100644 --- a/src/core/game/GameUpdates.ts +++ b/src/core/game/GameUpdates.ts @@ -70,6 +70,12 @@ export interface UnitUpdate { constructionType?: UnitType; } +export interface AttackUpdate { + attackerID: number; + targetID: number; + troops: number; +} + export interface PlayerUpdate { type: GameUpdateType.Player; nameViewData?: NameViewData; @@ -90,6 +96,8 @@ export interface PlayerUpdate { isTraitor: boolean; targets: number[]; outgoingEmojis: EmojiMessage[]; + outgoingAttacks: AttackUpdate[]; + incomingAttacks: AttackUpdate[]; } export interface AllianceRequestUpdate { diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index ff1416c7f..4459b3437 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -7,7 +7,7 @@ import { PlayerProfile, Unit, } from "./Game"; -import { PlayerUpdate } from "./GameUpdates"; +import { AttackUpdate, PlayerUpdate } from "./GameUpdates"; import { UnitUpdate } from "./GameUpdates"; import { NameViewData } from "./Game"; import { GameUpdateType } from "./GameUpdates"; @@ -106,6 +106,14 @@ export class PlayerView { ); } + outgoingAttacks(): AttackUpdate[] { + return this.data.outgoingAttacks; + } + + incomingAttacks(): AttackUpdate[] { + return this.data.incomingAttacks; + } + units(...types: UnitType[]): UnitView[] { return this.game .units(...types) diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index a9481b361..8c45a895e 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -19,7 +19,7 @@ import { PlayerProfile, Attack, } from "./Game"; -import { PlayerUpdate } from "./GameUpdates"; +import { AttackUpdate, PlayerUpdate } from "./GameUpdates"; import { GameUpdateType } from "./GameUpdates"; import { ClientID } from "../Schemas"; import { @@ -116,6 +116,22 @@ export class PlayerImpl implements Player { isTraitor: this.isTraitor(), targets: this.targets().map((p) => p.smallID()), outgoingEmojis: this.outgoingEmojis(), + outgoingAttacks: this._outgoingAttacks.map( + (a) => + ({ + attackerID: a.attacker().smallID(), + targetID: a.target().smallID(), + troops: a.troops(), + } as AttackUpdate) + ), + incomingAttacks: this._incomingAttacks.map( + (a) => + ({ + attackerID: a.attacker().smallID(), + targetID: a.target().smallID(), + troops: a.troops(), + } as AttackUpdate) + ), }; }