Exemple #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();
    }
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        float p1VerticalAxis = p1InputController.GetAxisRaw(p1InputController.horizontalAxis);
        bool  p1AxisDown     = p1InputController.GetButtonDown(p1InputController.horizontalAxis);

        float p2VerticalAxis = p2InputController.GetAxisRaw(p2InputController.horizontalAxis);
        bool  p2AxisDown     = p2InputController.GetButtonDown(p2InputController.horizontalAxis);


        if (p1AxisDown)
        {
            if (p1VerticalAxis > 0f)
            {
                this.PreviousStage();
            }
            else if (p1VerticalAxis < 0f)
            {
                this.NextStage();
            }
        }

        if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            this.TrySelectStage();
        }
        else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            this.TryDeselectStage();
        }

        if (p2AxisDown)
        {
            if (p2VerticalAxis > 0f)
            {
                this.PreviousStage();
            }
            else if (p2VerticalAxis < 0f)
            {
                this.NextStage();
            }
        }

        if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            this.TrySelectStage();
        }
        else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            this.TryDeselectStage();
        }
    }
    // Output the blackboard as a string
    public IEnumerator BlackBoardLog(string player)
    {
        bool ai = false;

        // Check if player is AI
        if (player == Constants.p1Key)
        {
            UFEController p1Control = UFE.GetPlayer1Controller();
            if (p1Control.isCPU)
            {
                ai = true;
            }
        }
        if (player == Constants.p2Key)
        {
            UFEController p2Control = UFE.GetPlayer2Controller();
            if (p2Control.isCPU)
            {
                ai = true;
            }
        }

        // Record data for this player
        // Append _AI to all AI players
        KeyData data;

        if (ai)
        {
            data = new KeyData(UFE.GetTimer(), "BlackBoard Update", (flags[player][Constants.playerName] == "" ? player + "_AI" : flags[player][Constants.playerName] + "_AI"), BlackBoardToString());
        }
        else
        {
            data = new KeyData(UFE.GetTimer(), "BlackBoard Update", (flags[player][Constants.playerName] == "" ? player : flags[player][Constants.playerName]), BlackBoardToString());
        }

        string write_to = Constants.addLogUrl + data.AsUrlParams() + "&hash=" + data.Md5Sum(Constants.notSoSecretKey);

        //Debug.Log("Write to: " + write_to);
        // Enqueue for POSTing to server

        if (player == Constants.p1Key)
        {
            PostDataToServer.postQueueP1.Add(new WWW(write_to));
        }
        else if (player == Constants.p2Key)
        {
            PostDataToServer.postQueueP2.Add(new WWW(write_to));
        }
        else
        {
            Debug.Log("Error: 3 Players");
        }
        yield return(null);
    }
    public override void DoFixedUpdate()
    {
        // First, check if the network connection is working and
        // both players have entered their input for the current frame...
        if (this.inputReferences != null && UFE.GetPlayer1Controller().isReady&& UFE.GetPlayer2Controller().isReady)
        {
            // In that case, check if we have selected a menu option using the mouse instead of button-presses...
            int?oldSelection = this.optionSelections[this.currentFrameOffset - 1];
            int?newSelection = this.optionSelections[this.currentFrameOffset];

            if (oldSelection == null && newSelection != null)
            {
                this.SelectOption(newSelection.Value);
            }

            // Finally, remove the obsolete information from the buffer
            while (this.currentFrameOffset > 1)
            {
                ++this.currentFrame;
                this.inputBuffer.RemoveAt(0);
                this.optionSelections.RemoveAt(0);
            }
        }
    }
