mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-22 19:13:05 +00:00
working on port
This commit is contained in:
+8
-7
@@ -1,5 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { Difficulty, GameMap, PlayerType } from './game/Game';
|
||||
import { Difficulty, GameMap, PlayerType, UnitType } from './game/Game';
|
||||
|
||||
export type GameID = string
|
||||
export type ClientID = string
|
||||
@@ -15,7 +15,7 @@ export type Intent = SpawnIntent
|
||||
| DonateIntent
|
||||
| NukeIntent
|
||||
| TargetTroopRatioIntent
|
||||
| CreateDestroyerIntent
|
||||
| BuildUnitIntent
|
||||
|
||||
export type AttackIntent = z.infer<typeof AttackIntentSchema>
|
||||
export type SpawnIntent = z.infer<typeof SpawnIntentSchema>
|
||||
@@ -28,7 +28,7 @@ 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 TargetTroopRatioIntentSchema>
|
||||
export type CreateDestroyerIntent = z.infer<typeof CreateDestroyerIntentSchema>
|
||||
export type BuildUnitIntent = z.infer<typeof BuildUnitIntentSchema>
|
||||
|
||||
export type Turn = z.infer<typeof TurnSchema>
|
||||
export type GameConfig = z.infer<typeof GameConfigSchema>
|
||||
@@ -69,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', 'create_destroyer']),
|
||||
type: z.enum(['attack', 'spawn', 'boat', 'name', 'targetPlayer', 'emoji', 'nuke', 'troop_ratio', 'build_unit']),
|
||||
clientID: z.string(),
|
||||
});
|
||||
|
||||
@@ -161,9 +161,10 @@ export const TargetTroopRatioIntentSchema = BaseIntentSchema.extend({
|
||||
ratio: z.number().min(0).max(1),
|
||||
})
|
||||
|
||||
export const CreateDestroyerIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('create_destroyer'),
|
||||
export const BuildUnitIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('build_unit'),
|
||||
player: z.string(),
|
||||
unit: z.nativeEnum(UnitType),
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
})
|
||||
@@ -180,7 +181,7 @@ const IntentSchema = z.union([
|
||||
DonateIntentSchema,
|
||||
NukeIntentSchema,
|
||||
TargetTroopRatioIntentSchema,
|
||||
CreateDestroyerIntentSchema,
|
||||
BuildUnitIntentSchema,
|
||||
]);
|
||||
|
||||
const TurnSchema = z.object({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent, Difficulty } from "../game/Game";
|
||||
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent, Difficulty, UnitType } from "../game/Game";
|
||||
import { AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn } from "../Schemas";
|
||||
import { AttackExecution } from "./AttackExecution";
|
||||
import { SpawnExecution } from "./SpawnExecution";
|
||||
@@ -17,6 +17,7 @@ import { DonateExecution } from "./DonateExecution";
|
||||
import { NukeExecution } from "./NukeExecution";
|
||||
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
|
||||
import { DestroyerExecution } from "./DestroyerExecution";
|
||||
import { PortExecution } from "./PortExecution";
|
||||
|
||||
|
||||
|
||||
@@ -81,8 +82,15 @@ export class Executor {
|
||||
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude);
|
||||
case "troop_ratio":
|
||||
return new SetTargetTroopRatioExecution(intent.player, intent.ratio);
|
||||
case "create_destroyer":
|
||||
return new DestroyerExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
case "build_unit":
|
||||
switch (intent.unit) {
|
||||
case UnitType.Destroyer:
|
||||
return new DestroyerExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
case UnitType.Port:
|
||||
return new PortExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
default:
|
||||
throw Error(`unit type ${intent.unit} not supported`)
|
||||
}
|
||||
default:
|
||||
throw new Error(`intent type ${intent} not found`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { AllPlayers, Cell, Execution, MutableGame, MutablePlayer, PlayerID } from "../game/Game";
|
||||
|
||||
export class PortExecution implements Execution {
|
||||
|
||||
private active = true
|
||||
|
||||
constructor(
|
||||
private _owner: PlayerID,
|
||||
private cell: Cell
|
||||
) { }
|
||||
|
||||
|
||||
init(mg: MutableGame, ticks: number): void {
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,7 +27,8 @@ export enum GameMap {
|
||||
|
||||
export enum UnitType {
|
||||
TransportShip,
|
||||
Destroyer
|
||||
Destroyer,
|
||||
Port
|
||||
}
|
||||
|
||||
export class Item {
|
||||
@@ -36,7 +37,8 @@ export class Item {
|
||||
|
||||
export const Items = {
|
||||
Nuke: new Item("Nuke", 1_000_000),
|
||||
Destroyer: new Item("Destroyer", 10)
|
||||
Destroyer: new Item("Destroyer", 10),
|
||||
Port: new Item("Port", 10)
|
||||
} as const;
|
||||
|
||||
export class Nation {
|
||||
|
||||
Reference in New Issue
Block a user