Skip to content

Commit

Permalink
Snipers working
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrewgdewar committed Feb 1, 2025
1 parent 7b05258 commit 582e2a0
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 43 deletions.
1 change: 0 additions & 1 deletion src/GlobalValues.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/GlobalValues.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/GlobalValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class globalValues {
public static locationsBase: ILocationBase[] = undefined;
public static currentPreset: string = "";
public static forcedPreset: string = "random";
public static zoneHash: Record<number, Record<string, Ixyz>> = {};
public static addedMapZones: Record<number, string[]> = {};
public static indexedMapSpawns: Record<number, ISpawnPointParam[]> = {};
}
25 changes: 24 additions & 1 deletion src/Routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { globalValues } from "../GlobalValues";
import { kebabToTitle } from "../utils";
import PresetWeightingsConfig from "../../config/PresetWeightings.json";
import { Ixyz } from "@spt/models/eft/common/Ixyz";
import { deleteBotSpawn, updateBotSpawn, updatePlayerSpawn } from "../Spawns/updateUtils";
import {
deleteBotSpawn,
updateBotSpawn,
updatePlayerSpawn,
updateSniperSpawn,
} from "../Spawns/updateUtils";

export const setupRoutes = (container: DependencyContainer) => {
const staticRouterModService = container.resolve<StaticRouterModService>(
Expand Down Expand Up @@ -37,6 +42,24 @@ export const setupRoutes = (container: DependencyContainer) => {
"moarAddBotSpawn"
);

staticRouterModService.registerStaticRouter(
`moarAddSniperSpawn`,
[
{
url: "/moar/addSniperSpawn",
action: async (
url: string,
overrideConfig: AddSpawnRequest,
sessionID,
output
) => {
updateSniperSpawn(overrideConfig.map, overrideConfig.position);
return "success";
},
},
],
"moarAddSniperSpawn"
);

staticRouterModService.registerStaticRouter(
`moarDeleteBotSpawn`,
Expand Down
33 changes: 12 additions & 21 deletions src/SpawnZoneChanges/setupSpawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { globalValues } from "../GlobalValues";
import {
AddCustomBotSpawnPoints,
AddCustomPlayerSpawnPoints,
AddCustomSniperSpawnPoints,
cleanClosest,
removeClosestSpawnsFromCustomBots,
} from "../Spawning/spawnZoneUtils";
Expand Down Expand Up @@ -65,34 +66,21 @@ export const setupSpawns = (container: DependencyContainer) => {
}
);

sniperSpawnSpawnPoints.map((val, index) => {
if (!val.BotZoneName) val.BotZoneName === "ZoneSnipeMoar_" + index;
return val;
});

const sniperZones = new Set(
sniperSpawnSpawnPoints
.map((point) => point.BotZoneName)
.filter((item) => !!item)
);

const zoneHash: Record<string, Ixyz> = {};

[...coopSpawns, ...nonBossSpawns, ...bossSpawn].forEach((point) => {
if (!point.BotZoneName || sniperZones.has(point.BotZoneName)) return;
if (!zoneHash[point.BotZoneName]) {
zoneHash[point.BotZoneName] = point.Position;
} else {
zoneHash[point.BotZoneName].x = Math.round(
(zoneHash[point.BotZoneName].x + point.Position.x) / 2
);
zoneHash[point.BotZoneName].z = Math.round(
(zoneHash[point.BotZoneName].z + point.Position.z) / 2
);
}
});

globalValues.zoneHash[mapIndex] = zoneHash;

const limit = mapConfig[configLocations[mapIndex]].spawnMinDistance;

coopSpawns = cleanClosest(
AddCustomPlayerSpawnPoints(coopSpawns, map, configLocations[mapIndex]),
AddCustomPlayerSpawnPoints(coopSpawns, map),
mapIndex,
true
)
Expand Down Expand Up @@ -148,6 +136,11 @@ export const setupSpawns = (container: DependencyContainer) => {
: point;
});

sniperSpawnSpawnPoints = AddCustomSniperSpawnPoints(
sniperSpawnSpawnPoints,
map
);

indexedMapSpawns[mapIndex] = [
...sniperSpawnSpawnPoints,
...bossSpawn,
Expand Down Expand Up @@ -176,7 +169,5 @@ export const setupSpawns = (container: DependencyContainer) => {

advancedConfig.ActivateSpawnCullingOnServerStart &&
updateAllBotSpawns(botSpawnHash);
// console.log(globalValues.zoneHash)
// saveToFile(globalValues.zoneHash, "zoneHash.json");
globalValues.indexedMapSpawns = indexedMapSpawns;
};
53 changes: 37 additions & 16 deletions src/Spawning/spawnZoneUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _config from "../../config/config.json";
import { ISpawnPointParam } from "@spt/models/eft/common/ILocationBase";
import { shuffle } from "./utils";
import mapConfig from "../../config/mapConfig.json";
import { BotSpawns, PlayerSpawns } from "../Spawns";
import { BotSpawns, PlayerSpawns, SniperSpawns } from "../Spawns";
import { Ixyz } from "@spt/models/eft/common/Ixyz";
import { globalValues } from "../GlobalValues";
import { configLocations } from "./constants";
Expand Down Expand Up @@ -202,10 +202,44 @@ export const AddCustomBotSpawnPoints = (
return [...SpawnPointParams, ...botSpawns];
};

export const AddCustomSniperSpawnPoints = (
SpawnPointParams: ISpawnPointParam[],
map: string
) => {
if (!SniperSpawns[map] || !SniperSpawns[map].length) {
_config.debug && console.log("no custom Player spawns for " + map);
return SpawnPointParams;
}

const sniperSpawns = SniperSpawns[map].map((coords: Ixyz, index: number) => ({
BotZoneName: "SniperZone_" + index,
Categories: ["Bot"],
ColliderParams: {
_parent: "SpawnSphereParams",
_props: {
Center: {
x: 0,
y: 0,
z: 0,
},
Radius: 20,
},
},
CorePointId: 1,
DelayToCanSpawnSec: 4,
Id: uuidv4(),
Infiltration: "",
Position: coords,
Rotation: 116.208389,
Sides: ["Savage"],
}));

return [...SpawnPointParams, ...sniperSpawns];
};

export const AddCustomPlayerSpawnPoints = (
SpawnPointParams: ISpawnPointParam[],
map: string,
mapConfigMap: string
map: string
) => {
if (!PlayerSpawns[map] || !PlayerSpawns[map].length) {
_config.debug && console.log("no custom Player spawns for " + map);
Expand Down Expand Up @@ -285,19 +319,6 @@ export const getClosestZone = (
({ BotZoneName }) => !!BotZoneName
)?.BotZoneName || ""
);
// let closest = Infinity;
// let selectedZone = Object.keys(globalValues.zoneHash[mapIndex])?.[0];
// Object.keys(globalValues.zoneHash[mapIndex]).forEach((zone) => {
// const current = globalValues.zoneHash[mapIndex][zone];
// const dist = getDistance(current.x, current.y, current.z, x, y, z);
// if (dist < closest) {
// closest = dist;
// selectedZone = zone;
// }
// });
// // if (mapIndex === 0) console.log(selectedZone)

// return selectedZone || "";
};

export const removeClosestSpawnsFromCustomBots = (
Expand Down
5 changes: 3 additions & 2 deletions src/Spawns/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// context/index.js
export { default as PlayerSpawns } from "./playerSpawns.json"
export { default as BotSpawns } from "./botSpawns.json"
export { default as PlayerSpawns } from "./playerSpawns.json";
export { default as BotSpawns } from "./botSpawns.json";
export { default as SniperSpawns } from "./sniperSpawns.json";
14 changes: 14 additions & 0 deletions src/Spawns/sniperSpawns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"bigmap": [],
"factory4_day": [],
"factory4_night": [],
"interchange": [],
"laboratory": [],
"lighthouse": [],
"rezervbase": [],
"shoreline": [],
"tarkovstreets": [],
"woods": [],
"sandbox": [],
"sandbox_high": []
}
17 changes: 17 additions & 0 deletions src/Spawns/updateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ export const updatePlayerSpawn = (map: string, value: Ixyz) => {
);
};

export const updateSniperSpawn = (map: string, value: Ixyz) => {
map = map.toLowerCase();
updateJsonFile<Ixyz>(
currentDirectory +
"/user/mods/DewardianDev-MOAR/src/Spawns/sniperSpawns.json",
(jsonData) => {
value.y = value.y + 0.5;
if (jsonData[map]) {
jsonData[map].push(value);
} else {
jsonData[map] = [value];
}
},
"Successfully added one player spawn to " + map
);
};

export const updateAllBotSpawns = (values: Record<string, Ixyz[]>) =>
updateJsonFile<Ixyz>(
currentDirectory + "/user/mods/DewardianDev-MOAR/src/Spawns/botSpawns.json",
Expand Down

0 comments on commit 582e2a0

Please sign in to comment.