Exemple #5
0
    public void DoFixedUpdate()
    {
        if (isHit > 0)
        {
            isHit -= Time.fixedDeltaTime;
            return;
        }

        // Check if both controllers are ready
        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        if (p1InputController == null || !p1InputController.isReady || p2InputController == null || !p2InputController.isReady)
        {
            return;
        }

        if (UFE.freeCamera)
        {
            return;
        }

        transform.position += (movement * Time.fixedDeltaTime);

        hurtBox.position = gameObject.transform.position;
        if (projectileRenderer != null && (hurtBox.followXBounds || hurtBox.followYBounds))
        {
            hurtBox.rendererBounds = GetBounds();
            hitBox.rendererBounds  = GetBounds();
        }

        blockableArea.position = transform.position;
        if (!opControlsScript.isBlocking &&
            !opControlsScript.blockStunned &&
            opControlsScript.currentSubState != SubStates.Stunned &&
            opHitBoxesScript.TestCollision(blockableArea) != Vector3.zero)
        {
            opControlsScript.CheckBlocking(true);
        }

        if (data.projectileCollision)
        {
            if (opControlsScript.projectiles.Count > 0)
            {
                foreach (ProjectileMoveScript projectile in opControlsScript.projectiles)
                {
                    if (projectile == null)
                    {
                        continue;
                    }
                    if (projectile.hitBox == null)
                    {
                        continue;
                    }
                    if (projectile.hurtBox == null)
                    {
                        continue;
                    }

                    if (HitBoxesScript.TestCollision(new HitBox[] { projectile.hitBox }, new HurtBox[] { hurtBox }, HitConfirmType.Hit, mirror) != Vector3.zero)
                    {
                        if (data.impactPrefab != null)
                        {
                            GameObject hitEffect = (GameObject)Instantiate(data.impactPrefab, transform.position, Quaternion.Euler(0, 0, data.directionAngle));
                            UFE.DelaySynchronizedAction(delegate(){ try{ Destroy(hitEffect); }catch {} }, data.impactDuration);
                        }
                        totalHits--;
                        if (totalHits <= 0)
                        {
                            destroyMe = true;
                        }
                        isHit = spaceBetweenHits;
                        transform.Translate(movement * -1 * Time.fixedDeltaTime);
                        break;
                    }
                }
            }
        }

        if (opHitBoxesScript.TestCollision(new HurtBox[] { hurtBox }, HitConfirmType.Hit) != Vector3.zero &&
            opControlsScript.ValidateHit(hit))
        {
            if (data.impactPrefab != null)
            {
                GameObject hitEffect = (GameObject)Instantiate(data.impactPrefab, transform.position, Quaternion.Euler(0, 0, data.directionAngle));
                UFE.DelaySynchronizedAction(delegate(){ try{ Destroy(hitEffect); }catch {} }, data.impactDuration);
            }
            totalHits--;
            if (totalHits <= 0)
            {
                UFE.DelaySynchronizedAction(delegate(){ try{ Destroy(gameObject); }catch {} }, (float)(2 / UFE.config.fps));
            }


            if (opControlsScript.currentSubState != SubStates.Stunned && opControlsScript.isBlocking && opControlsScript.TestBlockStances(hit.hitType))
            {
                myControlsScript.AddGauge(data.gaugeGainOnBlock);
                opControlsScript.AddGauge(data.opGaugeGainOnBlock);
                opControlsScript.GetHitBlocking(hit, 20, transform.position);

                if (data.moveLinkOnBlock != null)
                {
                    myControlsScript.CastMove(data.moveLinkOnBlock, true, data.forceGrounded);
                }
            }
            else if (opControlsScript.potentialParry > 0 && opControlsScript.TestParryStances(hit.hitType))
            {
                opControlsScript.AddGauge(data.opGaugeGainOnParry);
                opControlsScript.GetHitParry(hit, 20, transform.position);

                if (data.moveLinkOnParry != null)
                {
                    myControlsScript.CastMove(data.moveLinkOnParry, true, data.forceGrounded);
                }
            }
            else
            {
                myControlsScript.AddGauge(data.gaugeGainOnHit);
                opControlsScript.AddGauge(data.opGaugeGainOnHit);
                opControlsScript.GetHit(hit, 30, Vector3.zero);

                if (data.moveLinkOnStrike != null)
                {
                    myControlsScript.CastMove(data.moveLinkOnStrike, true, data.forceGrounded);
                }
            }

            isHit = opControlsScript.GetHitFreezingTime(data.hitStrength) * 1.2f;
            opControlsScript.CheckBlocking(false);
        }
    }
