Example #1
0
    void Start()
    {
        if (!surfing)
        {
            updateMount(false);
        }

        updateAnimation("walk", walkFPS);
        StartCoroutine("animateSprite");
        animPause = true;

        reflect(false);
        followerScript.reflect(false);

        updateDirection(direction);

        StartCoroutine(control());


        //Check current map
        RaycastHit[] hitRays         = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
        int          closestIndex    = -1;
        float        closestDistance = float.PositiveInfinity;

        if (hitRays.Length > 0)
        {
            for (int i = 0; i < hitRays.Length; i++)
            {
                if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                {
                    if (hitRays[i].distance < closestDistance)
                    {
                        closestDistance = hitRays[i].distance;
                        closestIndex    = i;
                    }
                }
            }
        }
        if (closestIndex != -1)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
        }
        else
        {
            //if no map found
            //Check for map in front of player's direction
            hitRays         = Physics.RaycastAll(transform.position + Vector3.up + getForwardVectorRaw(), Vector3.down);
            closestIndex    = -1;
            closestDistance = float.PositiveInfinity;
            if (hitRays.Length > 0)
            {
                for (int i = 0; i < hitRays.Length; i++)
                {
                    if (hitRays[i].collider.gameObject.GetComponent <MapCollider>() != null)
                    {
                        if (hitRays[i].distance < closestDistance)
                        {
                            closestDistance = hitRays[i].distance;
                            closestIndex    = i;
                        }
                    }
                }
            }
            if (closestIndex != -1)
            {
                currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
            }
            else
            {
                Debug.Log("no map found");
            }
        }


        if (currentMap != null)
        {
            accessedMapSettings = currentMap.gameObject.GetComponent <MapSettings>();
            if (accessedAudio != accessedMapSettings.getBGM())
            {
                //if audio is not already playing
                accessedAudio = accessedMapSettings.getBGM();
                accessedAudioLoopStartSamples = accessedMapSettings.getBGMLoopStartSamples();
                BgmHandler.main.PlayMain(accessedAudio, accessedAudioLoopStartSamples);
            }
            if (accessedMapSettings.mapNameBoxTexture != null)
            {
                MapName.display(accessedMapSettings.mapNameBoxTexture, accessedMapSettings.mapName,
                                accessedMapSettings.mapNameColor);
            }
        }


        //check position for transparent bumpEvents
        Collider transparentCollider = null;

        Collider[] hitColliders = Physics.OverlapSphere(transform.position, 0.4f);
        if (hitColliders.Length > 0)
        {
            for (int i = 0; i < hitColliders.Length; i++)
            {
                if (hitColliders[i].name.ToLowerInvariant().Contains("_transparent"))
                {
                    if (!hitColliders[i].name.ToLowerInvariant().Contains("player") &&
                        !hitColliders[i].name.ToLowerInvariant().Contains("follower"))
                    {
                        transparentCollider = hitColliders[i];
                    }
                }
            }
        }
        if (transparentCollider != null)
        {
            //send bump message to the object's parent object
            transparentCollider.transform.parent.gameObject.SendMessage("bump", SendMessageOptions.DontRequireReceiver);
        }

        //DEBUG
        if (accessedMapSettings != null)
        {
            WildPokemonInitialiser[] encounterList =
                accessedMapSettings.getEncounterList(WildPokemonInitialiser.Location.Standard);
            string namez = "";
            for (int i = 0; i < encounterList.Length; i++)
            {
                namez += PokemonDatabase.getPokemon(encounterList[i].ID).getName() + ", ";
            }
            Debug.Log("Wild Pokemon for map \"" + accessedMapSettings.mapName + "\": " + namez);
        }
        //

        GlobalVariables.global.resetFollower();
    }
    void Start()
    {
        if (!surfing)
        {
            updateMount(false);
        }

        updateAnimation("walk", walkFPS);
        #if UNITY_STANDALONE_WIN
        if (SaveData.currentSave.getCVariable("female") == 0)
        {
            GlobalVariables.global.SetRPCSmallImageKey("m_" + SaveData.currentSave.playerOutfit, SaveData.currentSave.playerName);
        }
        else
        {
            GlobalVariables.global.SetRPCSmallImageKey("f_" + SaveData.currentSave.playerOutfit, SaveData.currentSave.playerName);
        }
        #endif
        StartCoroutine(animateSprite());
        animPause = true;

        reflect(false);
        followerScript.reflect(false);

        updateDirection(direction);

        StartCoroutine(control());


        //Check current map
        RaycastHit[] hitRays = Physics.RaycastAll(transform.position + Vector3.up, Vector3.down);
        int          closestIndex;
        float        closestDistance;

        CheckHitRaycastDistance(hitRays, out closestIndex, out closestDistance);

        if (closestIndex >= 0)
        {
            currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
        }
        else
        {
            //if no map found
            //Check for map in front of player's direction
            hitRays = Physics.RaycastAll(transform.position + Vector3.up + getForwardVectorRaw(), Vector3.down);

            CheckHitRaycastDistance(hitRays, out closestIndex, out closestDistance);

            if (closestIndex >= 0)
            {
                currentMap = hitRays[closestIndex].collider.gameObject.GetComponent <MapCollider>();
            }
            else
            {
                GlobalVariables.global.debug("no map found");
            }
        }


        if (currentMap != null)
        {
            accessedMapSettings = currentMap.gameObject.GetComponent <MapSettings>();
            AudioClip audioClip        = accessedMapSettings.getBGM();
            int       loopStartSamples = accessedMapSettings.getBGMLoopStartSamples();

            if (accessedAudio != audioClip)
            {
                //if audio is not already playing
                accessedAudio = audioClip;
                accessedAudioLoopStartSamples = loopStartSamples;
                BgmHandler.main.PlayMain(accessedAudio, accessedAudioLoopStartSamples);
            }
            if (accessedMapSettings.mapNameBoxTexture != null)
            {
                MapName.display(accessedMapSettings.mapNameBoxTexture, accessedMapSettings.mapName,
                                accessedMapSettings.mapNameColor);
            }
        }


        //check position for transparent bumpEvents
        Collider   transparentCollider = null;
        Collider[] hitColliders        = Physics.OverlapSphere(transform.position, 0.4f);

        transparentCollider = hitColliders.LastOrDefault(collider => collider.name.ToLowerInvariant().Contains("_transparent") &&
                                                         !collider.name.ToLowerInvariant().Contains("player") &&
                                                         !collider.name.ToLowerInvariant().Contains("follower"));

        if (transparentCollider != null)
        {
            //send bump message to the object's parent object
            transparentCollider.transform.parent.gameObject.SendMessage("bump", SendMessageOptions.DontRequireReceiver);
        }

        //DEBUG
        if (accessedMapSettings != null)
        {
            string pkmnNames = "";
            foreach (var encounter in accessedMapSettings.getEncounterList(WildPokemonInitialiser.Location.Standard))
            {
                pkmnNames += PokemonDatabase.getPokemon(encounter.ID).getName() + ", ";
            }
            GlobalVariables.global.debug("Wild Pokemon for map \"" + accessedMapSettings.mapName + "\": " + pkmnNames);

            /*if(GlobalVariables.global.presence.largeImageKey != accessedMapSettings.discordImageKey || accessedMapSettings.discordDetails != "")
             * {
             *  if(GlobalVariables.global.presence.largeImageKey != accessedMapSettings.discordImageKey)
             *      GlobalVariables.global.SetRPCLargeImageKey(accessedMapSettings.discordImageKey, accessedMapSettings.mapName);
             *  if(accessedMapSettings.discordDetails != "")
             *      GlobalVariables.global.SetRPCDetails(accessedMapSettings.discordDetails);
             *  GlobalVariables.global.UpdatePresence();
             * }*/
        }
        //

        GlobalVariables.global.resetFollower();
    }