Inheritance: MonoBehaviour
コード例 #1
0
    public void Start()
    {
        /*Plane groundPlane = (Plane) GameObject.FindObjectOfType(typeof(Plane));
         * if (groundPlane == null) Debug.LogError("Plane not found. Please add a plane mesh to your stage prefab!");*/

        groundLayer      = LayerMask.NameToLayer("Ground");
        groundMask       = 1 << groundLayer;
        myControlsScript = GetComponent <ControlsScript>();
        character        = myControlsScript.character;
        myHitBoxesScript = character.GetComponent <HitBoxesScript>();
        myMoveSetScript  = character.GetComponent <MoveSetScript>();
        appliedGravity   = myControlsScript.myInfo.physics.weight * UFE.config.gravity;
    }
コード例 #2
0
    public void Generate_Map()
    {
        Cs       = GameObject.Find("Controls").GetComponent <ControlsScript>();
        tribePos = GameObject.Find("Tribe").GetComponent <Transform>();
        TileP    = Resources.Load("Play/Prefabs/Tiles/Tile_Plains") as GameObject;
        TileF    = Resources.Load("Play/Prefabs/Tiles/Tile_Forests") as GameObject;
        Tiles    = new List <List <GameObject> >(SizeX);
        TileMap  = new List <List <TileScript> >(SizeX);
        for (int x = 0; x < SizeX; x++)
        {
            //List<GameObject> temp = new List<GameObject>(SizeY);
            List <TileScript> tempMap = new List <TileScript>(SizeY);
            for (int y = 0; y < SizeY; y++)
            {
                int        first_random = (int)Random.Range(1.0f, 101.0f);
                TileScript tempTile     = new TileScript();
                Vector3    offset       = new Vector3(x * TileSizeX + (y * 2.75f), Cs.GroundPlane, y * TileSizeY);
                if (first_random <= 95)
                {
                    tempTile.type     = "Forest";
                    tempTile.position = offset;
                    tempTile.x        = x;
                    tempTile.y        = y;
                    if ((Camera.main.WorldToViewportPoint(tempTile.position).x > 0) && (Camera.main.WorldToViewportPoint(tempTile.position).x < 1) && (Camera.main.WorldToViewportPoint(tempTile.position).y > 0) && (Camera.main.WorldToViewportPoint(tempTile.position).y < 1))
                    {
                        tempTile.displayed = true;
                        tempTile.Tile      = Instantiate(TileF);
                        tempTile.Tile.GetComponent <Transform>().position = offset;
                    }
                }
                else
                {
                    tempTile.type     = "Plains";
                    tempTile.position = offset;
                    tempTile.x        = x;
                    tempTile.y        = y;
                    if ((Camera.main.WorldToViewportPoint(tempTile.position).x > 0) && (Camera.main.WorldToViewportPoint(tempTile.position).x < 1) && (Camera.main.WorldToViewportPoint(tempTile.position).y > 0) && (Camera.main.WorldToViewportPoint(tempTile.position).y < 1))
                    {
                        tempTile.displayed = true;
                        tempTile.Tile      = Instantiate(TileP);
                        tempTile.Tile.GetComponent <Transform>().position = offset;
                    }
                }
                tempMap.Add(tempTile);
            }
            TileMap.Add(tempMap);
        }

        Generate_Biomes();
    }
コード例 #3
0
    protected virtual string SetStringValues(string msg, ControlsScript controlsScript)
    {
        UFE3D.CharacterInfo character = controlsScript != null ? controlsScript.myInfo : null;
        if (controlsScript != null)
        {
            msg = msg.Replace("%combo%", controlsScript.opControlsScript.comboHits.ToString());
        }
        if (character != null)
        {
            msg = msg.Replace("%character%", character.characterName);
        }
        msg = msg.Replace("%round%", UFE.config.currentRound.ToString());

        return(msg);
    }
コード例 #4
0
    //[HideInInspector] public Rect characterBounds = new Rect(0,0,0,0);

    void Start()
    {
        if (transform.parent != null)
        {
            controlsScript = transform.parent.gameObject.GetComponent <ControlsScript>();
        }
        moveSetScript = GetComponent <MoveSetScript>();
        UpdateRenderer();

        if (moveSetScript != null)
        {
            foreach (MoveInfo move in moveSetScript.moves)
            {
                if (move == null)
                {
                    Debug.LogWarning("You have empty entries in your move list. Check your special moves under Character Editor.");
                    continue;
                }
                foreach (InvincibleBodyParts invBodyPart in move.invincibleBodyParts)
                {
                    List <HitBox> invHitBoxes = new List <HitBox>();
                    foreach (BodyPart bodyPart in invBodyPart.bodyParts)
                    {
                        foreach (HitBox hitBox in hitBoxes)
                        {
                            if (bodyPart == hitBox.bodyPart)
                            {
                                invHitBoxes.Add(hitBox);
                                break;
                            }
                        }
                    }
                    invBodyPart.hitBoxes = invHitBoxes.ToArray();
                }
            }
        }

        rectangleHitBoxLocationTest = false;
        rectTexture = new Texture2D(1, 1);
        rectTexture.SetPixel(0, 0, Color.red);
        rectTexture.Apply();
    }
コード例 #5
0
    void Start()
    {
        GameObject.Find("SwitchChar").GetComponent <Button>().onClick.AddListener(SwitchChar_Click);
        GameObject.Find("SwitchMap").GetComponent <Button>().onClick.AddListener(SwitchMap_Click);
        GameObject.Find("SwitchResources").GetComponent <Button>().onClick.AddListener(SwitchResources_Click);
        Controls = GameObject.Find("Controls").GetComponent <ControlsScript>();
        Tribe    = GameObject.Find("Tribe").GetComponent <TribeScript>();

        Tribe_Unity       = GameObject.Find("Tribe_Unity").GetComponent <Text>();
        Tribe_Rank        = GameObject.Find("Tribe_Rank").GetComponent <Text>();
        Tribe_Adults      = GameObject.Find("Tribe_Adults").GetComponent <Text>();
        Tribe_Youngs      = GameObject.Find("Tribe_Youngs").GetComponent <Text>();
        Tribe_Generations = GameObject.Find("Tribe_Generations").GetComponent <Text>();
        Tribe_Food        = GameObject.Find("Tribe_Food").GetComponent <Text>();
        Tribe_Water       = GameObject.Find("Tribe_Water").GetComponent <Text>();
        Tribe_Confort     = GameObject.Find("Tribe_Confort").GetComponent <Text>();
        Tribe_Social      = GameObject.Find("Tribe_Social").GetComponent <Text>();
        Tribe_Tools       = GameObject.Find("Tribe_Tools").GetComponent <Text>();
        Tribe_Crafts      = GameObject.Find("Tribe_Crafts").GetComponent <Text>();
        Tribe_Herbs       = GameObject.Find("Tribe_Herbs").GetComponent <Text>();
        Tribe_Speed       = GameObject.Find("Tribe_Speed").GetComponent <Text>();

        Tribe_Gather   = GameObject.Find("Tribe_Gather").GetComponent <Text>();
        Tribe_Fish     = GameObject.Find("Tribe_Fish").GetComponent <Text>();
        Tribe_Hunt     = GameObject.Find("Tribe_Hunt").GetComponent <Text>();
        Tribe_Cook     = GameObject.Find("Tribe_Cook").GetComponent <Text>();
        Tribe_Source   = GameObject.Find("Tribe_Source").GetComponent <Text>();
        Tribe_Manage   = GameObject.Find("Tribe_Manage").GetComponent <Text>();
        Tribe_Mentor   = GameObject.Find("Tribe_Mentor").GetComponent <Text>();
        Tribe_Sage     = GameObject.Find("Tribe_Sage").GetComponent <Text>();
        Tribe_Shaman   = GameObject.Find("Tribe_Shaman").GetComponent <Text>();
        Tribe_Skin     = GameObject.Find("Tribe_Skin").GetComponent <Text>();
        Tribe_Wood     = GameObject.Find("Tribe_Wood").GetComponent <Text>();
        Tribe_Stone    = GameObject.Find("Tribe_Stone").GetComponent <Text>();
        Tribe_Protect  = GameObject.Find("Tribe_Protect").GetComponent <Text>();
        Tribe_Leader   = GameObject.Find("Tribe_Leader").GetComponent <Text>();
        Tribe_Scout    = GameObject.Find("Tribe_Scout").GetComponent <Text>();
        Tribe_Rest     = GameObject.Find("Tribe_Rest").GetComponent <Text>();
        Tribe_Pregnant = GameObject.Find("Tribe_Pregnant").GetComponent <Text>();
    }
コード例 #6
0
    // Use this for initialization
    void Start()
    {
        tribe                 = GameObject.Find("Tribe").GetComponent <TribeScript>();
        TimeScaler            = GameObject.Find("TimeScaler").GetComponent <Slider>();
        TimeScalerText        = GameObject.Find("TimeScalerText").GetComponent <Text>();
        TribeAgeCumul         = GameObject.Find("TribeCumulAge").GetComponent <Text>();
        TribeAgeCumulSave     = GameObject.Find("TribeCumulAgeSave").GetComponent <Text>();
        TimeScalerCurrentText = GameObject.Find("TimeScalerCurrentText").GetComponent <Text>();
        Button temp = GameObject.Find("TimeScalerApply").GetComponent <Button>();

        temp.onClick.AddListener(TimeScalerApply_Click);
        temp = GameObject.Find("SaveGameButton").GetComponent <Button>();
        temp.onClick.AddListener(SaveGame_Click);
        temp = GameObject.Find("RemoveSaveButton").GetComponent <Button>();
        temp.onClick.AddListener(RemoveSaveApply_Click);
        Cs        = GameObject.Find("Controls").GetComponent <ControlsScript>();
        TDusk     = GameObject.Find("ToggleDusk").GetComponent <Toggle>();
        TDuskText = GameObject.Find("ToggleDuskText").GetComponent <Text>();
        TDusk.onValueChanged.AddListener(delegate {
            ToggleValueChanged(TDusk);
        });
        // Cs.dusk_cycle = true;
    }
コード例 #7
0
ファイル: TribeScript.cs プロジェクト: Nyarlygames/Plug
    void Start()
    {
        // settings variables to reduce GetComponent calls
        trb      = gameObject.GetComponent <Rigidbody>();
        tt       = gameObject.GetComponent <Transform>();
        Controls = GameObject.Find("Controls").GetComponent <ControlsScript>();
        //load ressources
        GameObject.Find("Tribename").GetComponent <Text>().text = PlayerPrefs.GetString("Name");
        CampOn      = Resources.Load <Sprite>("Play/TribeChar/camp");
        CampOff     = Resources.Load <Sprite>("Play/TribeChar/camp_night");
        TribeSprite = gameObject.GetComponent <SpriteRenderer>();
        EMS         = GameObject.Find("EventManager").GetComponent <EventManagerScript>();

        // manual player add
        if (PlayerPrefs.GetString("Seed") != null)
        {
            if (PlayerPrefs.GetString("Seed") == "Seed hack")
            {
                AddChar(0, "Leader", "Play/Prefabs/Characters/Leader");
                AddChar(1, "Man1", "Play/Prefabs/Characters/Man1");
                AddChar(2, "Man2", "Play/Prefabs/Characters/Man2");
                AddChar(3, "Woman1", "Play/Prefabs/Characters/Woman1");
                AddChar(4, "Woman2", "Play/Prefabs/Characters/Woman2");
                AddChar(5, "Son", "Play/Prefabs/Characters/Son");
                AddChar(6, "Daughter", "Play/Prefabs/Characters/Daughter");
                AddChar(7, "Elder", "Play/Prefabs/Characters/Elder");
            }
        }
        foreach (GameObject chars in Characters)
        {
            if (chars.GetComponent <CharacterScript>().speed < TrbSpeed)
            {
                TrbSpeed = chars.GetComponent <CharacterScript>().speed;
            }
        }
    }
コード例 #8
0
    void Start()
    {
        Cs = GameObject.Find("Controls").GetComponent <ControlsScript>();
        gameObject.GetComponent <Transform>().position = new Vector3(gameObject.GetComponent <Transform>().position.x, Cs.CharacterPlane, gameObject.GetComponent <Transform>().position.z);
        prb = gameObject.GetComponent <Rigidbody>();
        pt  = gameObject.GetComponent <Transform>();
        GameObject.Find("Tribename").GetComponent <Text>().text = PlayerPrefs.GetString("Name");
        tribe    = GameObject.Find("Tribe").GetComponent <TribeScript>();
        tribePos = tribe.GetComponent <Transform>();
        EMS      = GameObject.Find("EventManager").GetComponent <EventManagerScript>();
        if (age > 15)
        {
            tribe.TrbAdults++;
        }
        else
        {
            tribe.TrbYoungs++;
        }
        tribe.TrbUnity += moral;
        tribe.TrbRank  += exp;

        //add ? or ratio ? or more complex ? add for now.
        if (endu + speed + percept + social > 10)
        {
            //gatherer
            tribe.TrbGather.Add(gameObject);
            if (available == true)
            {
                EMS.Gatherers_Available.Add(this);
            }
            else
            {
                EMS.Gatherers_Unavailable.Add(this);
            }
        }
    }