Exemple #6
0
    public static void DefaultNavigationSystem(
        this UFEScreen screen,
        AudioClip selectSound     = null,
        AudioClip moveCursorSound = null,
        Action cancelAction       = null,
        AudioClip cancelSound     = null
        )
    {
        // Retrieve the controller assigned to each player
        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        float p1HorizontalAxis = p1InputController.GetAxisRaw(p1InputController.horizontalAxis);
        float p1VerticalAxis   = p1InputController.GetAxisRaw(p1InputController.verticalAxis);
        bool  p1AxisDown       =
            p1InputController.GetButtonDown(p1InputController.horizontalAxis) ||
            p1InputController.GetButtonDown(p1InputController.verticalAxis);

        float p2HorizontalAxis = p2InputController.GetAxisRaw(p2InputController.horizontalAxis);
        float p2VerticalAxis   = p2InputController.GetAxisRaw(p2InputController.verticalAxis);
        bool  p2AxisDown       =
            p2InputController.GetButtonDown(p2InputController.horizontalAxis) ||
            p2InputController.GetButtonDown(p2InputController.verticalAxis);

        // Check if we should change the selected option
        if (p1AxisDown)
        {
            screen.MoveCursor(new Vector3(p1HorizontalAxis, p1VerticalAxis), moveCursorSound);
        }

        if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            screen.SelectOption(selectSound);
        }
        else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            if (cancelSound != null)
            {
                UFE.PlaySound(cancelSound);
            }
            if (cancelAction != null)
            {
                cancelAction();
            }
        }
        else
        {
            if (p2AxisDown)
            {
                screen.MoveCursor(new Vector3(p2HorizontalAxis, p2VerticalAxis), moveCursorSound);
            }

            if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                screen.SelectOption(selectSound);
            }
            else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                if (cancelSound != null)
                {
                    UFE.PlaySound(cancelSound);
                }
                if (cancelAction != null)
                {
                    cancelAction();
                }
            }
        }
    }
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        if (this.isRunning)
        {
            AbstractInputController p1InputController = UFE.GetPlayer1Controller();
            AbstractInputController p2InputController = UFE.GetPlayer2Controller();
            float deltaTime = Time.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.config.player1Character.currentLifePoints)
            {
                this.player1.targetLife -= this.lifeDownSpeed * deltaTime;
                if (this.player1.targetLife < UFE.config.player1Character.currentLifePoints)
                {
                    this.player1.targetLife = UFE.config.player1Character.currentLifePoints;
                }
            }
            if (this.player1.targetLife < UFE.config.player1Character.currentLifePoints)
            {
                this.player1.targetLife += this.lifeUpSpeed * deltaTime;
                if (this.player1.targetLife > UFE.config.player1Character.currentLifePoints)
                {
                    this.player1.targetLife = UFE.config.player1Character.currentLifePoints;
                }
            }

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


            if (
                // Check if both players have their life points above zero...
                UFE.config.player1Character.currentLifePoints > 0 &&
                UFE.config.player2Character.currentLifePoints > 0 &&
                UFE.gameMode != GameMode.NetworkGame &&
                (
                    // and at least one of the players have pressed the Start button...
                    p1InputController != null && p1InputController.GetButtonDown(ButtonPress.Start) ||
                    p2InputController != null && p2InputController.GetButtonDown(ButtonPress.Start)
                )
                )
            {
                // 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)
            {
                if (this.player1GUI != null && this.player1GUI.gaugeMeter != null)
                {
                    this.player1GUI.gaugeMeter.fillAmount = UFE.config.player1Character.currentGaugePoints / UFE.config.player1Character.maxGaugePoints;
                }

                if (this.player2GUI != null && this.player2GUI.gaugeMeter != null)
                {
                    this.player2GUI.gaugeMeter.fillAmount = UFE.config.player2Character.currentGaugePoints / UFE.config.player2Character.maxGaugePoints;
                }
            }

            if (this.pause != null)
            {
                this.pause.DoFixedUpdate();
            }


            /*
             * 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
             *      );
             * }
             */
        }
    }
    public override void DoUpdate()
    {
        if (UFE.synchronizedRandomSeed)
        {
            int frameDelayOffset = (this.frameDelay >= 0 ? this.frameDelay : this.CalculateFrameDelay()) + 2;
            this.synchronizingRandomSeed = false;

            if (
                this.inputReferences != null &&
                UFE.isConnected &&
                (
                    this.currentFrameOffset < 2
                    ||
                    this.inputBuffer.Count < frameDelayOffset
                    ||
                    this.fixedUpdatesSinceLastUpdate > 0 &&
                    UFE.GetPlayer1Controller().isReady&&
                    UFE.GetPlayer2Controller().isReady
                )
                )
            {
                //-----------------------------------------------------------------------------------------------------
                // In that case, read the player input
                //-----------------------------------------------------------------------------------------------------
                this.currentFrameInputs.Clear();
                base.DoUpdate();

                foreach (InputReferences input in this.inputReferences)
                {
                    if (this.cpuController != null && this.isCPU && UFE.gameRunning && !UFE.isPaused())
                    {
                        this.currentFrameInputs[input] = this.cpuController.ReadInput(input);
                    }
                    else if (this.humanController != null)
                    {
                        this.currentFrameInputs[input] = this.humanController.ReadInput(input);
                    }
                    else
                    {
                        this.currentFrameInputs[input] = InputEvents.Default;
                    }
                }

                //-----------------------------------------------------------------------------------------------------
                // Calculate the start and the end frame where the current input should be copied.
                //-----------------------------------------------------------------------------------------------------
                int targetFrame = (int)(this.currentFrameOffset) + frameDelayOffset;
                if (this.inputBuffer.Count < targetFrame)
                {
                    //-------------------------------------------------------------------------------------------------
                    // Check if there are some "empty slots" between the current frame and the target frame
                    // and fill those "slots" with the "Default Input Event".
                    //-------------------------------------------------------------------------------------------------
                    while (this.inputBuffer.Count + this.fixedUpdatesSinceLastUpdate < targetFrame - 1)
                    {
//						Debug.Log(
//							UFE.currentNetworkFrame + " >>> " +
//							this.inputBuffer.Count + " + " +
//							this.fixedUpdatesSinceLastUpdate + " < " +
//							(targetFrame - 1)
//						);

                        int?previousOption = this.optionSelections[this.optionSelections.Count - 1];
                        Dictionary <InputReferences, InputEvents> previous = this.inputBuffer[this.inputBuffer.Count - 1];
                        Dictionary <InputReferences, InputEvents> current  = new Dictionary <InputReferences, InputEvents>();

                        foreach (InputReferences input in this.inputReferences)
                        {
                            current[input] = new InputEvents(previous[input]);
                        }

                        this.inputBuffer.Add(previous);
                        this.optionSelections.Add(previousOption != null ? new int?(previousOption.Value) : null);
                    }

                    //-------------------------------------------------------------------------------------------------
                    // Read the input for the target frames, checking if we have already entered the input
                    // for those frames (for example: if the game is paused waiting for the other player).
                    //-------------------------------------------------------------------------------------------------
                    for (int i = 0; i < this.fixedUpdatesSinceLastUpdate; ++i)
                    {
                        Dictionary <InputReferences, InputEvents> dict = new Dictionary <InputReferences, InputEvents>();
                        foreach (InputReferences input in this.inputReferences)
                        {
                            dict[input] = this.currentFrameInputs[input];
                        }

                        this.inputBuffer.Add(dict);
                        this.optionSelections.Add(this.requestedOption);
                        this.requestedOption = null;
                    }
                }
            }

            //---------------------------------------------------------------------------------------------------------
            // It doesn't matter whether we have read the inputs for a new frame or not, if we haven't lose the
            // connection, we send (or resend) the input buffer to the other player every frame
            //---------------------------------------------------------------------------------------------------------
            if (UFE.isConnected)
            {
                this.SendNetworkPackage();
            }

            //-------------------------------------------------------------------------------------------------------------
            // Finally, start counting the number of FixedUpdate() calls before the next Update() call.
            //-------------------------------------------------------------------------------------------------------------
            this.fixedUpdatesSinceLastUpdate = 0;
        }
        else if (!this.synchronizingRandomSeed && this.player == 1)
        {
            // If the random seed hasn't been synchronized and the local player is the host of the game
            this.synchronizingRandomSeed = true;
            int randomSeed = (int)DateTime.UtcNow.Ticks;

            if (UFE.config.networkOptions.fakeNetwork)
            {
                UFE.SetSynchronizedRandomSeed(randomSeed);
            }
            else
            {
                UFE.multiplayerAPI.SendNetworkMessage(
                    new RandomSeedSynchronizationMessage(this.player, this.currentFrame, randomSeed)
                    );
            }
        }
    }
