示例#1
0
        public Vector3 GetRandomPositionWithinBounds()
        {
            EncounterBoundaryChunkGameLogic chunkBoundary = MissionControl.Instance.EncounterLayerGameObject.GetComponentInChildren <EncounterBoundaryChunkGameLogic>();
            EncounterBoundaryRectGameLogic  boundaryLogic = chunkBoundary.GetComponentInChildren <EncounterBoundaryRectGameLogic>();
            Rect boundaryRec = chunkBoundary.GetEncounterBoundaryRectBounds();

            Vector3 randomRecPosition = boundaryRec.GetRandomPosition();

            return(randomRecPosition.GetClosestHexLerpedPointOnGrid());
        }
示例#2
0
    public static Vector3 GetRandomPositionWithinBounds(Vector3 target, float maxDistance)
    {
        GameObject chunkBoundaryRect = MissionControl.MissionControl.Instance.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();

        Vector3 randomRecPosition = boundaryRec.GetRandomPositionFromTarget(target, maxDistance);

        return(randomRecPosition.GetClosestHexLerpedPointOnGrid());
    }
        public Vector3 GetRandomPositionWithinBounds()
        {
            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();

            Vector3 randomRecPosition = boundaryRec.GetRandomPosition();

            return(randomRecPosition.GetClosestHexLerpedPointOnGrid());
        }
示例#4
0
        private void EnableBoundary()
        {
            GameObject chunkBoundaryRect = activeEncounter.transform.Find("Chunk_EncounterBoundary").gameObject;
            GameObject boundary          = chunkBoundaryRect.transform.Find("EncounterBoundaryRect").gameObject;
            EncounterBoundaryChunkGameLogic chunkBoundaryLogic = chunkBoundaryRect.GetComponent <EncounterBoundaryChunkGameLogic>();
            EncounterBoundaryRectGameLogic  boundaryLogic      = boundary.GetComponent <EncounterBoundaryRectGameLogic>();
            Rect boundaryRec = chunkBoundaryLogic.GetEncounterBoundaryRectBounds();

            GameObject placeholderPoint = GameObject.CreatePrimitive(PrimitiveType.Cube);

            placeholderPoint.name                 = "BoundaryGizmo";
            placeholderPoint.transform.parent     = boundary.transform;
            placeholderPoint.transform.position   = boundary.transform.position;
            placeholderPoint.transform.localScale = new Vector3(boundaryRec.width, boundaryRec.height, boundaryRec.height);

            placeholderPoint.GetComponent <Renderer>().sharedMaterial = boundaryMaterial;

            boundaryRepresemtation = placeholderPoint;
        }
        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);
            }
        }