Exemple #1
0
    public void OnShotEnded(ShotResult shotResult)
    {
        BallPhysics.instance.state = BallPhysics.BallState.Cooldown;

        UnityEngine.Debug.Log("RESULTADO: " + shotResult.Result +
                              " PUNTOS: " + shotResult.ScorePoints +
                              " MINUTOS: " + FieldControl.instance.minutes +
                              " GK_RESULTADO " + shotResult.DefenseResult);

        // si estamos en modo time_attack y el tiro ha llegado fuera de tiempo
        if (GameplayService.modoJuego.tipoModo == ModoJuego.TipoModo.TIME_ATTACK &&
            cntCronoTimeAttack.instance.tiempoRestante <= 0.0f)
        {
            Debug.LogWarning(">>> TIRO FUERA DE TIEMPO");

            if (ShotFinished != null)
            {
                ShotFinished(shotResult);
            }
            return;
        }

        if ((GameplayService.networked) &&
            (!Goalkeeper.instance.m_networkDefenseSent) &&
            (ServiceLocator.Request <IGameplayService>().GetGameMode() == GameMode.GoalKeeper))
        {
            MsgDefend msg = Shark.instance.mensaje <MsgDefend>();

            /*
             * msg.info.success = shotResult.Result == Result.OutOfBounds
             || shotResult.Result == Result.Saved
             || shotResult.Result == Result.Stopped;
             ||msg.info.late = true;
             ||msg.info.precisionFail = false;
             ||msg.info.perfect = false;
             ||msg.info.noDefense = noDefense;
             */
            msg.LoadDefense(DefenseService.lastDefense.Target, shotResult.DefenseResult);
            if (noDefense)
            {
                msg.info.noDefense = true;
            }
            msg.points = shotResult.ScorePoints;// + shotResult.ScorePoints;
            msg.send();
        }

        // Calculamos la puntuacion correspondiente al resultado del tiro y la sumamos
        ScoreManager.Instance.CalculateScore(ref shotResult);
        ScoreManager.Instance.AddScore(shotResult);


        if (!GameplayService.networked)
        {
            MissionStats.Instance.OnShotResult(shotResult);
        }

        ServiceLocator.Request <IDifficultyService>().OnShotFinished(shotResult);
        ServiceLocator.Request <IPlayerService>().TryShotResult(shotResult);

        if (ServiceLocator.Request <IPlayerService>().IsGameOver())
        {
            FieldControl.instance.GameOver();
        }

        // Lanzamos el evento de ShotFinished, para notificar a todos los interesados
        // que el tiro ya se ha resuelto
        if (ShotFinished != null)
        {
            ShotFinished(shotResult);
        }
    }