Exemple #9
0
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        bool p1AxisDown =
            p1InputController.GetButtonDown(p1InputController.horizontalAxis) ||
            p1InputController.GetButtonDown(p1InputController.verticalAxis);

        bool p2AxisDown =
            p2InputController.GetButtonDown(p2InputController.horizontalAxis) ||
            p2InputController.GetButtonDown(p2InputController.verticalAxis);

        // Process the player input...
        if (UFE.gameMode != GameMode.StoryMode && !UFE.GetCPU(2))
        {
            // If we are in "Story Mode" or in "Player vs Player (versus mode)", the controller assigned to
            // the first player will be used always for selecting the character assigned to that player. If
            // that player has already selected a character, he can't move the cursor unless he deselects
            // the character first.
            if (p1AxisDown)
            {
                this.MoveCursor(p1InputController, 1);
            }

            if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.TrySelectCharacter(this.p1HoverIndex, 1);
            }
            else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                this.TryDeselectCharacter(1);
            }

            // The controller assigned to the second player only can be used for selecting the character assigned to
            // the second player in "Player vs Player (versus mode)". In other game modes, the character assigned to
            // the second player will be chosen randomly (Story Mode) or will be selected by Player 1 (Player vs CPU).
            if (p2AxisDown)
            {
                this.MoveCursor(p2InputController, 2);
            }

            if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.TrySelectCharacter(this.p2HoverIndex, 2);
            }
            else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                this.TryDeselectCharacter(2);
            }
        }
        else
        {
            // However, the character assigned to the second player will be chosen by the first player in other
            // game modes (for example: Player vs CPU).
            if (p1AxisDown)
            {
                this.MoveCursor(p1InputController);
            }

            if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.TrySelectCharacter();
            }
            else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                this.TryDeselectCharacter();
            }
        }
    }