コード例 #9
0
ファイル: RuleBasedAI.cs プロジェクト: Reshille/Gentlemanners
    protected virtual void RequestAIUpdate(ControlsScript self, ControlsScript opponent, float deltaTime)
    {
        if (self != null && opponent != null){
            // If both ControlsScript are defined, retrieve the current position of each character...
            Vector3 currentPositionSelf = self.transform.position;
            if (this.previousPositionSelf == null){
                this.previousPositionSelf = currentPositionSelf;
            }

            Vector3 currentPositionOpponent = opponent.transform.position;
            if (this.previousPositionOpponent == null){
                this.previousPositionOpponent = currentPositionOpponent;
            }

            // Calculate the "normalized speed" of each character...
            // (if the enemy is on the left side of the screen, multiply the speed.X by -1)
            Vector3 speedSelf = (currentPositionSelf - this.previousPositionSelf.Value) / deltaTime;
            Vector3 speedOpponent = (currentPositionOpponent - this.previousPositionOpponent.Value) / deltaTime;

            if (currentPositionOpponent.x < currentPositionSelf.x){
                speedSelf = new Vector3(-speedSelf.x, speedSelf.y, speedSelf.z);
                speedOpponent = new Vector3(-speedOpponent.x, speedOpponent.y, speedOpponent.z);
            }

            // Update the "previous position" so we can calculate the speed the next time we invoke this function
            this.previousPositionSelf = currentPositionSelf;
            this.previousPositionOpponent = currentPositionOpponent;

            //---------------------------------------------------------------------------------------------------------
            // INFERENCE SYSTEM REQUEST: ASK THE GAME ENGINE THE VALUES OF THE INPUT VARIABLES
            //---------------------------------------------------------------------------------------------------------
            // Retrieve the information of the AI-Controlled character
            float attackingSelf = (float)((int)AIBoolean.FALSE);
            float attackTypeSelf = float.MinValue;
            float attackDamageSelf = float.MinValue;
            float attackGaugeSelf = float.MinValue;
            float attackHitConfirmSelf = float.MinValue;
            float attackStartupSpeedSelf = float.MinValue;
            float attackRecoverySpeedSelf = float.MinValue;
            float attackHitTypeSelf = float.MinValue;
            float attackFrameDataSelf = float.MinValue;
            float attackPreferableDistanceSelf = float.MinValue;
            float characterBlockingSelf = (float)((int)(self.isBlocking ? AIBoolean.TRUE : AIBoolean.FALSE));
            float characterDistanceSelf = self.normalizedDistance;
            float characterDownSelf = (float)((int)(self.currentState == PossibleStates.Down ? AIBoolean.TRUE : AIBoolean.FALSE));
            float characterGaugeSelf = self.myInfo.currentGaugePoints / (float)(self.myInfo.maxGaugePoints);
            float characterHealthSelf = self.myInfo.currentLifePoints / (float)(self.myInfo.lifePoints);
            float characterHorizontalMovementSelf;
            float characterHorizontalMovementSpeedSelf;
            float characterJumpArcSelf = self.normalizedJumpArc;
            float characterStunnedSelf = (float)((int)(self.currentSubState == SubStates.Stunned ? AIBoolean.TRUE : AIBoolean.FALSE));

            float normalizedHorizontalSpeedSelf = speedSelf.x;
            if (Mathf.Approximately(normalizedHorizontalSpeedSelf, 0f)){
                characterHorizontalMovementSelf = (float)((int)AIHorizontalMovement.Still);
                characterHorizontalMovementSpeedSelf = 0f;
            }else if (normalizedHorizontalSpeedSelf > 0f){
                characterHorizontalMovementSelf = (float)((int)AIHorizontalMovement.MovingForward);
                characterHorizontalMovementSpeedSelf = normalizedHorizontalSpeedSelf;
            }else{
                characterHorizontalMovementSelf = (float)((int)AIHorizontalMovement.MovingBack);
                characterHorizontalMovementSpeedSelf = -normalizedHorizontalSpeedSelf;
            }

            float characterVerticalMovementSelf = float.MinValue;
            if (self.currentState == PossibleStates.Crouch){
                characterVerticalMovementSelf = (float)((int)AIVerticalMovement.Crouching);
            }else if(self.currentState == PossibleStates.BackJump || self.currentState == PossibleStates.StraightJump || self.currentState == PossibleStates.ForwardJump){
                characterVerticalMovementSelf = (float)((int)AIVerticalMovement.Jumping);
            }else{
                characterVerticalMovementSelf = (float)((int)AIVerticalMovement.Standing);
            }

            MoveInfo myMoveInfo = self.currentMove;
            if (myMoveInfo != null){
                attackingSelf = (float)((int)AIBoolean.TRUE);
                attackTypeSelf = (float)((int)myMoveInfo.moveClassification.attackType);
                attackGaugeSelf = (float)(myMoveInfo.gaugeUsage) / (float)(self.myInfo.maxGaugePoints);
                attackFrameDataSelf = (float)((int)myMoveInfo.currentFrameData);
                attackPreferableDistanceSelf = (float)((int)myMoveInfo.moveClassification.preferableDistance);

                attackHitConfirmSelf = (float)((int)myMoveInfo.moveClassification.hitConfirmType);
                attackStartupSpeedSelf = (float)((int)myMoveInfo.moveClassification.startupSpeed);
                attackRecoverySpeedSelf = (float)((int)myMoveInfo.moveClassification.recoverySpeed);
                attackHitTypeSelf = (float)((int)myMoveInfo.moveClassification.hitType);

                attackDamageSelf = 0f;
                foreach(Hit hit in myMoveInfo.hits) attackDamageSelf += hit.damageOnHit;
            }

            // Retrieve the information about the opponent...
            float attackingOpponent = (float)((int)AIBoolean.FALSE);
            float attackTypeOpponent = float.MinValue;
            float attackDamageOpponent = float.MinValue;
            float attackGaugeOpponent = float.MinValue;
            float attackHitConfirmOpponent = float.MinValue;
            float attackStartupSpeedOpponent = float.MinValue;
            float attackRecoverySpeedOpponent = float.MinValue;
            float attackHitTypeOpponent = float.MinValue;
            float attackFrameDataOpponent = float.MinValue;
            float attackPreferableDistanceOpponent = float.MinValue;
            float characterBlockingOpponent = (float)((int)(opponent.isBlocking ? AIBoolean.TRUE : AIBoolean.FALSE));
            float characterDistanceOpponent = opponent.normalizedDistance;
            float characterDownOpponent = (float)((int)(opponent.currentState == PossibleStates.Down ? AIBoolean.TRUE : AIBoolean.FALSE));
            float characterGaugeOpponent = opponent.myInfo.currentGaugePoints / (float)(opponent.myInfo.maxGaugePoints);
            float characterHealthOpponent = opponent.myInfo.currentLifePoints / (float)(opponent.myInfo.lifePoints);
            float characterHorizontalMovementOpponent;
            float characterHorizontalMovementSpeedOpponent;
            float characterJumpArcOpponent = opponent.normalizedJumpArc;
            float characterStunnedOpponent = (float)((int)(opponent.currentSubState == SubStates.Stunned ? AIBoolean.TRUE : AIBoolean.FALSE));

            float normalizedHorizontalSpeedOpponent = speedOpponent.x;
            if (Mathf.Approximately(normalizedHorizontalSpeedOpponent, 0f)){
                characterHorizontalMovementOpponent = (float)((int)AIHorizontalMovement.Still);
                characterHorizontalMovementSpeedOpponent = 0f;
            }else if (normalizedHorizontalSpeedOpponent > 0f){
                characterHorizontalMovementOpponent = (float)((int)AIHorizontalMovement.MovingForward);
                characterHorizontalMovementSpeedOpponent = normalizedHorizontalSpeedOpponent;
            }else{
                characterHorizontalMovementOpponent = (float)((int)AIHorizontalMovement.MovingBack);
                characterHorizontalMovementSpeedOpponent = -normalizedHorizontalSpeedOpponent;
            }

            float characterVerticalMovementOpponent = float.MinValue;
            if (opponent.currentState == PossibleStates.Crouch){
                characterVerticalMovementOpponent = (float)((int)AIVerticalMovement.Crouching);
            }else if(opponent.currentState == PossibleStates.BackJump || opponent.currentState == PossibleStates.StraightJump || opponent.currentState == PossibleStates.ForwardJump){
                characterVerticalMovementOpponent = (float)((int)AIVerticalMovement.Jumping);
            }else{
                characterVerticalMovementOpponent = (float)((int)AIVerticalMovement.Standing);
            }

            MoveInfo opMoveInfo = opponent.currentMove;
            if (opMoveInfo != null){
                attackingOpponent = (float)((int)AIBoolean.TRUE);
                attackTypeOpponent = (float)((int)opMoveInfo.moveClassification.attackType);
                attackGaugeOpponent = (float)(opMoveInfo.gaugeUsage) / (float)(opponent.myInfo.maxGaugePoints);
                attackFrameDataOpponent = (float)((int)opMoveInfo.currentFrameData);
                attackPreferableDistanceOpponent =  (float)((int)opMoveInfo.moveClassification.preferableDistance);

                attackHitConfirmOpponent = (float)((int)opMoveInfo.moveClassification.hitConfirmType);
                attackStartupSpeedOpponent = (float)((int)opMoveInfo.moveClassification.startupSpeed);
                attackRecoverySpeedOpponent = (float)((int)opMoveInfo.moveClassification.recoverySpeed);
                attackHitTypeOpponent = (float)((int)opMoveInfo.moveClassification.hitType);

                attackDamageOpponent = 0f;
                foreach(Hit hit in opMoveInfo.hits) attackDamageOpponent += hit.damageOnHit;
            }

            //---------------------------------------------------------------------------------------------------------
            // INFERENCE SYSTEM REQUEST: SEND THE INFORMATION OF THE ENGINE TO THE INFERENCE ENGINE
            //---------------------------------------------------------------------------------------------------------
            this.inferenceEngine.SetInput(AICondition.Attacking_Self, attackingSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_AttackType_Self, attackTypeSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_Damage_Self, attackDamageSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_GaugeUsage_Self, attackGaugeSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_HitConfirmType_Self, attackHitConfirmSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_StartupSpeed_Self, attackStartupSpeedSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_RecoverySpeed_Self, attackRecoverySpeedSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_HitType_Self, attackHitTypeSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_FrameData_Self, attackFrameDataSelf);
            this.inferenceEngine.SetInput(AICondition.Attacking_PreferableDistance_Self, attackPreferableDistanceSelf);
            this.inferenceEngine.SetInput(AICondition.Blocking_Self, characterBlockingSelf);
            this.inferenceEngine.SetInput(AICondition.Distance_Self, characterDistanceSelf);
            this.inferenceEngine.SetInput(AICondition.Down_Self, characterDownSelf);
            this.inferenceEngine.SetInput(AICondition.Gauge_Self, characterGaugeSelf);
            this.inferenceEngine.SetInput(AICondition.Health_Self, characterHealthSelf);
            this.inferenceEngine.SetInput(AICondition.HorizontalMovement_Self, characterHorizontalMovementSelf);
            this.inferenceEngine.SetInput(AICondition.HorizontalMovementSpeed_Self, characterHorizontalMovementSpeedSelf);
            this.inferenceEngine.SetInput(AICondition.JumpArc_Self, characterJumpArcSelf);
            this.inferenceEngine.SetInput(AICondition.Stunned_Self, characterStunnedSelf);
            this.inferenceEngine.SetInput(AICondition.VerticalMovement_Self, characterVerticalMovementSelf);

            this.inferenceEngine.SetInput(AICondition.Attacking_Opponent, attackingOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_AttackType_Opponent, attackTypeOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_Damage_Opponent, attackDamageOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_GaugeUsage_Opponent, attackGaugeOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_HitConfirmType_Opponent, attackHitConfirmOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_StartupSpeed_Opponent, attackStartupSpeedOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_RecoverySpeed_Opponent, attackRecoverySpeedOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_HitType_Opponent, attackHitTypeOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_FrameData_Opponent, attackFrameDataOpponent);
            this.inferenceEngine.SetInput(AICondition.Attacking_PreferableDistance_Opponent, attackPreferableDistanceOpponent);
            this.inferenceEngine.SetInput(AICondition.Blocking_Opponent, characterBlockingOpponent);
            this.inferenceEngine.SetInput(AICondition.Distance_Opponent, characterDistanceOpponent);
            this.inferenceEngine.SetInput(AICondition.Down_Opponent, characterDownOpponent);
            this.inferenceEngine.SetInput(AICondition.Gauge_Opponent, characterGaugeOpponent);
            this.inferenceEngine.SetInput(AICondition.Health_Opponent, characterHealthOpponent);
            this.inferenceEngine.SetInput(AICondition.HorizontalMovement_Opponent, characterHorizontalMovementOpponent);
            this.inferenceEngine.SetInput(AICondition.HorizontalMovementSpeed_Opponent, characterHorizontalMovementSpeedOpponent);
            this.inferenceEngine.SetInput(AICondition.JumpArc_Opponent, characterJumpArcOpponent);
            this.inferenceEngine.SetInput(AICondition.Stunned_Opponent, characterStunnedOpponent);
            this.inferenceEngine.SetInput(AICondition.VerticalMovement_Opponent, characterVerticalMovementOpponent);

            //---------------------------------------------------------------------------------------------------------
            // INFERENCE SYSTEM REQUEST: CHECK WHICH OF THE POSSIBLE REACTIONS ARE PHISICALLY POSSIBLE AT THIS MOMENT
            //---------------------------------------------------------------------------------------------------------
            HashSet<string> requestedOutputs = new HashSet<string>();
            if (this.ValidateReaction(AIReactionType.Crouch, self, opponent)){
                requestedOutputs.Add(AIReaction.Crouch);
            }
            if (this.ValidateReaction(AIReactionType.CrouchBlock, self, opponent)){
                requestedOutputs.Add(AIReaction.CrouchBlock);
            }
            if (this.ValidateReaction(AIReactionType.Idle, self, opponent)){
                requestedOutputs.Add(AIReaction.Idle);
            }
            if (this.ValidateReaction(AIReactionType.JumpBack, self, opponent)){
                requestedOutputs.Add(AIReaction.JumpBackward);
            }
            if (this.ValidateReaction(AIReactionType.JumpBlock, self, opponent)){
                requestedOutputs.Add(AIReaction.JumpBlock);
            }
            if (this.ValidateReaction(AIReactionType.JumpForward, self, opponent)){
                requestedOutputs.Add(AIReaction.JumpForward);
            }
            if (this.ValidateReaction(AIReactionType.JumpStraight, self, opponent)){
                requestedOutputs.Add(AIReaction.JumpStraight);
            }
            if (this.ValidateReaction(AIReactionType.MoveBack, self, opponent)){
                requestedOutputs.Add(AIReaction.MoveBackward);
            }
            if (this.ValidateReaction(AIReactionType.MoveForward, self, opponent)){
                requestedOutputs.Add(AIReaction.MoveForward);
            }
            if (this.ValidateReaction(AIReactionType.StandBlock, self, opponent)){
                requestedOutputs.Add(AIReaction.StandBlock);
            }
            if (this.ValidateReaction(AIReactionType.PlayMove, self, opponent)){
                requestedOutputs.Add(AIReaction.PlayMove_RandomAttack);

                if (ai.advancedOptions.reactionParameters.enableAttackTypeFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_AntiAir);
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_BackLauncher);
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_Dive);
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_ForwardLauncher);
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_Neutral);
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_NormalAttack);
                    requestedOutputs.Add(AIReaction.PlayMove_AttackType_Projectile);
                }

                if (ai.advancedOptions.reactionParameters.enableDamageFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_Damage_Medium);
                    requestedOutputs.Add(AIReaction.PlayMove_Damage_Strong);
                    requestedOutputs.Add(AIReaction.PlayMove_Damage_VeryStrong);
                    requestedOutputs.Add(AIReaction.PlayMove_Damage_VeryWeak);
                    requestedOutputs.Add(AIReaction.PlayMove_Damage_Weak);
                }

                if (ai.advancedOptions.reactionParameters.enableGaugeFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_GaugeUsage_All);
                    requestedOutputs.Add(AIReaction.PlayMove_GaugeUsage_Half);
                    requestedOutputs.Add(AIReaction.PlayMove_GaugeUsage_None);
                    requestedOutputs.Add(AIReaction.PlayMove_GaugeUsage_Quarter);
                    requestedOutputs.Add(AIReaction.PlayMove_GaugeUsage_ThreeQuarters);
                }

                if (ai.advancedOptions.reactionParameters.enableHitConfirmTypeFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_HitConfirmType_Hit);
                    requestedOutputs.Add(AIReaction.PlayMove_HitConfirmType_Throw);
                }

                if (ai.advancedOptions.reactionParameters.enableAttackSpeedFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_StartupSpeed_VeryFast);
                    requestedOutputs.Add(AIReaction.PlayMove_StartupSpeed_Fast);
                    requestedOutputs.Add(AIReaction.PlayMove_StartupSpeed_Normal);
                    requestedOutputs.Add(AIReaction.PlayMove_StartupSpeed_Slow);
                    requestedOutputs.Add(AIReaction.PlayMove_StartupSpeed_VerySlow);

                    requestedOutputs.Add(AIReaction.PlayMove_RecoverySpeed_VeryFast);
                    requestedOutputs.Add(AIReaction.PlayMove_RecoverySpeed_Fast);
                    requestedOutputs.Add(AIReaction.PlayMove_RecoverySpeed_Normal);
                    requestedOutputs.Add(AIReaction.PlayMove_RecoverySpeed_Slow);
                    requestedOutputs.Add(AIReaction.PlayMove_RecoverySpeed_VerySlow);
                }

                if (ai.advancedOptions.reactionParameters.enableHitTypeFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_HighKnockdown);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_HighLow);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_KnockBack);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_Launcher);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_Low);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_MidKnockdown);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_Overhead);
                    requestedOutputs.Add(AIReaction.PlayMove_HitType_Sweep);
                }

                if (ai.advancedOptions.reactionParameters.enableDistanceFilter){
                    requestedOutputs.Add(AIReaction.PlayMove_PreferableDistance_Close);
                    requestedOutputs.Add(AIReaction.PlayMove_PreferableDistance_Far);
                    requestedOutputs.Add(AIReaction.PlayMove_PreferableDistance_Mid);
                    requestedOutputs.Add(AIReaction.PlayMove_PreferableDistance_VeryClose);
                    requestedOutputs.Add(AIReaction.PlayMove_PreferableDistance_VeryFar);
                }
            }

            //---------------------------------------------------------------------------------------------------------
            // INFERENCE SYSTEM REQUEST: THE "CHANGE BEHAVIOUR" REACTIONS ARE ALWASY POSSIBLE
            //---------------------------------------------------------------------------------------------------------
            requestedOutputs.Add(AIReaction.ChangeBehaviour_Aggressive);
            requestedOutputs.Add(AIReaction.ChangeBehaviour_Any);
            requestedOutputs.Add(AIReaction.ChangeBehaviour_Balanced);
            requestedOutputs.Add(AIReaction.ChangeBehaviour_Defensive);
            requestedOutputs.Add(AIReaction.ChangeBehaviour_VeryAggressive);
            requestedOutputs.Add(AIReaction.ChangeBehaviour_VeryDefensive);

            //---------------------------------------------------------------------------------------------------------
            // INFERENCE SYSTEM REQUEST: FINALLY, MAKE THE REQUEST TO THE INFERENCE SYSTEM
            //---------------------------------------------------------------------------------------------------------
            if (UFE.config.aiOptions.multiCoreSupport){
                this.inferenceEngine.AsyncCalculateOutputs(requestedOutputs);
            }else{
                this.inferenceEngine.SyncCalculateOutputs(requestedOutputs);
                this.aiOutput = this.inferenceEngine.Output;
            }
        }
    }
