From 66c8261438a6993c1d058b2099e261162426c682 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 9 Mar 2024 05:58:17 +0000 Subject: [PATCH] =?UTF-8?q?refac:=20=EA=B0=92=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @sammo/game_logic/src/Entity/GameEnvEntity.ts | 38 +++++++++++++++++++ @sammo/game_logic/src/Entity/GeneralEntity.ts | 7 +++- @sammo/game_logic/src/Entity/index.ts | 7 +++- @sammo/game_logic/src/GameEnv.ts | 19 +++++++++- @sammo/game_logic/src/General.ts | 6 +++ @sammo/game_logic/src/IAction.ts | 21 +++++++++- @sammo/game_logic/src/ResourceController.ts | 15 ++++++-- 7 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 @sammo/game_logic/src/Entity/GameEnvEntity.ts diff --git a/@sammo/game_logic/src/Entity/GameEnvEntity.ts b/@sammo/game_logic/src/Entity/GameEnvEntity.ts new file mode 100644 index 0000000..7542a36 --- /dev/null +++ b/@sammo/game_logic/src/Entity/GameEnvEntity.ts @@ -0,0 +1,38 @@ +export type UnitedGameState = 'onGame' | 'united' | 'onEvent' | 'endEvent'; + +export interface IGameEnvEntity { + startTime: Date; + lastExecuted: Date; + + initYear: number; + initMonth: number; + + gameStartYear: number; + gameStartMonth: number; + + year: number; + month: number; + + turntermSec: number; + + refreshedKillTurn: number; + + isFictionMode: boolean; + unitedGameState: UnitedGameState; + blockGeneralCreate: boolean; + + mapTheme: string; + prevWinnerName?: string; + + scenarioID: number; + scenarioName: string; + gameSeason: number; + + maxGeneralCnt: number; + maxNationCnt: number; + + remainGeniusCnt: number; + autorunUserPolicy: Record; + + //게임 외부는 다른 엔티티로 분리 +} \ No newline at end of file diff --git a/@sammo/game_logic/src/Entity/GeneralEntity.ts b/@sammo/game_logic/src/Entity/GeneralEntity.ts index b09ea2c..7a82bbc 100644 --- a/@sammo/game_logic/src/Entity/GeneralEntity.ts +++ b/@sammo/game_logic/src/Entity/GeneralEntity.ts @@ -55,7 +55,12 @@ export interface IGeneralEntity { specialityDomestic: SpecialityDomesticType; specialityWar: SpecialityWarType; - defenceTrain: number; + defenceTrained: number; + + crewType: number; + crew: number; + trained: number; + morale: number; npcSpec?: { msg?: string; diff --git a/@sammo/game_logic/src/Entity/index.ts b/@sammo/game_logic/src/Entity/index.ts index b4ef2ce..4b41ca5 100644 --- a/@sammo/game_logic/src/Entity/index.ts +++ b/@sammo/game_logic/src/Entity/index.ts @@ -3,6 +3,7 @@ import type { ICityEntity } from './CityEntity.js'; import type { IGeneralEntity } from './GeneralEntity.js'; import type { INationEntity } from './NationEntity.js'; import type { ITroopEntity } from './TroopEntity.js'; +import type { IGameEnvEntity } from './GameEnvEntity.js'; export type { IGeneralEntity } from './GeneralEntity.js'; export type { ICityEntity } from './CityEntity.js'; @@ -11,10 +12,12 @@ export type { INationEntity } from './NationEntity.js'; export type ValidEntityList = { - 'General': IGeneralEntity; - 'City': ICityEntity; 'Nation': INationEntity; + 'City': ICityEntity; 'Troop': ITroopEntity; + 'General': IGeneralEntity; + + 'GameEnv': IGameEnvEntity; }; export type ValidEntity = ValuesOf; diff --git a/@sammo/game_logic/src/GameEnv.ts b/@sammo/game_logic/src/GameEnv.ts index 22b9ee5..3b2cd9b 100644 --- a/@sammo/game_logic/src/GameEnv.ts +++ b/@sammo/game_logic/src/GameEnv.ts @@ -1,3 +1,20 @@ -export class GameEnv{ +import type { IGameEnvEntity } from "./Entity/GameEnvEntity.js"; +import { LazyEntityUpdater } from "./LazyEntityUpdater.js"; +import type { IResourceController } from "./ResourceController.js"; + +export class GameEnv extends LazyEntityUpdater{ + protected readonly _indirectNames: readonly (keyof IGameEnvEntity)[] = [ + //사실상 모두. + ]; + protected readonly _entityType = "GameEnv"; + protected readonly _raw: IGameEnvEntity; + + constructor( + raw: IGameEnvEntity, + protected readonly resourceController: IResourceController + ){ + super(); + this._raw = raw; + } } \ No newline at end of file diff --git a/@sammo/game_logic/src/General.ts b/@sammo/game_logic/src/General.ts index 20a47fe..4f3f876 100644 --- a/@sammo/game_logic/src/General.ts +++ b/@sammo/game_logic/src/General.ts @@ -7,6 +7,7 @@ import { must } from "@sammo/util"; import { Nation } from "./Nation.js"; import { Troop } from "./Troop.js"; import { LazyEntityUpdater } from "./LazyEntityUpdater.js"; +import type { IAction, IActionKey } from "./IAction.js"; export class General extends LazyEntityUpdater { protected readonly _indirectNames: (keyof IGeneralEntity)[] = ["id", "nationID", "troopID", "nationID"]; @@ -17,6 +18,8 @@ export class General extends LazyEntityUpdater { protected _troop: WeakRef | undefined; protected _nation: WeakRef; + protected readonly iActionHandlers: Map; + constructor( raw: IGeneralEntity, protected readonly resourceController: IResourceController @@ -29,6 +32,9 @@ export class General extends LazyEntityUpdater { if(raw.troopID){ this._troop = new WeakRef(must(resourceController.troop(raw.troopID, raw.nationID))); } + + //TODO: iAction 처리해야함 + this.iActionHandlers = new Map(); } public get id(): GeneralID { diff --git a/@sammo/game_logic/src/IAction.ts b/@sammo/game_logic/src/IAction.ts index f7ccaf0..884b294 100644 --- a/@sammo/game_logic/src/IAction.ts +++ b/@sammo/game_logic/src/IAction.ts @@ -1,4 +1,6 @@ +import type { ValuesOf } from "@sammo/util"; import type * as IMethod from "./IActionMethod.js"; +import type { ItemKeyType } from "./defs.js"; export type * as IMethod from "./IActionMethod.js"; export interface IActionMethod extends @@ -20,4 +22,21 @@ export interface IAction extends Partial { getName(): string; getInfo(): string[] | string; -} \ No newline at end of file +} + +export const IActionOrder = [ + 'nationType', + 'officerLevel', + 'specialityDomestic', + 'specialityWar', + 'personlity', + 'crewType', + 'inheritBuff', + 'scenarioEffect', + 'horse', + 'weapon', + 'book', + 'item', +]; + +export type IActionKey = ValuesOf; \ No newline at end of file diff --git a/@sammo/game_logic/src/ResourceController.ts b/@sammo/game_logic/src/ResourceController.ts index b08f2de..9fe952c 100644 --- a/@sammo/game_logic/src/ResourceController.ts +++ b/@sammo/game_logic/src/ResourceController.ts @@ -13,22 +13,29 @@ import type { EntityType, ValidEntityType } from "./Entity/index.js"; import type { IReservedTurn } from "./Entity/ReservedTurn.js"; export interface IResourceController { - city(id: CityID): City | undefined; + nation(id: NationID): Nation | undefined; + city(id: CityID): City | undefined; troop(id: TroopID, nation: NationID): Troop | undefined; general(id: GeneralID): General | undefined; - getGameEnv(): GameEnv; + gameEnv(): GameEnv; allNations(): Map; allCities(): Map; + allCitiesByNation(): Map>; + allTroops(): Map>; allGenerals(): Map; + generalByNation(id: NationID): Map; + generalByCity(id: CityID, nationID?: NationID): Map; generalByTroop(id: TroopID): Map; cityByNation(id: NationID): Map; - generalByNation(id: NationID): Map; - generalByCity(id: CityID, nationID?: NationID): Map; + + troopByNation(id: NationID): Map; + + //----Insert, Update, Delete reserveUpdate(entity: LazyEntityUpdater): void; reserveDelete(entity: LazyEntityUpdater): void;