Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@
"boat_attack_desc": "Send a boat attack to the tile under your cursor.",
"ground_attack": "Ground Attack",
"ground_attack_desc": "Send a ground attack to the tile under your cursor.",
"ally_keybinds": "Ally Keybinds",
"request_alliance": "Request Alliance",
"request_alliance_desc": "Send an alliance request to the player whose tile is under your cursor.",
"break_alliance": "Break Alliance (Betray)",
"break_alliance_desc": "Break alliance with the player whose tile is under your cursor.",
"swap_direction": "Swap Rocket Direction",
"swap_direction_desc": "Toggle rocket launch direction (up/down).",
"zoom_controls": "Zoom Controls",
Expand Down Expand Up @@ -760,6 +765,7 @@
"sent_emoji": "Sent {name}: {emoji}",
"renew_alliance": "Request to renew",
"request_alliance": "{name} requests an alliance!",
"alliance_request_sent": "Alliance request sent to {name}.",
"focus": "Focus",
"accept_alliance": "Accept",
"reject_alliance": "Reject",
Expand Down
56 changes: 56 additions & 0 deletions src/client/ClientGameRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import { getPersistentID } from "./Auth";
import {
AutoUpgradeEvent,
DoBoatAttackEvent,
DoBreakAllianceEvent,
DoGroundAttackEvent,
DoRequestAllianceEvent,
InputHandler,
MouseMoveEvent,
MouseUpEvent,
Expand All @@ -40,8 +42,10 @@ import {
import { endGame, startGame, startTime } from "./LocalPersistantStats";
import { terrainMapFileLoader } from "./TerrainMapFileLoader";
import {
SendAllianceRequestIntentEvent,
SendAttackIntentEvent,
SendBoatAttackIntentEvent,
SendBreakAllianceIntentEvent,
SendHashEvent,
SendSpawnIntentEvent,
SendUpgradeStructureIntentEvent,
Expand Down Expand Up @@ -348,6 +352,14 @@ export class ClientGameRunner {
DoGroundAttackEvent,
this.doGroundAttackUnderCursor.bind(this),
);
this.eventBus.on(
DoRequestAllianceEvent,
this.doRequestAllianceUnderCursor.bind(this),
);
this.eventBus.on(
DoBreakAllianceEvent,
this.doBreakAllianceUnderCursor.bind(this),
);

this.renderer.initialize();
this.input.initialize();
Expand Down Expand Up @@ -687,6 +699,50 @@ export class ClientGameRunner {
});
}

private doRequestAllianceUnderCursor(): void {
const tile = this.getTileUnderCursor();
if (tile === null) return;

const myPlayer =
this.myPlayer ?? this.gameView.playerByClientID(this.lobby.clientID);
if (myPlayer === null) return;
this.myPlayer = myPlayer;

const tileOwner = this.gameView.owner(tile);
if (!tileOwner.isPlayer()) return;
const recipient = tileOwner as PlayerView;

myPlayer.actions(tile).then((actions) => {
if (actions.interaction?.canSendAllianceRequest) {
this.eventBus.emit(
new SendAllianceRequestIntentEvent(myPlayer, recipient),
);
}
});
}

private doBreakAllianceUnderCursor(): void {
const tile = this.getTileUnderCursor();
if (tile === null) return;

const myPlayer =
this.myPlayer ?? this.gameView.playerByClientID(this.lobby.clientID);
if (myPlayer === null) return;
this.myPlayer = myPlayer;

const tileOwner = this.gameView.owner(tile);
if (!tileOwner.isPlayer()) return;
const recipient = tileOwner as PlayerView;

myPlayer.actions(tile).then((actions) => {
if (actions.interaction?.canBreakAlliance) {
this.eventBus.emit(
new SendBreakAllianceIntentEvent(myPlayer, recipient),
);
}
});
}

private getTileUnderCursor(): TileRef | null {
if (!this.isActive || !this.lastMousePosition) {
return null;
Expand Down
16 changes: 16 additions & 0 deletions src/client/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export class DoBoatAttackEvent implements GameEvent {}

export class DoGroundAttackEvent implements GameEvent {}

export class DoRequestAllianceEvent implements GameEvent {}

export class DoBreakAllianceEvent implements GameEvent {}

export class AttackRatioEvent implements GameEvent {
constructor(public readonly attackRatio: number) {}
}
Expand Down Expand Up @@ -225,6 +229,8 @@ export class InputHandler {
buildAtomBomb: "Digit8",
buildHydrogenBomb: "Digit9",
buildMIRV: "Digit0",
requestAlliance: "KeyK",
breakAlliance: "KeyL",
...saved,
};

Expand Down Expand Up @@ -441,6 +447,16 @@ export class InputHandler {
this.setGhostStructure(UnitType.MIRV);
}

if (e.code === this.keybinds.requestAlliance) {
e.preventDefault();
this.eventBus.emit(new DoRequestAllianceEvent());
}

if (e.code === this.keybinds.breakAlliance) {
e.preventDefault();
this.eventBus.emit(new DoBreakAllianceEvent());
}

if (e.code === this.keybinds.swapDirection) {
e.preventDefault();
const nextDirection = !this.uiState.rocketDirectionUp;
Expand Down
28 changes: 28 additions & 0 deletions src/client/UserSettingModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const DefaultKeybinds: Record<string, string> = {
attackRatioUp: "KeyY",
boatAttack: "KeyB",
groundAttack: "KeyG",
requestAlliance: "KeyK",
breakAlliance: "KeyL",
swapDirection: "KeyU",
zoomOut: "KeyQ",
zoomIn: "KeyE",
Expand Down Expand Up @@ -669,6 +671,32 @@ export class UserSettingModal extends BaseModal {
@change=${this.handleKeybindChange}
></setting-keybind>

<h2
class="text-blue-200 text-xl font-bold mt-8 mb-3 border-b border-white/10 pb-2"
>
${translateText("user_setting.ally_keybinds")}
</h2>

<setting-keybind
action="requestAlliance"
label=${translateText("user_setting.request_alliance")}
description=${translateText("user_setting.request_alliance_desc")}
defaultKey="KeyK"
.value=${this.getKeyValue("requestAlliance")}
.display=${this.getKeyChar("requestAlliance")}
@change=${this.handleKeybindChange}
></setting-keybind>

<setting-keybind
action="breakAlliance"
label=${translateText("user_setting.break_alliance")}
description=${translateText("user_setting.break_alliance_desc")}
defaultKey="KeyL"
.value=${this.getKeyValue("breakAlliance")}
.display=${this.getKeyChar("breakAlliance")}
@change=${this.handleKeybindChange}
></setting-keybind>

<h2
class="text-blue-200 text-xl font-bold mt-8 mb-3 border-b border-white/10 pb-2"
>
Expand Down
22 changes: 21 additions & 1 deletion src/client/graphics/layers/EventsDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
CancelBoatIntentEvent,
SendAllianceExtensionIntentEvent,
SendAllianceReplyIntentEvent,
SendAllianceRequestIntentEvent,
SendAttackIntentEvent,
} from "../../Transport";
import { Layer } from "./Layer";
Expand Down Expand Up @@ -199,7 +200,26 @@ export class EventsDisplay extends LitElement implements Layer {
this.outgoingBoats = [];
}

init() {}
init() {
this.eventBus.on(
SendAllianceRequestIntentEvent,
this.onAllianceRequestSentConfirmation.bind(this),
);
}

private onAllianceRequestSentConfirmation(e: SendAllianceRequestIntentEvent) {
const myPlayer = this.game.myPlayer();
if (!myPlayer || e.requestor.id() !== myPlayer.id()) {
return;
}
this.addEvent({
description: translateText("events_display.alliance_request_sent", {
name: e.recipient.name(),
}),
type: MessageType.ALLIANCE_REQUEST,
createdAt: this.game.ticks(),
});
}

tick() {
this.active = true;
Expand Down
Loading