-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
295 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/engine/core/utils/job/__test__/job_create_stalker_collector.default.ltx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[logic@test_smart_collector_1_walk] | ||
active = walker@test_smart_collector_1_walk | ||
[walker@test_smart_collector_1_walk] | ||
sound_idle = state | ||
meet = meet@generic_lager | ||
path_walk = collector_1_walk | ||
def_state_standing = guard | ||
def_state_moving = patrol | ||
path_look = collector_1_look |
12 changes: 12 additions & 0 deletions
12
src/engine/core/utils/job/__test__/job_create_stalker_collector.ignore.ltx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[logic@test_smart_collector_1_walk] | ||
active = walker@test_smart_collector_1_walk | ||
[walker@test_smart_collector_1_walk] | ||
sound_idle = state | ||
meet = meet@generic_lager | ||
path_walk = collector_1_walk | ||
def_state_standing = guard | ||
def_state_moving = patrol | ||
path_look = collector_1_look | ||
out_restr = test_defend_restrictor | ||
combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true | ||
combat_ignore_keep_when_attacked = true |
13 changes: 13 additions & 0 deletions
13
src/engine/core/utils/job/__test__/job_create_stalker_collector.invulnerable.ltx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[logic@test_smart_collector_1_walk] | ||
active = walker@test_smart_collector_1_walk | ||
[walker@test_smart_collector_1_walk] | ||
sound_idle = state | ||
meet = meet@generic_lager | ||
path_walk = collector_1_walk | ||
def_state_standing = guard | ||
def_state_moving = patrol | ||
path_look = collector_1_look | ||
invulnerable = {=npc_in_zone(smart.safe_restr)} true | ||
out_restr = test_defend_restrictor | ||
combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true | ||
combat_ignore_keep_when_attacked = true |
10 changes: 10 additions & 0 deletions
10
src/engine/core/utils/job/__test__/job_create_stalker_collector.restrictor.ltx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[logic@test_smart_collector_1_walk] | ||
active = walker@test_smart_collector_1_walk | ||
[walker@test_smart_collector_1_walk] | ||
sound_idle = state | ||
meet = meet@generic_lager | ||
path_walk = collector_1_walk | ||
def_state_standing = guard | ||
def_state_moving = patrol | ||
path_look = collector_1_look | ||
out_restr = test_defend_restrictor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
src/engine/core/utils/job/job_create_stalker_collector.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import * as path from "path"; | ||
|
||
import { describe, expect, it, jest } from "@jest/globals"; | ||
|
||
import { IRegistryObjectState, registerObject, registerZone, registry } from "@/engine/core/database"; | ||
import { SmartTerrain, SmartTerrainControl } from "@/engine/core/objects"; | ||
import { createStalkerCollectorJobs } from "@/engine/core/utils/job/job_create_stalker_collector"; | ||
import { ServerHumanObject } from "@/engine/lib/types"; | ||
import { readInGameTestLtx } from "@/fixtures/engine"; | ||
import { mockClientGameObject, mockServerAlifeHumanStalker } from "@/fixtures/xray"; | ||
|
||
describe("jobs_general should correctly generate stalker collector jobs", () => { | ||
it("should correctly generate default camper jobs with no collector patrols", async () => { | ||
const smartTerrain: SmartTerrain = new SmartTerrain("test_smart"); | ||
|
||
smartTerrain.ini = smartTerrain.spawn_ini(); | ||
|
||
jest.spyOn(smartTerrain, "name").mockImplementation(() => "test_smart_without_collector"); | ||
|
||
const [jobsList, ltx] = createStalkerCollectorJobs(smartTerrain); | ||
|
||
expect(ltx).toBe(""); | ||
expect(jobsList).toEqualLuaTables({ priority: 25, jobs: $fromArray([]) }); | ||
}); | ||
|
||
it("should correctly generate default camper jobs with test smart", async () => { | ||
const jobsLtx: string = await readInGameTestLtx( | ||
path.resolve(__dirname, "__test__", "job_create_stalker_collector.default.ltx") | ||
); | ||
|
||
const smartTerrain: SmartTerrain = new SmartTerrain("test_smart"); | ||
|
||
smartTerrain.ini = smartTerrain.spawn_ini(); | ||
|
||
jest.spyOn(smartTerrain, "name").mockImplementation(() => "test_smart"); | ||
|
||
const [jobsList, ltx, count] = createStalkerCollectorJobs(smartTerrain); | ||
|
||
expect(count).toBe(2); | ||
expect(ltx).toBe(jobsLtx); | ||
expect(jobsList).toEqualLuaTables({ | ||
priority: 25, | ||
jobs: $fromArray([ | ||
{ | ||
_precondition_function: expect.any(Function), | ||
_precondition_params: {}, | ||
job_id: { | ||
job_type: "path_job", | ||
section: "logic@test_smart_collector_1_walk", | ||
}, | ||
priority: 25, | ||
}, | ||
]), | ||
}); | ||
}); | ||
|
||
it("should correctly generate default camper jobs with restrictor", async () => { | ||
const jobsLtx: string = await readInGameTestLtx( | ||
path.resolve(__dirname, "__test__", "job_create_stalker_collector.restrictor.ltx") | ||
); | ||
|
||
const smartTerrain: SmartTerrain = new SmartTerrain("test_smart"); | ||
|
||
smartTerrain.ini = smartTerrain.spawn_ini(); | ||
smartTerrain.defendRestrictor = "test_defend_restrictor"; | ||
|
||
jest.spyOn(smartTerrain, "name").mockImplementation(() => "test_smart"); | ||
|
||
const [jobsList, ltx, count] = createStalkerCollectorJobs(smartTerrain); | ||
|
||
expect(count).toBe(2); | ||
expect(ltx).toBe(jobsLtx); | ||
expect(jobsList).toEqualLuaTables({ | ||
priority: 25, | ||
jobs: $fromArray([ | ||
{ | ||
_precondition_function: expect.any(Function), | ||
_precondition_params: {}, | ||
job_id: { | ||
job_type: "path_job", | ||
section: "logic@test_smart_collector_1_walk", | ||
}, | ||
priority: 25, | ||
}, | ||
]), | ||
}); | ||
}); | ||
|
||
it("should correctly generate default camper jobs with ignore restrictor", async () => { | ||
const jobsLtx: string = await readInGameTestLtx( | ||
path.resolve(__dirname, "__test__", "job_create_stalker_collector.ignore.ltx") | ||
); | ||
|
||
const smartTerrain: SmartTerrain = new SmartTerrain("test_smart"); | ||
|
||
smartTerrain.ini = smartTerrain.spawn_ini(); | ||
smartTerrain.defendRestrictor = "test_defend_restrictor"; | ||
smartTerrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl; | ||
|
||
registerZone(mockClientGameObject({ name: () => "some_restrictor", inside: () => true })); | ||
|
||
jest.spyOn(smartTerrain, "name").mockImplementation(() => "test_smart"); | ||
|
||
const [jobsList, ltx, count] = createStalkerCollectorJobs(smartTerrain); | ||
|
||
expect(count).toBe(2); | ||
expect(ltx).toBe(jobsLtx); | ||
expect(jobsList).toEqualLuaTables({ | ||
priority: 25, | ||
jobs: $fromArray([ | ||
{ | ||
_precondition_function: expect.any(Function), | ||
_precondition_params: {}, | ||
job_id: { | ||
job_type: "path_job", | ||
section: "logic@test_smart_collector_1_walk", | ||
}, | ||
priority: 25, | ||
}, | ||
]), | ||
}); | ||
}); | ||
|
||
it("should correctly generate default camper jobs with invulnerable state", async () => { | ||
const jobsLtx: string = await readInGameTestLtx( | ||
path.resolve(__dirname, "__test__", "job_create_stalker_collector.invulnerable.ltx") | ||
); | ||
|
||
const smartTerrain: SmartTerrain = new SmartTerrain("test_smart"); | ||
|
||
smartTerrain.ini = smartTerrain.spawn_ini(); | ||
smartTerrain.defendRestrictor = "test_defend_restrictor"; | ||
smartTerrain.smartTerrainActorControl = { ignoreZone: "some_restrictor" } as SmartTerrainControl; | ||
smartTerrain.safeRestrictor = "safe_restrictor_test"; | ||
|
||
registerZone(mockClientGameObject({ name: () => "safe_restrictor_test", inside: () => true })); | ||
|
||
jest.spyOn(smartTerrain, "name").mockImplementation(() => "test_smart"); | ||
|
||
const [jobsList, ltx, count] = createStalkerCollectorJobs(smartTerrain); | ||
|
||
expect(count).toBe(2); | ||
expect(ltx).toBe(jobsLtx); | ||
expect(jobsList).toEqualLuaTables({ | ||
priority: 25, | ||
jobs: $fromArray([ | ||
{ | ||
_precondition_function: expect.any(Function), | ||
_precondition_params: {}, | ||
job_id: { | ||
job_type: "path_job", | ||
section: "logic@test_smart_collector_1_walk", | ||
}, | ||
priority: 25, | ||
}, | ||
]), | ||
}); | ||
}); | ||
|
||
it("should correctly check camper jobs preconditions", async () => { | ||
const smartTerrain: SmartTerrain = new SmartTerrain("test_smart"); | ||
const stalker: ServerHumanObject = mockServerAlifeHumanStalker(); | ||
|
||
smartTerrain.ini = smartTerrain.spawn_ini(); | ||
|
||
jest.spyOn(smartTerrain, "name").mockImplementation(() => "test_smart"); | ||
|
||
const [jobsList] = createStalkerCollectorJobs(smartTerrain); | ||
const precondition = jobsList.jobs.get(1)._precondition_function; | ||
|
||
expect(precondition?.(stalker, smartTerrain, {}, {})).toBe(false); | ||
|
||
registerObject( | ||
mockClientGameObject({ | ||
idOverride: stalker.id, | ||
object: (section: string) => { | ||
return section === "detector_elite" ? mockClientGameObject() : null; | ||
}, | ||
}) | ||
); | ||
expect(precondition?.(stalker, smartTerrain, {}, {})).toBe(true); | ||
|
||
jest.spyOn(stalker, "community").mockImplementation(() => "zombied"); | ||
expect(precondition?.(stalker, smartTerrain, {}, {})).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.