Skip to content

Commit

Permalink
Separate files for jobs creators.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neloreck committed Aug 15, 2023
1 parent 528dbf8 commit 1fb15b1
Show file tree
Hide file tree
Showing 9 changed files with 820 additions and 722 deletions.
728 changes: 8 additions & 720 deletions src/engine/core/utils/job/job_create_stalker.ts

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions src/engine/core/utils/job/job_create_stalker_animpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { registry } from "@/engine/core/database";
import { SmartTerrain } from "@/engine/core/objects";
import { isJobPatrolInRestrictor } from "@/engine/core/utils/job/job_check";
import { IJobListDescriptor } from "@/engine/core/utils/job/job_types";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { communities } from "@/engine/lib/constants/communities";
import { AnyObject, EJobType, ServerHumanObject, TCount, TIndex, TName } from "@/engine/lib/types";

/**
* todo;
*/
export function createStalkerAnimpointJobs(
smartTerrain: SmartTerrain,
stalkerJobs: IJobListDescriptor
): LuaMultiReturn<[IJobListDescriptor, string, TCount]> {
const smartTerrainName: TName = smartTerrain.name();

let ltx: string = "";
let index: TIndex = 1;

while (registry.smartCovers.get(`${smartTerrainName}_animpoint_${index}`) !== null) {
const smartCoverName: TName = `${smartTerrainName}_animpoint_${index}`;

table.insert(stalkerJobs.jobs, {
priority: logicsConfig.JOBS.STALKER_ANIMPOINT.PRIORITY,
job_id: {
section: `logic@${smartCoverName}`,
job_type: EJobType.SMART_COVER_JOB,
},
_precondition_params: {},
_precondition_function: (
serverObject: ServerHumanObject,
smartTerrain: SmartTerrain,
precondParams: AnyObject
): boolean => {
return serverObject.community() !== communities.zombied;
},
});

let jobLtx: string =
"[logic@" +
smartCoverName +
"]\n" +
"active = animpoint@" +
smartCoverName +
"\n" +
"[animpoint@" +
smartCoverName +
"]\n" +
"meet = meet@generic_animpoint\n" +
"cover_name = " +
smartCoverName +
"\n";

if (smartTerrain.defendRestrictor !== null) {
jobLtx += `out_restr = ${smartTerrain.defendRestrictor}\n`;
}

// todo: Bad path name?
if (
smartTerrain.safeRestrictor !== null &&
isJobPatrolInRestrictor(smartTerrain, smartTerrain.safeRestrictor, null as any)
) {
jobLtx += "invulnerable = {=npc_in_zone(smart.safe_restr)} true\n";
}

if (smartTerrain.smartTerrainActorControl !== null && smartTerrain.smartTerrainActorControl.ignoreZone !== null) {
jobLtx +=
"combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true \n" +
"combat_ignore_keep_when_attacked = true \n";
}

ltx += jobLtx;
index += 1;
}

return $multi(stalkerJobs, ltx, index);
}
93 changes: 93 additions & 0 deletions src/engine/core/utils/job/job_create_stalker_camper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { level, patrol } from "xray16";

import { SmartTerrain } from "@/engine/core/objects";
import { EStalkerState } from "@/engine/core/objects/animation";
import { IWaypointData, parseWaypointData } from "@/engine/core/utils/ini";
import { isAccessibleJob } from "@/engine/core/utils/job/job_check";
import { IJobListDescriptor } from "@/engine/core/utils/job/job_types";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { AnyObject, EJobType, Patrol, ServerHumanObject, TCount, TIndex, TName } from "@/engine/lib/types";

/**
* todo;
*/
export function createStalkerCamperJobs(
smartTerrain: SmartTerrain
): LuaMultiReturn<[IJobListDescriptor, string, TCount]> {
const smartTerrainName: TName = smartTerrain.name();
const stalkerDefCamper: IJobListDescriptor = {
priority: logicsConfig.JOBS.STALKER_CAMPER.PRIORITY,
jobs: new LuaTable(),
};

let ltx: string = "";
let index: TIndex = 1;

while (level.patrol_path_exists(smartTerrainName + "_camper_" + index + "_walk")) {
const wayName: TName = smartTerrainName + "_camper_" + index + "_walk";
const ptr: Patrol = new patrol(wayName);
const wpProp: IWaypointData = parseWaypointData(wayName, ptr.flags(0), ptr.name(0));
let state: TName = EStalkerState.HIDE;
let radius = 0;

if (wpProp.state !== null) {
if (wpProp.state === "stand") {
state = EStalkerState.THREAT;
}
}

if (wpProp.radius !== null) {
radius = wpProp.radius as number;
}

table.insert(stalkerDefCamper.jobs, {
priority: logicsConfig.JOBS.STALKER_CAMPER.PRIORITY,
job_id: {
section: `logic@${wayName}`,
job_type: EJobType.PATH_JOB,
},
_precondition_params: { way_name: wayName },
_precondition_function: (serverObject: ServerHumanObject, smart: SmartTerrain, precond_params: AnyObject) => {
return isAccessibleJob(serverObject, precond_params.way_name);
},
});

let jobLtx: string =
"[logic@" +
wayName +
"]\n" +
"active = camper@" +
wayName +
"\n" +
"[camper@" +
wayName +
"]\n" +
"meet = meet@generic_lager\n" +
"radius = " +
tostring(radius) +
"\n" +
"path_walk = camper_" +
index +
"_walk\n" +
"def_state_moving = rush\n" +
"def_state_campering =" +
state +
"\n" +
"def_state_campering_fire =" +
state +
"_fire\n";

if (level.patrol_path_exists(`${smartTerrainName}_camper_${index}_look`)) {
jobLtx += `path_look = camper_${index}_look\n`;
}

if (smartTerrain.defendRestrictor !== null) {
jobLtx += `out_restr = ${smartTerrain.defendRestrictor}\n`;
}

ltx += jobLtx;
index += 1;
}

return $multi(stalkerDefCamper, ltx, index);
}
129 changes: 129 additions & 0 deletions src/engine/core/utils/job/job_create_stalker_collector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { level } from "xray16";

