용어 재정의

This commit is contained in:
2024-03-11 16:53:44 +00:00
parent 21a9fc54f3
commit 28b78e0872
17 changed files with 100 additions and 95 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
import type { IResourceController } from "@/IResourceController.js";
import type { CityID, GeneralID, NationID, TroopID } from "@/defs.js";
import type { CityID, GeneralID, NationID, SquadID } from "@/defs.js";
import { NotYetImplemented } from "@sammo/util";
@@ -10,7 +10,7 @@ export function setDefenceTrained(invoker: QueueType, arg: { generalID: GeneralI
throw new NotYetImplemented();
}
export function kickTroopMember(invoker: QueueType, arg: { nationID: NationID, troopID: TroopID, memberID: GeneralID }, rsc: IResourceController): void {
export function kickSquadMember(invoker: QueueType, arg: { nationID: NationID, squadID: SquadID, memberID: GeneralID }, rsc: IResourceController): void {
throw new NotYetImplemented();
}
@@ -51,7 +51,7 @@ export type ActionPackDef = {
export const ActionRequestList = {
setDefenceTrained,
kickTroopMember,
kickSquadMember,
blockAttackCommand,
blockJoinNation,
createGeneral,
+10 -5
View File
@@ -1,4 +1,4 @@
import type { CityID, CityLevel, CityName, CityOfficerLevel, CityState, FrontStatus, NationID, RegionID } from "../defs.js";
import type { CityID, CityLevel, CityName, CityOfficerLevel, CityState, FrontStatus, NationID, FractionalRange, RegionID, RemainMonth } from "../defs.js";
export interface ICityEntity{
@@ -9,7 +9,7 @@ export interface ICityEntity{
level: CityLevel;
//보급품 있음
hasSupply: boolean;
isSupplied: boolean;
//도시 접경 상태
frontStatus: FrontStatus;
@@ -60,15 +60,20 @@ export interface ICityEntity{
battleDeath: number;
//상인 존재 및 거래율, base 1
trader?: number;
traderStatus: {
exists: false;
} | {
exists: true;
rate: FractionalRange;
}
officerSet: Record<CityOfficerLevel, boolean>;
officerAssignability: Record<CityOfficerLevel, boolean>;
regionID: RegionID;
state: CityState;
//전투 잔여 개월
remainWarMonth: number;
remainWarMonth: RemainMonth;
//국가별 수비병 사살 수
conflict: Record<NationID, number>;
+2 -2
View File
@@ -21,8 +21,8 @@ export interface IDiplomaticLetter {
icon: string;
};
textBrief: string;
textDetail: string;
publicText: string;
privateText: string;
createdAt: Date;
updatedAt: Date;
@@ -13,7 +13,7 @@ export interface IGameEnvEntity {
year: number;
month: number;
turntermSec: number;
secondsPerTurn: number;
refreshedKillTurn: number;
@@ -32,7 +32,7 @@ export interface IGameEnvEntity {
maxNationCnt: number;
remainGeniusCnt: number;
autorunUserPolicy: Record<string, unknown>;
autoRunUserPolicy: Record<string, unknown>;
//게임 외부는 다른 엔티티로 분리
}
@@ -1,4 +1,4 @@
import type { CityID, DiplomaticPermission, GeneralID, GeneralName, ItemID, ItemKeyType, NationID, NpcType, OfficerLevel, PersonalityType, SpecialityDomesticType, SpecialityWarType, TroopID, UserID, UserName } from "../defs.js";
import type { CityID, DiplomaticPermission, GeneralID, GeneralName, ItemID, ItemKeyType, NationID, NpcType, OfficerLevel, PersonalityType, SpecialityDomesticType, SpecialityWarType, SquadID, UserID, UserName } from "../defs.js";
export interface IGeneralEntity {
id: GeneralID;
@@ -10,7 +10,7 @@ export interface IGeneralEntity {
ownerName?: UserName;
nationID: NationID;
cityID: number;
troopID?: TroopID;
squadID?: SquadID;
leadership: number;
leadershipExp: number;
@@ -27,7 +27,7 @@ export interface IGeneralEntity {
experienceLevel: number;
dedicationLevel: number;
dex: number[];
armyClassExperience: number[];
officerLevel: OfficerLevel;
officerCityID?: CityID;
@@ -59,8 +59,8 @@ export interface IGeneralEntity {
defenceTrained: number;
crewType: number;
crew: number;
armyType: number;
armyCount: number;
trained: number;
morale: number;
+3 -3
View File
@@ -1,4 +1,4 @@
import type { CityID, ColorType, IntYearMonth, NationCmdType, NationID, NationLevel, NationName, NationType, RemainMonth, ReservedTurn, StaffLevel, StrategicCmdType } from "../defs.js";
import type { CityID, ColorType, IntYearMonth, NationCmdType, NationID, NationLevel, NationName, NationType, FractionalRange, RemainMonth, ReservedTurn, StaffLevel, StrategicCmdType } from "../defs.js";
export interface INationEntity{
id: NationID;
@@ -20,9 +20,9 @@ export interface INationEntity{
strategicCmdLimit: Record<StrategicCmdType, IntYearMonth>;
//세율
taxRate: number;
taxRate: FractionalRange;
//지급율
payRate: number;
payRate: FractionalRange;
gold: number;
rice: number;
@@ -19,7 +19,7 @@ export interface IHistory {
cities: Map<CityID, {
nationID: NationID;
name: string;
hasSupply: boolean;
isSupplied: boolean;
level: CityLevel;
state: CityState;
@@ -16,7 +16,7 @@ export interface OldGeneral {
general: IGeneralEntity;
rank: IGeneralRankEntity;
troopName?: string;
squadName?: string;
cityBasic: {
name: string;
level: CityLevel;
+3 -3
View File
@@ -1,7 +1,7 @@
import type { NationID, TroopID } from "../defs.js";
import type { NationID, SquadID } from "../defs.js";
export interface ITroopEntity {
id: TroopID;
export interface ISquadEntity {
id: SquadID;
nationID: NationID;
name: string;
}
+3 -3
View File
@@ -2,19 +2,19 @@ import type { ValuesOf } from '@sammo/util';
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 { ISquadEntity } from './SquadEntity.js';
import type { IGameEnvEntity } from './GameEnvEntity.js';
export type { IGeneralEntity } from './GeneralEntity.js';
export type { ICityEntity } from './CityEntity.js';
export type { ITroopEntity } from './TroopEntity.js';
export type { ISquadEntity } from './SquadEntity.js';
export type { INationEntity } from './NationEntity.js';
export type ValidEntityList = {
'Nation': INationEntity;
'City': ICityEntity;
'Troop': ITroopEntity;
'Squad': ISquadEntity;
'General': IGeneralEntity;
'GameEnv': IGameEnvEntity;
+31 -31
View File
@@ -2,23 +2,23 @@ import { InvalidArgument } from "@sammo/util";
import { City } from "./City.js";
import type { IGeneralEntity } from "./Entity/GeneralEntity.js";
import type { IResourceController } from "./IResourceController.js";
import { DiplomaticPermission, type CityID, type GeneralID, type GeneralName, type NationID, OfficerLevel, type TroopID } from "./defs.js";
import { DiplomaticPermission, type CityID, type GeneralID, type GeneralName, type NationID, OfficerLevel, type SquadID } from "./defs.js";
import { must } from "@sammo/util";
import { Nation } from "./Nation.js";
import { Troop } from "./Troop.js";
import { Squad } from "./Squad.js";
import { LazyEntityUpdater } from "./LazyEntityUpdater.js";
import type { IAction, IActionKey } from "./IAction.js";
import { addSeconds } from "date-fns";
export class General extends LazyEntityUpdater<IGeneralEntity> {
protected readonly _indirectNames: (keyof IGeneralEntity)[] = [
"id", "nationID", "troopID", "nationID", "turntime"
"id", "nationID", "squadID", "nationID", "turntime"
];
protected readonly _entityType = "General";
protected readonly _raw: IGeneralEntity;
protected _city: WeakRef<City>;
protected _troop: WeakRef<Troop> | undefined;
protected _squad: WeakRef<Squad> | undefined;
protected _nation: WeakRef<Nation>;
protected readonly iActionHandlers: Map<IActionKey, IAction>;
@@ -32,8 +32,8 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
this._city = new WeakRef(must(rsc.city(raw.cityID)));
this._nation = new WeakRef(must(rsc.nation(raw.nationID)));
if(raw.troopID){
this._troop = new WeakRef(must(rsc.troop(raw.troopID, raw.nationID)));
if(raw.squadID){
this._squad = new WeakRef(must(rsc.squad(raw.squadID, raw.nationID)));
}
//TODO: iAction 처리해야함
@@ -52,8 +52,8 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
return must(this._city.deref());
}
public get troop(): Troop | undefined {
return this._troop?.deref();
public get squad(): Squad | undefined {
return this._squad?.deref();
}
public get nation(): Nation {
@@ -79,43 +79,43 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
});
}
public quitTroop(){
if(!this._troop){
public quitSquad(){
if(!this._squad){
return;
}
const troop = must(this._troop.deref());
if(troop.leader.id === this._raw.id){
troop.destructTroop(false);
const squad = must(this._squad.deref());
if(squad.leader.id === this._raw.id){
squad.destructSquad(false);
}
else{
troop.members.delete(this._raw.id);
squad.members.delete(this._raw.id);
}
this._troop = undefined;
this._squad = undefined;
this.forceUpdate((raw) => {
raw.troopID = undefined;
raw.squadID = undefined;
});
}
public changeTroop(troop: TroopID | Troop){
this.quitTroop();
public changeSquad(squad: SquadID | Squad){
this.quitSquad();
const troopObj: Troop = (()=>{
if(troop instanceof Troop){
return troop;
const squadObj: Squad = (()=>{
if(squad instanceof Squad){
return squad;
}
const troopObj = this.rsc.troop(troop, this._raw.nationID);
if(!troopObj){
throw new InvalidArgument(`Troop not found: ${troop}`);
const squadObj = this.rsc.squad(squad, this._raw.nationID);
if(!squadObj){
throw new InvalidArgument(`Squad not found: ${squad}`);
}
return troopObj;
return squadObj;
})();
troopObj.members.set(this._raw.id, new WeakRef(this));
this._troop = new WeakRef(troopObj);
squadObj.members.set(this._raw.id, new WeakRef(this));
this._squad = new WeakRef(squadObj);
this.forceUpdate((raw) => {
raw.troopID = troopObj.id;
raw.squadID = squadObj.id;
});
}
@@ -131,7 +131,7 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
return nationObj;
})();
this._nation = new WeakRef(nationObj);
this.quitTroop();
this.quitSquad();
this.forceUpdate((raw) => {
raw.nationID = nationObj.id;
@@ -147,10 +147,10 @@ export class General extends LazyEntityUpdater<IGeneralEntity> {
}
public updateTurntime(){
const turntermSec = this.rsc.gameEnv().raw.turntermSec;
const secondsPerTurn = this.rsc.gameEnv().raw.secondsPerTurn;
this.forceUpdate((raw) => {
raw.turntime = addSeconds(raw.turntime, turntermSec);
raw.turntime = addSeconds(raw.turntime, secondsPerTurn);
});
}
+1 -1
View File
@@ -30,7 +30,7 @@ export const IActionOrder = [
'specialityDomestic',
'specialityWar',
'personlity',
'crewType',
'armyType',
'inheritBuff',
'scenarioEffect',
'horse',
+8 -8
View File
@@ -1,11 +1,11 @@
import type { General } from "./General.js";
import type { City } from "./City.js";
import type { Nation } from "./Nation.js";
import type { CityID, GeneralID, NationID, ReservedTurn, TroopID } from "./defs.js";
import type { CityID, GeneralID, NationID, ReservedTurn, SquadID } from "./defs.js";
import type { GameEnv } from "./GameEnv.js";
import type { IGeneralEntity } from "./Entity/GeneralEntity.js";
import type { Troop } from "./Troop.js";
import type { ITroopEntity } from "./Entity/TroopEntity.js";
import type { Squad } from "./Squad.js";
import type { ISquadEntity } from "./Entity/SquadEntity.js";
import type { LazyEntityUpdater } from "./LazyEntityUpdater.js";
import type { ICityEntity } from "./Entity/CityEntity.js";
import type { INationEntity } from "./Entity/NationEntity.js";
@@ -15,7 +15,7 @@ export interface IResourceController {
nation(id: NationID): Nation | undefined;
city(id: CityID): City | undefined;
troop(id: TroopID, nation: NationID): Troop | undefined;
squad(id: SquadID, nation: NationID): Squad | undefined;
general(id: GeneralID): General | undefined;
peekGeneralTurntimeQueue(): General | undefined;
@@ -27,16 +27,16 @@ export interface IResourceController {
allNations(): Map<NationID, Nation>;
allCities(): Map<CityID, City>;
allCitiesByNation(): Map<NationID, Map<CityID, City>>;
allTroops(): Map<NationID, Map<TroopID, Troop>>;
allSquads(): Map<NationID, Map<SquadID, Squad>>;
allGenerals(): Map<GeneralID, General>;
generalByNation(id: NationID): Map<GeneralID, General>;
generalByCity(id: CityID, nationID?: NationID): Map<GeneralID, General>;
generalByTroop(id: TroopID): Map<GeneralID, General>;
generalBySquad(id: SquadID): Map<GeneralID, General>;
cityByNation(id: NationID): Map<CityID, City>;
troopByNation(id: NationID): Map<TroopID, Troop>;
squadByNation(id: NationID): Map<SquadID, Squad>;
//----Insert, Update, Delete
@@ -49,7 +49,7 @@ export interface IResourceController {
//TODO: reserveInsert와 구현 방식 비교
createGeneral(raw: IGeneralEntity): General;
createNation(raw: INationEntity): Nation;
createTroop(raw: ITroopEntity): Troop;
createSquad(raw: ISquadEntity): Squad;
_getAllChanges(): Record<
@@ -1,25 +1,25 @@
import { must } from "@sammo/util";
import type { General } from "./General.js";
import type { IResourceController } from "./IResourceController.js";
import type { ITroopEntity } from "./Entity/TroopEntity.js";
import type { ISquadEntity } from "./Entity/SquadEntity.js";
import type { GeneralID } from "./defs.js";
import { LazyEntityUpdater } from "./LazyEntityUpdater.js";
export class Troop extends LazyEntityUpdater<ITroopEntity> {
protected readonly _indirectNames: (keyof ITroopEntity)[] = ["id"];
protected readonly _entityType = "Troop";
protected readonly _raw: ITroopEntity;
export class Squad extends LazyEntityUpdater<ISquadEntity> {
protected readonly _indirectNames: (keyof ISquadEntity)[] = ["id"];
protected readonly _entityType = "Squad";
protected readonly _raw: ISquadEntity;
private _leader: WeakRef<General>;
private _members: Map<GeneralID, WeakRef<General>>;
constructor(
raw: ITroopEntity,
raw: ISquadEntity,
protected rsc: IResourceController
){
super();
this._raw = raw;
const members = rsc.generalByTroop(raw.id);
const members = rsc.generalBySquad(raw.id);
const leaderID: GeneralID = raw.id as GeneralID;
this._leader = new WeakRef(must(members.get(leaderID)));
members.delete(leaderID);
@@ -38,13 +38,13 @@ export class Troop extends LazyEntityUpdater<ITroopEntity> {
return this._members;
}
public destructTroop(withLeader = true){
public destructSquad(withLeader = true){
this._members.forEach((member)=>{
const general = must(member.deref());
general.quitTroop();
general.quitSquad();
});
if(withLeader){
this.leader.quitTroop();
this.leader.quitSquad();
}
this.rsc.reserveDelete(this);
@@ -56,6 +56,6 @@ export class Troop extends LazyEntityUpdater<ITroopEntity> {
});
}
//joinTroop은 General에서 처리
//quitTroop은 General에서 처리
//joinSquad은 General에서 처리
//quitSquad은 General에서 처리
}
+4 -4
View File
@@ -8,8 +8,8 @@ export type GeneralName = string & { zz_t?: "GeneralName" };
export type CityID = number & { zz_t?: "CityID" };
export type CityName = string & { zz_t?: "CityName" };
export type TroopID = number & { zz_t?: "TroopID" };
export type TroopName = string & { zz_t?: "TroopName" };
export type SquadID = number & { zz_t?: "SquadID" };
export type SquadName = string & { zz_t?: "SquadName" };
export type NationID = number & { zz_t?: "NationID" };
export type NationName = string & { zz_t?: "NationName" };
@@ -39,7 +39,7 @@ export const enum NpcType {
npc_scenario = 2,
npc_generated = 3,
npc_strategic = 4,
npc_troop_leader = 5,
npc_squad_leader = 5,
npc_unselectable = 6,
npc_invader = 9,
@@ -253,4 +253,4 @@ export interface ReservedTurn {
export type IntYearMonth = number & { zz_t?: "YearMonth" };
export type RemainMonth = number & { zz_t?: "RemainMonth" };
//1.0을 기준으로한 number 타입
export type Ratio = number & { zz_t?: "Ratio" };
export type FractionalRange = number & { zz_t?: "FractionalRange" };
+1 -1
View File
@@ -1,7 +1,7 @@
import type { RPCLists } from "@sammo/server_util";
import type { ActionRequest, ActionResult } from "./GameEngine.js";
import type { MessagePort } from "node:worker_threads";
import type { CityID, GeneralID, NationID, TroopID } from "@sammo/game_logic/src/defs.js";
import type { CityID, GeneralID, NationID, SquadID } from "@sammo/game_logic/src/defs.js";
import type { ActionPackDef } from "@sammo/game_logic";
import type { ActionRequestList, QueueType } from "@sammo/game_logic/src/ActionRequest/index.js";
//Remove Third argument. Use Infer
+10 -10
View File
@@ -1,16 +1,16 @@
import type { IResourceController } from "@sammo/game_logic";
import type { City } from "@sammo/game_logic/src/City.js";
import type { CityID, GeneralID, NationID, TroopID } from "@sammo/game_logic/src/defs.js";
import type { CityID, GeneralID, NationID, SquadID } from "@sammo/game_logic/src/defs.js";
import type { IGeneralEntity } from "@sammo/game_logic/src/Entity/GeneralEntity.js";
import type { ICityEntity, ValidEntityType } from "@sammo/game_logic/src/Entity/index.js";
import type { INationEntity } from "@sammo/game_logic/src/Entity/NationEntity.js";
import type { IReservedTurn } from "@sammo/game_logic/src/Entity/ReservedTurn.js";
import type { ITroopEntity } from "@sammo/game_logic/src/Entity/TroopEntity.js";
import type { ISquadEntity } from "@sammo/game_logic/src/Entity/SquadEntity.js";
import type { GameEnv } from "@sammo/game_logic/src/GameEnv.js";
import { General } from "@sammo/game_logic/src/General.js";
import type { LazyEntityUpdater } from "@sammo/game_logic/src/LazyEntityUpdater.js";
import type { Nation } from "@sammo/game_logic/src/Nation.js";
import type { Troop } from "@sammo/game_logic/src/Troop.js";
import type { Squad } from "@sammo/game_logic/src/Squad.js";
import { insertItemAtArrayLike, NotYetImplemented } from "@sammo/util";
import Denque from "denque";
import type { Mongoose } from "mongoose";
@@ -27,7 +27,7 @@ export class ResourceController implements IResourceController{
private _nation: Map<number, Nation> = new Map();
private _city: Map<number, City> = new Map();
private _troop: Map<number, Troop> = new Map();
private _squad: Map<number, Squad> = new Map();
private _general: Map<number, General> = new Map();
//내부적으로 turntime asc, id asc로 동작하는 PriorityQueue
@@ -38,7 +38,7 @@ export class ResourceController implements IResourceController{
private changes = {
Nation: new Map<number, [ChangeType, Nation]>(),
City: new Map<number, [ChangeType, City]>(),
Troop: new Map<number, [ChangeType, Troop]>(),
Squad: new Map<number, [ChangeType, Squad]>(),
General: new Map<number, [ChangeType, General]>(),
GameEnv: new Map<number, [ChangeType, GameEnv]>(),
@@ -52,7 +52,7 @@ export class ResourceController implements IResourceController{
throw new NotYetImplemented();
}
troop(id: TroopID, nation: NationID): Troop | undefined {
squad(id: SquadID, nation: NationID): Squad | undefined {
throw new NotYetImplemented();
}
@@ -88,7 +88,7 @@ export class ResourceController implements IResourceController{
throw new NotYetImplemented();
}
allTroops(): Map<NationID, Map<TroopID, Troop>> {
allSquads(): Map<NationID, Map<SquadID, Squad>> {
throw new NotYetImplemented();
}
@@ -104,7 +104,7 @@ export class ResourceController implements IResourceController{
throw new NotYetImplemented();
}
generalByTroop(id: TroopID): Map<GeneralID, General> {
generalBySquad(id: SquadID): Map<GeneralID, General> {
throw new NotYetImplemented();
}
@@ -112,7 +112,7 @@ export class ResourceController implements IResourceController{
throw new NotYetImplemented();
}
troopByNation(id: NationID): Map<TroopID, Troop> {
squadByNation(id: NationID): Map<SquadID, Squad> {
throw new NotYetImplemented();
}
@@ -139,7 +139,7 @@ export class ResourceController implements IResourceController{
throw new NotYetImplemented();
}
createTroop(raw: ITroopEntity): Troop {
createSquad(raw: ISquadEntity): Squad {
throw new NotYetImplemented();
}