Example #1
0
    public override void DoFixedUpdate()
    {
        //-------------------------------------------------------------------------------------------------------------
        // First, store the player positions at the current frame (if they aren't already stored)
        // because we will use them later for synchronization purpose
        //-------------------------------------------------------------------------------------------------------------
        if (this.inputReferences != null && UFE.GetPlayer1Controller().isReady&& UFE.GetPlayer2Controller().isReady)
        {
            ControlsScript p1 = UFE.GetPlayer1ControlsScript();
            ControlsScript p2 = UFE.GetPlayer2ControlsScript();

            if (
                p1 != null &&
                p2 != null &&
                //UFE.currentNetworkFrame % 100 == 0 &&
                !this.gameState.ContainsKey(UFE.currentNetworkFrame)
                )
            {
                //-----------------------------------------------------------------------------------------------------
                // Send a synchronization message every few frames
                //-----------------------------------------------------------------------------------------------------
                GameState state = new GameState(p1.transform.position, p2.transform.position);
                this.gameState[UFE.currentNetworkFrame] = state;
                UFE.multiplayerAPI.SendNetworkMessage(new SynchronizationMessage(this.player, UFE.currentNetworkFrame, state));
                //Debug.LogWarning("Store State: " + state + "\t(Frame = " + UFE.currentNetworkFrame + ")");
            }
        }

        //-------------------------------------------------------------------------------------------------------------
        // Execute the parent's method
        //-------------------------------------------------------------------------------------------------------------
        base.DoFixedUpdate();
    }
Example #2
0
    /* What does this skill do?
     *
     * Passive effect: Stack rally
     * Active effect:
     *      Evade: Move through and behind opponent
     *      Everything else: iframes during move
     */
    public override Modifier Resolve(SkillTree move, MoveInfo ufeMove, bool p1UsedMove, bool passive)
    {
        Modifier mod = new Modifier();

        if (passive)
        {
            // As damage increases, stack more rally
            // Rally calculation: deltaR = (|p1.currentLifePoints - p2.currentLifePoints| / p1.lifePoints) * .5f * move.hits[0].damageOnHit
            float deltaR = 0.0f;
            if (p1UsedMove && move.players[0].currentLifePoints > move.players[1].currentLifePoints)
            {
                // P1 has a health advantage and just landed an attack
                // P2 rallies in response
                deltaR = (0.5f * ufeMove.hits[0].damageOnHit * Mathf.Abs(move.players[0].currentLifePoints - move.players[1].currentLifePoints)) / move.players[0].lifePoints;
                rallyScript.PassiveEffect(deltaR, Constants.p2Key);
            }
            else if (!p1UsedMove && move.players[1].currentLifePoints > move.players[0].currentLifePoints)
            {
                // P2 has a health advantage and just landed an attack
                // P1 rallies in response
                deltaR = (0.5f * ufeMove.hits[0].damageOnHit * Mathf.Abs(move.players[1].currentLifePoints - move.players[0].currentLifePoints)) / move.players[0].lifePoints;
                rallyScript.PassiveEffect(deltaR, Constants.p1Key);
            }
        }
        else
        {
            // Do something depending on the move that called it
            switch (move.move)
            {
            case Constants.BASIC:
            case Constants.STRONG:
            case Constants.GRAB:
                break;

            case Constants.EVADE:
                Dictionary <string, string> atLeast = new Dictionary <string, string>()
                {
                    { Constants.indexRally, evadePenalty.ToString() }
                };

                if (Vector3.Distance(UFE.GetPlayer1ControlsScript().transform.position, UFE.GetPlayer2ControlsScript().transform.position) <= triggerDist)
                {
                    if (p1UsedMove && UFE.GetPlayer1().currentLifePoints < UFE.GetPlayer2().currentLifePoints)
                    {
                        if (rallyScript.VerifyActiveEffect(atLeast, null, null, Constants.p1Key))
                        {
                            mod = new Modifier(0, 0, 0, "Maneuver");

                            // Update BlackBoard with penalty
                            rallyScript.PassiveEffect(-1.0f * evadePenalty, (p1UsedMove ? Constants.p1Key : Constants.p2Key));
                        }
                    }
                    else if (!p1UsedMove && UFE.GetPlayer2().currentLifePoints < UFE.GetPlayer1().currentLifePoints)
                    {
                        if (rallyScript.VerifyActiveEffect(atLeast, null, null, Constants.p2Key))
                        {
                            mod = new Modifier(0, 0, 0, "Maneuver");

                            // Update BlackBoard with penalty
                            rallyScript.PassiveEffect(-1.0f * evadePenalty, Constants.p2Key);
                        }
                    }
                }

                break;

            default:
                break;
            }
        }

        return(mod);
    }
    protected override void OnNewAlert(string msg, 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 == this.player1.character)
        {
            ControlsScript controlsScript   = UFE.GetPlayer1ControlsScript();
            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 if (player == this.player2.character)
        {
            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.fight)
                {
                    this.mainAlertTimer = 1f;
                }
                else if (msg == UFE.config.selectedLanguage.ko)
                {
                    this.mainAlertTimer = 2f;
                }
                else
                {
                    this.mainAlertTimer = 60f;
                }
            }
        }
    }
