mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-28 07:14:49 +00:00
adding destroyer
This commit is contained in:
+14
-4
@@ -15,6 +15,7 @@ export type Intent = SpawnIntent
|
||||
| DonateIntent
|
||||
| NukeIntent
|
||||
| TargetTroopRatioIntent
|
||||
| CreateDestroyerIntent
|
||||
|
||||
export type AttackIntent = z.infer<typeof AttackIntentSchema>
|
||||
export type SpawnIntent = z.infer<typeof SpawnIntentSchema>
|
||||
@@ -26,7 +27,8 @@ export type TargetPlayerIntent = z.infer<typeof TargetPlayerIntentSchema>
|
||||
export type EmojiIntent = z.infer<typeof EmojiIntentSchema>
|
||||
export type DonateIntent = z.infer<typeof DonateIntentSchema>
|
||||
export type NukeIntent = z.infer<typeof NukeIntentSchema>
|
||||
export type TargetTroopRatioIntent = z.infer<typeof TargetTroopRatioSchema>
|
||||
export type TargetTroopRatioIntent = z.infer<typeof TargetTroopRatioIntentSchema>
|
||||
export type CreateDestroyerIntent = z.infer<typeof CreateDestroyerIntentSchema>
|
||||
|
||||
export type Turn = z.infer<typeof TurnSchema>
|
||||
export type GameConfig = z.infer<typeof GameConfigSchema>
|
||||
@@ -67,7 +69,7 @@ const EmojiSchema = z.string().refine(
|
||||
);
|
||||
// Zod schemas
|
||||
const BaseIntentSchema = z.object({
|
||||
type: z.enum(['attack', 'spawn', 'boat', 'name', 'targetPlayer', 'emoji', 'nuke', 'troop_ratio']),
|
||||
type: z.enum(['attack', 'spawn', 'boat', 'name', 'targetPlayer', 'emoji', 'nuke', 'troop_ratio', 'create_destroyer']),
|
||||
clientID: z.string(),
|
||||
});
|
||||
|
||||
@@ -153,12 +155,19 @@ export const NukeIntentSchema = BaseIntentSchema.extend({
|
||||
magnitude: z.number().nullable(),
|
||||
})
|
||||
|
||||
export const TargetTroopRatioSchema = BaseIntentSchema.extend({
|
||||
export const TargetTroopRatioIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('troop_ratio'),
|
||||
player: z.string(),
|
||||
ratio: z.number().min(0).max(1),
|
||||
})
|
||||
|
||||
export const CreateDestroyerIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('create_destroyer'),
|
||||
player: z.string(),
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
})
|
||||
|
||||
const IntentSchema = z.union([
|
||||
AttackIntentSchema,
|
||||
SpawnIntentSchema,
|
||||
@@ -170,7 +179,8 @@ const IntentSchema = z.union([
|
||||
EmojiIntentSchema,
|
||||
DonateIntentSchema,
|
||||
NukeIntentSchema,
|
||||
TargetTroopRatioSchema,
|
||||
TargetTroopRatioIntentSchema,
|
||||
CreateDestroyerIntentSchema,
|
||||
]);
|
||||
|
||||
const TurnSchema = z.object({
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { AllPlayers, Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, UnitType } from "../game/Game";
|
||||
|
||||
export class DestroyerExecution implements Execution {
|
||||
|
||||
private _owner: MutablePlayer
|
||||
private active = true
|
||||
private destroyer: MutableUnit = null
|
||||
private mg: MutableGame = null
|
||||
|
||||
constructor(
|
||||
private playerID: PlayerID,
|
||||
private cell: Cell,
|
||||
) { }
|
||||
|
||||
|
||||
init(mg: MutableGame, ticks: number): void {
|
||||
this._owner = mg.player(this.playerID)
|
||||
this.mg = mg
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
if (this.destroyer == null) {
|
||||
this.destroyer = this._owner.addUnit(UnitType.Destroyer, 0, this.mg.tile(this.cell))
|
||||
}
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn } from "../S
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
import { SpawnExecution } from "./SpawnExecution";
|
||||
import { BotSpawner } from "./BotSpawner";
|
||||
import { BoatAttackExecution } from "./BoatAttackExecution";
|
||||
import { TransportShipExecution } from "./TransportShipExecution";
|
||||
import { PseudoRandom } from "../PseudoRandom";
|
||||
import { FakeHumanExecution } from "./FakeHumanExecution";
|
||||
import Usernames from '../../../resources/Usernames.txt'
|
||||
@@ -52,7 +52,7 @@ export class Executor {
|
||||
new Cell(intent.x, intent.y)
|
||||
)
|
||||
} else if (intent.type == "boat") {
|
||||
return new BoatAttackExecution(
|
||||
return new TransportShipExecution(
|
||||
intent.attackerID,
|
||||
intent.targetID,
|
||||
new Cell(intent.x, intent.y),
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Cell, Execution, MutableGame, MutablePlayer, Player, PlayerInfo, Player
|
||||
import { PseudoRandom } from "../PseudoRandom"
|
||||
import { and, bfs, dist, simpleHash } from "../Util";
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
import { BoatAttackExecution } from "./BoatAttackExecution";
|
||||
import { TransportShipExecution } from "./TransportShipExecution";
|
||||
import { SpawnExecution } from "./SpawnExecution";
|
||||
|
||||
export class FakeHumanExecution implements Execution {
|
||||
@@ -194,7 +194,7 @@ export class FakeHumanExecution implements Execution {
|
||||
continue
|
||||
}
|
||||
|
||||
this.mg.addExecution(new BoatAttackExecution(
|
||||
this.mg.addExecution(new TransportShipExecution(
|
||||
this.player.id(),
|
||||
dst.hasOwner() ? dst.owner().id() : null,
|
||||
dst.cell(),
|
||||
|
||||
@@ -48,7 +48,9 @@ export class NukeExecution implements Execution {
|
||||
mp.removeTroops(mp.troops() / mp.numTilesOwned())
|
||||
}
|
||||
}
|
||||
this.mg.boats().filter(b => euclideanDist(this.cell, b.tile().cell()) < this.magnitude + 50).forEach(b => b.delete())
|
||||
this.mg.units()
|
||||
.filter(b => euclideanDist(this.cell, b.tile().cell()) < this.magnitude + 50)
|
||||
.forEach(b => b.delete())
|
||||
this.active = false
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -4,7 +4,7 @@ import { and, bfs, manhattanDistWrapped, sourceDstOceanShore } from "../Util";
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/EventsDisplay";
|
||||
|
||||
export class BoatAttackExecution implements Execution {
|
||||
export class TransportShipExecution implements Execution {
|
||||
|
||||
private lastMove: number
|
||||
|
||||
@@ -86,7 +86,7 @@ export class BoatAttackExecution implements Execution {
|
||||
this.aStarPre.compute(5)
|
||||
this.path = this.aStarPre.reconstructPath()
|
||||
if (this.path != null) {
|
||||
this.boat = this.attacker.addBoat(this.troops, this.src, this.target)
|
||||
this.boat = this.attacker.addUnit(UnitType.TransportShip, this.troops, this.src)
|
||||
} else {
|
||||
console.log('got null path')
|
||||
this.active = false
|
||||
@@ -126,7 +126,9 @@ export class BoatAttackExecution implements Execution {
|
||||
this.target.addTroops(this.troops)
|
||||
} else {
|
||||
this.attacker.conquer(this.dst)
|
||||
this.mg.addExecution(new AttackExecution(this.troops, this.attacker.id(), this.targetID, this.dst.cell(), null, false))
|
||||
this.mg.addExecution(
|
||||
new AttackExecution(this.troops, this.attacker.id(), this.targetID, this.dst.cell(), null, false)
|
||||
)
|
||||
}
|
||||
this.boat.delete()
|
||||
this.active = false
|
||||
@@ -26,7 +26,8 @@ export enum GameMap {
|
||||
}
|
||||
|
||||
export enum UnitType {
|
||||
TransportShip
|
||||
TransportShip,
|
||||
Destroyer
|
||||
}
|
||||
|
||||
export class Item {
|
||||
@@ -35,6 +36,7 @@ export class Item {
|
||||
|
||||
export const Items = {
|
||||
Nuke: new Item("Nuke", 1_000_000),
|
||||
Destroyer: new Item("Destroyer", 100_000)
|
||||
} as const;
|
||||
|
||||
export class Nation {
|
||||
@@ -226,7 +228,6 @@ export interface MutablePlayer extends Player {
|
||||
allianceWith(other: Player): MutableAlliance | null
|
||||
breakAlliance(alliance: Alliance): void
|
||||
createAllianceRequest(recipient: Player): MutableAllianceRequest
|
||||
addBoat(troops: number, tile: Tile, target: Player | TerraNullius): MutableUnit
|
||||
target(other: Player): void
|
||||
targets(): MutablePlayer[]
|
||||
transitiveTargets(): MutablePlayer[]
|
||||
@@ -242,6 +243,8 @@ export interface MutablePlayer extends Player {
|
||||
setTroops(troops: number): void
|
||||
addTroops(troops: number): void
|
||||
removeTroops(troops: number): number
|
||||
|
||||
addUnit(type: UnitType, troops: number, tile: Tile): MutableUnit
|
||||
}
|
||||
|
||||
export interface Game {
|
||||
@@ -266,7 +269,7 @@ export interface Game {
|
||||
nations(): Nation[]
|
||||
config(): Config
|
||||
displayMessage(message: string, type: MessageType, playerID: PlayerID | null): void
|
||||
boats(): Unit[]
|
||||
units(...types: UnitType[]): Unit[]
|
||||
}
|
||||
|
||||
export interface MutableGame extends Game {
|
||||
@@ -275,7 +278,7 @@ export interface MutableGame extends Game {
|
||||
players(): MutablePlayer[]
|
||||
addPlayer(playerInfo: PlayerInfo, manpower: number): MutablePlayer
|
||||
executions(): Execution[]
|
||||
boats(): MutableUnit[]
|
||||
units(...types: UnitType[]): MutableUnit[]
|
||||
}
|
||||
|
||||
export class TileEvent implements GameEvent {
|
||||
@@ -286,8 +289,8 @@ export class PlayerEvent implements GameEvent {
|
||||
constructor(public readonly player: Player) { }
|
||||
}
|
||||
|
||||
export class BoatEvent implements GameEvent {
|
||||
constructor(public readonly boat: Unit, public oldTile: Tile) { }
|
||||
export class UnitEvent implements GameEvent {
|
||||
constructor(public readonly unit: Unit, public oldTile: Tile) { }
|
||||
}
|
||||
|
||||
export class AllianceRequestEvent implements GameEvent {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { info } from "console";
|
||||
import { Config } from "../configuration/Config";
|
||||
import { EventBus } from "../EventBus";
|
||||
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Unit, BoatEvent as UnitEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent, AllianceRequestEvent, BrokeAllianceEvent, MutableAlliance, Alliance, AllianceExpiredEvent, Nation } from "./Game";
|
||||
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Unit, UnitEvent as UnitEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent, AllianceRequestEvent, BrokeAllianceEvent, MutableAlliance, Alliance, AllianceExpiredEvent, Nation, UnitType } from "./Game";
|
||||
import { TerrainMap } from "./TerrainMapLoader";
|
||||
import { PlayerImpl } from "./PlayerImpl";
|
||||
import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
@@ -58,8 +58,8 @@ export class GameImpl implements MutableGame {
|
||||
n.strength
|
||||
))
|
||||
}
|
||||
boats(): UnitImpl[] {
|
||||
return Array.from(this._players.values()).flatMap(p => p._units)
|
||||
units(...types: UnitType[]): UnitImpl[] {
|
||||
return Array.from(this._players.values()).flatMap(p => p.units(...types))
|
||||
}
|
||||
nations(): Nation[] {
|
||||
return this.nations_
|
||||
|
||||
@@ -73,8 +73,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
}
|
||||
|
||||
|
||||
addBoat(troops: number, tile: Tile): UnitImpl {
|
||||
const b = new UnitImpl(UnitType.TransportShip, this.gs, tile, troops, this);
|
||||
addUnit(type: UnitType, troops: number, tile: Tile): UnitImpl {
|
||||
const b = new UnitImpl(type, this.gs, tile, troops, this);
|
||||
this._units.push(b);
|
||||
this.gs.fireUnitUpdateEvent(b, b.tile());
|
||||
return b;
|
||||
|
||||
Reference in New Issue
Block a user