Exemple #2
0
    public void TryShotResult(ShotResult shotResult)
    {
        bool playingGoalkeeper = GameplayService.IsGoalkeeper();

        if (playingGoalkeeper)
        {
            Habilidades.EndRound(shotResult.Result == Result.Goal);
        }

        if (!GameplayService.networked)
        {
            if (!playingGoalkeeper)
            {
                if (shotResult.Result == Result.Goal || shotResult.Result == Result.Target)
                {
                    if (shotResult.Perfect && attempts < maxAttempts)
                    {
                        GeneralSounds.instance.vidaExtra();
                        kickEffects.instance.ExtraLife(shotResult.Point);
                        this.attempts++;
                        if (Habilidades.IsActiveSkill(Habilidades.Skills.VIP) && (attempts < maxAttempts))
                        {
                            this.attempts++;
                            kickEffects.instance.ExtraLife(shotResult.Point + (Vector3.up * -1f));
                        }
                    }

                    /*if (this.attempts >= maxAttempts && shotResult.Perfect)
                     * {
                     * if (perfects > 1 || Habilidades.IsActiveSkill(Habilidades.Skills.VIP))
                     * {
                     *    if (this.attempts != 3)
                     *    {
                     *      GeneralSounds.instance.vidaExtra();
                     *      kickEffects.instance.ExtraLife(shotResult.Point);
                     *      this.attempts = 3;
                     *    }
                     * }
                     * }
                     * if(this.attempts < maxAttempts) this.attempts = maxAttempts;*/
                }
                else
                {
                    ShotFailed();
                }
            }
            else
            {
                if (shotResult.Result == Result.Goal)
                {
                    ShotFailed();
                }
                else
                {
                    if (shotResult.Perfect && attempts < maxAttempts)
                    {
                        GeneralSounds.instance.vidaExtra();
                        kickEffects.instance.ExtraLife(shotResult.Point);
                        this.attempts++;
                        if (Habilidades.IsActiveSkill(Habilidades.Skills.VIP) && (attempts < maxAttempts))
                        {
                            this.attempts++;
                            kickEffects.instance.ExtraLife(shotResult.Point + (Vector3.up * -0.5f));
                        }
                    }
                    //else if (this.attempts < maxAttempts && shotResult.Result != Result.OutOfBounds) this.attempts = maxAttempts;
                }
            }

            SumarDineroPorPrimas();
        }
        else if (GameplayService.networked)
        {
            bool isPlayer1 = GameplayService.initialGameMode != GameMode.Shooter;

            if (playingGoalkeeper)
            {
                cntPastillaMultiplayer.marcadorRemoto.Lanzamientos++;
            }
            else
            {
                cntPastillaMultiplayer.marcadorLocal.Lanzamientos++;
            }

            if (newState)
            {
                Debug.Log("APPLYING");
                cntPastillaMultiplayer.marcadorLocal.SetEstado(GetSimpleState(serverState, isPlayer1));
                cntPastillaMultiplayer.marcadorRemoto.SetEstado(GetSimpleState(serverState, !isPlayer1));
                newState = false;
            }
            else
            {
                Debug.Log("CALCULATING");
                MatchState tempstate = serverState;
                if ((isPlayer1 == playingGoalkeeper))
                {
                    tempstate.rounds++;
                }
                if (playingGoalkeeper)
                {
                    MatchStateSimple state = cntPastillaMultiplayer.marcadorRemoto.AddResult(shotResult.Result == Result.Goal);
                    if (isPlayer1)
                    {
                        tempstate.marker_2 = state.marker;
                        tempstate.score_2  = state.score;
                    }
                    else
                    {
                        tempstate.marker_1 = state.marker;
                        tempstate.score_1  = state.score;
                    }
                }
                else
                {
                    MatchStateSimple stateF = cntPastillaMultiplayer.marcadorLocal.AddResult(shotResult.Result == Result.Goal);
                    if (isPlayer1)
                    {
                        tempstate.marker_1 = stateF.marker;
                        tempstate.score_1  = stateF.score;
                    }
                    else
                    {
                        tempstate.marker_2 = stateF.marker;
                        tempstate.score_2  = stateF.score;
                    }
                }
                serverState = tempstate;

                if (!playingGoalkeeper)
                {
                    Debug.Log("SENDING");
                    MsgSendState msg = Shark.instance.mensaje <MsgSendState>();
                    msg.state   = tempstate;
                    msg.defense = MsgDefend.ToDefenseInfoNet(Vector3.zero, shotResult.DefenseResult);
                    msg.send();
                }
                newState = false;
            }

            if (isPlayer1 == playingGoalkeeper)                                           //fin de ronda
            {
                if (serverState.rounds > 4 && serverState.score_1 != serverState.score_2) //fin de partida
                {
                    gameOver = true;

                    bool winner  = isPlayer1 ? (serverState.score_1 > serverState.score_2) : (serverState.score_2 > serverState.score_1);
                    bool perfect = isPlayer1 ? (serverState.score_2 == 0) : (serverState.score_1 == 0);
                    perfect = perfect && (isPlayer1 ? (serverState.score_1 >= 5) : (serverState.score_2 >= 5));

                    if (winner)
                    {
                        Interfaz.MonedasSoft += recompensaMultijugadorWin;
                    }
                    else
                    {
                        Interfaz.MonedasSoft += recompensaMultijugadorFail;
                    }

                    PersistenciaManager.instance.GuardarPartidaMultiPlayer(winner, perfect);
                }
            }
        }

        int points = shotResult.ScorePoints + shotResult.EffectBonusPoints;

        // actualizar la informacion de cada ronda
        RoundInfoManager.instance.AcumularRonda(shotResult.Result, points, shotResult.Perfect);//, GameplayService.IsGoalkeeper() ? (shotResult.DefenseResult == GKResult.Perfect) : (shotResult.Perfect));

        // acumular la recompensa
        // DINERO! MONEDAS!
        int monedas = Mathf.FloorToInt((float)points * DifficultyService.GetRatioRecompensa());

        Interfaz.recompensaAcumulada += monedas;
        Interfaz.MonedasSoft         += monedas;


        if (gameOver && !GameplayService.networked)
        {
            //ifcGameOver.instance.resultTime = FieldControl.instance.seconds;
            Mission mission = MissionManager.instance.GetMission();
            if (attempts > 0)
            {
                // persistir la mision que se acaba de superar
                PersistenciaManager.instance.ActualizarUltimoNivelDesbloqueado(mission.indexMision + 1);


                // comprobar si la en mision que se acaba de superar desbloquea algun jugador
                Jugador jugadorDesbloqueado = InfoJugadores.instance.GetJugadorDesbloqueableEnFase(mission.indexMision);
                if (jugadorDesbloqueado != null)
                {
                    // registrar el dialogo para mostrar el aviso de que se ha obtenido un nuevo jugador y actualizar su estado
                    jugadorDesbloqueado.estado = Jugador.Estado.DISPONIBLE;
                    DialogManager.instance.RegistrarDialogo(new DialogDefinition(DialogDefinition.TipoDialogo.JUGADOR_DESBLOQUEADO, jugadorDesbloqueado));
                }

                // comprobar si en la mision que se acaba de superar se desbloquea alguna equipacion
                Equipacion equipacionDesbloqueada = EquipacionManager.instance.GetEquipacionDesbloqueableEnFase(mission.indexMision);
                if (equipacionDesbloqueada != null)
                {
                    // registrar el dialogo para mostrar el aviso de que se ha obtenido una nueva equipacion y actualizar su estado
                    equipacionDesbloqueada.estado = Equipacion.Estado.DISPONIBLE;
                    DialogManager.instance.RegistrarDialogo(new DialogDefinition(DialogDefinition.TipoDialogo.EQUIPACION_DESBLOQUEADA, equipacionDesbloqueada));
                }

                // comprobar si en la mision que se acaba de superar se ha desbloqueado algun escudo
                Debug.Log(">>> Compruebo escudo => fase ");
                Escudo escudoDesbloqueado = EscudosManager.instance.GetEscudoDesbloqueableEnFase(mission.indexMision);
                if (escudoDesbloqueado != null)
                {
                    // registrar el dialogo para mostrar el aviso de que se ha obtenido un nuevo escudo y desbloquearlo
                    escudoDesbloqueado.bloqueado = false;
                    DialogManager.instance.RegistrarDialogo(new DialogDefinition(DialogDefinition.TipoDialogo.ESCUDO_DESBLOQUEADO, escudoDesbloqueado));
                }
            }
        }

        if (firstShot)
        {
            firstShot = false;
        }
        UpdateEvent();
    }