Пример #1
0
    public void GetHitBlocking(Hit hit, int remainingFrames, Vector3 location)
    {
        // Lose life
        if (hit.damageOnBlock >= myInfo.currentLifePoints){
            GetHit(hit, remainingFrames, location);
            return;
        }else{
            DamageMe(hit.damageOnBlock);
        }

        blockStunned = true;
        currentSubState = SubStates.Blocking;

        myHitBoxesScript.isHit = true;

        int stunFrames = 0;
        BasicMoveInfo currentHitInfo = myMoveSetScript.basicMoves.blockingHighHit;

        if (hit.hitStunType == HitStunType.FrameAdvantage) {
            stunFrames = hit.frameAdvantageOnBlock + remainingFrames;
            if (stunFrames < 1) stunFrames = 1;
            stunTime = (float)stunFrames/(float)UFE.config.fps;
        }else if (hit.hitStunType == HitStunType.Frames) {
            stunFrames = (int) hit.hitStunOnBlock;
            if (stunFrames < 1) stunFrames = 1;
            stunTime = (float)stunFrames/(float)UFE.config.fps;
        }else{
            stunTime = hit.hitStunOnBlock;
        }

        // Create hit blocking effect
        GameObject particle = UFE.config.blockOptions.blockHitEffects.hitParticle;
        float killTime = UFE.config.blockOptions.blockHitEffects.killTime;
        AudioClip soundEffect = UFE.config.blockOptions.blockHitEffects.hitSound;
        if (location != Vector3.zero && particle != null){
            GameObject pTemp = (GameObject) Instantiate(particle);
            pTemp.transform.position = location;
            pTemp.transform.localScale = new Vector3(-mirror, 1, 1);
            Destroy(pTemp, killTime);
        }
        UFE.PlaySound(soundEffect);

        // Shake Options
        shakeCamera = UFE.config.blockOptions.blockHitEffects.shakeCameraOnHit;
        shakeCharacter = UFE.config.blockOptions.blockHitEffects.shakeCharacterOnHit;
        shakeDensity = UFE.config.blockOptions.blockHitEffects.shakeDensity;

        if (currentState == PossibleStates.Crouch){
            currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.blockingCrouchingHit, hit);
            currentHitInfo = myMoveSetScript.basicMoves.blockingCrouchingHit;

            if (!myMoveSetScript.AnimationExists(currentHitAnimation))
                Debug.LogError("Blocking Crouching Hit animation not found! Make sure you have it set on Character -> Basic Moves -> Blocking Crouching Hit");
        }else if (currentState == PossibleStates.Stand){
            HitBox strokeHit = myHitBoxesScript.GetStrokeHitBox();
            if (strokeHit.type == HitBoxType.low && myMoveSetScript.basicMoves.blockingLowHit.clip1 != null){
                currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.blockingLowHit, hit);
                currentHitInfo = myMoveSetScript.basicMoves.blockingLowHit;

            }else{
                currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.blockingHighHit, hit);
                currentHitInfo = myMoveSetScript.basicMoves.blockingHighHit;
                if (!myMoveSetScript.AnimationExists(currentHitAnimation))
                    Debug.LogError("Blocking High Hit animation not found! Make sure you have it set on Character -> Basic Moves -> Blocking High Hit");

            }

        }else if (!myPhysicsScript.IsGrounded()){
            currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.blockingAirHit, hit);
            currentHitInfo = myMoveSetScript.basicMoves.blockingAirHit;
            if (!myMoveSetScript.AnimationExists(currentHitAnimation))
                Debug.LogError("Blocking Air Hit animation not found! Make sure you have it set on Character -> Basic Moves -> Blocking Air Hit");
        }

        myMoveSetScript.PlayBasicMove(currentHitInfo, currentHitAnimation);
        float hitAnimationSpeed = myMoveSetScript.GetAnimationLengh(currentHitAnimation) / stunTime;

        if (currentHitInfo.autoSpeed) {
            myMoveSetScript.SetAnimationSpeed(currentHitAnimation, hitAnimationSpeed);
        }
        if (UFE.config.hitOptions.useHitStunDeceleration) {
            hitStunDeceleration = hitAnimationSpeed + (stunTime / 2);
        }

        // Freeze screen depending on how strong the hit was
        HitPause(GetHitAnimationSpeed(hit.hitStrength) * .01f);
        UFE.DelaySynchronizedAction(this.HitUnpause, GetHitFreezingTime(hit.hitStrength));

        // Reset hit to allow for another hit while the character is still stunned
        float spaceBetweenHits = 1;
        if (hit.spaceBetweenHits == Sizes.Small){
            spaceBetweenHits = 1.1f;
        }else if (hit.spaceBetweenHits == Sizes.Medium){
            spaceBetweenHits = 1.3f;
        }else if (hit.spaceBetweenHits == Sizes.High){
            spaceBetweenHits = 1.7f;
        }
        UFE.DelaySynchronizedAction(myHitBoxesScript.ResetHit, GetHitFreezingTime(hit.hitStrength) * spaceBetweenHits);

        // Add force to the move
        myPhysicsScript.ResetForces(hit.resetPreviousHorizontalPush, hit.resetPreviousVerticalPush);

        if (!UFE.config.blockOptions.ignoreAppliedForceBlock)
            myPhysicsScript.AddForce(new Vector3(hit.pushForce.x, 0, 0), -opControlsScript.mirror);
    }
