Esempio n. 1
0
    public void StartNewGame()
    {
        chessBoards   = new Dictionary <Trainer, ChessBoard>();
        waitingBoards = new Dictionary <Trainer, WaitingBoard>();

        float angle = 360 / trainers.Count;

        for (int i = 0; i < trainers.Count; i++)
        {
            Trainer trainer = trainers[i];

            GameObject chessFieldInstance = Instantiate(chessField);
            Vector3    position           = Quaternion.Euler(0f, 0f, angle / 4f + angle * i) * new Vector3(30f, 30f);
            chessFieldInstance.transform.position = new Vector3(Mathf.Floor(position.x), Mathf.Floor(position.y));
            ChessBoard   chessBoard   = chessFieldInstance.GetComponentInChildren <ChessBoard>();
            WaitingBoard waitingBoard = chessFieldInstance.GetComponentInChildren <WaitingBoard>();
            chessBoard.owner   = trainer;
            waitingBoard.owner = trainer;

            chessBoards[trainer]   = chessBoard;
            waitingBoards[trainer] = waitingBoard;

            if (trainer is Player)
            {
                Camera.main.transform.position = new Vector3(chessFieldInstance.transform.position.x, chessFieldInstance.transform.position.y, -10f);
                lapras.transform.position      = chessFieldInstance.transform.position + new Vector3(-12f, 0.5f);
            }
            else
            {
                // GameObject trainerObject = Instantiate(trainer.gameObject);
                // trainerObject.transform.position = chessFieldInstance.transform.position;
            }
        }

        pokemonSafari.Refresh();
    }
    public IEnumerator StartEvolutionIfPokemonCan(Trainer trainer, Pokemon pokemon)
    {
        int            samePokemonCount      = 0;
        List <Pokemon> placedSamePokemonList = new List <Pokemon>();

        if (!gameManager.battleManager.isInBattle)
        {
            foreach (Pokemon placedPokemon in trainer.placedPokemons.Keys)
            {
                if (placedPokemon.pokemonName == pokemon.pokemonName && placedPokemon.evolutionPhase == pokemon.evolutionPhase)
                {
                    samePokemonCount += 1;
                    placedSamePokemonList.Add(placedPokemon);
                }
            }
        }

        List <int> waitingSamePokemonsIndex = new List <int>();

        for (int i = 0; i < Trainer.CanWaitPokemonsNumber; i++)
        {
            Pokemon waitingPokemon = trainer.waitingPokemons[i];
            if (waitingPokemon != null && waitingPokemon.pokemonName == pokemon.pokemonName && waitingPokemon.evolutionPhase == pokemon.evolutionPhase)
            {
                samePokemonCount += 1;
                waitingSamePokemonsIndex.Add(i);
            }
        }

        if (samePokemonCount == 3)
        {
            Dictionary <PokemonPlaceableBoard, Vector2Int> placeEvolvedPokemonTo = new Dictionary <PokemonPlaceableBoard, Vector2Int>();

            ChessBoard   chessBoard   = gameManager.chessBoards[trainer];
            WaitingBoard waitingBoard = gameManager.waitingBoards[trainer];

            if (pokemon.evolution == null)
            {
                yield break;
            }

            Pokemon evolution = Instantiate(pokemon.evolution).GetComponent <Pokemon>();
            evolution.trainer        = trainer;
            evolution.cost           = pokemon.cost;
            evolution.evolutionPhase = pokemon.evolutionPhase + 1;

            Animator evolvedPokemonAnimator = evolution.GetComponentInChildren <Animator>();
            evolvedPokemonAnimator.enabled = false;

            SpriteRenderer evolvedPokemonSR = evolution.GetComponentInChildren <SpriteRenderer>();
            Sprite         evolveFromSprite = evolvedPokemonSR.sprite;
            Sprite         evolveToSprite   = evolvedPokemonSR.sprite;
            Material       defaultMaterial  = evolvedPokemonSR.material;

            foreach (Pokemon placedPokemon in placedSamePokemonList)
            {
                if (placeEvolvedPokemonTo.Count == 0)
                {
                    placeEvolvedPokemonTo[chessBoard] = chessBoard.GetIndex(placedPokemon);
                    evolveFromSprite = placedPokemon.GetComponentInChildren <SpriteRenderer>().sprite;
                    Destroy(placedPokemon.gameObject);
                }
                else
                {
                    StartCoroutine(FlyToEvolvedPokemon(placedPokemon, evolution));
                }
                chessBoard.RemovePokemon(placedPokemon);
            }

            foreach (int waitingPokemonIndex in waitingSamePokemonsIndex)
            {
                Pokemon waitingPokemon = trainer.waitingPokemons[waitingPokemonIndex];
                if (placeEvolvedPokemonTo.Count == 0)
                {
                    placeEvolvedPokemonTo[waitingBoard] = waitingBoard.GetIndex(waitingPokemon);
                    evolveFromSprite = waitingPokemon.GetComponentInChildren <SpriteRenderer>().sprite;
                    Destroy(waitingPokemon.gameObject);
                }
                else
                {
                    StartCoroutine(FlyToEvolvedPokemon(waitingPokemon, evolution));
                }
                waitingBoard.RemovePokemon(waitingPokemon);
            }

            foreach (KeyValuePair <PokemonPlaceableBoard, Vector2Int> placePair in placeEvolvedPokemonTo)
            {
                placePair.Key.SetPokemon(placePair.Value, evolution);
            }

            evolvedPokemonSR.material = Resources.Load("Materials/PaintWhite") as Material;
            for (float time = 0f; time < 0.45f; time += 0.05f)
            {
                if (time < 0.15f)
                {
                    evolution.transform.localScale += new Vector3(0.05f, 0.05f);
                }
                else if (time < 0.3f)
                {
                    evolution.transform.localScale -= new Vector3(0.1f, 0.1f);
                    evolvedPokemonSR.sprite         = evolveFromSprite;
                }
                else
                {
                    evolution.transform.localScale += new Vector3(0.05f, 0.05f);
                    evolvedPokemonSR.sprite         = evolveToSprite;
                }
                yield return(new WaitForSeconds(0.05f));
            }

            evolvedPokemonSR.material = defaultMaterial;
            Destroy(Instantiate(evolutionEffect, evolution.transform), 3f);
            evolvedPokemonAnimator.enabled = true;

            yield return(new WaitForSeconds(0.3f));

            StartCoroutine(StartEvolutionIfPokemonCan(trainer, evolution));
        }
    }