コード例 #10
0
    public void Start()
    {
        /*Plane groundPlane = (Plane) GameObject.FindObjectOfType(typeof(Plane));
        if (groundPlane == null) Debug.LogError("Plane not found. Please add a plane mesh to your stage prefab!");*/

        groundLayer = LayerMask.NameToLayer("Ground");
          		groundMask = 1 << groundLayer;
        myControlsScript = GetComponent<ControlsScript>();
        character = myControlsScript.character;
        myHitBoxesScript = character.GetComponent<HitBoxesScript>();
        myMoveSetScript = character.GetComponent<MoveSetScript>();
        appliedGravity = myControlsScript.myInfo.physics.weight * UFE.config.gravity;
    }
コード例 #11
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);
        }
    }
コード例 #12
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;
                }
            }
        }
    }
コード例 #13
0
ファイル: UFE.cs プロジェクト: Reshille/Gentlemanners
    private static void _StartGame(float fadeTime)
    {
        CameraFade.StartAlphaFade(Color.black, true, fadeTime);

        UFE.EndGame();
        UFE.HideScreen(UFE.currentScreen);
        if (UFE.config.gameGUI.battleGUI == null){
            Debug.LogError("Battle GUI not found! Make sure you have set the prefab correctly in the Global Editor");
            UFE.battleGUI = new GameObject("BattleGUI").AddComponent<UFEScreen>();
        }else{
            UFE.battleGUI = (UFEScreen) GameObject.Instantiate(UFE.config.gameGUI.battleGUI);
        }
        UFE.battleGUI.transform.SetParent(UFE.canvas != null ? UFE.canvas.transform : null, false);
        UFE.battleGUI.OnShow();
        UFE.canvasGroup.alpha = 0;

        gameEngine = new GameObject("Game");
        UFE.cameraScript = gameEngine.AddComponent<CameraScript>();

        if (UFE.config.player1Character == null){
            Debug.LogError("No character selected for player 1.");
            return;
        }
        if (UFE.config.player2Character == null){
            Debug.LogError("No character selected for player 2.");
            return;
        }
        if (UFE.config.selectedStage == null){
            Debug.LogError("No stage selected.");
            return;
        }

        if (UFE.config.aiOptions.engine == AIEngine.FuzzyAI){
            UFE.SetFuzzyAI(1, UFE.config.player1Character);
            UFE.SetFuzzyAI(2, UFE.config.player2Character);
        }

        UFE.config.player1Character.currentLifePoints = (float)UFE.config.player1Character.lifePoints;
        UFE.config.player2Character.currentLifePoints = (float)UFE.config.player2Character.lifePoints;
        UFE.config.player1Character.currentGaugePoints = 0;
        UFE.config.player2Character.currentGaugePoints = 0;

        if (UFE.config.selectedStage.prefab == null){
            Debug.LogError("Stage prefab not found! Make sure you have set the prefab correctly in the Global Editor");
        }
        GameObject stageInstance = (GameObject) Instantiate(config.selectedStage.prefab);

        stageInstance.transform.parent = gameEngine.transform;
        UFE.config.currentRound = 1;
        UFE.config.lockInputs = true;
        UFE.SetTimer(config.roundOptions.timer);
        UFE.PauseTimer();

        GameObject p1 = new GameObject("Player1");
        p1.transform.parent = gameEngine.transform;
        p1ControlsScript = p1.AddComponent<ControlsScript>();
        p1.AddComponent<PhysicsScript>();

        GameObject p2 = new GameObject("Player2");
        p2.transform.parent = gameEngine.transform;
        p2ControlsScript = p2.AddComponent<ControlsScript>();
        p2.AddComponent<PhysicsScript>();

        //Preload
        if (UFE.config.preloadHitEffects) {
            SearchAndCastGameObject(UFE.config.hitOptions);
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Hit Effects Loaded");
        }
        if (UFE.config.preloadStage) {
            SearchAndCastGameObject(UFE.config.selectedStage);
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Stage Loaded");
        }
        if (UFE.config.preloadCharacter1) {
            SearchAndCastGameObject(UFE.config.player1Character);
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Character 1 Loaded");
        }
        if (UFE.config.preloadCharacter2) {
            SearchAndCastGameObject(UFE.config.player2Character);
            if (UFE.config.debugOptions.preloadedObjects) Debug.Log("Character 2 Loaded");
        }
        if (UFE.config.warmAllShaders) Shader.WarmupAllShaders();

        memoryDump.Clear();
    }
コード例 #14
0
ファイル: HitBoxesScript.cs プロジェクト: alps001/MyFightGame
    void Start()
    {
        controlsScript  = transform.parent.gameObject.GetComponent <ControlsScript>();
        myMoveSetScript = GetComponent <MoveSetScript>();
        detect3dHits    = UFE.config.detect3D_Hits;

        foreach (HitBox hitBox in hitBoxes)
        {
            hitBox.storedRadius = hitBox.radius;
        }

        foreach (MoveInfo move in myMoveSetScript.moves)
        {
            foreach (InvincibleBodyParts invBodyPart in move.invincibleBodyParts)
            {
                List <HitBox> invHitBoxes = new List <HitBox>();
                foreach (BodyPart bodyPart in invBodyPart.bodyParts)
                {
                    foreach (HitBox hitBox in hitBoxes)
                    {
                        if (bodyPart == hitBox.bodyPart)
                        {
                            invHitBoxes.Add(hitBox);
                            break;
                        }
                    }
                }
                invBodyPart.hitBoxes = invHitBoxes.ToArray();
            }

            foreach (HitBox hitBox in hitBoxes)
            {
                if (move.blockableArea.bodyPart == hitBox.bodyPart)
                {
                    move.blockableArea.position = hitBox.position;
                    break;
                }
            }

            foreach (Hit hit in move.hits)
            {
                foreach (HitBox hitBox in hitBoxes)
                {
                    if (hit.pullEnemyIn.characterBodyPart == hitBox.bodyPart)
                    {
                        hit.pullEnemyIn.position = hitBox.position;
                        break;
                    }
                }
                foreach (HurtBox hurtBox in hit.hurtBoxes)
                {
                    foreach (HitBox hitBox in hitBoxes)
                    {
                        if (hurtBox.bodyPart == hitBox.bodyPart)
                        {
                            hurtBox.position = hitBox.position;
                            break;
                        }
                    }
                }
            }

            foreach (Projectile projectile in move.projectiles)
            {
                foreach (HitBox hitBox in hitBoxes)
                {
                    if (projectile.bodyPart == hitBox.bodyPart)
                    {
                        projectile.position = hitBox.position;
                    }
                }
            }
        }
    }