Exemple #10
0
    void OnMove(MoveInfo move, CharacterInfo player)
    {
        // Record the button that was pressed and the time it was pressed
        //Debug.Log("[" + Time.time + "] Player " + player.GetInstanceID() + " inputted " + (int)move.buttonExecution[0]);

        // New values
        Dictionary <string, string> p1Changes = new Dictionary <string, string>(),
                                    p2Changes = new Dictionary <string, string>();

        // Record move information
        if (player.GetInstanceID() == p1.GetInstanceID())
        {
            if (move.moveName != Constants.EVADE)
            {
                //bb.UpdateProperty(Constants.p1Key, Constants.lastAttackByPlayer, move.moveName);
                //bb.UpdateProperty(Constants.p2Key, Constants.lastAttackByOpponent, move.moveName);
                p1Changes.Add(Constants.lastAttackByPlayer, move.moveName);
                p2Changes.Add(Constants.lastAttackByOpponent, move.moveName);

                // This is an attack
                //bb.UpdateProperty(Constants.p1Key, Surprise.attackCount, (int.Parse(bb.GetProperties(Constants.p1Key)[Surprise.attackCount]) + 1).ToString());
                p1Changes.Add(Surprise.attackCount, (int.Parse(bb.GetProperties(Constants.p1Key)[Surprise.attackCount]) + 1).ToString());

                // Wait to see if it missed
                AttackMissed(move, player);
            }
            else
            {
                //bb.UpdateProperty(Constants.p1Key, Constants.lastEvade, Constants.TRUE);
                p1Changes.Add(Constants.lastEvade, Constants.TRUE);

                // This is an evade
                //bb.UpdateProperty(Constants.p1Key, Surprise.evadeCount, (int.Parse(bb.GetProperties(Constants.p1Key)[Surprise.evadeCount]) + 1).ToString());
                p1Changes.Add(Surprise.evadeCount, (int.Parse(bb.GetProperties(Constants.p1Key)[Surprise.evadeCount]) + 1).ToString());
            }

            // Update distance
            //bb.UpdateProperty(Constants.p1Key, Constants.distToOpponent, Vector3.Distance(UFE.GetPlayer1Controller().transform.position, UFE.GetPlayer2Controller().transform.position).ToString());
        }
        else
        {
            if (move.moveName != Constants.EVADE)
            {
                //bb.UpdateProperty(Constants.p2Key, Constants.lastAttackByPlayer, move.moveName);
                //bb.UpdateProperty(Constants.p1Key, Constants.lastAttackByOpponent, move.moveName);
                p2Changes.Add(Constants.lastAttackByPlayer, move.moveName);
                p1Changes.Add(Constants.lastAttackByOpponent, move.moveName);

                // This is an attack
                //bb.UpdateProperty(Constants.p2Key, Surprise.attackCount, (int.Parse(bb.GetProperties(Constants.p2Key)[Surprise.attackCount]) + 1).ToString());
                p2Changes.Add(Surprise.attackCount, (int.Parse(bb.GetProperties(Constants.p2Key)[Surprise.attackCount]) + 1).ToString());

                // Wait to see if it missed
                AttackMissed(move, player);
            }
            else
            {
                //bb.UpdateProperty(Constants.p2Key, Constants.lastEvade, Constants.TRUE);
                p2Changes.Add(Constants.lastEvade, Constants.TRUE);

                // This is an evade
                //bb.UpdateProperty(Constants.p2Key, Surprise.evadeCount, (int.Parse(bb.GetProperties(Constants.p2Key)[Surprise.evadeCount]) + 1).ToString());
                p2Changes.Add(Surprise.evadeCount, (int.Parse(bb.GetProperties(Constants.p2Key)[Surprise.evadeCount]) + 1).ToString());
            }

            // Update distance
            //bb.UpdateProperty(Constants.p2Key, Constants.distToOpponent, Vector3.Distance(UFE.GetPlayer1Controller().transform.position, UFE.GetPlayer2Controller().transform.position).ToString());
        }

        // Update distances
        p1Changes.Add(Constants.distToOpponent, Vector3.Distance(UFE.GetPlayer1Controller().transform.position, UFE.GetPlayer2Controller().transform.position).ToString());
        p2Changes.Add(Constants.distToOpponent, Vector3.Distance(UFE.GetPlayer1Controller().transform.position, UFE.GetPlayer2Controller().transform.position).ToString());

        // Save the state of the BlackBoard
        //Debug.Log("Saved BlackBoard state");
        bb.UpdateProperties(Constants.p1Key, p1Changes);
        bb.UpdateProperties(Constants.p2Key, p2Changes);
    }