Example #4
0
    public override void DoFixedUpdate(
        IDictionary <InputReferences, InputEvents> player1PreviousInputs,
        IDictionary <InputReferences, InputEvents> player1CurrentInputs,
        IDictionary <InputReferences, InputEvents> player2PreviousInputs,
        IDictionary <InputReferences, InputEvents> player2CurrentInputs
        )
    {
        base.DoFixedUpdate(player1PreviousInputs, player1CurrentInputs, player2PreviousInputs, player2CurrentInputs);

        if (this.isRunning)
        {
            float deltaTime = (float)UFE.fixedDeltaTime;

            // Animate the alert messages if they exist
            if (this.player1GUI != null && this.player1GUI.alert != null && this.player1GUI.alert.text != null)
            {
                this.player1GUI.alert.text.rectTransform.anchoredPosition = Vector3.Lerp(
                    this.player1GUI.alert.text.rectTransform.anchoredPosition,
                    this.player1GUI.alert.finalPosition,
                    this.player1GUI.alert.movementSpeed * deltaTime
                    );

                if (this.player1AlertTimer > 0f)
                {
                    this.player1AlertTimer -= deltaTime;
                }
                else if (!string.IsNullOrEmpty(this.player1GUI.alert.text.text))
                {
                    this.player1GUI.alert.text.text = string.Empty;
                }
            }

            if (this.player2GUI != null && this.player2GUI.alert != null && this.player2GUI.alert.text != null)
            {
                this.player2GUI.alert.text.rectTransform.anchoredPosition = Vector3.Lerp(
                    this.player2GUI.alert.text.rectTransform.anchoredPosition,
                    this.player2GUI.alert.finalPosition,
                    this.player2GUI.alert.movementSpeed * deltaTime
                    );

                if (this.player2AlertTimer > 0f)
                {
                    this.player2AlertTimer -= deltaTime;
                }
                else if (!string.IsNullOrEmpty(this.player2GUI.alert.text.text))
                {
                    this.player2GUI.alert.text.text = string.Empty;
                }
            }

            if (this.mainAlert != null && this.mainAlert.text != null)
            {
                if (this.mainAlertTimer > 0f)
                {
                    this.mainAlertTimer -= deltaTime;
                }
                else if (!string.IsNullOrEmpty(this.mainAlert.text.text))
                {
                    this.mainAlert.text.text = string.Empty;
                }
            }


            // Animate life points when it goes down (P1)
            if (this.player1.targetLife > UFE.GetPlayer1ControlsScript().currentLifePoints)
            {
                this.player1.targetLife -= this.lifeDownSpeed * deltaTime;
                if (this.player1.targetLife < UFE.GetPlayer1ControlsScript().currentLifePoints)
                {
                    this.player1.targetLife = (float)UFE.GetPlayer1ControlsScript().currentLifePoints;
                }
            }
            if (this.player1.targetLife < UFE.GetPlayer1ControlsScript().currentLifePoints)
            {
                this.player1.targetLife += this.lifeUpSpeed * deltaTime;
                if (this.player1.targetLife > UFE.GetPlayer1ControlsScript().currentLifePoints)
                {
                    this.player1.targetLife = (float)UFE.GetPlayer1ControlsScript().currentLifePoints;
                }
            }

            // Animate life points when it goes down (P2)
            if (this.player2.targetLife > UFE.GetPlayer2ControlsScript().currentLifePoints)
            {
                this.player2.targetLife -= this.lifeDownSpeed * deltaTime;
                if (this.player2.targetLife < UFE.GetPlayer2ControlsScript().currentLifePoints)
                {
                    this.player2.targetLife = (float)UFE.GetPlayer2ControlsScript().currentLifePoints;
                }
            }
            if (this.player2.targetLife < UFE.GetPlayer2ControlsScript().currentLifePoints)
            {
                this.player2.targetLife += this.lifeUpSpeed * deltaTime;
                if (this.player2.targetLife > UFE.GetPlayer2ControlsScript().currentLifePoints)
                {
                    this.player2.targetLife = (float)UFE.GetPlayer2ControlsScript().currentLifePoints;
                }
            }


            bool player1CurrentStartButton = false;
            foreach (KeyValuePair <InputReferences, InputEvents> pair in player1CurrentInputs)
            {
                if (pair.Key.inputType == InputType.Button && pair.Key.engineRelatedButton == ButtonPress.Start)
                {
                    player1CurrentStartButton = pair.Value.button;
                    break;
                }
            }

            bool player1PreviousStartButton = false;
            foreach (KeyValuePair <InputReferences, InputEvents> pair in player1PreviousInputs)
            {
                if (pair.Key.inputType == InputType.Button && pair.Key.engineRelatedButton == ButtonPress.Start)
                {
                    player1PreviousStartButton = pair.Value.button;
                    break;
                }
            }

            bool player2CurrentStartButton = false;
            foreach (KeyValuePair <InputReferences, InputEvents> pair in player2CurrentInputs)
            {
                if (pair.Key.inputType == InputType.Button && pair.Key.engineRelatedButton == ButtonPress.Start)
                {
                    player2CurrentStartButton = pair.Value.button;
                    break;
                }
            }

            bool player2PreviousStartButton = false;
            foreach (KeyValuePair <InputReferences, InputEvents> pair in player2PreviousInputs)
            {
                if (pair.Key.inputType == InputType.Button && pair.Key.engineRelatedButton == ButtonPress.Start)
                {
                    player2PreviousStartButton = pair.Value.button;
                    break;
                }
            }

            if (
                // Check if both players have their life points above zero...
                UFE.GetPlayer1ControlsScript().currentLifePoints > 0 &&
                UFE.GetPlayer2ControlsScript().currentLifePoints > 0 &&
                UFE.gameMode != GameMode.NetworkGame &&
                (
                    // and at least one of the players have pressed the Start button...
                    player1CurrentStartButton && !player1PreviousStartButton ||
                    player2CurrentStartButton && !player2PreviousStartButton
                )
                )
            {
                // In that case, we can process pause menu events
                UFE.PauseGame(!UFE.isPaused());
            }


            // Draw the Life Bars and Gauge Meters using the data stored in UFE.config.guiOptions
            if (this.player1GUI != null && this.player1GUI.lifeBar != null)
            {
                this.player1GUI.lifeBar.fillAmount = this.player1.targetLife / this.player1.totalLife;
            }

            if (this.player2GUI != null && this.player2GUI.lifeBar != null)
            {
                this.player2GUI.lifeBar.fillAmount = this.player2.targetLife / this.player2.totalLife;
            }

            if (UFE.config.gameGUI.hasGauge)
            {
                for (int i = 0; i < this.player1GUI.gauges.Length; i++)
                {
                    if (this.player1GUI.gauges[i].gameObject.activeInHierarchy)
                    {
                        this.player1GUI.gauges[i].fillAmount = (float)player1.controlsScript.currentGaugesPoints[i] / UFE.config.player1Character.maxGaugePoints;
                    }
                }
                for (int i = 0; i < this.player2GUI.gauges.Length; i++)
                {
                    if (this.player2GUI.gauges[i].gameObject.activeInHierarchy)
                    {
                        this.player2GUI.gauges[i].fillAmount = (float)player2.controlsScript.currentGaugesPoints[i] / UFE.config.player2Character.maxGaugePoints;
                    }
                }
            }

            if (this.pause != null)
            {
                this.pause.DoFixedUpdate(player1PreviousInputs, player1CurrentInputs, player2PreviousInputs, player2CurrentInputs);
            }


            /*
             * if (Debug.isDebugBuild){
             *      player1NameGO.guiText.text = string.Format(
             *              "{0}\t\t({1},\t{2},\t{3})",
             *              this.player1.characterName,
             *              UFE.GetPlayer1ControlsScript().transform.position.x,
             *              UFE.GetPlayer1ControlsScript().transform.position.y,
             *              UFE.GetPlayer1ControlsScript().transform.position.z
             *      );
             *
             *      player2NameGO.guiText.text = string.Format(
             *              "{0}\t\t({1},\t{2},\t{3})",
             *              this.player2.characterName,
             *              UFE.GetPlayer2ControlsScript().transform.position.x,
             *              UFE.GetPlayer2ControlsScript().transform.position.y,
             *              UFE.GetPlayer2ControlsScript().transform.position.z
             *      );
             * }
             */
        }
    }