import { IRegistryObjectState, registry } from "@/engine/core/database";
import { SmartTerrain } from "@/engine/core/objects";
import { isJobPatrolInRestrictor } from "@/engine/core/utils/job/job_check";
import { IJobListDescriptor } from "@/engine/core/utils/job/job_types";
import { logicsConfig } from "@/engine/lib/configs/LogicsConfig";
import { communities } from "@/engine/lib/constants/communities";
import {
AnyObject,
ClientObject,
EJobType,
Optional,
ServerHumanObject,
TCount,
TIndex,
TName,
} from "@/engine/lib/types";

/**
* todo;
*/
export function createStalkerCollectorJobs(
smartTerrain: SmartTerrain
): LuaMultiReturn<[IJobListDescriptor, string, TCount]> {
const smartTerrainName: TName = smartTerrain.name();
const collectorJobs: IJobListDescriptor = {
priority: logicsConfig.JOBS.STALKER_COLLECTOR.PRIORITY,
jobs: new LuaTable(),
};

let index: TIndex = 1;
let ltx: string = "";

// todo: While and single insert?
while (level.patrol_path_exists(`${smartTerrainName}_collector_${index}_walk`)) {
const wayName: TName = `${smartTerrainName}_collector_${index}_walk`;

table.insert(collectorJobs.jobs, {
priority: logicsConfig.JOBS.STALKER_COLLECTOR.PRIORITY,
job_id: {
section: `logic@${wayName}`,
job_type: EJobType.PATH_JOB,
},
_precondition_params: {},
_precondition_function: (
serverObject: ServerHumanObject,
smart: SmartTerrain,
precondParams: AnyObject
): boolean => {
if (serverObject.community() === communities.zombied) {
return false;
}

const state: Optional<IRegistryObjectState> = registry.objects.get(serverObject.id);

if (state === null) {
return false;
}

const object: Optional<ClientObject> = state.object!;

if (object === null) {
return false;
}

const detectors = ["detector_simple", "detector_advanced", "detector_elite", "detector_scientific"];

for (const [k, v] of detectors) {
const obj = object.object(v);

if (obj !== null) {
return true;
}
}

return false;
},
});

let jobLtx: string =
"[logic@" +
wayName +
"]\n" +
"active = walker@" +
wayName +
"\n" +
"[walker@" +
wayName +
"]\n" +
"sound_idle = state\n" +
"meet = meet@generic_lager\n" +
"path_walk = collector_" +
index +
"_walk\n" +
"def_state_standing = guard\n" +
"def_state_moving = patrol\n";

if (level.patrol_path_exists(`${smartTerrainName}_collector_${index}_look`)) {
jobLtx += `path_look = collector_${index}_look\n`;
}

if (
smartTerrain.safeRestrictor !== null &&
isJobPatrolInRestrictor(smartTerrain, smartTerrain.safeRestrictor, wayName)
) {
jobLtx += "invulnerable = {=npc_in_zone(smart.safe_restr)} true\n";
}

if (smartTerrain.defendRestrictor !== null) {
jobLtx += `out_restr = ${smartTerrain.defendRestrictor}\n`;
}

if (
smartTerrain.smartTerrainActorControl !== null &&
smartTerrain.smartTerrainActorControl.ignoreZone !== null &&
isJobPatrolInRestrictor(smartTerrain, smartTerrain.smartTerrainActorControl.ignoreZone, wayName)
) {
jobLtx +=
"combat_ignore_cond = {=npc_in_zone(smart.base_on_actor_control.ignore_zone)} true \n" +
"combat_ignore_keep_when_attacked = true \n";
}

ltx += jobLtx;
index += 1;
}

return $multi(collectorJobs, ltx, index);
}
Loading

0 comments on commit 1fb15b1

Please sign in to comment.