Exemplo n.º 1
0
    protected override void OnRoundEnd(UFE3D.CharacterInfo winner, UFE3D.CharacterInfo loser)
    {
        base.OnRoundEnd(winner, loser);

        // Find out who is the winner and who is the loser...
        int            winnerPlayer         = winner == this.player1.character ? 1 : 2;
        int            loserPlayer          = loser == this.player1.character ? 1 : 2;
        PlayerGUI      winnerGUI            = winnerPlayer == 1 ? this.player1GUI : this.player2GUI;
        PlayerGUI      loserGUI             = loserPlayer == 1 ? this.player1GUI : this.player2GUI;
        ControlsScript winnerControlsScript = UFE.GetControlsScript(winnerPlayer);

        // Then update the "Won Rounds" sprites...
        if (this.wonRounds.NotFinishedRounds == null)
        {
            Debug.LogError("\"Not Finished Rounds\" Sprite not found! Make sure you have set the sprite correctly in the Editor");
        }
        else if (this.wonRounds.WonRounds == null)
        {
            Debug.LogError("\"Won Rounds\" Sprite not found! Make sure you have set the sprite correctly in the Editor");
        }
        else if (this.wonRounds.LostRounds == null && this.wonRounds.VisibleImages == DefaultBattleGUI.VisibleImages.AllRounds)
        {
            Debug.LogError("\"Lost Rounds\" Sprite not found! If you want to display Lost Rounds, make sure you have set the sprite correctly in the Editor");
        }
        else
        {
            // To calculate the target number of images, check if the "Lost Rounds" Sprite is defined or not
            int targetNumberOfImages = this.wonRounds.GetNumberOfRoundsImages();

            if (this.wonRounds.VisibleImages == DefaultBattleGUI.VisibleImages.AllRounds)
            {
                // If the "Lost Rounds" sprite is defined, that means that we must display all won and lost rounds...
                if (
                    winnerGUI != null &&
                    winnerGUI.wonRoundsImages != null &&
                    winnerGUI.wonRoundsImages.Length >= targetNumberOfImages
                    )
                {
                    winnerGUI.wonRoundsImages[UFE.config.currentRound - 1].sprite = this.wonRounds.WonRounds;
                }
                else
                {
                    Debug.LogError(
                        "Player " + winnerPlayer + ": not enough \"Won Rounds\" Images not found! " +
                        "Expected:" + targetNumberOfImages + " / Found: " + winnerGUI.wonRoundsImages.Length +
                        "\nMake sure you have set the images correctly in the Editor"
                        );
                }

                if (
                    loserGUI != null &&
                    loserGUI.wonRoundsImages != null &&
                    loserGUI.wonRoundsImages.Length >= targetNumberOfImages
                    )
                {
                    loserGUI.wonRoundsImages[UFE.config.currentRound - 1].sprite = this.wonRounds.LostRounds;
                }
                else
                {
                    Debug.LogError(
                        "Player " + winnerPlayer + ": not enough \"Won Rounds\" Images not found! " +
                        "Expected:" + targetNumberOfImages + " / Found: " + winnerGUI.wonRoundsImages.Length +
                        "\nMake sure you have set the images correctly in the Editor"
                        );
                }
            }
            else
            {
                // If the "Lost Rounds" sprite is not defined, that means that we must only display won rounds...
                if (
                    winnerGUI != null &&
                    winnerGUI.wonRoundsImages != null &&
                    winnerGUI.wonRoundsImages.Length >= winnerControlsScript.roundsWon
                    )
                {
                    winnerGUI.wonRoundsImages[winnerControlsScript.roundsWon - 1].sprite = this.wonRounds.WonRounds;
                }
                else if (UFE.gameMode != GameMode.ChallengeMode)
                {
                    Debug.LogError(
                        "Player " + winnerPlayer + ": not enough \"Won Rounds\" Images not found! " +
                        "Expected:" + targetNumberOfImages + " / Found: " + winnerGUI.wonRoundsImages.Length +
                        "\nMake sure you have set the images correctly in the Editor"
                        );
                }
            }
        }

        if (this.announcer != null && !this.muteAnnouncer)
        {
            // Check if it was the last round
            if (winnerControlsScript.roundsWon > Mathf.Ceil(UFE.config.roundOptions.totalRounds / 2))
            {
                if (winnerPlayer == 1)
                {
                    UFE.PlaySound(this.announcer.player1Wins);
                }
                else
                {
                    UFE.PlaySound(this.announcer.player2Wins);
                }
            }

            // Finally, check if we should play any AudioClip
            if (winnerControlsScript.myInfo.currentLifePoints == winnerControlsScript.myInfo.lifePoints)
            {
                UFE.PlaySound(this.announcer.perfect);
            }
        }

        if (winnerControlsScript.myInfo.currentLifePoints == winnerControlsScript.myInfo.lifePoints)
        {
            this.OnNewAlert(this.SetStringValues(UFE.config.selectedLanguage.perfect, winnerControlsScript), null);
        }

        if (UFE.gameMode != GameMode.ChallengeMode &&
            winnerControlsScript.roundsWon > Mathf.Ceil(UFE.config.roundOptions.totalRounds / 2))
        {
            this.OnNewAlert(this.SetStringValues(UFE.config.selectedLanguage.victory, winnerControlsScript), null);
            UFE.PlayMusic(UFE.config.roundOptions.victoryMusic);
        }
        else if (UFE.gameMode == GameMode.ChallengeMode)
        {
            this.OnNewAlert(this.SetStringValues(UFE.config.selectedLanguage.challengeEnds, winnerControlsScript), null);
            UFE.PlayMusic(UFE.config.roundOptions.victoryMusic);
        }
    }