コード例 #15
0
ファイル: RuleBasedAI.cs プロジェクト: Reshille/Gentlemanners
    protected virtual MovementInfo ChooseMovement(ControlsScript self, ControlsScript opponent, float deltaTime)
    {
        // Find out if this AI is controlling the first or the second player.
        if (self != null && opponent != null){
            if (this.aiOutput != null){
                // Check if we want to use the best available move or the Weighted Random Selection in this decision step...
                float newRuleCompliance = (UFE.GetAIDifficulty() != null && UFE.GetAIDifficulty().overrideRuleCompliance) ?
                    UFE.GetAIDifficulty().ruleCompliance : this.ai.advancedOptions.ruleCompliance;

                bool useBestAvailableMove = UnityEngine.Random.Range(0f, 1f) < newRuleCompliance;

                // Then calculate the desirability of each possible movement...
                this.movements.Clear();

                float attackWeight = (UFE.GetAIDifficulty() != null && UFE.GetAIDifficulty().overrideAggressiveness) ?
                    UFE.GetAIDifficulty().aggressiveness : this.ai.advancedOptions.aggressiveness;

                if (self.currentMove != null && opponent.currentSubState == SubStates.Stunned) {
                    float newComboEfficiency = (UFE.GetAIDifficulty() != null && UFE.GetAIDifficulty().overrideAggressiveness) ?
                        UFE.GetAIDifficulty().comboEfficiency : this.ai.advancedOptions.comboEfficiency;

                    attackWeight = newComboEfficiency/2;
                }

                float basicMoveWeight =  1f - attackWeight;
                float weight;

                float newTimeBetweenDecisions = (UFE.GetAIDifficulty() != null && UFE.GetAIDifficulty().overrideTimeBetweenDecisions) ?
                    UFE.GetAIDifficulty().timeBetweenDecisions : this.ai.advancedOptions.timeBetweenDecisions;

                int frames = Mathf.FloorToInt(newTimeBetweenDecisions / deltaTime) + 1;

                int paddingBeforeJump = Mathf.Max(UFE.config.plinkingDelay + 1, Mathf.FloorToInt(self.myInfo.executionTiming / deltaTime) + 1);

                if (this.aiOutput.TryGetValue(AIReaction.Crouch, out weight) && this.ValidateReaction(AIReactionType.Crouch, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.Crouch, this.crouchSimulatedInput, weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.Idle, out weight) && this.ValidateReaction(AIReactionType.Idle, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.Idle, this.idleSimulatedInput, weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.JumpBackward, out weight) && this.ValidateReaction(AIReactionType.JumpBack, self, opponent)){
                    // We don't want to jump accidentally in the wrong direction, so we must have plinking into account
                    ButtonPress[][] jumpSimulatedInput = this.jumpBackwardSimulatedInput;

                    if (!Mathf.Approximately(this.inputBuffer[this.inputBuffer.Count - 1][this.horizontalAxis].axisRaw, 0f)){
                        List<ButtonPress[]> temp = new List<ButtonPress[]>();

                        for (int i = 0; i < paddingBeforeJump; ++i){
                            temp.Add(this.noButtonsPressed);
                        }

                        temp.AddRange(jumpSimulatedInput);
                        jumpSimulatedInput = temp.ToArray();
                    }

                    this.movements.Add(new MovementInfo(AIReaction.JumpBackward, jumpSimulatedInput.ToArray(), weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.JumpForward, out weight) && this.ValidateReaction(AIReactionType.JumpForward, self, opponent)){
                    // We don't want to jump accidentally in the wrong direction, so we must have plinking into account
                    ButtonPress[][] jumpSimulatedInput = this.jumpForwardSimulatedInput;

                    if (!Mathf.Approximately(this.inputBuffer[this.inputBuffer.Count - 1][this.horizontalAxis].axisRaw, 0f)){
                        List<ButtonPress[]> temp = new List<ButtonPress[]>();

                        for (int i = 0; i < paddingBeforeJump; ++i){
                            temp.Add(this.noButtonsPressed);
                        }

                        temp.AddRange(jumpSimulatedInput);
                        jumpSimulatedInput = temp.ToArray();
                    }

                    this.movements.Add(new MovementInfo(AIReaction.JumpForward, jumpSimulatedInput.ToArray(), weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.JumpStraight, out weight) && this.ValidateReaction(AIReactionType.JumpStraight, self, opponent)){
                    // We don't want to jump accidentally in the wrong direction, so we must have plinking into account
                    ButtonPress[][] jumpSimulatedInput = this.jumpBackwardSimulatedInput;

                    if (!Mathf.Approximately(this.inputBuffer[this.inputBuffer.Count - 1][this.horizontalAxis].axisRaw, 0f)){
                        List<ButtonPress[]> temp = new List<ButtonPress[]>();

                        for (int i = 0; i < paddingBeforeJump; ++i){
                            temp.Add(this.noButtonsPressed);
                        }

                        temp.AddRange(jumpSimulatedInput);
                        jumpSimulatedInput = temp.ToArray();
                    }

                    this.movements.Add(new MovementInfo(AIReaction.JumpStraight, jumpSimulatedInput.ToArray(), weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.MoveBackward, out weight) && this.ValidateReaction(AIReactionType.MoveBack, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.MoveBackward, this.moveBackwardSimulatedInput, weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.MoveForward, out weight) && this.ValidateReaction(AIReactionType.MoveForward, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.MoveForward, this.moveForwardSimulatedInput, weight * basicMoveWeight));
                }

                // Including blocks...
                if (this.aiOutput.TryGetValue(AIReaction.CrouchBlock, out weight) && this.ValidateReaction(AIReactionType.CrouchBlock, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.CrouchBlock, this.crouchBlockSimulatedInput, weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.JumpBlock, out weight) && this.ValidateReaction(AIReactionType.JumpBlock, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.JumpBlock, this.jumpBlockSimulatedInput, weight * basicMoveWeight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.StandBlock, out weight) && this.ValidateReaction(AIReactionType.StandBlock, self, opponent)){
                    this.movements.Add(new MovementInfo(AIReaction.StandBlock, this.standBlockSimulatedInput, weight * basicMoveWeight));
                }

                // Changing AI behaviours...
                if (this.aiOutput.TryGetValue(AIReaction.ChangeBehaviour_Aggressive, out weight)){
                    this.movements.Add(new MovementInfo(AIReaction.ChangeBehaviour_Aggressive, null, weight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.ChangeBehaviour_Any, out weight)){
                    this.movements.Add(new MovementInfo(AIReaction.ChangeBehaviour_Any, null, weight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.ChangeBehaviour_Balanced, out weight)){
                    this.movements.Add(new MovementInfo(AIReaction.ChangeBehaviour_Balanced, null, weight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.ChangeBehaviour_Defensive, out weight)){
                    this.movements.Add(new MovementInfo(AIReaction.ChangeBehaviour_Defensive, null, weight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.ChangeBehaviour_VeryAggressive, out weight)){
                    this.movements.Add(new MovementInfo(AIReaction.ChangeBehaviour_VeryAggressive, null, weight));
                }
                if (this.aiOutput.TryGetValue(AIReaction.ChangeBehaviour_VeryDefensive, out weight)){
                    this.movements.Add(new MovementInfo(AIReaction.ChangeBehaviour_VeryDefensive, null, weight));
                }

                // And attack movements...
                if(
                    this.aiOutput.ContainsKey(AIReaction.PlayMove_RandomAttack) &&
                    this.ValidateReaction(AIReactionType.PlayMove, self, opponent)
                    ){
                    this.AddValidMoves(
                        self,
                        opponent,
                        this.inferenceEngine.DefaultValue,
                        useBestAvailableMove,
                        deltaTime
                        );
                }

                // Check if the character can execute any movement...
                MovementInfo currentMovement;
                if (this.movements.Count > 0){
                    // Check if we want to select only the best available movement or if we want to choose
                    // a random movement giving higher chances to movements with higher desirability...
                    //
                    // If we want to select the best available movement, but there are several movements with
                    // the best weight, we choose one of those movements randomly.
                    this.movements.Sort(delegate(MovementInfo move1, MovementInfo move2) {
                        return move2.weight.CompareTo(move1.weight);
                    });

                    self.aiDebugger = "";
                    if (self.debugger != null && UFE.config.debugOptions.debugMode && ai.debugMode && ai.debug_ReactionWeight){
                        self.aiDebugger = "-----AI Reaction Weights-----\n";
                        StringBuilder sb = new StringBuilder();
                        sb.Append("Instruction Set: ").Append(ai.instructionsName).AppendLine();

                        foreach(MovementInfo mInfo in this.movements){
                            sb.Append(mInfo.name).Append(" = ").Append(mInfo.weight).AppendLine();
                        }

                        self.aiDebugger += sb.ToString();
                    }

                    if (useBestAvailableMove){
                        //---------------------------------------------------------------------------------------------
                        // If we want to use the best available move, find the move with the best weight and discard
                        // the rest of the moves. If there are several moves with the best weight, choose one of them
                        // randomly.
                        //---------------------------------------------------------------------------------------------
                        float maxWeight = 0f;

                        for (int i = 0; i < this.movements.Count; ++i){
                            currentMovement = this.movements[i];

                            //-----------------------------------------------------------------------------------------
                            // We know the moves are already sorted by its weight,
                            // but we want to check if the simulated input is null
                            // because those are special cases.
                            //-----------------------------------------------------------------------------------------
                            if (currentMovement != null && currentMovement.simulatedInput != null){
                                maxWeight = currentMovement.weight;
                                break;
                            }
                        }

                        for (int i = this.movements.Count - 1; i > 0; --i){
                            currentMovement = this.movements[i];

                            if (
                                currentMovement == null
                                ||
                                (
                                currentMovement.weight < maxWeight &&
                                !Mathf.Approximately(currentMovement.weight, maxWeight)
                                )
                                ){
                                this.movements.RemoveAt(i);
                            }
                        }
                    }

                    MovementInfo chosenMovement = null;
                    while (chosenMovement == null || chosenMovement.simulatedInput == null){
                        //---------------------------------------------------------------------------------------------
                        // Calculate the total weight of all possible moves
                        //---------------------------------------------------------------------------------------------

                        //---------------------------------------------------------------------------------------------
                        // It's look like the iOS AOT Compiler doesn't like this function, so I implement it myself.
                        //---------------------------------------------------------------------------------------------
                        //float totalWeight = this.movements.Sum((MovementInfo m) => m.weight);
                        float totalWeight = 0f;
                        foreach (MovementInfo movement in movements){
                            if (movement != null){
                                totalWeight += movement.weight;
                            }
                        }

                        if (totalWeight > 0f){
                            //-----------------------------------------------------------------------------------------
                            // If the total weight is greater than zero, choose a random movement
                            // (taking the weight of that movement into account)
                            //-----------------------------------------------------------------------------------------
                            float random = UnityEngine.Random.Range(0f, totalWeight);

                            int length = this.movements.Count;
                            float accumulatedWeight = 0f;
                            float currentWeight;

                            for (int i = 0; i < length - 1; ++i){
                                currentMovement = this.movements[i];

                                if (currentMovement != null){
                                    currentWeight = currentMovement.weight;

                                    if (currentWeight > 0f){
                                        accumulatedWeight += currentWeight;

                                        if (random < accumulatedWeight){
                                            chosenMovement = currentMovement;
                                            break;
                                        }
                                    }
                                }
                            }

                            if (chosenMovement == null && length > 0){
                                chosenMovement = this.movements[length - 1];
                            }

                            //-----------------------------------------------------------------------------------------
                            // If the chosen movement doesn't have a simulated input, it's a special case
                            //-----------------------------------------------------------------------------------------
                            if (chosenMovement != null && chosenMovement.simulatedInput.Length == 0){
                                if (AIReaction.ChangeBehaviour_Aggressive.Equals(chosenMovement.name)){
                                    foreach (AIInstructionsSet instructionsSet in self.myInfo.aiInstructionsSet){
                                        if (instructionsSet != null && instructionsSet.behavior == AIBehavior.Aggressive){
                                            this.SetAIInformation(instructionsSet.aiInfo);
                                            break;
                                        }
                                    }
                                }else if (AIReaction.ChangeBehaviour_Any.Equals(chosenMovement.name)){
                                    List<AIInstructionsSet> instructions = new List<AIInstructionsSet>(self.myInfo.aiInstructionsSet);
                                    AIInstructionsSet instructionsSet = null;

                                    while (instructionsSet == null && instructions.Count > 0){
                                        int r = UnityEngine.Random.Range(0, instructions.Count);
                                        instructionsSet = instructions[r];
                                        instructions.RemoveAt(r);
                                    }

                                    if (instructionsSet != null){
                                        this.SetAIInformation(instructionsSet.aiInfo);
                                    }

                                }else if (AIReaction.ChangeBehaviour_Balanced.Equals(chosenMovement.name)){
                                    foreach (AIInstructionsSet instructionsSet in self.myInfo.aiInstructionsSet){
                                        if (instructionsSet != null && instructionsSet.behavior == AIBehavior.Balanced){
                                            this.SetAIInformation(instructionsSet.aiInfo);
                                            break;
                                        }
                                    }
                                }else if (AIReaction.ChangeBehaviour_Defensive.Equals(chosenMovement.name)){
                                    foreach (AIInstructionsSet instructionsSet in self.myInfo.aiInstructionsSet){
                                        if (instructionsSet != null && instructionsSet.behavior == AIBehavior.Defensive){
                                            this.SetAIInformation(instructionsSet.aiInfo);
                                            break;
                                        }
                                    }
                                }else if (AIReaction.ChangeBehaviour_VeryAggressive.Equals(chosenMovement.name)){
                                    foreach (AIInstructionsSet instructionsSet in self.myInfo.aiInstructionsSet){
                                        if (instructionsSet != null && instructionsSet.behavior == AIBehavior.VeryAggressive){
                                            this.SetAIInformation(instructionsSet.aiInfo);
                                            break;
                                        }
                                    }
                                }else if (AIReaction.ChangeBehaviour_VeryDefensive.Equals(chosenMovement.name)){
                                    foreach (AIInstructionsSet instructionsSet in self.myInfo.aiInstructionsSet){
                                        if (instructionsSet != null && instructionsSet.behavior == AIBehavior.VeryDefensive){
                                            this.SetAIInformation(instructionsSet.aiInfo);
                                            break;
                                        }
                                    }
                                }

                                //-------------------------------------------------------------------------------------
                                // As soon as the special case is processed,
                                // remove it from the list and choose another movement
                                //-------------------------------------------------------------------------------------
                                this.movements.Remove (chosenMovement);
                            }
                        }else{
                            break;
                        }
                    }

                    if (chosenMovement == null){
                        chosenMovement = new MovementInfo(AIReaction.Idle, this.Repeat(this.noButtonsPressed, frames), 1f);
                    }

                    return chosenMovement;
                }
            }
        }

        return null;
    }
コード例 #16
0
    protected virtual string ProcessMessage(string msg, ControlsScript controlsScript)
    {
        if (msg == UFE.config.selectedLanguage.combo){
            if (this.announcer != null && !this.muteAnnouncer){
                foreach(ComboAnnouncer comboAnnouncer in this.announcer.combos){
                    if (controlsScript.opControlsScript.comboHits >= comboAnnouncer.hits){
                        UFE.PlaySound(comboAnnouncer.audio);
                        break;
                    }
                }
            }
        }else if (msg == UFE.config.selectedLanguage.parry){
            if (this.announcer != null && !this.muteAnnouncer){
                UFE.PlaySound(this.announcer.parry);
            }
            UFE.PlaySound(UFE.config.blockOptions.parrySound);
        }else if (msg == UFE.config.selectedLanguage.counterHit){
            if (this.announcer != null && !this.muteAnnouncer){
                UFE.PlaySound(this.announcer.counterHit);
            }
            UFE.PlaySound(UFE.config.counterHitOptions.sound);
        }else if (msg == UFE.config.selectedLanguage.firstHit){
            if (this.announcer != null && !this.muteAnnouncer){
                UFE.PlaySound(this.announcer.firstHit);
            }
        }else{
            return this.SetStringValues(msg, null);
        }

        return this.SetStringValues(msg, controlsScript);
    }
コード例 #17
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);
    }
コード例 #18
0
ファイル: ControlsScript.cs プロジェクト: Andi07/TestRepo
    public void DoFixedUpdate()
    {
        // If both controllers aren't ready, ignore the player input
        if (!UFE.GetPlayer1Controller().isReady || !UFE.GetPlayer2Controller().isReady) return;

        // Training Mode
        if ((playerNum == 1 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p1Life == LifeBarTrainingMode.Refill) ||
            (playerNum == 2 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p2Life == LifeBarTrainingMode.Refill)) {
            if (!UFE.FindDelaySynchronizedAction(this.RefillLife))
                UFE.DelaySynchronizedAction(this.RefillLife, UFE.config.trainingModeOptions.refillTime);
        }

        if ((playerNum == 1 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p1Gauge == LifeBarTrainingMode.Refill) ||
            (playerNum == 2 && UFE.gameMode == GameMode.TrainingRoom && UFE.config.trainingModeOptions.p2Gauge == LifeBarTrainingMode.Refill)) {
            if (!UFE.FindDelaySynchronizedAction(this.RefillGauge))
                UFE.DelaySynchronizedAction(this.RefillGauge, UFE.config.trainingModeOptions.refillTime);
        }

        if (UFE.gameMode == GameMode.TrainingRoom && myInfo.currentGaugePoints < myInfo.maxGaugePoints &&
            ((playerNum == 1 && UFE.config.trainingModeOptions.p1Gauge == LifeBarTrainingMode.Infinite) ||
            (playerNum == 2 && UFE.config.trainingModeOptions.p2Gauge == LifeBarTrainingMode.Infinite))) RefillGauge();

        if (UFE.gameMode == GameMode.TrainingRoom && myInfo.currentLifePoints < myInfo.lifePoints &&
            ((playerNum == 1 && UFE.config.trainingModeOptions.p1Life == LifeBarTrainingMode.Infinite) ||
            (playerNum == 2 && UFE.config.trainingModeOptions.p2Life == LifeBarTrainingMode.Infinite))) RefillLife();

        // Debugger
        if (debugger != null && UFE.config.debugOptions.debugMode){
            debugger.text = "";
            if (UFE.config.debugOptions.debugMode) {
                debugger.text += "-----Character Info-----\n";
                if (debugInfo.lifePoints) debugger.text += "Life Points: " + myInfo.currentLifePoints + "\n";
                if (debugInfo.position) debugger.text += "Position: " + transform.position + "\n";
                if (debugInfo.currentState) debugger.text += "State: " + currentState + "\n";
                if (debugInfo.currentSubState) debugger.text += "Sub State: " + currentSubState + "\n";
                if (debugInfo.stunTime && stunTime > 0) debugger.text += "Stun Time: " + stunTime + "\n";
                if (opControlsScript != null && opControlsScript.comboHits > 0) {
                    debugger.text += "Current Combo\n";
                    if (debugInfo.comboHits) debugger.text += "- Total Hits: "+ opControlsScript.comboHits + "\n";
                    if (debugInfo.comboDamage) {
                        debugger.text += "- Total Damage: " + opControlsScript.comboDamage + "\n";
                        debugger.text += "- Hit Damage: " + opControlsScript.comboHitDamage + "\n";
                    }
                }

                // Other uses
                //if (potentialParry > 0) debugger.text += "Parry Window: "+ potentialParry + "\n";
                //debugger.text += "Air Jumps: "+ myPhysicsScript.currentAirJumps + "\n";

                if (UFE.config.debugOptions.p1DebugInfo.currentMove && currentMove != null) {
                    debugger.text += "Move: "+ currentMove.name + " ("+ currentMove.currentFrame +"/"+ currentMove.totalFrames +") \n";
                    /*if (currentMove.chargeMove) {
                        debugger.text += "First Input Charge: "+ myMoveSetScript.chargeValues[currentMove.buttonSequence[0]] + "\n";
                    }*/
                    //debugger.text += "StartupFrames: "+ currentMove.moveClassification.startupSpeed +" \n";
                }
            }
            if (aiDebugger != null && debugInfo.aiWeightList) debugger.text += aiDebugger;
        }

        // Once per game
        if (opHitBoxesScript == null) {
            opControlsScript = opponent.GetComponent<ControlsScript>();
            opPhysicsScript = opponent.GetComponent<PhysicsScript>();
            opHitBoxesScript = opponent.GetComponentInChildren<HitBoxesScript>();
            opInfo = opControlsScript.myInfo;

            if (myInfo.enableAlternativeColor){
                if (gameObject.name == "Player2" && character.name == opControlsScript.character.name){  // Alternative Costume
                    Renderer[] charRenders = character.GetComponentsInChildren<Renderer>();
                    foreach(Renderer charRender in charRenders){
                        charRender.material.color = myInfo.alternativeColor;
                        //charRender.material.shader = Shader.Find("VertexLit");
                        //charRender.material.SetColor("_Emission", myInfo.alternativeColor);
                    }
                }
            }

            Renderer[] charRenderers = character.GetComponentsInChildren<Renderer>();
            List<Shader> shaderList = new List<Shader>();
            List<Color> colorList = new List<Color>();
            foreach(Renderer char_rend in charRenderers){
                //if (char_rend.material.HasProperty("color") && char_rend.material.HasProperty("shader")){
                    shaderList.Add(char_rend.material.shader);
                    colorList.Add(char_rend.material.color);
                //}
            }
            normalShaders = shaderList.ToArray();
            normalColors = colorList.ToArray();

            myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle);
        }

        // Once per round
        if ((gameObject.name == "Player1" && !introPlayed && currentMove == null) ||
            (gameObject.name == "Player2" && !introPlayed && opControlsScript.introPlayed && currentMove == null))
        {
            KillCurrentMove();
            CastMove(myMoveSetScript.intro, true, true, false);
            if (currentMove == null) {
                introPlayed = true;
                UFE.CastNewRound();
            }
        }

        // Resolve move
        resolveMove();

        // Check inputs
        translateInputs(inputController);

        // Validate rotation
        validateRotation();

        // Input Viewer
        List<InputReferences> inputList = new List<InputReferences>();
        foreach (InputReferences inputRef in inputController.inputReferences){
            if (debugger != null && UFE.config.debugOptions.debugMode && debugInfo.inputs){
                debugger.text += inputRef.inputButtonName + " - "+ inputRef.heldDown + "\n";
            }
            if (inputRef.heldDown > 0 && inputRef.heldDown <= (2f/(float)UFE.config.fps)){
                inputList.Add(inputRef);
            }
        }
        UFE.CastInput(inputList.ToArray(), playerNum);

        // Force character local position
        if (ignoreAnimationTransform && (currentMove == null || !currentMove.applyRootMotion))
            character.transform.localPosition = new Vector3(0, 0, 0);

        // Force stand state
        if (!myPhysicsScript.freeze
            && !isDead
            && currentSubState != SubStates.Stunned
            && introPlayed
            && myPhysicsScript.IsGrounded()
            && !myPhysicsScript.IsMoving()
            && currentMove == null
            && !myMoveSetScript.IsBasicMovePlaying(myMoveSetScript.basicMoves.idle)
            && !myMoveSetScript.IsAnimationPlaying("fallStraight")
            && isAxisRested(inputController)
            && !myPhysicsScript.isTakingOff
            && !myPhysicsScript.isLanding
            && !blockStunned
            && currentState != PossibleStates.Crouch
            && !isBlocking
            ){

                myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle);
                currentState = PossibleStates.Stand;
                currentSubState = SubStates.Resting;
                if (UFE.config.blockOptions.blockType == BlockType.AutoBlock
                    && myMoveSetScript.basicMoves.blockEnabled) potentialBlock = true;
        }

        if (myMoveSetScript.IsAnimationPlaying("idle")
            && !UFE.config.lockInputs
            && !UFE.config.lockMovements) {
            afkTimer += Time.fixedDeltaTime;
            if (afkTimer >= myMoveSetScript.basicMoves.idle.restingClipInterval) {
                afkTimer = 0;
                int clipNum = Mathf.RoundToInt(Random.Range(2, 6));
                if (myMoveSetScript.AnimationExists("idle_" + clipNum)) {
                    myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle, "idle_" + clipNum, false);
                }
            }
        } else {
            afkTimer = 0;
        }

        // Character colliders based on collision mass and body colliders
        normalizedDistance = Mathf.Clamp01(Vector3.Distance(opponent.transform.position, transform.position) / UFE.config.cameraOptions.maxDistance);
        if (!ignoreCollisionMass && !opControlsScript.ignoreCollisionMass) {
            float pushForce = myHitBoxesScript.TestCollision(opHitBoxesScript.hitBoxes);
            if (pushForce > 0) {
                if (transform.position.x < opponent.transform.position.x) {
                    transform.Translate(new Vector3(-.1f * pushForce, 0, 0));
                }else{
                    transform.Translate(new Vector3(.1f * pushForce, 0, 0));
                }
                if (opponent.transform.position.x == UFE.config.selectedStage.rightBoundary){
                    opponent.transform.Translate(new Vector3(-.2f * pushForce, 0, 0));
                }
            }

            pushForce = myInfo.physics.groundCollisionMass - Vector3.Distance(transform.position, opponent.transform.position);
            if (pushForce > 0) {
                if (transform.position.x < opponent.transform.position.x) {
                    transform.Translate(new Vector3(-.5f * pushForce, 0, 0));
                }else{
                    transform.Translate(new Vector3(.5f * pushForce, 0, 0));
                }
                if (opponent.transform.position.x == UFE.config.selectedStage.rightBoundary){
                    opponent.transform.Translate(new Vector3(-.2f * pushForce, 0, 0));
                }
            }
        }

        // Shake character
        if (shakeDensity > 0) {
            shakeDensity -= Time.fixedDeltaTime;
            if (myHitBoxesScript.isHit && myPhysicsScript.freeze){
                if (shakeCharacter) shake();
                if (shakeCamera) shakeCam();
            }else{
                if (UFE.config.bounceOptions.shakeCamOnBounce && myPhysicsScript.isBouncing) shakeCam();
            }
        }else if (shakeDensity < 0) {
            shakeDensity = 0;
            shakeCamera = false;
            shakeCharacter = false;
        }

        // Validate Parry
        if (potentialParry > 0){
            potentialParry -= Time.fixedDeltaTime;
            if (potentialParry <= 0) potentialParry = 0;
        }

        // Update head movement
        if (headLookScript != null && opHitBoxesScript != null)
            headLookScript.target = opHitBoxesScript.GetPosition(myInfo.headLook.target);

        // Execute Move
        if (currentMove != null) ReadMove(currentMove);

        // Apply Stun
        if ((currentSubState == SubStates.Stunned || blockStunned) && stunTime > 0 && !myPhysicsScript.freeze && !isDead)
            ApplyStun();

        // Apply Forces
        myPhysicsScript.ApplyForces(currentMove);
    }
コード例 #19
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);
    }