Пример #2
0
    public void GetHit(Hit hit, int remainingFrames, Vector3 location)
    {
        // Get what animation should be played depending on the character's state
        bool airHit = false;
        bool armored = false;
        bool isKnockDown = false;
        float verticalPush = 0;
        float damageModifier = 1;
        float hitStunModifier = 1;
        BasicMoveInfo currentHitInfo;
        hitStunDeceleration = 0;

        myHitBoxesScript.isHit = true;

        if (myInfo.headLook.disableOnHit) ToggleHeadLook(false);

        if (currentMove != null && currentMove.frameLinks.Length > 0){
            foreach (FrameLink frameLink in currentMove.frameLinks){
                if (currentMove.currentFrame >= frameLink.activeFramesBegins &&
                    currentMove.currentFrame <= frameLink.activeFramesEnds) {
                    if (frameLink.linkType == LinkType.CounterMove){
                        bool cancelable = false;
                        if (frameLink.counterMoveType == CounterMoveType.SpecificMove){
                            if (frameLink.counterMoveFilter == currentMove) cancelable = true;
                        }else{
                            HitBox strokeHitBox = myHitBoxesScript.GetStrokeHitBox();
                            if ((frameLink.anyHitStrength || frameLink.hitStrength == hit.hitStrength) &&
                                (frameLink.anyStrokeHitBox || frameLink.hitBoxType == strokeHitBox.type) &&
                                (frameLink.anyHitType || frameLink.hitType == hit.hitType)){
                                cancelable = true;
                            }
                        }

                        if (cancelable){
                            frameLink.cancelable = true;
                            currentMove.cancelable = true;

                            if (frameLink.disableHitImpact) {
                                float timeLeft = (float)(currentMove.totalFrames - currentMove.currentFrame)/(float)UFE.config.fps;

                                myHitBoxesScript.ResetHit();
                                UFE.DelaySynchronizedAction(myHitBoxesScript.ResetHit, timeLeft);
                                return;
                            }
                        }
                    }
                }
            }
        }

        // Set position in case of pull enemy in
        activePullIn = null;
        if (hit.pullEnemyIn.enemyBodyPart != BodyPart.none && hit.pullEnemyIn.characterBodyPart != BodyPart.none){
            Vector3 newPos = myHitBoxesScript.GetPosition(hit.pullEnemyIn.enemyBodyPart);
            if (newPos != Vector3.zero){
                activePullIn = new PullIn();
                activePullIn.position = transform.position + (opHitBoxesScript.GetPosition(hit.pullEnemyIn.characterBodyPart) - newPos);
                activePullIn.speed = hit.pullEnemyIn.speed;
                activePullIn.forceStand = hit.pullEnemyIn.forceStand;
                activePullIn.position.z = 0;
                if (hit.pullEnemyIn.forceStand) {
                    activePullIn.position.y = 0;
                    myPhysicsScript.ForceGrounded();
                }
            }
        }

        if (myPhysicsScript.IsGrounded()) {
            if (hit.hitStrength == HitStrengh.Crumple){
                if (myMoveSetScript.basicMoves.getHitCrumple.clip1 == null)
                    Debug.LogError("Get Hit Crumple animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Crumple");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitCrumple.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitCrumple;
                if (myMoveSetScript.basicMoves.getHitCrumple.invincible) myHitBoxesScript.HideHitBoxes(true);
            }else if (hit.hitType == HitType.Launcher){
                if (myMoveSetScript.basicMoves.getHitAir.clip1 == null)
                    Debug.LogError("Get Hit Air animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Air");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitAir.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitAir;
                if (myMoveSetScript.basicMoves.getHitAir.invincible) myHitBoxesScript.HideHitBoxes(true);
                airHit = true;
            }else if (hit.hitType == HitType.KnockBack){
                if (myMoveSetScript.basicMoves.getHitKnockBack.clip1 == null)
                    Debug.LogError("Get Hit Knock Back animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Knock Back");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitKnockBack.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitKnockBack;
                if (myMoveSetScript.basicMoves.getHitKnockBack.invincible) myHitBoxesScript.HideHitBoxes(true);
                airHit = true;
            }else if (hit.hitType == HitType.HighKnockdown){
                if (myMoveSetScript.basicMoves.getHitHighKnockdown.clip1 == null)
                    Debug.LogError("Get Hit High Knockdown animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit High Knockdown");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitHighKnockdown.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitHighKnockdown;
                if (myMoveSetScript.basicMoves.getHitHighKnockdown.invincible) myHitBoxesScript.HideHitBoxes(true);
                isKnockDown = true;
            }else if (hit.hitType == HitType.MidKnockdown){
                if (myMoveSetScript.basicMoves.getHitHighLowKnockdown.clip1 == null)
                    Debug.LogError("Get Hit High-Low Knockdown animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit High-Low Knockdown");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitHighLowKnockdown.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitHighLowKnockdown;
                if (myMoveSetScript.basicMoves.getHitHighLowKnockdown.invincible) myHitBoxesScript.HideHitBoxes(true);
                isKnockDown = true;
            }else if (hit.hitType == HitType.Sweep){
                if (myMoveSetScript.basicMoves.getHitSweep.clip1 == null)
                    Debug.LogError("Get Hit Sweep animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Sweep");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitSweep.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitSweep;
                if (myMoveSetScript.basicMoves.getHitSweep.invincible) myHitBoxesScript.HideHitBoxes(true);
                isKnockDown = true;
            }else if (currentState == PossibleStates.Crouch){
                if (myMoveSetScript.basicMoves.getHitCrouching.clip1 == null)
                    Debug.LogError("Get Hit Crouching animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Crouching");
                currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.getHitCrouching, hit);
                currentHitInfo = myMoveSetScript.basicMoves.getHitCrouching;
                if (myMoveSetScript.basicMoves.getHitCrouching.invincible) myHitBoxesScript.HideHitBoxes(true);
            }else{
                HitBox strokeHit = myHitBoxesScript.GetStrokeHitBox();
                if (strokeHit.type == HitBoxType.low && myMoveSetScript.basicMoves.getHitLow.clip1 != null){
                    currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.getHitLow, hit);
                    currentHitInfo = myMoveSetScript.basicMoves.getHitLow;
                    if (myMoveSetScript.basicMoves.getHitLow.invincible) myHitBoxesScript.HideHitBoxes(true);
                }else{
                    if (myMoveSetScript.basicMoves.getHitHigh.clip1 == null)
                        Debug.LogError("Get Hit High animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit High");
                    currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.getHitHigh, hit);
                    currentHitInfo = myMoveSetScript.basicMoves.getHitHigh;
                    if (myMoveSetScript.basicMoves.getHitHigh.invincible) myHitBoxesScript.HideHitBoxes(true);
                }
            }
        }else{
            if (hit.hitStrength == HitStrengh.Crumple && myMoveSetScript.basicMoves.getHitKnockBack.clip1 != null){
                currentHitAnimation = myMoveSetScript.basicMoves.getHitKnockBack.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitKnockBack;
            }else{
                if (myMoveSetScript.basicMoves.getHitAir.clip1 == null)
                    Debug.LogError("Get Hit Air animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Air");
                currentHitAnimation = myMoveSetScript.basicMoves.getHitAir.name;
                currentHitInfo = myMoveSetScript.basicMoves.getHitAir;
            }
            airHit = true;
        }

        // Differenciate hit types
        HitTypeOptions hitEffects = hit.hitEffects;
        if (!hit.overrideHitEffects) {
            if (hit.hitStrength == HitStrengh.Weak) hitEffects = UFE.config.hitOptions.weakHit;
            if (hit.hitStrength == HitStrengh.Medium) hitEffects = UFE.config.hitOptions.mediumHit;
            if (hit.hitStrength == HitStrengh.Heavy) hitEffects = UFE.config.hitOptions.heavyHit;
            if (hit.hitStrength == HitStrengh.Crumple) hitEffects = UFE.config.hitOptions.crumpleHit;
            if (hit.hitStrength == HitStrengh.Custom1) hitEffects = UFE.config.hitOptions.customHit1;
            if (hit.hitStrength == HitStrengh.Custom2) hitEffects = UFE.config.hitOptions.customHit2;
            if (hit.hitStrength == HitStrengh.Custom3) hitEffects = UFE.config.hitOptions.customHit3;
        }

        // Cancel current move if any
        if (!hit.armorBreaker && currentMove != null && currentMove.armorOptions.hitAbsorption > 0 &&
            currentMove.currentFrame >= currentMove.armorOptions.activeFramesBegin &&
            currentMove.currentFrame <= currentMove.armorOptions.activeFramesEnds){
            armored = true;
            currentMove.armorOptions.hitAbsorption --;
            damageModifier -= currentMove.armorOptions.damageAbsorption * .01f;
            if (currentMove.armorOptions.overrideHitEffects)
                hitEffects = currentMove.armorOptions.hitEffects;

        }else if (currentMove != null && !currentMove.hitAnimationOverride){
            if ((UFE.config.counterHitOptions.startUpFrames && currentMove.currentFrameData == CurrentFrameData.StartupFrames) ||
                (UFE.config.counterHitOptions.activeFrames && currentMove.currentFrameData == CurrentFrameData.ActiveFrames) ||
                (UFE.config.counterHitOptions.recoveryFrames && currentMove.currentFrameData == CurrentFrameData.RecoveryFrames)){
                UFE.FireAlert(UFE.config.selectedLanguage.counterHit, opInfo);
                damageModifier += UFE.config.counterHitOptions.damageIncrease * .01f;
                hitStunModifier += UFE.config.counterHitOptions.hitStunIncrease * .01f;
            }
            storedMove = null;

            KillCurrentMove();
        }

        // Create hit effect
        if (location != Vector3.zero && hitEffects.hitParticle != null){
            GameObject pTemp = (GameObject) Instantiate(hitEffects.hitParticle, location, Quaternion.identity);
            Destroy(pTemp, hitEffects.killTime);
        }

        // Play sound
        UFE.PlaySound(hitEffects.hitSound);

        // Shake Options
        shakeCamera = hitEffects.shakeCameraOnHit;
        shakeCharacter = hitEffects.shakeCharacterOnHit;
        shakeDensity = hitEffects.shakeDensity;

        // Cast First Hit if true
        if (!firstHit && !opControlsScript.firstHit){
            opControlsScript.firstHit = true;
            UFE.FireAlert(UFE.config.selectedLanguage.firstHit, opInfo);
        }
        UFE.FireHit(myHitBoxesScript.GetStrokeHitBox(), opControlsScript.currentMove, opInfo);

        // Convert Percentage
        if (hit.damageType == DamageType.Percentage) hit.damageOnHit = myInfo.lifePoints * (hit.damageOnHit/100);

        // Damage deterioration
        float damage = 0;
        if (!hit.damageScaling || UFE.config.comboOptions.damageDeterioration == Sizes.None){
            damage = hit.damageOnHit;
        }else if (UFE.config.comboOptions.damageDeterioration == Sizes.Small){
            damage = hit.damageOnHit - (hit.damageOnHit * (float)comboHits * .1f);
        }else if (UFE.config.comboOptions.damageDeterioration == Sizes.Medium){
            damage = hit.damageOnHit - (hit.damageOnHit * (float)comboHits * .2f);
        }else if (UFE.config.comboOptions.damageDeterioration == Sizes.High){
            damage = hit.damageOnHit - (hit.damageOnHit * (float)comboHits * .4f);
        }
        if (damage < UFE.config.comboOptions.minDamage) damage = UFE.config.comboOptions.minDamage;
        damage *= damageModifier;
        comboHitDamage = damage;
        comboDamage += damage;
        comboHits ++;

        // Lose life
        isDead = DamageMe(damage, hit.doesntKill);

        // Reset hit to allow for another hit while the character is still stunned
        float spaceBetweenHits = 1;
        if (hit.spaceBetweenHits == Sizes.Small){
            spaceBetweenHits = 1.1f;
        }else if (hit.spaceBetweenHits == Sizes.Medium){
            spaceBetweenHits = 1.3f;
        }else if (hit.spaceBetweenHits == Sizes.High){
            spaceBetweenHits = 1.7f;
        }
        UFE.DelaySynchronizedAction(myHitBoxesScript.ResetHit, hitEffects.freezingTime * spaceBetweenHits);

        if ((currentMove == null || !currentMove.hitAnimationOverride) && !armored) {
            // Stun
            // Hit stun deterioration (the longer the combo gets, the harder it is to combo)
            currentSubState = SubStates.Stunned;
            int stunFrames = 0;
            if (hit.hitStunType == HitStunType.FrameAdvantage) {
                stunFrames = hit.frameAdvantageOnHit + remainingFrames;
                if (stunFrames < 1) stunFrames = 1;
                if (stunFrames < UFE.config.comboOptions.minHitStun) stunTime = UFE.config.comboOptions.minHitStun;
                stunTime = (float)stunFrames/(float)UFE.config.fps;
            }else if (hit.hitStunType == HitStunType.Frames) {
                stunFrames = (int) hit.hitStunOnHit;
                if (stunFrames < 1) stunFrames = 1;
                if (stunFrames < UFE.config.comboOptions.minHitStun) stunTime = UFE.config.comboOptions.minHitStun;
                stunTime = (float)stunFrames/(float)UFE.config.fps;
            }else{
                stunTime = hit.hitStunOnHit;
            }

            if (!hit.resetPreviousHitStun){
                if (UFE.config.comboOptions.hitStunDeterioration == Sizes.Small){
                    stunTime -= (float)comboHits * .01f;
                }else if (UFE.config.comboOptions.hitStunDeterioration == Sizes.Medium){
                    stunTime -= (float)comboHits * .02f;
                }else if (UFE.config.comboOptions.hitStunDeterioration == Sizes.High){
                    stunTime -= (float)comboHits * .04f;
                }
            }
            stunTime *= hitStunModifier;

            verticalPush = hit.pushForce.y;
            // Add force to the move
            // Air juggle deterioration (the longer the combo, the harder it is to push the opponent higher)
            if (verticalPush > 0 || (isDead && !isKnockDown)){
                if (UFE.config.comboOptions.airJuggleDeteriorationType == AirJuggleDeteriorationType.ComboHits){
                    airJuggleHits = comboHits - 1;
                }
                if (UFE.config.comboOptions.airJuggleDeterioration == Sizes.None){
                    verticalPush = hit.pushForce.y;
                }else if (UFE.config.comboOptions.airJuggleDeterioration == Sizes.Small){
                    verticalPush = hit.pushForce.y - (hit.pushForce.y * (float)airJuggleHits * .04f);
                }else if (UFE.config.comboOptions.airJuggleDeterioration == Sizes.Medium){
                    verticalPush = hit.pushForce.y - (hit.pushForce.y * (float)airJuggleHits * .1f);
                }else if (UFE.config.comboOptions.airJuggleDeterioration == Sizes.High){
                    verticalPush = hit.pushForce.y - (hit.pushForce.y * (float)airJuggleHits * .3f);
                }
                if (verticalPush < UFE.config.comboOptions.minPushForce) verticalPush = UFE.config.comboOptions.minPushForce;
                airJuggleHits ++;
            }

            if (UFE.config.comboOptions.fixJuggleWeight){
                myPhysicsScript.ApplyNewWeight(UFE.config.comboOptions.juggleWeight);
            }

            if (isDead) stunTime = 9999;

            if ((airHit || UFE.config.comboOptions.neverAirRecover) && verticalPush > 0){

                if (myMoveSetScript.basicMoves.getHitAir.clip1 == null)
                    Debug.LogError("Get Hit Air animation not found! Make sure you have it set on Character -> Basic Moves -> Get Hit Air");
                if (myMoveSetScript.basicMoves.getHitAir.invincible) myHitBoxesScript.HideHitBoxes(true);

                myPhysicsScript.ResetForces(hit.resetPreviousHorizontalPush, hit.resetPreviousVerticalPush);
                myPhysicsScript.AddForce(new Vector2(hit.pushForce.x, verticalPush), -opControlsScript.mirror);
                if (myMoveSetScript.basicMoves.getHitKnockBack.clip1 != null &&
                    hit.pushForce.x > UFE.config.comboOptions.knockBackMinForce) {
                    currentHitAnimation = myMoveSetScript.basicMoves.getHitKnockBack.name;
                    currentHitInfo = myMoveSetScript.basicMoves.getHitKnockBack;
                }else{
                    currentHitAnimation = myMoveSetScript.basicMoves.getHitAir.name;
                    currentHitInfo = myMoveSetScript.basicMoves.getHitAir;
                }

                myMoveSetScript.PlayBasicMove(currentHitInfo, currentHitAnimation, UFE.config.hitOptions.resetAnimationOnHit);

                if (currentHitInfo.autoSpeed) {
                    // if the hit was in the air, calculate the time it will take for the character to hit the ground
                    float airTime = myPhysicsScript.GetPossibleAirTime(verticalPush) * 2;
                    if (stunTime > airTime || UFE.config.comboOptions.neverAirRecover) stunTime = airTime;
                    myMoveSetScript.SetAnimationNormalizedSpeed(currentHitAnimation, (myMoveSetScript.GetAnimationLengh(currentHitAnimation) / stunTime));
                }

            }else{

                float hitAnimationSpeed = 0;
                float knockoutAnimationLenght = 0;

                if (hit.hitType == HitType.HighKnockdown){
                    // if its a knockdown, animation will run at normal speed and character will stay knockdown for -stunTime- seconds.
                    knockoutAnimationLenght = myMoveSetScript.GetAnimationLengh(currentHitAnimation)/myMoveSetScript.basicMoves.getHitHighKnockdown.animationSpeed;
                    stunTime = knockoutAnimationLenght + AdjustKnockdownVariables(UFE.config.knockDownOptions.high);
                }else if (hit.hitType == HitType.MidKnockdown){
                    // if its a knockdown, animation will run at normal speed and character will stay knockdown for -stunTime- seconds.
                    knockoutAnimationLenght = myMoveSetScript.GetAnimationLengh(currentHitAnimation)/myMoveSetScript.basicMoves.getHitHighLowKnockdown.animationSpeed;
                    stunTime = knockoutAnimationLenght + AdjustKnockdownVariables(UFE.config.knockDownOptions.highLow);
                }else if (hit.hitType == HitType.Sweep){
                    // if its a knockdown, animation will run at normal speed and character will stay knockdown for -stunTime- seconds.
                    knockoutAnimationLenght = myMoveSetScript.GetAnimationLengh(currentHitAnimation)/myMoveSetScript.basicMoves.getHitSweep.animationSpeed;
                    stunTime = knockoutAnimationLenght + AdjustKnockdownVariables(UFE.config.knockDownOptions.sweep);
                }else if (hit.hitStrength == HitStrengh.Crumple){
                    stunTime += UFE.config.knockDownOptions.crumple.standUpTime;
                }else {
                    hitAnimationSpeed = myMoveSetScript.GetAnimationLengh(currentHitAnimation)/stunTime;

                    myPhysicsScript.ResetForces(hit.resetPreviousHorizontalPush, hit.resetPreviousVerticalPush);
                    myPhysicsScript.AddForce(new Vector2(hit.pushForce.x, verticalPush), -opControlsScript.mirror);

                    // Set deceleration of hit stun animation so it can look more natural
                    if (UFE.config.hitOptions.useHitStunDeceleration) {
                        hitStunDeceleration = hitAnimationSpeed + (stunTime / 2);
                    }
                }

                myMoveSetScript.PlayBasicMove(currentHitInfo, currentHitAnimation, UFE.config.hitOptions.resetAnimationOnHit);
                if (currentHitInfo.autoSpeed && hitAnimationSpeed > 0) {
                    myMoveSetScript.SetAnimationSpeed(currentHitAnimation, hitAnimationSpeed);
                }

            }
        }

        // Freeze screen depending on how strong the hit was
        HitPause(GetHitAnimationSpeed(hit.hitStrength) * .01f);
        UFE.DelaySynchronizedAction(this.HitUnpause, hitEffects.freezingTime);
    }