Exemplo n.º 2
0
    protected override void OnRoundBegin(int roundNumber)
    {
        base.OnRoundBegin(roundNumber);

        if (this.player1GUI != null && this.player1GUI.alert != null && this.player1GUI.alert.text != null)
        {
            this.player1GUI.alert.text.text = string.Empty;
        }

        if (this.player2GUI != null && this.player2GUI.alert != null && this.player2GUI.alert.text != null)
        {
            this.player2GUI.alert.text.text = string.Empty;
        }

        if (UFE.gameMode == GameMode.ChallengeMode)
        {
            this.OnNewAlert(UFE.config.selectedLanguage.challengeBegins, null);
        }
        else if (roundNumber < UFE.config.roundOptions.totalRounds)
        {
            this.OnNewAlert(UFE.config.selectedLanguage.round, null);

            if (this.announcer != null && !this.muteAnnouncer)
            {
                if (roundNumber == 1)
                {
                    UFE.PlaySound(this.announcer.round1);
                }
                if (roundNumber == 2)
                {
                    UFE.PlaySound(this.announcer.round2);
                }
                if (roundNumber == 3)
                {
                    UFE.PlaySound(this.announcer.round3);
                }
                if (roundNumber > 3)
                {
                    UFE.PlaySound(this.announcer.otherRounds);
                }
            }
        }
        else
        {
            this.OnNewAlert(UFE.config.selectedLanguage.finalRound, null);

            if (this.announcer != null && !this.muteAnnouncer)
            {
                UFE.PlaySound(this.announcer.finalRound);
            }

            // If network game, point which character the local player is
            if ((UFE.gameMode == GameMode.NetworkGame || UFE.config.debugOptions.emulateNetwork) &&
                networkPlayerPointer != null)
            {
                int localPlayer = 1;
                if (UFE.isConnected)
                {
                    localPlayer = UFE.localPlayerController.player;
                }

                GameObject pointer = new GameObject("Local Pointer");
                pointer.transform.SetParent(UFE.GetControlsScript(localPlayer).transform);
                pointer.transform.localPosition = new Vector3(0, 7, 0);
                SpriteRenderer spriteRenderer = pointer.AddComponent <SpriteRenderer>();
                spriteRenderer.sprite = networkPlayerPointer;
                Destroy(pointer, pointerTimer);
            }
        }

        // If network game, point which character the local player is
        if ((UFE.gameMode == GameMode.NetworkGame || UFE.config.debugOptions.emulateNetwork) &&
            networkPlayerPointer != null)
        {
            int localPlayer = 1;
            if (UFE.isConnected)
            {
                localPlayer = UFE.localPlayerController.player;
            }

            GameObject pointer = new GameObject("Local Pointer");
            pointer.transform.SetParent(UFE.GetControlsScript(localPlayer).transform);
            pointer.transform.localPosition = new Vector3(0, 7, 0);
            SpriteRenderer spriteRenderer = pointer.AddComponent <SpriteRenderer>();
            spriteRenderer.sprite = networkPlayerPointer;
            Destroy(pointer, pointerTimer);
        }
    }
