private void SetBoundarySizeToCustom(EncounterLayerData encounterLayerData, float size) { EncounterBoundaryChunkGameLogic encounterBoundaryChunk = encounterLayerData.GetComponentInChildren <EncounterBoundaryChunkGameLogic>(); if (encounterBoundaryChunk != null) { Main.Logger.Log($"[MaximiseBoundarySize.SetBoundarySizeToCustom] Increasing Boundary Size by '{size * 100}%'"); List <RectHolder> encounterBoundaryRectList = new List <RectHolder>(); EncounterObjectGameLogic[] childEncounterObjectGameLogicList = encounterBoundaryChunk.childEncounterObjectGameLogicList; float mapBorderSize = 50f; float mapSize = 2048f; int mapSide = (int)(mapSize - mapBorderSize); for (int i = 0; i < childEncounterObjectGameLogicList.Length; i++) { EncounterBoundaryRectGameLogic encounterBoundaryRectGameLogic = childEncounterObjectGameLogicList[i] as EncounterBoundaryRectGameLogic; int sizeFactor = (int)(encounterBoundaryRectGameLogic.width * (1f + size)); int movementFactor = (int)(encounterBoundaryRectGameLogic.width * size); if (sizeFactor > mapSide) { Main.Logger.Log($"[MaximiseBoundarySize.SetBoundarySizeToCustom] Custom size would be greater than map size. Using map size.'"); MatchBoundarySizeToMapSize(encounterLayerData); } else { if (encounterBoundaryRectGameLogic != null) { Vector3 position = encounterBoundaryRectGameLogic.transform.position; Main.Logger.Log($"[MaximiseBoundarySize.SetBoundarySizeToCustom] Boundary [X,Z] originally was [{position.x}, {position.z}]"); float xPosition = 0; if (position.x > 0) { xPosition = position.x - movementFactor; // (movementFactor / 2f); if (xPosition < 0) { xPosition = 0; } } else if (position.x < 0) { xPosition = position.x + movementFactor; // (movementFactor / 2f); if (xPosition > 0) { xPosition = 0; } } float zPosition = 0; if (position.z > 0) { zPosition = position.z - movementFactor; // (movementFactor / 2f); if (zPosition < 0) { zPosition = 0; } } else if (position.z < 0) { zPosition = position.z + movementFactor; // (movementFactor / 2f); if (zPosition > 0) { zPosition = 0; } } encounterBoundaryRectGameLogic.width = (int)sizeFactor; encounterBoundaryRectGameLogic.height = (int)sizeFactor; encounterBoundaryRectGameLogic.transform.position = new Vector3(xPosition, encounterBoundaryRectGameLogic.transform.position.y, zPosition); Main.Logger.Log($"[MaximiseBoundarySize.SetBoundarySizeToCustom] Boundary [X,Z] is now [{xPosition}, {zPosition}]"); encounterLayerData.CalculateEncounterBoundary(); } else { Main.Logger.Log($"[MaximiseBoundarySize] This encounter has no boundary to maximise."); } } } } }
public override void Run(RunPayload payload) { if (!GetObjectReferences()) { return; } SaveSpawnPositions(lance); Main.Logger.Log($"[SpawnLanceAtEdgeOfBoundary] Attemping for '{lance.name}'. Attempt: '{AttemptCount}/{AttemptCountMax}' and Edge Check: '{EdgeCheckCount}/{EdgeCheckMax}'"); AttemptCount++; Init(); CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat; MissionControl EncounterManager = MissionControl.Instance; GameObject chunkBoundaryRect = EncounterManager.EncounterLayerGameObject.transform.Find("Chunk_EncounterBoundary").gameObject; GameObject boundary = chunkBoundaryRect.transform.Find("EncounterBoundaryRect").gameObject; EncounterBoundaryChunkGameLogic chunkBoundary = chunkBoundaryRect.GetComponent <EncounterBoundaryChunkGameLogic>(); EncounterBoundaryRectGameLogic boundaryLogic = boundary.GetComponent <EncounterBoundaryRectGameLogic>(); Rect boundaryRec = chunkBoundary.GetEncounterBoundaryRectBounds(); Rect usableBounds = boundaryRec.GenerateUsableBoundary(); RectEdgePosition xzEdge = usableBounds.CalculateRandomXZEdge(boundary.transform.position, edge); Vector3 lancePosition = lance.transform.position.GetClosestHexLerpedPointOnGrid(); Vector3 newSpawnPosition = new Vector3(xzEdge.Position.x, lancePosition.y, xzEdge.Position.z); newSpawnPosition = GetClosestValidPathFindingHex(lance, newSpawnPosition, $"NewSpawnPosition.{lance.name}", IsLancePlayerLance(lanceKey) ? orientationTarget.transform.position : Vector3.zero, 2); lance.transform.position = newSpawnPosition; Main.LogDebug($"[SpawnLanceAtEdgeBoundary] Attempting to spawn lance at point on lerped grid '{newSpawnPosition}'"); if (useOrientationTarget) { RotateToTarget(lance, orientationTarget); } if (!useMiniumDistance || IsWithinBoundedDistanceOfTarget(newSpawnPosition, validOrientationTargetPosition, minimumDistance)) { List <GameObject> invalidLanceSpawns = GetInvalidLanceMemberSpawns(lance, validOrientationTargetPosition); if (invalidLanceSpawns.Count > 0) { if (AttemptCount > AttemptCountMax) // Attempt to spawn on the selected edge. If it's not possible, select another edge { edge = RectExtensions.RectEdge.ANY; if (EdgeCheckCount >= EdgeCheckMax) { HandleFallback(payload, this.lanceKey, this.orientationTargetKey); return; } } if (invalidLanceSpawns.Count <= 2) { Main.Logger.Log($"[SpawnLanceAtEdgeOfBoundary] Fitting invalid lance member spawns"); foreach (GameObject invalidSpawn in invalidLanceSpawns) { SpawnLanceMember(invalidSpawn, lance.transform.position); } Main.Logger.Log("[SpawnLanceAtEdgeOfBoundary] Lance spawn complete"); } else { CheckAttempts(); Run(payload); } } else { CorrectLanceMemberSpawns(lance); Main.Logger.Log("[SpawnLanceAtEdgeOfBoundary] Lance spawn complete"); } } else { CheckAttempts(); Main.LogDebug("[SpawnLanceAtEdgeOfBoundary] Spawn is too close to the target. Selecting a new spawn."); edge = xzEdge.Edge; Run(payload); } }