Пример #3
0
    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);
    }
Пример #4
0
    // Release character to be playable again
    private void ReleaseStun()
    {
        if (currentSubState != SubStates.Stunned && !blockStunned) return;
        if (!isBlocking && comboHits > 1) {
            UFE.FireAlert(UFE.config.selectedLanguage.combo, opInfo);
        }
        currentSubState = SubStates.Resting;
        blockStunned = false;
        stunTime = 0;
        comboHits = 0;
        comboDamage = 0;
        comboHitDamage = 0;
        airJuggleHits = 0;
        CheckBlocking(false);

        standUpOverride = StandUpOptions.None;

        myPhysicsScript.ResetWeight();
        if (!isDead) ToggleHeadLook(true);

        if (myPhysicsScript.IsGrounded()) currentState = PossibleStates.Stand;
        translateInputs(inputController);

        myHitBoxesScript.HideHitBoxes(false);
    }
Пример #5
0
    public void ResetData(bool resetLife)
    {
        if (UFE.config.roundOptions.resetPositions){
            if (gameObject.name == "Player1"){
                transform.position = new Vector2(UFE.config.roundOptions.p1XPosition, .009f);
            }else{
                transform.position = new Vector2(UFE.config.roundOptions.p2XPosition, .009f);
            }
            myMoveSetScript.PlayBasicMove(myMoveSetScript.basicMoves.idle, myMoveSetScript.basicMoves.idle.name, 0);
            myPhysicsScript.ForceGrounded();

        }else if (currentState == PossibleStates.Down && myPhysicsScript.IsGrounded()){
            myMoveSetScript.PlayAnimation("standUp", 0);
        }

        if (resetLife || UFE.config.roundOptions.resetLifePoints){
            myInfo.currentLifePoints = (float)myInfo.lifePoints;
        }
        blockStunned = false;
        stunTime = 0;
        comboHits = 0;
        comboDamage = 0;
        comboHitDamage = 0;
        airJuggleHits = 0;
        CheckBlocking(false);
        isDead = false;
        myPhysicsScript.isTakingOff = false;
        myPhysicsScript.isLanding = false;

        myHitBoxesScript.HideHitBoxes(false);
        myPhysicsScript.ResetWeight();
        ToggleHeadLook(true);

        currentState = PossibleStates.Stand;
        currentSubState = SubStates.Resting;
    }