Exemplo n.º 3
0
    protected override void OnNewAlert(string msg, UFE3D.CharacterInfo player)
    {
        base.OnNewAlert(msg, player);


        // You can use this to have your own custom events when a new text alert is fired from the engine
        if (player != null)
        {
            if (player.playerNum == 1)
            {
                ControlsScript controlsScript   = UFE.GetControlsScript(1);
                string         processedMessage = this.ProcessMessage(msg, controlsScript);

                if (this.player1GUI != null && this.player1GUI.alert != null && this.player1GUI.alert.text != null)
                {
                    this.player1GUI.alert.text.text = processedMessage;

                    if (
                        msg != UFE.config.selectedLanguage.combo ||
                        controlsScript.opControlsScript.comboHits == 2 ||
                        UFE.config.comboOptions.comboDisplayMode == ComboDisplayMode.ShowAfterComboExecution
                        )
                    {
                        this.player1GUI.alert.text.rectTransform.anchoredPosition = this.player1GUI.alert.initialPosition;
                    }
                    this.player1AlertTimer = 2f;
                }
            }
            else
            {
                ControlsScript controlsScript   = UFE.GetPlayer2ControlsScript();
                string         processedMessage = this.ProcessMessage(msg, controlsScript);

                if (this.player2GUI != null && this.player2GUI.alert != null && this.player2GUI.alert.text != null)
                {
                    this.player2GUI.alert.text.text = processedMessage;

                    if (
                        msg != UFE.config.selectedLanguage.combo ||
                        controlsScript.opControlsScript.comboHits == 2 ||
                        UFE.config.comboOptions.comboDisplayMode == ComboDisplayMode.ShowAfterComboExecution
                        )
                    {
                        this.player2GUI.alert.text.rectTransform.anchoredPosition = this.player2GUI.alert.initialPosition;
                    }
                    this.player2AlertTimer = 2f;
                }
            }
        }
        else
        {
            string processedMessage = this.ProcessMessage(msg, null);

            if (this.mainAlert != null && this.mainAlert.text != null)
            {
                this.mainAlert.text.text = processedMessage;

                if (msg == UFE.config.selectedLanguage.round || msg == UFE.config.selectedLanguage.finalRound)
                {
                    this.mainAlertTimer = 2f;
                }
                else if (msg == UFE.config.selectedLanguage.challengeBegins)
                {
                    this.mainAlertTimer = 2f;
                }
                else if (msg == UFE.config.selectedLanguage.fight)
                {
                    this.mainAlertTimer = 1f;
                }
                else if (msg == UFE.config.selectedLanguage.ko)
                {
                    this.mainAlertTimer = 2f;
                }
                else
                {
                    this.mainAlertTimer = 60f;
                }
            }
        }
    }