コード例 #20
0
 void Awake()
 {
     controlsScript = transform.parent.gameObject.GetComponent <ControlsScript>();
     controlsScript.myInfo.currentCombatStance = CombatStances.Stance10;
     changeMoveStances(CombatStances.Stance1);
 }
コード例 #21
0
    void Start()
    {
        controlsScript = transform.parent.gameObject.GetComponent<ControlsScript>();
        myMoveSetScript = GetComponent<MoveSetScript>();
        UpdateRenderer();

        foreach(MoveInfo move in myMoveSetScript.moves){
            foreach(InvincibleBodyParts invBodyPart in move.invincibleBodyParts){
                List<HitBox> invHitBoxes = new List<HitBox>();
                foreach(BodyPart bodyPart in invBodyPart.bodyParts){
                    foreach(HitBox hitBox in hitBoxes){
                        if (bodyPart == hitBox.bodyPart) {
                            invHitBoxes.Add(hitBox);
                            break;
                        }
                    }
                }
                invBodyPart.hitBoxes = invHitBoxes.ToArray();
            }
        }
    }
コード例 #22
0
ファイル: RuleBasedAI.cs プロジェクト: Reshille/Gentlemanners
    protected virtual bool ValidateReaction(AIReactionType reactionType, ControlsScript self, ControlsScript opponent)
    {
        if (self == null || opponent == null){
            return false;
        }

        if (reactionType == AIReactionType.Idle){
            //---------------------------------------------------------------------------------------------------------
            // We can always choose to not press any key, although the character won't become idle immediately
            //---------------------------------------------------------------------------------------------------------
            return true;
        }else if (self.Physics.isTakingOff){
            //---------------------------------------------------------------------------------------------------------
            // To avoid confusions (we don't know if the character is standing or jumping)
            // the AI shouldn't take any decision if the character is taking off,
            // the AI should wait until the character is in the middle of the jump.
            //---------------------------------------------------------------------------------------------------------
            return false;
        }

        bool attackMovesLocked = UFE.config.lockMovements;
        bool basicMovesLocked = UFE.config.lockInputs && !UFE.config.roundOptions.allowMovement;
        bool isAttacking = self.currentMove != null || self.storedMove != null;
        bool isDown = (!ai.advancedOptions.reactionParameters.inputWhenDown && self.currentState == PossibleStates.Down);
        bool isStunned = (!ai.advancedOptions.reactionParameters.inputWhenStunned && self.currentSubState == SubStates.Stunned);
        bool isBlocking = (!ai.advancedOptions.reactionParameters.inputWhenBlocking && self.currentSubState == SubStates.Blocking);

        bool isJumping =
            self.currentState == PossibleStates.BackJump ||
                self.currentState == PossibleStates.ForwardJump ||
                self.currentState == PossibleStates.StraightJump;

        //bool isOpponentAttacking = opponent.currentMove != null || opponent.storedMove != null;
        bool isOpponentDown = opponent.currentState == PossibleStates.Down;
        bool isOpponentStunned = opponent.currentSubState == SubStates.Stunned;
        bool isOpponentBlocking = opponent.currentSubState == SubStates.Blocking;

        //-------------------------------------------------------------------------------------------------------------
        // Check if the character can execute the desired reaction at this moment:
        //-------------------------------------------------------------------------------------------------------------
        switch(reactionType){
        case AIReactionType.Crouch:
            //---------------------------------------------------------------------------------------------------------
            // The character can't crouch while he is jumping, stunned, down or executing a non-crouched attack.
            //---------------------------------------------------------------------------------------------------------
            return !basicMovesLocked && !isJumping && !isStunned && !isDown && !isAttacking;

        case AIReactionType.CrouchBlock:
            //---------------------------------------------------------------------------------------------------------
            // The character can't crouch-block while he is jumping, stunned, down or executing any kind of attack.
            //---------------------------------------------------------------------------------------------------------
            return
                !basicMovesLocked &&
                    !isJumping &&
                    !isStunned &&
                    !isDown &&
                    !isAttacking &&
                    !(this.ai.advancedOptions.reactionParameters.stopBlockingWhenEnemyIsStunned && isOpponentStunned);

        case AIReactionType.JumpBack:
            //---------------------------------------------------------------------------------------------------------
            // The character can't jump backwards while he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return
                !basicMovesLocked &&
                    !isStunned &&
                    !isDown &&
                    !isAttacking &&
                    self.Physics.currentAirJumps < self.myInfo.physics.multiJumps;

        case AIReactionType.JumpBlock:
            //---------------------------------------------------------------------------------------------------------
            // The character can't jump-block if he isn't jumping or if he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return
                UFE.config.blockOptions.allowAirBlock &&
                    !basicMovesLocked &&
                    !isStunned &&
                    !isDown &&
                    isJumping &&
                    !isAttacking &&
                    !(this.ai.advancedOptions.reactionParameters.stopBlockingWhenEnemyIsStunned && isOpponentStunned);

        case AIReactionType.JumpForward:
            //---------------------------------------------------------------------------------------------------------
            // The character can't jump forwards while he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return
                !basicMovesLocked &&
                    !isStunned &&
                    !isDown &&
                    !isAttacking &&
                    self.Physics.currentAirJumps < self.myInfo.physics.multiJumps;

        case AIReactionType.JumpStraight:
            //---------------------------------------------------------------------------------------------------------
            // The character can't jump straight while he is stunned or down.
            // He can't jump either if he is already jumping and has reached the max number of jumps without landing.
            //---------------------------------------------------------------------------------------------------------
            return
                !basicMovesLocked &&
                    !isStunned &&
                    !isDown &&
                    !isAttacking && self.Physics.currentAirJumps < self.myInfo.physics.multiJumps;

        case AIReactionType.MoveBack:
            //---------------------------------------------------------------------------------------------------------
            // The character can't move backwards if he is jumping or if he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return !basicMovesLocked && !isStunned && !isDown && !isJumping && !isAttacking;

        case AIReactionType.MoveForward:
            //---------------------------------------------------------------------------------------------------------
            // The character can't move forwards if he is jumping or if he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return !basicMovesLocked && !isStunned && !isDown && !isJumping && !isAttacking;

        case AIReactionType.StandBlock:
            //---------------------------------------------------------------------------------------------------------
            // The character can't stand block if he is jumping or if he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return
                !basicMovesLocked &&
                    !isStunned &&
                    !isDown &&
                    !isJumping &&
                    !isAttacking &&
                    !(this.ai.advancedOptions.reactionParameters.stopBlockingWhenEnemyIsStunned && isOpponentStunned);

        case AIReactionType.PlayMove:
            //---------------------------------------------------------------------------------------------------------
            // The character can't execute any "attack move" while he is stunned or down.
            //---------------------------------------------------------------------------------------------------------
            return
                !basicMovesLocked &&
                    !attackMovesLocked &&
                    !isStunned &&
                    !isDown &&
                    !isBlocking &&
                    (this.ai.advancedOptions.reactionParameters.attackWhenEnemyIsDown || !isOpponentDown) &&
                    (this.ai.advancedOptions.reactionParameters.attackWhenEnemyIsBlocking || !isOpponentBlocking);
        default:
            return true;
        }
    }