Пример #6
0
    public void GetHitParry(Hit hit, int remainingFrames, Vector3 location)
    {
        UFE.FireAlert(UFE.config.selectedLanguage.parry, myInfo);

        BasicMoveInfo currentHitInfo = myMoveSetScript.basicMoves.parryHigh;
        blockStunned = true;
        currentSubState = SubStates.Blocking;

        myHitBoxesScript.isHit = true;

        potentialParry = 0;

        if (UFE.config.blockOptions.resetButtonSequence){
            myMoveSetScript.ClearLastButtonSequence();
        }

        if (UFE.config.blockOptions.parryStunType == ParryStunType.Fixed){
            stunTime = (float)UFE.config.blockOptions.parryStunFrames/(float)UFE.config.fps;
        }else{
            int stunFrames = 0;
            if (hit.hitStunType == HitStunType.FrameAdvantage) {
                stunFrames = hit.frameAdvantageOnBlock + remainingFrames;
                stunFrames *= (UFE.config.blockOptions.parryStunFrames/100);
                if (stunFrames < 1) stunFrames = 1;
                stunTime = (float)stunFrames/(float)UFE.config.fps;
            }else if (hit.hitStunType == HitStunType.Frames) {
                stunFrames = (int) hit.hitStunOnBlock;
                stunFrames *= (UFE.config.blockOptions.parryStunFrames/100);
                if (stunFrames < 1) stunFrames = 1;
                stunTime = (float)stunFrames/(float)UFE.config.fps;
            }else{
                stunTime = hit.hitStunOnBlock * (UFE.config.blockOptions.parryStunFrames/100);
            }
        }

        // Create hit parry effect
        GameObject particle = UFE.config.blockOptions.parryHitEffects.hitParticle;
        float killTime = UFE.config.blockOptions.parryHitEffects.killTime;
        AudioClip soundEffect = UFE.config.blockOptions.parryHitEffects.hitSound;
        if (location != Vector3.zero && particle != null){
            GameObject pTemp = (GameObject) Instantiate(particle);
            pTemp.transform.position = location;
            pTemp.transform.localScale = new Vector3(-mirror, 1, 1);
            Destroy(pTemp, killTime);
        }
        UFE.PlaySound(soundEffect);

        // Shake Options
        shakeCamera = UFE.config.blockOptions.parryHitEffects.shakeCameraOnHit;
        shakeCharacter = UFE.config.blockOptions.parryHitEffects.shakeCharacterOnHit;
        shakeDensity = UFE.config.blockOptions.parryHitEffects.shakeDensity;

        // Get correct animation according to stance
        if (currentState == PossibleStates.Crouch) {
            currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.parryCrouching, hit);
            currentHitInfo = myMoveSetScript.basicMoves.parryCrouching;
            if (!myMoveSetScript.AnimationExists(currentHitAnimation))
                Debug.LogError("Parry Crouching animation not found! Make sure you have it set on Character -> Basic Moves -> Parry Animations -> Crouching");
        }else if (currentState == PossibleStates.Stand){
            HitBox strokeHit = myHitBoxesScript.GetStrokeHitBox();
            if (strokeHit.type == HitBoxType.low && myMoveSetScript.basicMoves.parryLow.clip1 != null) {
                currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.parryLow, hit);
                currentHitInfo = myMoveSetScript.basicMoves.parryLow;

            } else {
                currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.parryHigh, hit);
                currentHitInfo = myMoveSetScript.basicMoves.parryHigh;
                if (!myMoveSetScript.AnimationExists(currentHitAnimation))
                    Debug.LogError("Parry High animation not found! Make sure you have it set on Character -> Basic Moves -> Parry Animations -> Standing");

            }
        } else if (!myPhysicsScript.IsGrounded()) {
            currentHitAnimation = GetHitAnimation(myMoveSetScript.basicMoves.parryAir, hit);
            currentHitInfo = myMoveSetScript.basicMoves.parryAir;
            if (!myMoveSetScript.AnimationExists(currentHitAnimation))
                Debug.LogError("Parry Air animation not found! Make sure you have it set on Character -> Basic Moves -> Parry Animations -> Air");
        }

        myMoveSetScript.PlayBasicMove(currentHitInfo, currentHitAnimation);
        if (currentHitInfo.autoSpeed) {
            myMoveSetScript.SetAnimationSpeed(currentHitAnimation, (myMoveSetScript.GetAnimationLengh(currentHitAnimation) / stunTime));
        }

        // Highlight effect when parry
        if (UFE.config.blockOptions.highlightWhenParry){
            HighlightOn(gameObject, true);
            UFE.DelaySynchronizedAction(this.HighlightOff, 0.2f);
        }

        // Freeze screen depending on how strong the hit was
        HitPause(GetHitAnimationSpeed(hit.hitStrength) * .01f);
        UFE.DelaySynchronizedAction(this.HitUnpause, GetHitFreezingTime(hit.hitStrength));

        // Reset hit to allow for another hit while the character is still stunned
        float spaceBetweenHits = 1;
        if (hit.spaceBetweenHits == Sizes.Small){
            spaceBetweenHits = 1.1f;
        }else if (hit.spaceBetweenHits == Sizes.Medium){
            spaceBetweenHits = 1.3f;
        }else if (hit.spaceBetweenHits == Sizes.High){
            spaceBetweenHits = 1.7f;
        }

        UFE.DelaySynchronizedAction(myHitBoxesScript.ResetHit,GetHitFreezingTime(hit.hitStrength) * spaceBetweenHits * 1.2f);

        // Add force to the move
        myPhysicsScript.ResetForces(hit.resetPreviousHorizontalPush, hit.resetPreviousVerticalPush);

        if (!UFE.config.blockOptions.ignoreAppliedForceParry)
            myPhysicsScript.AddForce(new Vector3(hit.pushForce.x, 0, 0), -opControlsScript.mirror);
    }