Exemplo n.º 4
0
    public override InputEvents ReadInput(InputReferences inputReference)
    {
        ControlsScript self = UFE.GetControlsScript(this.player);

        if (self != null)
        {
            ControlsScript opponent = self.opControlsScript;

            if (opponent != null)
            {
                bool  isOpponentDown = opponent.currentState == PossibleStates.Down;
                float dx             = opponent.transform.position.x - self.transform.position.x;
                int   distance       = Mathf.RoundToInt(100f * Mathf.Clamp01((float)self.normalizedDistance));

                float maxDistance             = float.NegativeInfinity;
                AIDistanceBehaviour behaviour = null;

                // Try to find the correct "Distance Behaviour"
                // If there are several overlapping "Distance Behaviour", we choose the first in the list.
                foreach (AIDistanceBehaviour thisBehaviour in UFE.config.aiOptions.distanceBehaviour)
                {
                    if (thisBehaviour != null)
                    {
                        if (distance >= thisBehaviour.proximityRangeBegins && distance <= thisBehaviour.proximityRangeEnds)
                        {
                            behaviour = thisBehaviour;
                            break;
                        }

                        if (thisBehaviour.proximityRangeEnds > maxDistance)
                        {
                            maxDistance = thisBehaviour.proximityRangeEnds;
                        }
                    }
                }

                // If we don't find the correct "Distance Behaviour", make our best effort...
                if (behaviour == null)
                {
                    foreach (AIDistanceBehaviour thisBehaviour in UFE.config.aiOptions.distanceBehaviour)
                    {
                        if (thisBehaviour != null && thisBehaviour.proximityRangeEnds == maxDistance)
                        {
                            behaviour = thisBehaviour;
                        }
                    }
                }

                if (behaviour == null)
                {
                    return(InputEvents.Default);
                }
                else if (inputReference.inputType == InputType.HorizontalAxis)
                {
                    float axis = 0f;
                    if (UFE.config.aiOptions.moveWhenEnemyIsDown || !isOpponentDown)
                    {
                        axis =
                            Mathf.Sign(dx)
                            *
                            (
                                (Random.Range(0f, 1f) < behaviour.movingForwardProbability ? 1f : 0f) -
                                (Random.Range(0f, 1f) < behaviour.movingBackProbability ? 1f : 0f)
                            );
                    }

                    return(new InputEvents(axis));
                }
                else if (inputReference.inputType == InputType.VerticalAxis)
                {
                    float axis = 0f;
                    if (UFE.config.aiOptions.moveWhenEnemyIsDown || !isOpponentDown)
                    {
                        axis =
                            (Random.Range(0f, 1f) < behaviour.jumpingProbability ? 1f : 0f) -
                            (Random.Range(0f, 1f) < behaviour.movingBackProbability ? 1f : 0f);
                    }

                    return(new InputEvents(axis));
                }
                else
                {
                    if (!UFE.config.aiOptions.attackWhenEnemyIsDown && isOpponentDown)
                    {
                        return(InputEvents.Default);
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button1)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button2)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button3)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button4)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button5)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button6)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button7)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button8)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button9)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button10)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button11)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else if (inputReference.engineRelatedButton == ButtonPress.Button12)
                    {
                        return(new InputEvents(Random.Range(0f, 1f) < behaviour.attackProbability));
                    }
                    else
                    {
                        return(InputEvents.Default);
                    }
                }
            }
        }
        return(InputEvents.Default);
    }
Exemplo n.º 5
0
    public override void DoFixedUpdate()
    {
        //this.ShowDebugInformation();


        ControlsScript self = UFE.GetControlsScript(this.player);

        if (this.inputReferences != null && this.inputBuffer != null && self != null)
        {
            ControlsScript opponent = self.opControlsScript;
            if (opponent != null)
            {
                //-------------------------------------------------------------------------------------------------
                // Check the information stored in the input buffer...
                //-------------------------------------------------------------------------------------------------
                if (this.inputBuffer.Count == 0)
                {
                    //---------------------------------------------------------------------------------------------
                    // If the we don't have the input of the previous frame, use the default input...
                    //---------------------------------------------------------------------------------------------
                    Dictionary <InputReferences, InputEvents> frame = new Dictionary <InputReferences, InputEvents>();
                    foreach (InputReferences input in this.inputReferences)
                    {
                        frame[input] = InputEvents.Default;
                    }
                    this.inputBuffer.Add(frame);
                }
                else if (this.inputBuffer.Count >= 2)
                {
                    this.inputBuffer.RemoveAt(0);
                }

                //-----------------------------------------------------------------------------------------------------
                // If we haven't decided the input for the current frame yet...
                //-----------------------------------------------------------------------------------------------------
                if (this.inputBuffer.Count < 2)
                {
                    //-------------------------------------------------------------------------------------------------
                    // And simulate the input required for executing the next movement
                    //-------------------------------------------------------------------------------------------------
                    if (
                        this.behaviour != null
                        &&
                        this.behaviour.steps.Length > 0
                        &&
                        self.currentMove == null
                        &&
                        (
                            self.currentBasicMove == BasicMoveReference.Idle ||
                            self.currentBasicMove == BasicMoveReference.Crouching
                        )
                        )
                    {
                        float sign = Mathf.Sign(opponent.transform.position.x - self.transform.position.x);

                        foreach (SimpleAIStep step in this.behaviour.steps)
                        {
                            Dictionary <InputReferences, InputEvents> frame = new Dictionary <InputReferences, InputEvents>();
                            foreach (InputReferences input in this.inputReferences)
                            {
                                frame[input] = InputEvents.Default;
                            }

                            foreach (InputReferences input in this.inputReferences)
                            {
                                if (input.inputType == InputType.HorizontalAxis)
                                {
                                    foreach (ButtonPress buttonPress in step.buttons)
                                    {
                                        if (buttonPress == ButtonPress.Back)
                                        {
                                            frame[input] = new InputEvents(-1f * sign);
                                        }
                                        else if (buttonPress == ButtonPress.Forward)
                                        {
                                            frame[input] = new InputEvents(1f * sign);
                                        }
                                    }
                                }
                                else if (input.inputType == InputType.VerticalAxis)
                                {
                                    foreach (ButtonPress buttonPress in step.buttons)
                                    {
                                        if (buttonPress == ButtonPress.Up)
                                        {
                                            frame[input] = new InputEvents(1f);
                                        }
                                        else if (buttonPress == ButtonPress.Down)
                                        {
                                            frame[input] = new InputEvents(-1f);
                                        }
                                    }
                                }
                                else
                                {
                                    foreach (ButtonPress buttonPress in step.buttons)
                                    {
                                        if (input.engineRelatedButton == buttonPress)
                                        {
                                            frame[input] = new InputEvents(true);
                                        }
                                    }
                                }
                            }

                            for (int i = 0; i < step.frames; ++i)
                            {
                                this.inputBuffer.Add(frame);
                            }
                        }
                    }
                    else
                    {
                        Dictionary <InputReferences, InputEvents> frame = new Dictionary <InputReferences, InputEvents>();
                        foreach (InputReferences input in this.inputReferences)
                        {
                            frame[input] = InputEvents.Default;
                        }
                        this.inputBuffer.Add(frame);
                    }
                }
            }
        }
    }
