2024-02-22 16:41:42 -06:00
|
|
|
import {
|
2025-04-14 19:26:41 -05:00
|
|
|
ModelDefinition,
|
2024-09-14 18:32:36 -05:00
|
|
|
type EngineDefinition,
|
|
|
|
|
type GunDefinition,
|
|
|
|
|
type ProvisionDefinitions,
|
|
|
|
|
type ShellDefinition,
|
|
|
|
|
type TankDefinition,
|
|
|
|
|
type TrackDefinition,
|
|
|
|
|
type TurretDefinition,
|
2024-09-06 23:17:53 -05:00
|
|
|
} from '@blitzkit/core';
|
|
|
|
|
import { create } from 'zustand';
|
|
|
|
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
|
|
|
import { tankToDuelMember } from '../../core/blitzkit/tankToDuelMember';
|
2024-09-21 20:26:58 -05:00
|
|
|
import { createContextualStore } from '../../core/zustand/createContextualStore';
|
2024-02-22 16:41:42 -06:00
|
|
|
|
|
|
|
|
type EquipmentMatrixItem = -1 | 0 | 1;
|
|
|
|
|
type EquipmentMatrixRow = [
|
|
|
|
|
EquipmentMatrixItem,
|
|
|
|
|
EquipmentMatrixItem,
|
|
|
|
|
EquipmentMatrixItem,
|
|
|
|
|
];
|
|
|
|
|
export type EquipmentMatrix = [
|
|
|
|
|
EquipmentMatrixRow,
|
|
|
|
|
EquipmentMatrixRow,
|
|
|
|
|
EquipmentMatrixRow,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export interface DuelMember {
|
|
|
|
|
tank: TankDefinition;
|
|
|
|
|
engine: EngineDefinition;
|
|
|
|
|
turret: TurretDefinition;
|
|
|
|
|
gun: GunDefinition;
|
|
|
|
|
shell: ShellDefinition;
|
|
|
|
|
track: TrackDefinition;
|
2024-04-04 13:51:07 -05:00
|
|
|
equipmentMatrix: EquipmentMatrix;
|
2024-02-22 16:41:42 -06:00
|
|
|
consumables: number[];
|
|
|
|
|
provisions: number[];
|
|
|
|
|
camouflage: boolean;
|
|
|
|
|
cooldownBooster: number;
|
2025-08-01 12:25:09 -05:00
|
|
|
assaultDistance: number;
|
2024-02-22 16:41:42 -06:00
|
|
|
}
|
2024-01-22 18:04:13 -06:00
|
|
|
|
2024-09-21 20:26:58 -05:00
|
|
|
export interface DuelStore {
|
2024-07-09 20:35:36 -05:00
|
|
|
protagonist: DuelMember;
|
|
|
|
|
antagonist: DuelMember;
|
2024-01-22 18:04:13 -06:00
|
|
|
}
|
|
|
|
|
|
2024-09-21 20:26:58 -05:00
|
|
|
export const Duel = createContextualStore(
|
|
|
|
|
({
|
|
|
|
|
tank,
|
2025-04-14 19:26:41 -05:00
|
|
|
model,
|
2024-09-21 20:26:58 -05:00
|
|
|
provisionDefinitions,
|
|
|
|
|
}: {
|
|
|
|
|
tank: TankDefinition;
|
2025-04-14 19:26:41 -05:00
|
|
|
model: ModelDefinition;
|
2024-09-21 20:26:58 -05:00
|
|
|
provisionDefinitions: ProvisionDefinitions;
|
|
|
|
|
}) => {
|
2025-04-14 19:26:41 -05:00
|
|
|
const protagonist = tankToDuelMember(tank, model, provisionDefinitions);
|
2024-07-09 20:35:36 -05:00
|
|
|
|
2024-09-21 20:26:58 -05:00
|
|
|
return create<DuelStore>()(
|
|
|
|
|
subscribeWithSelector<DuelStore>(() => ({
|
|
|
|
|
protagonist,
|
2025-04-14 19:26:41 -05:00
|
|
|
model,
|
2024-09-21 20:26:58 -05:00
|
|
|
antagonist: protagonist,
|
|
|
|
|
})),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|