Exemplo n.º 1
0
    public bool FindGroundPathToTarget(GameObject target)
    {
        bool playerFound = false;

        //Debug.Log("GROUND PATHFINDING STARTED");

        PlatformHandler platformFound = GetCurrentPlatform();

        if (platformFound != null)
        {
            currentPlatform = platformFound;
        }

        testedPlatform.Clear();
        testedPlatform.Add(currentPlatform);

        GameData.playerMovement.currentPlayerPlatform = null;

        if (FindNextConnection(currentPlatform, target, feetPos.position) > 0)
        {
            playerFound = true;
            //Debug.Log("Player accessible !");
        }
        //Instantiate(debugParticlePrefab, targetConnection.transform.position, Quaternion.identity);

        return(playerFound);
    }
        private static void PostCloseDetour(this Page_ModsConfig self)
        {
            if (SettingsHandler.LastRestartOnClose.Value != RestartOnClose)
            {
                SettingsHandler.LastRestartOnClose.Value = RestartOnClose;
                HugsLibController.Instance.Settings.SaveChanges();
            }

            ModsConfig.Save();
            int activeModsWhenOpenedHash = (int)typeof(Page_ModsConfig).GetField("activeModsWhenOpenedHash", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(self);

            if (activeModsWhenOpenedHash != ModLister.InstalledModsListHash(true))
            {
                if (RestartOnClose)
                {
                    PlatformHandler.RestartRimWorld();
                }

                //Copy of source from here
                bool assemblyWasLoaded = LoadedModManager.RunningMods.Any((ModContentPack m) => m.LoadedAnyAssembly);
                LongEventHandler.QueueLongEvent(delegate
                {
                    PlayDataLoader.ClearAllPlayData();
                    PlayDataLoader.LoadAllPlayData(false);
                    if (assemblyWasLoaded)
                    {
                        LongEventHandler.ExecuteWhenFinished(delegate
                        {
                            Find.WindowStack.Add(new Dialog_MessageBox("ModWithAssemblyWasUnloaded".Translate(), null, null, null, null, null, false));
                        });
                    }
                }, "LoadingLongEvent", true, null);
            }
        }
Exemplo n.º 3
0
    public PlatformHandler GetCurrentPlatform()
    {
        PlatformHandler platform = null;
        Collider2D      collider = Physics2D.OverlapCircle(feetPos.position, 1.2f, LayerMask.GetMask("Ground"));

        if (collider != null && (currentPlatform == null || currentPlatform.gameObject != collider.gameObject))
        {
            //Debug.Log("Set current platform for " + gameObject.name + " to " + collider.gameObject.name);
            platform = collider.GetComponent <PlatformHandler>();
        }

        return(platform);
    }
Exemplo n.º 4
0
 void Start()
 {
     Debug.Assert(Instance == null);
     Instance = this;
     // SoundHandler.Instance.OnSoundLoaded.AddListener(CreatePlatforms);
 }
Exemplo n.º 5
0
    /// <summary>
    /// Change the value of targetConnection and targetConnectedConnection.
    /// Return the distance between the connected connection and the next connection in negative, if positive it's the distance between the player and the connected connection
    /// </summary>
    /// <param name="platform"></param>
    /// <param name="target"></param>
    /// <param name="originConnectionPos"></param>
    /// <param name="linkedConnection"></param>
    /// <returns></returns>
    private float FindNextConnection(PlatformHandler platform, GameObject target, Vector2 originConnectionPos)
    {
        //Debug.Log("Testing player presence on " + platform.gameObject.name);

        if (GameData.playerMovement.currentPlayerPlatform == null && platform.IsUnder(target))
        {
            GameData.playerMovement.currentPlayerPlatform = platform;
        }

        if (platform == GameData.playerMovement.currentPlayerPlatform)
        {
            //Debug.Log("Player found on " + platform.gameObject.name + " !");

            float distanceToPlayer = Vector2.Distance(originConnectionPos, target.transform.position);
            return(distanceToPlayer);
        }
        else
        {
            //Debug.Log("No player found. Now testing connections on " + platform.gameObject.name);

            float minDistanceBetweenConnection = -1;

            foreach (PlatformConnection connection in platform.connections)
            {
                //Debug.Log("Testing " + connection.gameObject.name);
                if (connection.connectedConnections.Count > 0)
                {
                    //Debug.Log(connection.gameObject.name + " has at least 1 connected connection");

                    float minDistanceBetweenConnected = -1;
                    float distanceToConnection        = Vector2.Distance(originConnectionPos, connection.transform.position) + pathfindingJumpWeight;
                    PlatformConnection tempCC         = null;

                    for (int i = 0; i < connection.connectedConnections.Count; i++)
                    {
                        //Debug.Log("Testing connected " + connection.connectedConnections[i].gameObject.name);
                        if (!testedPlatform.Contains(connection.connectedConnections[i].attachedPlatformHandler))
                        {
                            testedPlatform.Add(connection.connectedConnections[i].attachedPlatformHandler);

                            float distanceFromEnd = FindNextConnection(connection.connectedConnections[i].attachedPlatformHandler, target, connection.connectedConnections[i].transform.position);

                            if (distanceFromEnd > 0)
                            {
                                testedPlatform.Remove(connection.connectedConnections[i].attachedPlatformHandler);
                                //Debug.Log("Player found at " + distanceFromEnd + " passing by " + connection.connectedConnections[i].gameObject.name + " linked with " + connection.gameObject.name);
                                if (distanceFromEnd < minDistanceBetweenConnected || minDistanceBetweenConnected == -1)
                                {
                                    //Debug.Log("Better CC found with " + distanceFromEnd + " instead of " + minDistanceBetweenConnected);
                                    minDistanceBetweenConnected = distanceFromEnd;
                                    tempCC = connection.connectedConnections[i];
                                }
                            }
                        }
                        else
                        {
                            //Debug.Log(connection.connectedConnections[i].attachedPlatformHandler.gameObject.name + " has already been tested");
                        }
                    }

                    if (minDistanceBetweenConnected != -1)
                    {
                        if ((minDistanceBetweenConnected + distanceToConnection) < minDistanceBetweenConnection || minDistanceBetweenConnection == -1)
                        {
                            //Debug.Log("Better connection found with " + minDistanceBetweenConnected + distanceToConnection + " instead of " + minDistanceBetweenConnection);
                            minDistanceBetweenConnection = minDistanceBetweenConnected + distanceToConnection;

                            if (platform == currentPlatform)
                            {
                                //Debug.Log("Target Connection found ! + \"" + connection.gameObject.name + " is the chosen one ! Linked to " + tempCC.gameObject.name);
                                targetConnection          = connection;
                                targetConnectedConnection = tempCC;
                            }
                        }
                    }
                    else
                    {
                        //Debug.Log("No CC linked to " + connection.gameObject.name + " lead to the player");
                    }
                }
                else
                {
                    //Debug.Log("Connection " + connection.gameObject.name + " has no connected connection");
                }
            }

            if (minDistanceBetweenConnection != -1)
            {
                return(minDistanceBetweenConnection);
            }
            else
            {
                //Debug.Log(platform.gameObject.name + " has no connection leading to the player");
            }
        }
        return(0);
    }