Exemplo n.º 6
0
    public InputEvents DoBestMove(InputReferences inputReference, string bestMove)
    {
        //Debug.Log("Trying to fire " + bestMove);
        //StartCoroutine(Wait(Random.Range(0,1)));

        ControlsScript self = UFE.GetControlsScript(this.player);

        if (self != null)
        {
            ControlsScript opponent = self.opControlsScript;

            if (opponent != null)
            {
                bool  isOpponentDown = opponent.currentState == PossibleStates.Down;
                float dx             = opponent.transform.position.x - self.transform.position.x;
                float axis           = 0f;
                int   distance       = Mathf.RoundToInt(100f * Mathf.Clamp01(self.normalizedDistance));
                if (bestMove == "Foward")
                {
                    //Debug.Log("Trying to move forward");
                    axis = Mathf.Sign(dx) * 1f;
                    //StartCoroutine(HoldButton(0.5f, 1.0f));
                    return(new InputEvents(axis));
                }
                if (bestMove == "Backward")
                {
                    axis = Mathf.Sign(dx) * 0f;
                    return(new InputEvents(axis));
                }
                if (bestMove == "Down")
                {
                    return(new InputEvents(axis));
                }
                if (bestMove == "Up")
                {
                    axis = 1f;
                    return(new InputEvents(axis));
                }
                switch (inputReference.engineRelatedButton)
                {
                case ButtonPress.Button1:
                    if (bestMove == "Button1")
                    {
                        //StartCoroutine(Wait(0.05F));
                        //Debug.Log("Waiting to fire Button1");
                        return(new InputEvents(true));
                    }
                    break;

                case ButtonPress.Button2:
                    if (bestMove == "Button2")
                    {
                        //StartCoroutine(Wait(0.05F));
                        //Debug.Log("Waiting to fire Button2");
                        return(new InputEvents(true));
                    }
                    break;

                case ButtonPress.Button3:
                    if (bestMove == "Button3")
                    {
                        //StartCoroutine(Wait(0.05F));
                        //Debug.Log("Waiting to fire Button3");
                        return(new InputEvents(true));
                    }
                    break;

                case ButtonPress.Button4:
                    if (bestMove == "Button4")
                    {
                        //StartCoroutine(Wait(0.05F));
                        //Debug.Log("Waiting to fire Button4");
                        return(new InputEvents(true));
                    }
                    break;

                default:
                    //Debug.Log("Waiting to fire Button ERR");
                    return(new InputEvents(true));
                }
            }
        }
        return(InputEvents.Default);
    }