Exemple #11
0
    /* UFE events
     */
    void OnInput(InputReferences[] inputReferences, int player)
    {
        foreach (InputReferences inRef in inputReferences)
        {
            StartCoroutine(InputLog(inRef.engineRelatedButton.ToString(), (player == 1 ? GameObject.Find("Name").GetComponent <NameHolder>().username : Constants.p2Key) + (player == 1 && UFE.GetPlayer1Controller().isCPU || player == 2 && UFE.GetPlayer2Controller().isCPU ? "_AI" : "")));
            //Debug.Log(inRef.engineRelatedButton.ToString() + " by Player " + player);

            // Record move distribution
            if (distr.Increment(Constants.ToMove(inRef.engineRelatedButton)))
            {
                // Reloads the distribution graph on valid changes
                distr.Visualize();
            }
        }
    }
Exemple #12
0
    // Happens every round
    public void OnRoundBegins(int roundNumber)
    {
        // Reset the BlackBoard to clear out information from the previous round
        bb.ClearBlackBoard();

        // Reset Distribution if enabled
        distr.ResetCount();

        // Set diagnostics on battle screen
        GameObject nameObj = GameObject.Find("Name");

        if (nameObj != null)
        {
            NameHolder name = nameObj.GetComponent <NameHolder>();
            if (name != null)
            {
                name.setRoundStarted(true);
            }
        }

        // Add information about each player to Blackboard
        bb.Register(Constants.p1Key, new Dictionary <string, string>()
        {
            // Who am I?
            { Constants.playerName, "" },

            // Passives
            { Constants.indexLifePoints, p1.currentLifePoints.ToString() },
            { Constants.indexFavor, Constants.MIN_FAVOR.ToString() },
            { Constants.indexRally, Constants.MIN_RALLY.ToString() },
            { Constants.indexBalance, Constants.STARTING_BALANCE.ToString() },

            // Extra data for conditioning on moves
            { Constants.lastHitDamage, "0" },
            { Constants.lastAttackByPlayer, "" },
            { Constants.landedLastAttack, "" },
            { Constants.lastEvade, "" },
            { Constants.lastEvadeSuccessful, "" },
            { Constants.lastAttackByOpponent, "" },
            { Constants.opponentLandedLastAttack, "" },

            // Extra data for skill tree nodes

            // Surprise
            { Surprise.attackCount, "0" },
            { Surprise.evadeCount, "0" },

            // Distance to opponent
            { Constants.distToOpponent, Vector3.Distance(UFE.GetPlayer1Controller().transform.position, UFE.GetPlayer2Controller().transform.position).ToString() },

            // Match results
            { Constants.winner, "false" }
        });
        bb.Register(Constants.p2Key, new Dictionary <string, string>()
        {
            // Who am I?
            { Constants.playerName, "" },

            // Passives
            { Constants.indexLifePoints, p2.currentLifePoints.ToString() },
            { Constants.indexFavor, Constants.MIN_FAVOR.ToString() },
            { Constants.indexRally, Constants.MIN_RALLY.ToString() },
            { Constants.indexBalance, Constants.STARTING_BALANCE.ToString() },

            // Extra data for conditioning on moves
            { Constants.lastHitDamage, "0" },
            { Constants.lastAttackByPlayer, "" },
            { Constants.landedLastAttack, "" },
            { Constants.lastEvade, "" },
            { Constants.lastEvadeSuccessful, "" },
            { Constants.lastAttackByOpponent, "" },
            { Constants.opponentLandedLastAttack, "" },

            // Extra data for skill tree nodes

            // Surprise
            { Surprise.attackCount, "0" },
            { Surprise.evadeCount, "0" },

            // Distance to opponent
            { Constants.distToOpponent, Vector3.Distance(UFE.GetPlayer1Controller().transform.position, UFE.GetPlayer2Controller().transform.position).ToString() },

            // Match results
            { Constants.winner, "false" }
        });

        // Save BlackBoard state
        if (Network.peerType == NetworkPeerType.Disconnected)
        {
            bb.UpdateProperty(Constants.p1Key, Constants.playerName, GameObject.Find("Name").GetComponent <NameHolder>().username);
            bb.DumpBlackBoard(Constants.p2Key);
        }
        else
        {
            if (UFE.GetLocalPlayer() == 1)
            {
                bb.UpdateProperty(Constants.p1Key, Constants.playerName, GameObject.Find("Name").GetComponent <NameHolder>().username);
            }
            else
            {
                bb.UpdateProperty(Constants.p2Key, Constants.playerName, GameObject.Find("Name").GetComponent <NameHolder>().username);
            }
        }
    }
