From 7be735435a82e6e30e453d08043cadb599c37242 Mon Sep 17 00:00:00 2001 From: andrewgdewar Date: Wed, 29 Jan 2025 17:29:59 -0700 Subject: [PATCH] Add spawn culler, update player spawns, update customs, fix floating point bug, use CorePointId to set first to last spawning --- src/SpawnZoneChanges/setupSpawn.ts | 15 ++++--- src/Spawning/buildPmcs.ts | 1 - src/Spawning/buildScavMarksmanWaves.ts | 7 +-- src/Spawning/spawnZoneUtils.ts | 6 ++- src/Spawning/updateSpawnLocations.ts | 60 ++++++++++++++------------ 5 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/SpawnZoneChanges/setupSpawn.ts b/src/SpawnZoneChanges/setupSpawn.ts index d49b3e2..714cc54 100644 --- a/src/SpawnZoneChanges/setupSpawn.ts +++ b/src/SpawnZoneChanges/setupSpawn.ts @@ -9,6 +9,7 @@ import { AddCustomBotSpawnPoints, AddCustomPlayerSpawnPoints, cleanClosest, + getClosestZone, removeClosestSpawnsFromCustomBots, } from "../Spawning/spawnZoneUtils"; import { shuffle } from "../Spawning/utils"; @@ -121,16 +122,17 @@ export const setupSpawns = (container: DependencyContainer) => { if (advancedConfig.ActivateSpawnCullingOnServerStart) { botSpawnHash[map] = removeClosestSpawnsFromCustomBots(nonBossSpawns, map, configLocations[mapIndex]) || [] } + nonBossSpawns = cleanClosest( AddCustomBotSpawnPoints(nonBossSpawns, map, mapIndex), - configLocations[mapIndex] - ).map((point, index) => + configLocations[mapIndex], + ).map((point) => !!point.Categories.length ? { ...point, BotZoneName: point?.BotZoneName ? point.BotZoneName - : "open_" + index, + : getClosestZone(mapIndex, point.Position.x, point.Position.y, point.Position.z), Categories: ["Bot"], // Infiltration: "", Sides: ["Savage"], @@ -139,8 +141,9 @@ export const setupSpawns = (container: DependencyContainer) => { : point ); - // if (map === "sandbox") { - // console.log(nonBossSpawns.map(({ BotZoneName }) => BotZoneName)); + // if (map === "factory4_day") { + // zoneHash[mapIndex], + // console.log(new Set(nonBossSpawns.map(({ BotZoneName }) => BotZoneName))); // } indexedMapSpawns[mapIndex] = [ @@ -171,6 +174,6 @@ export const setupSpawns = (container: DependencyContainer) => { }); advancedConfig.ActivateSpawnCullingOnServerStart && updateAllBotSpawns(botSpawnHash) - saveToFile(globalValues.zoneHash, "zoneHash.json"); + // saveToFile(globalValues.zoneHash, "zoneHash.json"); globalValues.indexedMapSpawns = indexedMapSpawns; }; diff --git a/src/Spawning/buildPmcs.ts b/src/Spawning/buildPmcs.ts index d6c4611..f08096e 100644 --- a/src/Spawning/buildPmcs.ts +++ b/src/Spawning/buildPmcs.ts @@ -37,7 +37,6 @@ export default function buildPmcs( let pmcZones = getSortedSpawnPointList( locationList[index].base.SpawnPointParams.filter( ({ Categories, DelayToCanSpawnSec, BotZoneName }, index) => - BotZoneName && index % 3 === 0 && !Categories.includes("Boss") && Categories[0] === "Bot" && diff --git a/src/Spawning/buildScavMarksmanWaves.ts b/src/Spawning/buildScavMarksmanWaves.ts index 600ee2d..4865197 100644 --- a/src/Spawning/buildScavMarksmanWaves.ts +++ b/src/Spawning/buildScavMarksmanWaves.ts @@ -98,10 +98,10 @@ export default function buildScavMarksmanWaves( // ); const { - Position: { x, z }, + Position: { x, y, z }, } = locationList[index].base.SpawnPointParams[ - locationList[index].base.SpawnPointParams.length - 1 + locationList[index].base.SpawnPointParams.length - 1 ]; let sniperLocations = getSortedSpawnPointList( @@ -113,6 +113,7 @@ export default function buildScavMarksmanWaves( DelayToCanSpawnSec > 40) ), x, + y, z ).map(({ BotZoneName }) => BotZoneName); @@ -129,7 +130,6 @@ export default function buildScavMarksmanWaves( let scavZones = getSortedSpawnPointList( locationList[index].base.SpawnPointParams.filter( ({ Categories, DelayToCanSpawnSec, BotZoneName }, index) => - BotZoneName && !Categories.includes("Boss") && index % 3 !== 0 && Categories[0] === "Bot" && @@ -139,6 +139,7 @@ export default function buildScavMarksmanWaves( ) ), x, + y, z, 0.1 ).map(({ BotZoneName }) => BotZoneName); diff --git a/src/Spawning/spawnZoneUtils.ts b/src/Spawning/spawnZoneUtils.ts index 2e66d0a..d4b86fd 100644 --- a/src/Spawning/spawnZoneUtils.ts +++ b/src/Spawning/spawnZoneUtils.ts @@ -134,7 +134,7 @@ function uuidv4() { export const AddCustomBotSpawnPoints = ( SpawnPointParams: ISpawnPointParam[], map: string, - mapIndex: number + mapIndex: number, ) => { const mapConfigMap = configLocations[mapIndex]; @@ -148,7 +148,7 @@ export const AddCustomBotSpawnPoints = ( const botSpawns = BotSpawns[map].map((coords: Ixyz, index: number) => ({ BotZoneName: - getClosestZone(mapIndex, coords.x, coords.y, coords.z) || "Added_" + index, + getClosestZone(mapIndex, coords.x, coords.y, coords.z) || "", Categories: ["Bot"], ColliderParams: { _parent: "SpawnSphereParams", @@ -244,6 +244,7 @@ export const AddCustomPlayerSpawnPoints = ( export const getClosestZone = (mapIndex: number, x: number, y: number, z: number) => { if (!globalValues.zoneHash[mapIndex]) return ""; + let closest = Infinity; let selectedZone = Object.keys(globalValues.zoneHash[mapIndex])?.[0]; Object.keys(globalValues.zoneHash[mapIndex]).forEach((zone) => { @@ -254,6 +255,7 @@ export const getClosestZone = (mapIndex: number, x: number, y: number, z: number selectedZone = zone; } }); + // if (mapIndex === 0) console.log(selectedZone) return selectedZone || ""; }; diff --git a/src/Spawning/updateSpawnLocations.ts b/src/Spawning/updateSpawnLocations.ts index 7409f91..cb1c8ba 100644 --- a/src/Spawning/updateSpawnLocations.ts +++ b/src/Spawning/updateSpawnLocations.ts @@ -4,16 +4,16 @@ import _config from "../../config/config.json"; import { getRandomInArray, shuffle } from "./utils"; import { ISpawnPointParam } from "@spt/models/eft/common/ILocationBase"; import { globalValues } from "../GlobalValues"; -import { getClosestZone } from "./spawnZoneUtils"; +import getSortedSpawnPointList from "./spawnZoneUtils"; export default function updateSpawnLocations(locationList: ILocation[]) { for (let index = 0; index < locationList.length; index++) { const map = configLocations[index]; const playerSpawns: ISpawnPointParam[] = []; - const addedSpawns: ISpawnPointParam[] = []; + // const addedSpawns: ISpawnPointParam[] = []; const mapSpawns = globalValues.indexedMapSpawns[index]; - locationList[index].base.SpawnPointParams = [...mapSpawns].filter( + const filteredSpawns = [...mapSpawns].filter( (point) => { if (point?.Categories[0] === "Player") { playerSpawns.push(point); @@ -22,37 +22,41 @@ export default function updateSpawnLocations(locationList: ILocation[]) { return true; } - ); + ) - // console.log(playerSpawns.length); - // if (point.BotZoneName.includes("Added_")) { - // addedSpawns.push(point); - // return false; - // } const playerSpawn: ISpawnPointParam = getRandomInArray(playerSpawns); + const { x, y, z } = playerSpawn.Position + + const hash = {} + + const sortedSpawnPointList = getSortedSpawnPointList(filteredSpawns, x, y, z).map((point, pIndex) => { + const { BotZoneName, Categories, DelayToCanSpawnSec } = point + if (BotZoneName && !Categories.includes("Boss") && + Categories[0] === "Bot" && + !( + BotZoneName?.toLowerCase().includes("snipe") || + DelayToCanSpawnSec > 40 + )) { + + if (!hash[BotZoneName]) hash[BotZoneName] = 1 + + hash[BotZoneName] = pIndex % 2 === 0 ? hash[BotZoneName] + 1 : hash[BotZoneName] + + point.CorePointId = hash[BotZoneName] + + return point + } else return point + }) + + + // console.log(map, hash) + + locationList[index].base.SpawnPointParams = sortedSpawnPointList + playerSpawn.ColliderParams._props.Radius = 1; - // console.log(map, playerSpawn.Position); - - // const spawnsToAdd = playerSpawns - // .filter((point) => point.Id !== playerSpawn.Id) - // .map((point, pindex) => ({ - // ...point, - // BotZoneName: point.BotZoneName.includes("Added_") - // ? getClosestZone(pindex, point.Position.x, point.Position.y, point.Position.z) - // : point.BotZoneName, - // Categories: ["Bot"], - // // Infiltration: "", - // Sides: ["Savage"], - // CorePointId: 1, - // })) - // .filter(({ BotZoneName }) => !!BotZoneName); - - // console.log(spawnsToAdd.map(({ BotZoneName }) => BotZoneName)); - - // locationList[index].base.SpawnPointParams.push(...spawnsToAdd); const listToAddToOpenZones = shuffle([ ...new Set(