コード例 #23
0
ファイル: RuleBasedAI.cs プロジェクト: Reshille/Gentlemanners
    protected virtual void AddValidMoves(
		ControlsScript self, 
		ControlsScript opponent, 
		float defaultValue, 
		bool useBestAvailableMove,
		float deltaTime
		)
    {
        int oldCount = this.movements.Count;
        float weight;

        //-------------------------------------------------------------------------------------------------------------
        // Cached values (required for improving performance)
        //-------------------------------------------------------------------------------------------------------------
        float attackWeight = this.ai.advancedOptions.aggressiveness;
        float maxGaugePoints = (float)(self.myInfo.maxGaugePoints);
        //float executionTiming = self.myInfo.executionTiming;
        //int plinkingDelay = UFE.config.plinkingDelay + 1;
        //int executionTimingDelay = Mathf.FloorToInt(executionTiming / deltaTime) + 2;
        //int timeBetweenActionsDelay = Mathf.FloorToInt(this.ai.advancedOptions.timeBetweenActions / deltaTime) + 2;
        //int framesAfterAttack = Mathf.Max(plinkingDelay, executionTimingDelay, timeBetweenActionsDelay);

        float attackTypeAntiAir = 0f;
        float attackTypeBackLauncher = 0f;
        float attackTypeDive = 0f;
        float attackTypeForwardLauncher = 0f;
        float attackTypeNeutral = 0f;
        float attackTypeNormalAttack = 0f;
        float attackTypeProjectile = 0f;

        float damageVeryWeak = 0f;
        float damageWeak = 0f;
        float damageMedium = 0f;
        float damageStrong = 0f;
        float damageVeryStrong = 0f;

        float gaugeUsageNone = 0f;
        float gaugeUsageQuarter = 0f;
        float gaugeUsageHalf = 0f;
        float gaugeUsageThreeQuarters = 0f;
        float gaugeUsageAll = 0f;

        float hitConfirmTypeHit = 0f;
        float hitConfirmTypeThrow = 0f;

        float hitTypeHighKnockdown = 0f;
        float hitTypeHighLow = 0f;
        float hitTypeKnockBack = 0f;
        float hitTypeLauncher = 0f;
        float hitTypeLow = 0f;
        float hitTypeMidKnockdown = 0f;
        float hitTypeOverhead = 0f;
        float hitTypeSweep = 0f;

        float preferableDistanceVeryClose = 0f;
        float preferableDistanceClose = 0f;
        float preferableDistanceMid = 0f;
        float preferableDistanceFar = 0f;
        float preferableDistanceVeryFar = 0f;

        float recoverySpeedVeryFast = 0f;
        float recoverySpeedFast = 0f;
        float recoverySpeedNormal = 0f;
        float recoverySpeedSlow = 0f;
        float recoverySpeedVerySlow = 0f;

        float startupSpeedVeryFast = 0f;
        float startupSpeedFast = 0f;
        float startupSpeedNormal = 0f;
        float startupSpeedSlow = 0f;
        float startupSpeedVerySlow = 0f;

        if (this.ai.advancedOptions.reactionParameters.enableAttackTypeFilter){
            attackTypeAntiAir = this.aiOutput[AIReaction.PlayMove_AttackType_AntiAir];
            attackTypeBackLauncher = this.aiOutput[AIReaction.PlayMove_AttackType_BackLauncher];
            attackTypeDive = this.aiOutput[AIReaction.PlayMove_AttackType_Dive];
            attackTypeForwardLauncher = this.aiOutput[AIReaction.PlayMove_AttackType_ForwardLauncher];
            attackTypeNeutral = this.aiOutput[AIReaction.PlayMove_AttackType_Neutral];
            attackTypeNormalAttack = this.aiOutput[AIReaction.PlayMove_AttackType_NormalAttack];
            attackTypeProjectile = this.aiOutput[AIReaction.PlayMove_AttackType_Projectile];
        }

        if (ai.advancedOptions.reactionParameters.enableDamageFilter){
            damageVeryWeak = this.aiOutput[AIReaction.PlayMove_Damage_VeryWeak];
            damageWeak = this.aiOutput[AIReaction.PlayMove_Damage_Weak];
            damageMedium = this.aiOutput[AIReaction.PlayMove_Damage_Medium];
            damageStrong = this.aiOutput[AIReaction.PlayMove_Damage_Strong];
            damageVeryStrong = this.aiOutput[AIReaction.PlayMove_Damage_VeryStrong];
        }

        if (ai.advancedOptions.reactionParameters.enableGaugeFilter){
            gaugeUsageNone = this.aiOutput[AIReaction.PlayMove_GaugeUsage_None];
            gaugeUsageQuarter = this.aiOutput[AIReaction.PlayMove_GaugeUsage_Quarter];
            gaugeUsageHalf = this.aiOutput[AIReaction.PlayMove_GaugeUsage_Half];
            gaugeUsageThreeQuarters = this.aiOutput[AIReaction.PlayMove_GaugeUsage_ThreeQuarters];
            gaugeUsageAll = this.aiOutput[AIReaction.PlayMove_GaugeUsage_All];
        }

        if (ai.advancedOptions.reactionParameters.enableDistanceFilter){
            preferableDistanceVeryClose = this.aiOutput[AIReaction.PlayMove_PreferableDistance_VeryClose];
            preferableDistanceClose = this.aiOutput[AIReaction.PlayMove_PreferableDistance_Close];
            preferableDistanceMid = this.aiOutput[AIReaction.PlayMove_PreferableDistance_Mid];
            preferableDistanceFar = this.aiOutput[AIReaction.PlayMove_PreferableDistance_Far];
            preferableDistanceVeryFar = this.aiOutput[AIReaction.PlayMove_PreferableDistance_VeryFar];
        }

        if (ai.advancedOptions.reactionParameters.enableHitConfirmTypeFilter){
            hitConfirmTypeHit = this.aiOutput[AIReaction.PlayMove_HitConfirmType_Hit];
            hitConfirmTypeThrow = this.aiOutput[AIReaction.PlayMove_HitConfirmType_Throw];
        }

        if (ai.advancedOptions.reactionParameters.enableAttackSpeedFilter){
            startupSpeedVeryFast = this.aiOutput[AIReaction.PlayMove_StartupSpeed_VeryFast];
            startupSpeedFast = this.aiOutput[AIReaction.PlayMove_StartupSpeed_Fast];
            startupSpeedNormal = this.aiOutput[AIReaction.PlayMove_StartupSpeed_Normal];
            startupSpeedSlow = this.aiOutput[AIReaction.PlayMove_StartupSpeed_Slow];
            startupSpeedVerySlow = this.aiOutput[AIReaction.PlayMove_StartupSpeed_VerySlow];

            recoverySpeedVeryFast = this.aiOutput[AIReaction.PlayMove_RecoverySpeed_VeryFast];
            recoverySpeedFast = this.aiOutput[AIReaction.PlayMove_RecoverySpeed_Fast];
            recoverySpeedNormal = this.aiOutput[AIReaction.PlayMove_RecoverySpeed_Normal];
            recoverySpeedSlow = this.aiOutput[AIReaction.PlayMove_RecoverySpeed_Slow];
            recoverySpeedVerySlow = this.aiOutput[AIReaction.PlayMove_RecoverySpeed_VerySlow];
        }

        if (ai.advancedOptions.reactionParameters.enableHitTypeFilter){
            hitTypeHighKnockdown = this.aiOutput[AIReaction.PlayMove_HitType_HighKnockdown];
            hitTypeHighLow = this.aiOutput[AIReaction.PlayMove_HitType_HighLow];
            hitTypeKnockBack = this.aiOutput[AIReaction.PlayMove_HitType_KnockBack];
            hitTypeLauncher = this.aiOutput[AIReaction.PlayMove_HitType_Launcher];
            hitTypeLow = this.aiOutput[AIReaction.PlayMove_HitType_Low];
            hitTypeMidKnockdown = this.aiOutput[AIReaction.PlayMove_HitType_MidKnockdown];
            hitTypeOverhead = this.aiOutput[AIReaction.PlayMove_HitType_Overhead];
            hitTypeSweep = this.aiOutput[AIReaction.PlayMove_HitType_Sweep];
        }

        //-------------------------------------------------------------------------------------------------------------
        // Retrieve a list with the movements that can be executed at this moment.
        //-------------------------------------------------------------------------------------------------------------
        // When we decide if a movement can be executed at this moment, we should take into account (for example)
        // the current stance of the character, if the character is in the middle of a combo, the gauge usage of
        // the attack or if the character is blocking, stunned or down.
        //-------------------------------------------------------------------------------------------------------------
        int index = 0;
        for (int i = 0; i < self.myInfo.moves.Length; ++i){
            MoveSetData move = self.myInfo.moves[i];

            for (int j = 0; j < move.attackMoves.Length; ++j){
                MoveInfo moveInfo = move.attackMoves[j];

                if (moveInfo != null && self.MoveSet.ValidateMoveExecution(moveInfo)){
                    //-------------------------------------------------------------------------------------------------
                    // Now that we know the attack can be executed at this moment,
                    // we simulate the input required to execute the attack...
                    //-------------------------------------------------------------------------------------------------
                    ButtonPress? chargeButton = null;
                    int chargeFrames = 0;
                    int count;

                    // Check if it's a "charge move" or not
                    if (moveInfo.buttonSequence.Length > 0){
                        if (moveInfo.chargeMove){
                            // If it's a "charge move", check if we have already started to charge the attack
                            chargeButton = moveInfo.buttonSequence[0];
                            float charged = 0f;

                            if (chargeButton == ButtonPress.Back){
                                if (this.previousInputs[this.horizontalAxis].axisRaw < 0f){
                                    charged = this.horizontalAxis.heldDown;
                                }
                            }else if (chargeButton == ButtonPress.Foward){
                                if (this.previousInputs[this.horizontalAxis].axisRaw > 0f){
                                    charged = this.horizontalAxis.heldDown;
                                }
                            }else if (chargeButton == ButtonPress.Up){
                                if (this.previousInputs[this.verticalAxis].axisRaw > 0f){
                                    charged = this.verticalAxis.heldDown;
                                }
                            }else if (chargeButton == ButtonPress.Down){
                                if (this.previousInputs[this.verticalAxis].axisRaw < 0f){
                                    charged = this.verticalAxis.heldDown;
                                }
                            }else{
                                foreach (InputReferences input in this.inputReferences){
                                    if (input.inputType == InputType.Button && input.engineRelatedButton == chargeButton){
                                        charged = input.heldDown;
                                        break;
                                    }
                                }
                            }

                            // Calculate how many frames do we need to press the button to charge the attack
                            chargeFrames = Mathf.FloorToInt((moveInfo.chargeTiming - charged) * UFE.config.fps);
                            //chargeFrames = Mathf.FloorToInt((moveInfo.chargeTiming - charged) / deltaTime) + 1;
                        }else{
                            // TODO: if it wasn't a charge attack but we already had the first button
                            // of the sequence pressed, we could use that input to execute the movement faster.

                            // If it isn't a charge move, we enter a few empty frames before the move
                            // just to be completely sure the move is executed correctly
                            //chargeFrames = Mathf.Max(plinkingDelay, executionTimingDelay);
                        }
                    }

                    List<ButtonPress[]> sequence = new List<ButtonPress[]>();
                    if (chargeButton != null){
                        // If it's a "charge move", we need to repeat the first input for several frames
                        for (int k = 0; k < chargeFrames; ++k){
                            sequence.Add(new ButtonPress[]{chargeButton.Value});
                        }
                    }else{
                        // Otherwise, add some "empty frames" before the attack
                        for (int k = 0; k < chargeFrames; ++k){
                            sequence.Add(this.noButtonsPressed);
                        }
                    }

                    sequence.AddRange(moveInfo.simulatedInputs);

                    //-------------------------------------------------------------------------------------------------
                    // Finally, calcultate the weight associated to each valid movement...
                    //-------------------------------------------------------------------------------------------------
                    float attackTypeWeight = 0f;
                    float gaugeUsageWeight = 0f;
                    float preferableDistanceWeight = 0f;
                    float hitConfirmTypeWeight = 0f;
                    float startupSpeedWeight = 0f;
                    float recoverySpeedWeight = 0f;
                    float hitTypeWeight = 0f;
                    float damageWeight = 0f;

                    weight = 0f;
                    count = 0;

                    if (this.ai.advancedOptions.reactionParameters.enableAttackTypeFilter){
                        switch(moveInfo.moveClassification.attackType){
                        case AttackType.AntiAir:		attackTypeWeight += attackTypeAntiAir;			break;
                        case AttackType.BackLauncher:	attackTypeWeight += attackTypeBackLauncher;		break;
                        case AttackType.Dive:			attackTypeWeight += attackTypeDive;				break;
                        case AttackType.ForwardLauncher:attackTypeWeight += attackTypeForwardLauncher;	break;
                        case AttackType.Neutral:		attackTypeWeight += attackTypeNeutral;			break;
                        case AttackType.NormalAttack:	attackTypeWeight += attackTypeNormalAttack;		break;
                        case AttackType.Projectile:		attackTypeWeight += attackTypeProjectile;		break;
                        default:
                            attackTypeWeight += (
                                attackTypeAntiAir +
                                attackTypeBackLauncher +
                                attackTypeDive +
                                attackTypeForwardLauncher +
                                attackTypeNeutral +
                                attackTypeNormalAttack +
                                attackTypeProjectile
                                ) / 7f;
                            break;
                        }
                        ++count;
                    }

                    if (ai.advancedOptions.reactionParameters.enableGaugeFilter){
                        float gaugeUsage = (float)(moveInfo.gaugeUsage) / maxGaugePoints;
                        gaugeUsageWeight += gaugeVar.GetLabelMembership(RuleBasedAI.gaugeUsageNone, gaugeUsage) * gaugeUsageNone;
                        gaugeUsageWeight += gaugeVar.GetLabelMembership(RuleBasedAI.gaugeUsageQuarter, gaugeUsage) * gaugeUsageQuarter;
                        gaugeUsageWeight += gaugeVar.GetLabelMembership(RuleBasedAI.gaugeUsageHalf, gaugeUsage) * gaugeUsageHalf;
                        gaugeUsageWeight += gaugeVar.GetLabelMembership(RuleBasedAI.gaugeUsageThreeQuarters, gaugeUsage) * gaugeUsageThreeQuarters;
                        gaugeUsageWeight += gaugeVar.GetLabelMembership(RuleBasedAI.gaugeUsageAll, gaugeUsage) * gaugeUsageAll;
                        ++count;
                    }

                    if (ai.advancedOptions.reactionParameters.enableDistanceFilter){
                        switch(moveInfo.moveClassification.preferableDistance){
                        case CharacterDistance.VeryClose:	preferableDistanceWeight += preferableDistanceVeryClose;	break;
                        case CharacterDistance.Close:		preferableDistanceWeight += preferableDistanceClose;		break;
                        case CharacterDistance.Mid:			preferableDistanceWeight += preferableDistanceMid;			break;
                        case CharacterDistance.Far:			preferableDistanceWeight += preferableDistanceFar;			break;
                        case CharacterDistance.VeryFar:		preferableDistanceWeight += preferableDistanceVeryFar;		break;
                        default:
                            preferableDistanceWeight += (
                                preferableDistanceVeryClose +
                                preferableDistanceClose +
                                preferableDistanceMid +
                                preferableDistanceFar +
                                preferableDistanceVeryFar
                                ) / 5f;
                            break;
                        }
                        ++count;
                    }

                    float damage = 0f;
                    foreach(Hit hit in moveInfo.hits) damage += hit.damageOnHit;

                    if (moveInfo.hits.Length > 0){
                        if (ai.advancedOptions.reactionParameters.enableDamageFilter){
                            damage /= (float)(opponent.myInfo.lifePoints);
                            damageWeight += damageVar.GetLabelMembership(RuleBasedAI.damageVeryWeak, damage) * damageVeryWeak;
                            damageWeight += damageVar.GetLabelMembership(RuleBasedAI.damageWeak, damage) * damageWeak;
                            damageWeight += damageVar.GetLabelMembership(RuleBasedAI.damageMedium, damage) * damageMedium;
                            damageWeight += damageVar.GetLabelMembership(RuleBasedAI.damageStrong, damage) * damageStrong;
                            damageWeight += damageVar.GetLabelMembership(RuleBasedAI.damageVeryStrong, damage) * damageVeryStrong;
                            ++count;
                        }

                        if (ai.advancedOptions.reactionParameters.enableHitConfirmTypeFilter){
                            switch(moveInfo.moveClassification.hitConfirmType){
                            case HitConfirmType.Hit:	hitConfirmTypeWeight += hitConfirmTypeHit;		break;
                            case HitConfirmType.Throw:	hitConfirmTypeWeight += hitConfirmTypeThrow;	break;
                            default:
                                hitConfirmTypeWeight += (hitConfirmTypeHit + hitConfirmTypeThrow) / 2f;
                                break;
                            }
                            ++count;
                        }

                        if (ai.advancedOptions.reactionParameters.enableAttackSpeedFilter){
                            switch(moveInfo.moveClassification.startupSpeed){
                            case FrameSpeed.VeryFast:	startupSpeedWeight += startupSpeedVeryFast;	break;
                            case FrameSpeed.Fast:		startupSpeedWeight += startupSpeedFast;		break;
                            case FrameSpeed.Normal:		startupSpeedWeight += startupSpeedNormal;	break;
                            case FrameSpeed.Slow:		startupSpeedWeight += startupSpeedSlow;		break;
                            case FrameSpeed.VerySlow:	startupSpeedWeight += startupSpeedVerySlow;	break;
                            default:
                                startupSpeedWeight += (
                                    startupSpeedVeryFast +
                                    startupSpeedFast +
                                    startupSpeedNormal +
                                    startupSpeedSlow +
                                    startupSpeedVerySlow
                                    ) / 5f;
                                break;
                            }
                            ++count;

                            switch(moveInfo.moveClassification.recoverySpeed){
                            case FrameSpeed.VeryFast:	recoverySpeedWeight += recoverySpeedVeryFast;	break;
                            case FrameSpeed.Fast:		recoverySpeedWeight += recoverySpeedFast;		break;
                            case FrameSpeed.Normal:		recoverySpeedWeight += recoverySpeedNormal;		break;
                            case FrameSpeed.Slow:		recoverySpeedWeight += recoverySpeedSlow;		break;
                            case FrameSpeed.VerySlow:	recoverySpeedWeight += recoverySpeedVerySlow;	break;
                            default:
                                recoverySpeedWeight += (
                                    recoverySpeedVeryFast +
                                    recoverySpeedFast +
                                    recoverySpeedNormal +
                                    recoverySpeedSlow +
                                    recoverySpeedVerySlow
                                    ) / 5f;
                                break;
                            }
                            ++count;
                        }

                        if (ai.advancedOptions.reactionParameters.enableHitTypeFilter){
                            switch(moveInfo.moveClassification.hitType){
                            case HitType.HighKnockdown:	hitTypeWeight += hitTypeHighKnockdown;	break;
                            case HitType.Mid:		hitTypeWeight += hitTypeHighLow;		break;
                            case HitType.KnockBack:		hitTypeWeight += hitTypeKnockBack;		break;
                            case HitType.Launcher:		hitTypeWeight += hitTypeLauncher;		break;
                            case HitType.Low:			hitTypeWeight += hitTypeLow;			break;
                            case HitType.MidKnockdown:	hitTypeWeight += hitTypeMidKnockdown;	break;
                            case HitType.Overhead:		hitTypeWeight += hitTypeOverhead;		break;
                            case HitType.Sweep:			hitTypeWeight += hitTypeSweep;			break;
                            default:
                                hitTypeWeight += (
                                    hitTypeHighKnockdown +
                                    hitTypeHighLow +
                                    hitTypeKnockBack +
                                    hitTypeLauncher +
                                    hitTypeLow +
                                    hitTypeMidKnockdown +
                                    hitTypeOverhead +
                                    hitTypeSweep
                                    ) / 8f;
                                break;
                            }
                            ++count;
                        }
                    }

                    if (count > 0){
                        if (this.ai.advancedOptions.attackDesirabilityCalculation == AIAttackDesirabilityCalculation.Average){
                            weight = (
                                attackTypeWeight +
                                gaugeUsageWeight +
                                preferableDistanceWeight +
                                hitConfirmTypeWeight +
                                startupSpeedWeight +
                                recoverySpeedWeight +
                                hitTypeWeight +
                                damageWeight
                                ) / (float)(count);
                        }else if (this.ai.advancedOptions.attackDesirabilityCalculation == AIAttackDesirabilityCalculation.ClampedSum){
                            weight = Mathf.Clamp01(
                                attackTypeWeight +
                                gaugeUsageWeight +
                                preferableDistanceWeight +
                                hitConfirmTypeWeight +
                                startupSpeedWeight +
                                recoverySpeedWeight +
                                hitTypeWeight +
                                damageWeight
                                );
                        }else if (this.ai.advancedOptions.attackDesirabilityCalculation == AIAttackDesirabilityCalculation.Max){
                            weight = Mathf.Max(
                                attackTypeWeight,
                                gaugeUsageWeight,
                                preferableDistanceWeight,
                                hitConfirmTypeWeight,
                                startupSpeedWeight,
                                recoverySpeedWeight,
                                hitTypeWeight,
                                damageWeight
                                );
                        }else if (this.ai.advancedOptions.attackDesirabilityCalculation == AIAttackDesirabilityCalculation.Min){
                            weight = Mathf.Min(
                                !this.ai.advancedOptions.reactionParameters.enableAttackTypeFilter ? float.PositiveInfinity : attackTypeWeight,
                                !this.ai.advancedOptions.reactionParameters.enableGaugeFilter ? float.PositiveInfinity : gaugeUsageWeight,
                                !this.ai.advancedOptions.reactionParameters.enableDistanceFilter ? float.PositiveInfinity : preferableDistanceWeight,
                                !this.ai.advancedOptions.reactionParameters.enableHitConfirmTypeFilter ? float.PositiveInfinity : hitConfirmTypeWeight,
                                !this.ai.advancedOptions.reactionParameters.enableAttackSpeedFilter ? float.PositiveInfinity : startupSpeedWeight,
                                !this.ai.advancedOptions.reactionParameters.enableHitTypeFilter ? float.PositiveInfinity : hitTypeWeight,
                                !this.ai.advancedOptions.reactionParameters.enableDamageFilter ? float.PositiveInfinity : damageWeight
                                );
                        }
                    }

                    this.movements.Add(new MovementInfo(moveInfo.moveName, sequence.ToArray(), weight * attackWeight));
                    ++index;
                }
            }
        }

        // Check if we have found any valid movement...
        int newCount = this.movements.Count;
        if (newCount > oldCount){
            // In that case, check if we're using the "Weighted Random Selection" mode to compensate the weights of the moves...
            if (!useBestAvailableMove){
                float compensation = (float)(newCount - oldCount);

                for (int i = oldCount; i < newCount; ++i){
                    this.movements[i].weight /= compensation;
                }
            }

            // And add the possibility of executing a random move...
            if (ai.advancedOptions.playRandomMoves){
                if (this.aiOutput.TryGetValue(AIReaction.PlayMove_RandomAttack, out weight)){
                    MovementInfo randomMovement = this.movements[UnityEngine.Random.Range(oldCount, newCount)];
                    this.movements.Add(new MovementInfo("Random: " + randomMovement.name, randomMovement.simulatedInput, weight * attackWeight));
                }
            }
        }
    }