Exemple #13
0
    public override void DoFixedUpdate()
    {
        base.DoFixedUpdate();

        // Retrieve the controller assigned to each player
        AbstractInputController p1InputController = UFE.GetPlayer1Controller();
        AbstractInputController p2InputController = UFE.GetPlayer2Controller();

        // Retrieve the values of the horizontal and vertical axis
        float p1HorizontalAxis     = p1InputController.GetAxisRaw(p1InputController.horizontalAxis);
        float p1VerticalAxis       = p1InputController.GetAxisRaw(p1InputController.verticalAxis);
        bool  p1HorizontalAxisDown = p1InputController.GetButtonDown(p1InputController.horizontalAxis);
        bool  p1VerticalAxisDown   = p1InputController.GetButtonDown(p1InputController.verticalAxis);

        float p2HorizontalAxis     = p2InputController.GetAxisRaw(p2InputController.horizontalAxis);
        float p2VerticalAxis       = p2InputController.GetAxisRaw(p2InputController.verticalAxis);
        bool  p2HorizontalAxisDown = p2InputController.GetButtonDown(p2InputController.horizontalAxis);
        bool  p2VerticalAxisDown   = p2InputController.GetButtonDown(p2InputController.verticalAxis);

        // Check if we should change the selected option
        if (p1HorizontalAxisDown)
        {
            GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
            Slider     slider            = null;

            if (currentGameObject != null)
            {
                slider = currentGameObject.GetComponent <Slider>();
            }

            if (slider != null)
            {
                if (slider.wholeNumbers)
                {
                    slider.value += Mathf.Sign(p1HorizontalAxis);
                }
                else
                {
                    slider.value += Mathf.Sign(p1HorizontalAxis) * this.sliderSpeed;
                }
            }
            else if (p1VerticalAxisDown)
            {
                this.MoveCursor(new Vector3(p1HorizontalAxis, p1VerticalAxis), this.moveCursorSound);
            }
            else
            {
                this.MoveCursor(new Vector3(p1HorizontalAxis, 0f), this.moveCursorSound);
            }
        }
        else if (p1VerticalAxisDown)
        {
            this.MoveCursor(new Vector3(0f, p1VerticalAxis), this.moveCursorSound);
        }

        if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
        {
            this.SelectOption(this.selectSound);
        }
        else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
        {
            if (this.cancelSound != null)
            {
                UFE.PlaySound(cancelSound);
            }
            if (this.cancelButton != null && this.cancelButton.onClick != null)
            {
                this.cancelButton.onClick.Invoke();
            }
        }
        else
        {
            if (p2HorizontalAxisDown)
            {
                GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject;
                Slider     slider            = null;

                if (currentGameObject != null)
                {
                    slider = currentGameObject.GetComponent <Slider>();
                }

                if (slider != null)
                {
                    if (slider.wholeNumbers)
                    {
                        slider.value += Mathf.Sign(p2HorizontalAxis);
                    }
                    else
                    {
                        slider.value += Mathf.Sign(p2HorizontalAxis) * this.sliderSpeed;
                    }
                }
                else if (p2VerticalAxisDown)
                {
                    this.MoveCursor(new Vector3(p2HorizontalAxis, p2VerticalAxis), this.moveCursorSound);
                }
                else
                {
                    this.MoveCursor(new Vector3(p2HorizontalAxis, 0f), this.moveCursorSound);
                }
            }
            else if (p2VerticalAxisDown)
            {
                this.MoveCursor(new Vector3(0f, p2VerticalAxis), this.moveCursorSound);
            }

            if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton))
            {
                this.SelectOption(this.selectSound);
            }
            else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton))
            {
                if (this.cancelSound != null)
                {
                    UFE.PlaySound(cancelSound);
                }
                if (this.cancelButton != null && this.cancelButton.onClick != null)
                {
                    this.cancelButton.onClick.Invoke();
                }
            }
        }
    }