From 6a92b9ed101347a36a7d4e5353184eae347ea9f9 Mon Sep 17 00:00:00 2001 From: Rackar <27681135@qq.com> Date: Thu, 1 Aug 2024 15:37:58 +0800 Subject: [PATCH 1/3] Add DLC races units. --- scripts/constants.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/scripts/constants.ts b/scripts/constants.ts index bcb8ef2..506ed25 100644 --- a/scripts/constants.ts +++ b/scripts/constants.ts @@ -12,6 +12,13 @@ export const pbgs = { rus: "unit_spearman_4_rus", sultanate: "unit_spearman_4_sul", abbasid: "unit_spearman_4_abb", + + abbasid_ha_01: "unit_spearman_4_abb_ha_01", + chinese_ha_01: "unit_spearman_4_chi_ha_01", + french_ha_01: "unit_spearman_4_fre_ha_01", + hre_ha_01: "unit_spearman_4_hre_ha_01", + japanese: "unit_spearman_4_jpn", + byzantine: "unit_spearman_4_byz", }, manAtArms: { english: "unit_manatarms_4_eng", @@ -22,6 +29,13 @@ export const pbgs = { rus: "unit_manatarms_4_rus", sultanate: "unit_manatarms_4_sul", abbasid: "unit_manatarms_4_abb", + + abbasid_ha_01: "unit_manatarms_4_abb_ha_01", + chinese_ha_01: "unit_manatarms_4_chi_ha_01", + french_ha_01: "unit_manatarms_4_fre_ha_01", + hre_ha_01: "unit_manatarms_4_hre_ha_01", + japanese: "unit_manatarms_4_jpn", + byzantine: "unit_manatarms_4_byz", }, horseMan: { english: "unit_horseman_4_eng", @@ -32,6 +46,13 @@ export const pbgs = { rus: "unit_horseman_4_rus", sultanate: "unit_horseman_4_sul", abbasid: "unit_horseman_4_abb", + + abbasid_ha_01: "unit_horseman_4_abb_ha_01", + chinese_ha_01: "unit_horseman_4_chi_ha_01", + french_ha_01: "unit_horseman_4_fre_ha_01", + hre_ha_01: "unit_horseman_4_hre_ha_01", + japanese: "unit_horseman_4_jpn", + byzantine: "unit_horseman_4_byz", }, mangonel: { english: "unit_mangonel_3_eng", @@ -42,10 +63,17 @@ export const pbgs = { rus: "unit_mangonel_3_rus", sultanate: "unit_mangonel_3_sul", abbasid: "unit_mangonel_3_abb", + + abbasid_ha_01: "unit_mangonel_3_abb_ha_01", + chinese_ha_01: "unit_mangonel_3_chi_ha_01", + french_ha_01: "unit_mangonel_3_fre_ha_01", + hre_ha_01: "unit_mangonel_3_hre_ha_01", + japanese: "unit_mangonel_3_jpn", + byzantine: "unit_mangonel_3_byz", }, } export const sfxs = { roundFailure: "mus_stinger_landmark_objective_complete_fail", roundVictory: "Conquest_enemy_eliminated", -} \ No newline at end of file +} From 42a8894a5aa08eee1805bdd2454862d11f8994e6 Mon Sep 17 00:00:00 2001 From: Rackar <27681135@qq.com> Date: Thu, 1 Aug 2024 20:10:30 +0800 Subject: [PATCH 2/3] fix bug. Squad_EntityAt not exists, change to Squad_GetFirstEntity --- .gitignore | 1 + scripts/core/util.ts | 47 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index e6e3f5d..3a97b34 100644 --- a/.gitignore +++ b/.gitignore @@ -137,3 +137,4 @@ assets/scenarios/multiplayer/100-rounds/100-rounds.scar .aoe4/ cache/ archives/ +prettier.config.js \ No newline at end of file diff --git a/scripts/core/util.ts b/scripts/core/util.ts index 37cf116..d935700 100644 --- a/scripts/core/util.ts +++ b/scripts/core/util.ts @@ -4,7 +4,10 @@ import { Vector3 } from "./vector3" import { PRng } from "./prng" export function getSquadGroupEntity(squadGroup: SGroupID): EntityID { - return Squad_EntityAt(SGroup_GetSpawnedSquadAt(squadGroup, 1), 0) + const sq = SGroup_GetSpawnedSquadAt(squadGroup, 1) + // const et = Squad_EntityAt(sg, 0) + const entity = Squad_GetFirstEntity(sq) + return entity } export type SpawnEntityOptions = { @@ -14,13 +17,35 @@ export type SpawnEntityOptions = { } let nextEntityId = 0 -export function spawnSquadGroup(playerOwner: Player, position: Position, pbg: string, options?: SpawnEntityOptions): SGroupID { +/** + * Spawn a SquadGroup + * @param playerOwner + * @param position + * @param pbg should be sbp + * @param options + * @returns SGROUPID + */ +export function spawnSquadGroup( + playerOwner: Player, + position: Position, + pbg: string, + options?: SpawnEntityOptions +): SGroupID { + // @bug 报错 let dummySquadBlueprint: SquadBlueprint = BP_GetSquadBlueprint(pbg) const squadGroup = SGroup_CreateIfNotFound(`sg_${nextEntityId++}`) - UnitEntry_DeploySquads(playerOwner.id, squadGroup, [{ - sbp: dummySquadBlueprint, numSquads: 1 - }], position) + UnitEntry_DeploySquads( + playerOwner.id, + squadGroup, + [ + { + sbp: dummySquadBlueprint, + num_squads: 1, + }, + ], + position + ) if (options?.unselectable) { SGroup_SetSelectable(squadGroup, false) @@ -36,11 +61,15 @@ export function spawnSquadGroup(playerOwner: Player, position: Position, pbg: st SGroup_SetInvulnerable(squadGroup, true) } - return squadGroup } -export function spawnEntity(playerOwner: Player, position: Position, pbg: string, options?: SpawnEntityOptions): EntityID { +export function spawnEntity( + playerOwner: Player, + position: Position, + pbg: string, + options?: SpawnEntityOptions +): EntityID { return getSquadGroupEntity(spawnSquadGroup(playerOwner, position, pbg, options)) } @@ -102,7 +131,7 @@ export function copyPositionToVector3(vector: Vector3, position: Position) { * @returns Random integer between min (inclusive) and max (inclusive). */ export function randomInt(prng: PRng, min: number, max: number) { - const range = (max - min) + 1 + const range = max - min + 1 return (prng.get_random_32() % range) + min } @@ -112,4 +141,4 @@ export function showNotification(message: string) { export function isEntityValidAndAlive(entityId: EntityID) { return Entity_IsValid(entityId.EntityID) && Entity_IsAlive(entityId) -} \ No newline at end of file +} From b37c5d7e4a063ced4e3c19b49064cf8b11e5c452 Mon Sep 17 00:00:00 2001 From: Rackar <27681135@qq.com> Date: Thu, 1 Aug 2024 22:37:50 +0800 Subject: [PATCH 3/3] add type --- scripts/types.d.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 scripts/types.d.ts diff --git a/scripts/types.d.ts b/scripts/types.d.ts new file mode 100644 index 0000000..9ba8cc2 --- /dev/null +++ b/scripts/types.d.ts @@ -0,0 +1,4 @@ +/** + * ZERO-BASED get 0 of entities out of squads + */ +declare function Squad_GetFirstEntity(squad: SquadID): any; \ No newline at end of file