コード例 #24
0
    protected override void OnGameBegin(ControlsScript cPlayer1, ControlsScript cPlayer2, StageOptions stage)
    {
        base.OnGameBegin(cPlayer1, cPlayer2, stage);

        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.player1GUI != null &&
                this.player1GUI.wonRoundsImages != null &&
                this.player1GUI.wonRoundsImages.Length >= targetNumberOfImages
                )
            {
                for (int i = 0; i < targetNumberOfImages; ++i)
                {
                    this.player1GUI.wonRoundsImages[i].enabled = true;
                    this.player1GUI.wonRoundsImages[i].sprite  = this.wonRounds.NotFinishedRounds;
                }

                for (int i = targetNumberOfImages; i < this.player1GUI.wonRoundsImages.Length; ++i)
                {
                    this.player1GUI.wonRoundsImages[i].enabled = false;
                }
            }
            else
            {
                Debug.LogError(
                    "Player 1: not enough \"Won Rounds\" Images not found! " +
                    "Expected:" + targetNumberOfImages + " / Found: " + this.player1GUI.wonRoundsImages.Length +
                    "\nMake sure you have set the images correctly in the Editor"
                    );
            }

            if (
                this.player2GUI != null &&
                this.player2GUI.wonRoundsImages != null &&
                this.player2GUI.wonRoundsImages.Length >= targetNumberOfImages
                )
            {
                for (int i = 0; i < targetNumberOfImages; ++i)
                {
                    this.player2GUI.wonRoundsImages[i].enabled = true;
                    this.player2GUI.wonRoundsImages[i].sprite  = this.wonRounds.NotFinishedRounds;
                }

                for (int i = targetNumberOfImages; i < this.player2GUI.wonRoundsImages.Length; ++i)
                {
                    this.player2GUI.wonRoundsImages[i].enabled = false;
                }
            }
            else
            {
                Debug.LogError(
                    "Player 2: not enough \"Won Rounds\" Images not found! " +
                    "Expected:" + targetNumberOfImages + " / Found: " + this.player2GUI.wonRoundsImages.Length +
                    "\nMake sure you have set the images correctly in the Editor"
                    );
            }
        }

        // Set the character names
        if (this.player1GUI != null && this.player1GUI.name != null)
        {
            this.player1GUI.name.text = cPlayer1.myInfo.characterName;
        }

        if (this.player2GUI != null && this.player2GUI.name != null)
        {
            this.player2GUI.name.text = cPlayer2.myInfo.characterName;
        }

        // Set the character portraits
        if (this.player1GUI != null && this.player1GUI.portrait != null)
        {
            if (cPlayer1.myInfo.profilePictureSmall != null)
            {
                this.player1GUI.portrait.gameObject.SetActive(true);
                this.player1GUI.portrait.sprite = Sprite.Create(
                    cPlayer1.myInfo.profilePictureSmall,
                    new Rect(0f, 0f, cPlayer1.myInfo.profilePictureSmall.width, cPlayer1.myInfo.profilePictureSmall.height),
                    new Vector2(0.5f * cPlayer1.myInfo.profilePictureSmall.width, 0.5f * cPlayer1.myInfo.profilePictureSmall.height)
                    );
            }
            else
            {
                this.player1GUI.portrait.gameObject.SetActive(false);
            }
        }

        if (this.player2GUI != null && this.player2GUI.portrait != null)
        {
            if (cPlayer2.myInfo.profilePictureSmall != null)
            {
                this.player2GUI.portrait.gameObject.SetActive(true);
                this.player2GUI.portrait.sprite = Sprite.Create(
                    cPlayer2.myInfo.profilePictureSmall,
                    new Rect(0f, 0f, cPlayer2.myInfo.profilePictureSmall.width, cPlayer2.myInfo.profilePictureSmall.height),
                    new Vector2(0.5f * cPlayer2.myInfo.profilePictureSmall.width, 0.5f * cPlayer2.myInfo.profilePictureSmall.height)
                    );
            }
            else
            {
                this.player2GUI.portrait.gameObject.SetActive(false);
            }
        }

        // If we want to use a Timer, set the default value for the timer
        if (this.timer != null)
        {
            if (UFE.config.roundOptions.hasTimer)
            {
                this.timer.gameObject.SetActive(true);
                this.timer.text = UFE.config.roundOptions._timer.ToString().Replace("Infinity", "∞");
            }
            else
            {
                this.timer.gameObject.SetActive(false);
            }
        }

        // Set the max and min values for the Life Bars
        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;
        }

        // Enable Gauge Meters
        for (int i = 0; i < this.player1GUI.gauges.Length; i++)
        {
            if (!UFE.config.gameGUI.hasGauge || this.player1.controlsScript.myInfo.hideGauges[i])
            {
                this.player1GUI.gauges[i].gameObject.SetActive(false);
                if (this.player1GUI.gauges[i].gameObject.GetComponentInParent <Image>() != null)
                {
                    this.player1GUI.gauges[i].gameObject.transform.parent.gameObject.SetActive(false);
                }
            }
        }

        for (int i = 0; i < this.player2GUI.gauges.Length; i++)
        {
            if (!UFE.config.gameGUI.hasGauge || this.player2.controlsScript.myInfo.hideGauges[i])
            {
                this.player2GUI.gauges[i].gameObject.SetActive(false);
                if (this.player2GUI.gauges[i].gameObject.GetComponentInParent <Image>() != null)
                {
                    this.player2GUI.gauges[i].gameObject.transform.parent.gameObject.SetActive(false);
                }
            }
        }

        // Set values for the Gauge Bars
        if (UFE.config.gameGUI.hasGauge)
        {
            for (int i = 0; i < this.player1GUI.gauges.Length; i++)
            {
                if (this.player1.controlsScript.myInfo.hideGauges[i])
                {
                    continue;
                }
                this.player1GUI.gauges[i].gameObject.SetActive(true);
                this.player1GUI.gauges[i].fillAmount = (float)cPlayer1.currentGaugesPoints[i] / UFE.config.player1Character.maxGaugePoints;
            }

            for (int i = 0; i < this.player2GUI.gauges.Length; i++)
            {
                if (this.player2.controlsScript.myInfo.hideGauges[i])
                {
                    continue;
                }
                this.player2GUI.gauges[i].gameObject.SetActive(true);
                this.player2GUI.gauges[i].fillAmount = (float)cPlayer2.currentGaugesPoints[i] / UFE.config.player2Character.maxGaugePoints;
            }
        }
    }
コード例 #25
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);
                    }
                }
            }
        }
    }
コード例 #26
0
    protected virtual string SetStringValues(string msg, ControlsScript controlsScript)
    {
        CharacterInfo character = controlsScript != null ? controlsScript.myInfo : null;
        if (controlsScript != null) msg = msg.Replace("%combo%", controlsScript.opControlsScript.comboHits.ToString());
        if (character != null)		msg = msg.Replace("%character%", character.characterName);
        msg = msg.Replace("%round%", UFE.config.currentRound.ToString());

        return msg;
    }