mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-27 06:14:36 +00:00
adding destroyer
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Executor } from "../core/execution/ExecutionManager";
|
||||
import { Cell, MutableGame, PlayerEvent, PlayerID, MutablePlayer, TileEvent, Player, Game, BoatEvent, Tile, PlayerType, GameMap, Difficulty } from "../core/game/Game";
|
||||
import { Cell, MutableGame, PlayerEvent, PlayerID, MutablePlayer, TileEvent, Player, Game, UnitEvent, Tile, PlayerType, GameMap, Difficulty } from "../core/game/Game";
|
||||
import { createGame } from "../core/game/GameImpl";
|
||||
import { EventBus } from "../core/EventBus";
|
||||
import { Config, getConfig } from "../core/configuration/Config";
|
||||
|
||||
+19
-2
@@ -1,7 +1,7 @@
|
||||
import { Config } from "../core/configuration/Config"
|
||||
import { EventBus, GameEvent } from "../core/EventBus"
|
||||
import { AllianceRequest, AllPlayers, Cell, Player, PlayerID, PlayerType } from "../core/game/Game"
|
||||
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema } from "../core/Schemas"
|
||||
import { AllianceRequest, AllPlayers, Cell, Player, PlayerID, PlayerType, Tile } from "../core/game/Game"
|
||||
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, CreateDestroyerIntent, GameID, Intent, ServerMessage, ServerMessageSchema } from "../core/Schemas"
|
||||
import { LocalServer } from "./LocalServer"
|
||||
|
||||
|
||||
@@ -47,6 +47,12 @@ export class SendBoatAttackIntentEvent implements GameEvent {
|
||||
) { }
|
||||
}
|
||||
|
||||
export class SendCreateDestroyerIntentEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly cell: Cell,
|
||||
) { }
|
||||
}
|
||||
|
||||
export class SendTargetPlayerIntentEvent implements GameEvent {
|
||||
constructor(
|
||||
public readonly targetID: PlayerID,
|
||||
@@ -115,6 +121,7 @@ export class Transport {
|
||||
this.eventBus.on(SendDonateIntentEvent, (e) => this.onSendDonateIntent(e))
|
||||
this.eventBus.on(SendNukeIntentEvent, (e) => this.onSendNukeIntent(e))
|
||||
this.eventBus.on(SendSetTargetTroopRatioEvent, (e) => this.onSendSetTargetTroopRatioEvent(e))
|
||||
this.eventBus.on(SendCreateDestroyerIntentEvent, (e) => this.onCreateDestroyerIntent(e))
|
||||
}
|
||||
|
||||
connect(onconnect: () => void, onmessage: (message: ServerMessage) => void) {
|
||||
@@ -314,6 +321,16 @@ export class Transport {
|
||||
})
|
||||
}
|
||||
|
||||
private onCreateDestroyerIntent(event: SendCreateDestroyerIntentEvent) {
|
||||
this.sendIntent({
|
||||
type: "create_destroyer",
|
||||
clientID: this.clientID,
|
||||
player: this.playerID,
|
||||
x: event.cell.x,
|
||||
y: event.cell.y,
|
||||
})
|
||||
}
|
||||
|
||||
private sendIntent(intent: Intent) {
|
||||
if (this.isLocal || this.socket.readyState === WebSocket.OPEN) {
|
||||
const msg = ClientIntentMessageSchema.parse({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Colord } from "colord";
|
||||
import { Theme } from "../../../core/configuration/Config";
|
||||
import { Unit, BoatEvent, Cell, Game, Tile } from "../../../core/game/Game";
|
||||
import { Unit, UnitEvent, Cell, Game, Tile, UnitType } from "../../../core/game/Game";
|
||||
import { bfs, dist } from "../../../core/Util";
|
||||
import { Layer } from "./Layer";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
@@ -35,7 +35,7 @@ export class UnitLayer implements Layer {
|
||||
this.context.putImageData(this.imageData, 0, 0);
|
||||
this.initImageData()
|
||||
|
||||
this.eventBus.on(BoatEvent, e => this.onBoatEvent(e))
|
||||
this.eventBus.on(UnitEvent, e => this.onUnitEvent(e))
|
||||
}
|
||||
|
||||
initImageData() {
|
||||
@@ -58,28 +58,47 @@ export class UnitLayer implements Layer {
|
||||
}
|
||||
|
||||
|
||||
onBoatEvent(event: BoatEvent) {
|
||||
if (!this.boatToTrail.has(event.boat)) {
|
||||
this.boatToTrail.set(event.boat, new Set<Tile>())
|
||||
onUnitEvent(event: UnitEvent) {
|
||||
switch (event.unit.type()) {
|
||||
case UnitType.TransportShip:
|
||||
this.handleBoatEvent(event)
|
||||
break
|
||||
case UnitType.Destroyer:
|
||||
this.handleDestroyerEvent(event)
|
||||
break
|
||||
default:
|
||||
throw Error(`event for unit ${event.unit.type()} not supported`)
|
||||
}
|
||||
const trail = this.boatToTrail.get(event.boat)
|
||||
}
|
||||
|
||||
private handleDestroyerEvent(event: UnitEvent) {
|
||||
|
||||
}
|
||||
|
||||
private handleBoatEvent(event: UnitEvent) {
|
||||
if (!this.boatToTrail.has(event.unit)) {
|
||||
this.boatToTrail.set(event.unit, new Set<Tile>())
|
||||
}
|
||||
const trail = this.boatToTrail.get(event.unit)
|
||||
trail.add(event.oldTile)
|
||||
bfs(event.oldTile, dist(event.oldTile, 3)).forEach(t => {
|
||||
this.clearCell(t.cell())
|
||||
})
|
||||
if (event.boat.isActive()) {
|
||||
bfs(event.boat.tile(), dist(event.boat.tile(), 4)).forEach(
|
||||
if (event.unit.isActive()) {
|
||||
bfs(event.unit.tile(), dist(event.unit.tile(), 4)).forEach(
|
||||
t => {
|
||||
if (trail.has(t)) {
|
||||
this.paintCell(t.cell(), this.theme.territoryColor(event.boat.owner().info()), 150)
|
||||
this.paintCell(t.cell(), this.theme.territoryColor(event.unit.owner().info()), 150)
|
||||
}
|
||||
}
|
||||
)
|
||||
bfs(event.boat.tile(), dist(event.boat.tile(), 2)).forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.boat.owner().info()), 255))
|
||||
bfs(event.boat.tile(), dist(event.boat.tile(), 1)).forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.boat.owner().info()), 180))
|
||||
bfs(event.unit.tile(), dist(event.unit.tile(), 2))
|
||||
.forEach(t => this.paintCell(t.cell(), this.theme.borderColor(event.unit.owner().info()), 255))
|
||||
bfs(event.unit.tile(), dist(event.unit.tile(), 1))
|
||||
.forEach(t => this.paintCell(t.cell(), this.theme.territoryColor(event.unit.owner().info()), 180))
|
||||
} else {
|
||||
trail.forEach(t => this.clearCell(t.cell()))
|
||||
this.boatToTrail.delete(event.boat)
|
||||
this.boatToTrail.delete(event.unit)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@ import { LitElement, html, css } from 'lit';
|
||||
import { customElement, state } from 'lit/decorators.js';
|
||||
import { EventBus } from '../../../../core/EventBus';
|
||||
import { Cell, Game, Item, Items, Player } from '../../../../core/game/Game';
|
||||
import { SendNukeIntentEvent } from '../../../Transport';
|
||||
import { SendCreateDestroyerIntentEvent, SendNukeIntentEvent } from '../../../Transport';
|
||||
import nukeIcon from '../../../../../resources/images/NukeIconWhite.svg';
|
||||
import destroyerIcon from '../../../../../resources/images/DestroyerIconWhite.svg';
|
||||
import goldCoinIcon from '../../../../../resources/images/GoldCoinIcon.svg';
|
||||
import { renderNumber } from '../../Utils';
|
||||
import { ContextMenuEvent } from '../../../InputHandler';
|
||||
@@ -16,6 +17,7 @@ interface BuildItem {
|
||||
const buildTable: BuildItem[][] = [
|
||||
[
|
||||
{ item: Items.Nuke, icon: nukeIcon },
|
||||
{ item: Items.Destroyer, icon: destroyerIcon },
|
||||
// { id: 'battleship', name: 'Battleship', icon: '🚢', cost: 500, buildTime: 20 }
|
||||
]
|
||||
];
|
||||
@@ -146,8 +148,15 @@ export class BuildMenu extends LitElement {
|
||||
return this.myPlayer && this.myPlayer.gold() >= item.item.cost;
|
||||
}
|
||||
|
||||
public onBuildSelected: (item: BuildItem) => void = () => {
|
||||
this.eventBus.emit(new SendNukeIntentEvent(this.myPlayer, this.clickedCell, null))
|
||||
public onBuildSelected = (item: BuildItem) => {
|
||||
switch (item.item.name) {
|
||||
case "Nuke":
|
||||
this.eventBus.emit(new SendNukeIntentEvent(this.myPlayer, this.clickedCell, null))
|
||||
break
|
||||
case "Destroyer":
|
||||
this.eventBus.emit(new SendCreateDestroyerIntentEvent(this.clickedCell))
|
||||
|
||||
}
|
||||
this.hideMenu()
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user