Exemplo n.º 1
0
    private void CheckAmmo()
    {
        int retrievedAmmo        = AntiHackSystem.RetrieveInt("currentAmmo");
        int retrievedAmmoLeft    = AntiHackSystem.RetrieveInt("ammoLeft");
        int retrievedAmmoLeftCap = AntiHackSystem.RetrieveInt("ammoLeftCap");

        ammoLeft = Mathf.Clamp(retrievedAmmoLeft, 0, retrievedAmmoLeftCap);

        if (!reloadOnMouseClick && cInput.GetButtonDown("Fire Weapon") && (Time.time - lastClick) > 0.3f && retrievedAmmo <= 0 && !reloading && !RestrictionManager.restricted)
        {
            if (Topan.Network.isConnected && wm.rootNetView)
            {
                wm.rootNetView.UnreliableRPC(Topan.RPCMode.Others, "NetworkEmptyClick");
            }

            firePos.GetComponent <AudioSource>().PlayOneShot(emptySound);
            dm.EmptyAnimation();
            lastClick = Time.time;
        }

        int newMaxSize = AntiHackSystem.RetrieveInt("clipSize") + ((bulletInChamber) ? 1 : 0);

        currentAmmo = Mathf.Clamp(retrievedAmmo, 0, newMaxSize);
        ammoDif     = newMaxSize - retrievedAmmo;
        percent     = (float)retrievedAmmo / (float)newMaxSize;
    }
Exemplo n.º 2
0
    private void StartMagazineReload()
    {
        if (reloading)
        {
            return;
        }

        startReload  = Time.time;
        reloading    = true;
        tss.pitchMod = 1f;

        bool magIsEmpty = (AntiHackSystem.RetrieveInt("currentAmmo") <= 0);

        tss.GetComponent <AudioSource>().PlayOneShot((magIsEmpty && reloadSoundEmpty != null) ? reloadSoundEmpty : reloadSound, 0.5f);
        curReloadDur = (magIsEmpty && reloadSoundEmpty != null) ? reloadLengthEmpty : reloadLength;

        if (Topan.Network.isConnected && wm.rootNetView)
        {
            wm.rootNetView.RPC(Topan.RPCMode.Others, "NetworkReload", magIsEmpty);
        }

        //Assign a new variable called AnimationContainer instead of using parents...

        /*
         *      if(reloadAnim != "" && !transform.parent.parent.parent.animation.isPlaying) {
         *              transform.parent.parent.parent.animation.Play(reloadAnim);
         *      }
         */
    }
Exemplo n.º 3
0
 private void ClampGrenadeAmount()
 {
     typeOneMaxGrenades = AntiHackSystem.RetrieveInt("t1GrenadeMax");
     typeTwoMaxGrenades = AntiHackSystem.RetrieveInt("t2GrenadeMax");
     typeOneGrenades    = Mathf.Clamp(AntiHackSystem.RetrieveInt("t1Grenade"), 0, typeOneMaxGrenades);
     typeTwoGrenades    = Mathf.Clamp(AntiHackSystem.RetrieveInt("t2Grenade"), 0, typeTwoMaxGrenades);
 }
Exemplo n.º 4
0
 public void OnWeaponDraw()
 {
     AntiHackSystem.ProtectInt("currentAmmo", currentAmmo);
     AntiHackSystem.ProtectInt("clipSize", clipSize);
     AntiHackSystem.ProtectInt("ammoLeft", ammoLeft);
     AntiHackSystem.ProtectInt("ammoLeftCap", ammoLeftCap);
 }
Exemplo n.º 5
0
    void Start()
    {
        slotOneLabel = GeneralVariables.uiController.grenadeOneLabel;
        slotTwoLabel = GeneralVariables.uiController.grenadeTwoLabel;

        AntiHackSystem.ProtectInt("t1Grenade", typeOneGrenades);
        AntiHackSystem.ProtectInt("t1GrenadeMax", typeOneMaxGrenades);
        AntiHackSystem.ProtectInt("t2Grenade", typeTwoGrenades);
        AntiHackSystem.ProtectInt("t2GrenadeMax", typeTwoMaxGrenades);
        pe = GeneralVariables.player.GetComponent <PlayerEffects>();
    }
Exemplo n.º 6
0
    void Update()
    {
        ClampGrenadeAmount();

        if (Time.time - lastUpdateTime >= 0.1f)
        {
            slotOneLabel.text = (pe.hasEMP) ? Random.Range(0, 10).ToString() : AntiHackSystem.RetrieveInt("t1Grenade").ToString();
            slotTwoLabel.text = (pe.hasEMP) ? Random.Range(0, 10).ToString() : AntiHackSystem.RetrieveInt("t2Grenade").ToString();

            lastUpdateTime = Time.time;
        }
    }
Exemplo n.º 7
0
    public void ChangeGrenadeAmount(int id, int amount)
    {
        if (id == grenadeTypeOne)
        {
            AntiHackSystem.ProtectInt("t1Grenade", typeOneGrenades + amount);
        }
        else if (id == grenadeTypeTwo)
        {
            AntiHackSystem.ProtectInt("t2Grenade", typeTwoGrenades + amount);
        }

        ClampGrenadeAmount();
    }
Exemplo n.º 8
0
    void Start()
    {
        GeneralVariables.player = gameObject;
        GeneralVariables.uiController.guiCamera.enabled = true;
        tr             = transform;
        controller     = GetComponent <CharacterController>();
        tss            = footsteps.footstepPos.GetComponent <TimeScaleSound>();
        playerMeshAnim = animations.playerMesh.GetComponent <Animation>();

        UIController uic = GeneralVariables.uiController;

        fadeSprite = uic.fadeFromBlack;
        uic.guiCamera.GetComponent <GUISway>().InitializeVariables();

        PlayerReference pr = GetComponent <PlayerReference>();

        pv = GetComponent <PlayerVitals>();
        pl = GetComponent <PlayerLook>();
        ia = pr.ia;
        wc = pr.wc;
        ac = pr.ac;
        wm = pr.wm;
        dm = pr.dm;

        defaultHeight  = controller.height;
        defaultHeadPos = head.localPosition;
        defaultLegPos  = animations.playerMesh.transform.localPosition + (Vector3.down * animations.meshOffset);
        normalLimit    = Mathf.Cos(controller.slopeLimit * Mathf.Deg2Rad);
        curSpeed       = movement.runSpeed;
        jumpTime       = -0.25f;
        impactMod      = 1f;
        fDmgSpeedMult  = 1f;

        AntiHackSystem.ProtectFloat("runSpeed", movement.runSpeed);
        AntiHackSystem.ProtectFloat("sprintSpeed", movement.sprintSpeed);
        AntiHackSystem.ProtectFloat("crouchSpeed", movement.crouchSpeed);
        AntiHackSystem.ProtectFloat("walkSpeed", movement.walkSpeed);
        AntiHackSystem.ProtectFloat("jumpHeight", movement.jumpHeight);

        grounded = false;
        movement.crouchDetection.gameObject.SetActive(false);
        AudioSource.PlayClipAtPoint(initializeSound, footsteps.footstepPos.transform.position, 0.12f);
        StartCoroutine(FadeFromBlack());
    }
Exemplo n.º 9
0
    private void InsertBullet()
    {
        int retrievedAmmo     = AntiHackSystem.RetrieveInt("currentAmmo");
        int retrievedAmmoLeft = AntiHackSystem.RetrieveInt("ammoLeft");
        int retrievedClipSize = AntiHackSystem.RetrieveInt("clipSize");

        if (retrievedAmmo >= retrievedClipSize || retrievedAmmoLeft <= 0 || queueStopReload)
        {
            if (!doneReloading)
            {
                StartCoroutine(StopSingularReload());
            }

            return;
        }

        if (retrievedAmmo < retrievedClipSize && retrievedAmmoLeft > 0)
        {
            if (ammoDif < reloadAmount)
            {
                AntiHackSystem.ProtectInt("currentAmmo", currentAmmo + ammoDif);
                AntiHackSystem.ProtectInt("ammoLeft", ammoLeft - ammoDif);
            }
            else if (reloadAmount >= retrievedAmmoLeft)
            {
                AntiHackSystem.ProtectInt("currentAmmo", currentAmmo + ammoLeft);
                AntiHackSystem.ProtectInt("ammoLeft", 0);
            }
            else
            {
                AntiHackSystem.ProtectInt("currentAmmo", currentAmmo + reloadAmount);
                AntiHackSystem.ProtectInt("ammoLeft", ammoLeft - reloadAmount);
            }

            tss.pitchMod = Random.Range(0.95f, 1f);
            tss.GetComponent <AudioSource>().PlayOneShot(reloadSound, 0.5f);
            queueStopReload = forceStopReload;
            //Reload insert shell animation play.
        }

        reloadImpulseGUI += 0.1f;
    }
Exemplo n.º 10
0
    private IEnumerator Burst(float cwm, float vf, float af)
    {
        bursting = true;
        float burstTimer = 0f;
        int   fireCount  = 0;

        while (fireCount < bulletsPerBurst && AntiHackSystem.RetrieveInt("currentAmmo") > 0)
        {
            burstTimer += Time.deltaTime;
            if (burstTimer >= burstInterval)
            {
                Shoot(cwm, vf, af);
                fireCount++;
                burstTimer -= burstInterval;
            }
            yield return(null);
        }
        yield return(new WaitForSeconds(burstCooldown));

        bursting = false;
    }
Exemplo n.º 11
0
    public void MakePickup(Vector3 force)
    {
        Rigidbody body = gameObject.AddComponent <Rigidbody>();

        body.mass = 3f;

        UsableObject uo = gameObject.AddComponent <UsableObject>();

        uo.weaponPickup                 = new UsableObject.WeaponPickup();
        uo.weaponPickup.enabled         = true;
        uo.weaponPickup.ammoAmount      = AntiHackSystem.RetrieveInt("currentAmmo");
        uo.weaponPickup.reserveAmmo     = AntiHackSystem.RetrieveInt("ammoLeft");
        uo.weaponPickup.chamberedBullet = bulletInChamber;
        uo.weaponPickup.weaponID        = weaponID;
        transform.parent                = null;

        body.AddForce(force * 7f, ForceMode.Impulse);
        body.AddTorque(Random.rotation.eulerAngles * 3f, ForceMode.Impulse);

        uo.objectName = gunName;
        StripFunctions(false);
    }
Exemplo n.º 12
0
    private void Reload()
    {
        int retrievedAmmoLeft = AntiHackSystem.RetrieveInt("ammoLeft");

        bulletInChamber = (AntiHackSystem.RetrieveInt("currentAmmo") > 0 && includeChamberRound);
        CheckAmmo();

        AntiHackSystem.ProtectInt("currentAmmo", currentAmmo + ((ammoDif > retrievedAmmoLeft) ? retrievedAmmoLeft : (ammoDif + ((bulletInChamber) ? 1 : 0))));

        if (ammoDif > retrievedAmmoLeft)
        {
            AntiHackSystem.ProtectInt("ammoLeft", 0);
        }
        else
        {
            AntiHackSystem.ProtectInt("ammoLeft", ammoLeft - ammoDif);
        }

        reloadImpulseGUI += 0.1f;
        bsna              = baseSpreadAmount;
        endReload         = Time.time;
        reloading         = false;
    }
Exemplo n.º 13
0
    private Vector3 ApplyGravityAndJump(Vector3 vel)
    {
        if (!onLadder && grounded)
        {
            vel.y = Mathf.Min(0f, vel.y) - movement.gravity * Time.deltaTime;

            if (movement.enabled && !onLadder && (Time.time - jumpTime >= 0.25f + sprintJumpRestrict) && !RestrictionManager.restricted && !RestrictionManager.mpMatchRestrict && cInput.GetButtonDown("Jump") && groundNormal.y > normalLimit)
            {
                if (!crouching)
                {
                    int staminaDrain = (sprinting) ? 9 : 7;

                    if (pv.curStamina > staminaDrain)
                    {
                        float jumpWgtFactor = 1f - (wc.weightPercentage * 0.15f);
                        grounded = false;
                        didJump  = true;
                        ia.DoJumpAnimation();

                        jumpDir = Vector3.Slerp(Vector3.up, groundNormal, movement.perpAmount);

                        vel.y = 0f;
                        vel  += jumpDir * Mathf.Lerp(fDmgSpeedMult, 1f, 0.5f) * (Mathf.Sqrt(2f * AntiHackSystem.RetrieveFloat("jumpHeight") * jumpWgtFactor * 9.81f));

                        if (movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer || movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
                        {
                            Vector3 modVel = platformVelocity;
                            modVel.y = 0f;
                            modVel  *= 0.45f;

                            frameVelocity = modVel;
                            vel          += modVel;
                        }

                        pv.jumpRattleEquip = true;
                        pv.curStamina     -= Mathf.RoundToInt((staminaDrain - 2) * (1f / jumpWgtFactor));
                    }

                    sprintJumpRestrict = 0f;
                }
                else
                {
                    if (CanStandUp())
                    {
                        ia.DoImpactAnimation(1.9f);
                        crouching = false;
                    }
                }
            }
        }
        else if (onLadder)
        {
            vel       += currentLadder.climbDirection * Mathf.Clamp(inputVector.y + latchBoost, -1f, 1f) * movement.ladderClimbMagnitude * fDmgSpeedMult * (0.75f + (1f + Mathf.Cos(Time.time * 2f * Mathf.PI * movement.ladderClimbRate)) * 0.25f);
            latchBoost = Mathf.MoveTowards(latchBoost, 0f, Time.deltaTime * 3f);
            climbDir   = inputVector.normalized.y;

            float distanceToTop = Mathf.Max(-0.1f, currentLadder.topSpot.y - tr.position.y);
            if (distanceToTop < 0.9f)
            {
                pl.ladderClampAnim = Mathf.Lerp(pl.ladderClampAnim, (0.9f - distanceToTop) * 100f, Time.deltaTime * 5.5f);
            }
        }
        else
        {
            vel.y = Mathf.Max(velocity.y - movement.gravity * Time.deltaTime, (!onLadder) ? -movement.maxFallSpeed : 0f);
            dm.terminalVelocity = (vel.y <= -movement.maxFallSpeed * 0.85f);
            jumpTime            = Time.time;
        }

        return(vel);
    }
Exemplo n.º 14
0
    private Vector3 ApplyInputVelocity(Vector3 vel)
    {
        if (!movement.enabled)
        {
            moveDirection = Vector3.zero;
        }

        Vector3 desiredVelocity = Vector3.zero;

        if (grounded && groundNormal.y <= normalLimit)
        {
            isSliding       = true;
            desiredVelocity = new Vector3(groundNormal.x, 0, groundNormal.z).normalized;
            Vector3 projectedMoveDir = Vector3.Project(moveDirection, desiredVelocity);
            desiredVelocity  = desiredVelocity + (moveDirection - projectedMoveDir) * sliding.driftControl;
            desiredVelocity *= sliding.slidingSpeed;
        }
        else
        {
            isSliding = false;

            if (!onLadder)
            {
                if (grounded)
                {
                    if (sprinting)
                    {
                        curSpeed = Mathf.MoveTowards(curSpeed, AntiHackSystem.RetrieveFloat("sprintSpeed") - (Mathf.Clamp01((100f - pv.curStamina) / 100f) * 0.65f), Time.deltaTime * movement.sprintAcceleration);
                    }
                    else if (crouching)
                    {
                        curSpeed = AntiHackSystem.RetrieveFloat("crouchSpeed");
                    }
                    else if (walking)
                    {
                        curSpeed = AntiHackSystem.RetrieveFloat("walkSpeed");
                    }
                    else
                    {
                        curSpeed = Mathf.MoveTowards(curSpeed, AntiHackSystem.RetrieveFloat("runSpeed"), Time.deltaTime * movement.sprintAcceleration);
                    }
                }
                else
                {
                    curSpeed = Mathf.MoveTowards(curSpeed, AntiHackSystem.RetrieveFloat("runSpeed") * 0.5f, Time.deltaTime * 0.9f);
                }

                slopeMod = movement.slopeSpeedMultiplier.Evaluate(velocity.normalized.y * 55f);
            }

            float slipDamp = (xyVelocity > 2f) ? 0.45f : 1f;
            desiredVelocity = tr.TransformDirection(moveDirection * curSpeed * slopeMod * speedAimMod * sprintReloadBoost * fDmgSpeedMult) + (slipMovement * sliding.slipSpeed * slipDamp);

            if (onLadder)
            {
                desiredVelocity = Vector3.zero;
            }
        }

        if (movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
        {
            desiredVelocity  += frameVelocity;
            desiredVelocity.y = 0f;
        }

        if (grounded)
        {
            Vector3 sideways = Vector3.Cross(Vector3.up, desiredVelocity);
            desiredVelocity = Vector3.Cross(sideways, groundNormal).normalized *desiredVelocity.magnitude;
        }
        else
        {
            vel.y = 0f;
        }

        float maxVelocityChange = ((grounded) ? movement.groundAcceleration : movement.airAcceleration) * Time.deltaTime;

        if (onLadder)
        {
            maxVelocityChange = 0f;
        }

        Vector3 velocityChangeVector = (desiredVelocity - vel);

        if (velocityChangeVector.sqrMagnitude > maxVelocityChange * maxVelocityChange)
        {
            velocityChangeVector = velocityChangeVector.normalized * maxVelocityChange;
        }

        if (grounded || movement.enabled)
        {
            vel += velocityChangeVector;
        }

        if (grounded)
        {
            vel.y = Mathf.Min(0f, vel.y);
        }

        return(vel);
    }
Exemplo n.º 15
0
    void Update()
    {
        float receivedRunSpeed = AntiHackSystem.RetrieveFloat("runSpeed");

        inputVector = (!RestrictionManager.restricted && !RestrictionManager.mpMatchRestrict) ? new Vector2(cInput.GetAxis("Horizontal Move"), cInput.GetAxis("Vertical Move")) : Vector2.zero;

        bool reloading = (wm.currentGC != null && wm.currentGC.reloading);

        if (!RestrictionManager.restricted && (grounded || controller.isGrounded) && !onLadder)
        {
            if (cInput.GetButton("Run") && inputVector.y >= 0.15f && pv.canSprint && !ac.isAiming && (Time.time - lastRunTime) >= 0.5f && !dm.animationIsPlaying)
            {
                runOnce = false;

                if (reloading)
                {
                    sprintReloadBoost = 1.25f;
                }
                else
                {
                    if (xyVelocity >= Mathf.Clamp(curSpeed, 0f, receivedRunSpeed) * 0.45f * weightFactor * slopeMod)
                    {
                        if (!crouching)
                        {
                            sprinting = true;
                            walking   = false;
                        }

                        if (CanStandUp())
                        {
                            crouching = false;
                        }
                    }
                    else if (xyVelocity < receivedRunSpeed * 0.2f)
                    {
                        sprinting = false;
                    }

                    sprintReloadBoost = 1f;
                }
            }
            else
            {
                sprintReloadBoost = 1f;
                sprinting         = false;
            }

            if (cInput.GetButtonDown("Walk") && !sprinting && !crouching)
            {
                walking = !walking;
            }

            if (cInput.GetButtonDown("Crouch") && !sprinting && (Time.time - lastCrouchTime) >= 0.25f)
            {
                if (!crouching)
                {
                    ia.DoImpactAnimation(2.5f);
                    crouching = true;

                    movement.crouchDetection.gameObject.SetActive(true);
                }
                else
                {
                    if (CanStandUp())
                    {
                        ia.DoImpactAnimation(1.9f);
                        crouching = false;
                        movement.crouchDetection.gameObject.SetActive(false);
                    }
                }

                walking        = false;
                lastCrouchTime = Time.time;
            }
        }

        if (!sprinting && !runOnce && !reloading)
        {
            lastRunTime = Time.time;
            runOnce     = true;
        }

        float animSpeed      = Time.deltaTime * 8.5f;
        float fovLegsClipMod = (GameSettings.settingsController.FOV - 60) * 0.0065f;

        if (crouching && xyVelocity >= 0.5f)
        {
            controller.height = Mathf.Lerp(controller.height, movement.crouchHeight + 0.1f, animSpeed);
            animations.playerMesh.transform.localPosition = Vector3.Lerp(animations.playerMesh.transform.localPosition, defaultLegPos - new Vector3(0f, 0.31f, fovLegsClipMod), animSpeed);
        }
        else if (crouching && xyVelocity < 0.5f)
        {
            controller.height = Mathf.Lerp(controller.height, movement.crouchHeight, animSpeed);
            animations.playerMesh.transform.localPosition = Vector3.Lerp(animations.playerMesh.transform.localPosition, defaultLegPos - new Vector3(0f, 0.57f, fovLegsClipMod), animSpeed);
        }
        else
        {
            controller.height = Mathf.Lerp(controller.height, defaultHeight, animSpeed);
            animations.playerMesh.transform.localPosition = Vector3.Lerp(animations.playerMesh.transform.localPosition, defaultLegPos - new Vector3(0f, 0f, fovLegsClipMod), animSpeed);
        }

        if (onLadder)
        {
            wasSprinting = false;
            sprinting    = false;

            if (!RestrictionManager.restricted && cInput.GetButtonDown("Jump") && pv.curStamina > 5 && Time.time - ladderLatchTime >= 0.4f)
            {
                climbDir = 0f; //Avoid unlatch force.
                UnlatchLadder();
                velocity      += (-tr.forward * 2f) + (Vector3.up * 1.25f);
                pv.curStamina -= 5;
                jumpTime       = Time.time + 0.1f;
                AudioSource.PlayClipAtPoint(footsteps.jumpOffLadder, footsteps.footstepPos.transform.position, 0.5f);
            }
        }

        float heightOffset = ((defaultHeight - controller.height) * -0.5f);

        head.localPosition = defaultHeadPos + (Vector3.up * (0.05f + (heightOffset * 2f)));
        Vector3 targetCenter = Vector3.up * (heightOffset + 0.9f);

        if (controller.center != targetCenter)
        {
            controller.center = targetCenter;
        }

        botDetector.center = controller.center;
        botDetector.radius = controller.radius;
        botDetector.height = controller.height;

        if (grounded && sliding.slipInfluenceDist > 0.01f)
        {
            float movementInput = Mathf.Clamp01(moveDirection.sqrMagnitude);
            if (xyVelocity > 0.1f && movementInput > 0.001f)
            {
                influenceOffset = tr.TransformDirection(moveDirection.normalized);
            }

            Vector3 origin = tr.position + (influenceOffset * sliding.slipInfluenceDist);
            if (xyVelocity > 0.05f || influenceOffset != oldInfluenceOffset)
            {
                if (!Physics.Linecast(origin, origin + (Vector3.down * 1.2f), sliding.slipOnLayers.value))
                {
                    isSlipping = true;
                }
                else
                {
                    isSlipping = false;
                }

                oldInfluenceOffset = influenceOffset;
            }
        }

        slipMovement = (isSlipping) ? influenceOffset : Vector3.zero;

        weightFactor   = 1f - (wc.weightPercentage * 0.3f);
        impactMod      = Mathf.MoveTowards(impactMod, 1f, Time.deltaTime * 0.7f);
        diagonalFactor = (inputVector != Vector2.zero && !sprinting) ? (1f / Mathf.Max(1f, inputVector.magnitude)) : 1f;
        moveDirection  = new Vector3(inputVector.x * ((sprinting) ? 0.3f : 1f), 0f, inputVector.y) * diagonalFactor * weightFactor * impactMod;

        Vector3 velo = velocity;

        velo = ApplyInputVelocity(velo);
        velo = ApplyGravityAndJump(velo);
        Vector3 currentMovementOffset = velo * Time.deltaTime;

        if (grounded)
        {
            currentMovementOffset += Vector3.down * movement.pushDownFactor * Time.deltaTime;
        }

        if (activePlatform != null && (grounded || movingPlatform.movementTransfer == MovementTransferOnJump.PermaLocked))
        {
            try
            {
                Vector3 pointDiff = (activePlatform.TransformPoint(activeLocalPoint) - activeGlobalPoint);
                smoothPlatform   = Vector3.Lerp(smoothPlatform, pointDiff, Time.deltaTime * movingPlatform.platformSmoothing);
                smoothPlatform.y = pointDiff.y;

                if (smoothPlatform != Vector3.zero)
                {
                    controller.Move(smoothPlatform);
                }

                Quaternion rotationDiff = (activePlatform.rotation * activeLocalRotation) * Quaternion.Inverse(activeGlobalRotation);

                if (rotationDiff.eulerAngles.y != 0f)
                {
                    pl.xRot += rotationDiff.eulerAngles.y;
                }
            }
            catch
            {
            }
        }

        groundNormal = Vector3.zero;

        Vector3 lastPosition = tr.position;

        collisionFlags   = controller.Move(currentMovementOffset);
        lastHitPoint     = hitPoint;
        lastGroundNormal = groundNormal;

        Vector3 oldHVelocity = new Vector3(velo.x, 0f, velo.z);

        velocity = (tr.position - lastPosition) / Mathf.Max(0.0001f, Time.deltaTime);
        Vector3 newHVelocity = new Vector3(velocity.x, 0f, velocity.z);

        if (oldHVelocity == Vector3.zero)
        {
            velocity = Vector3.up * velocity.y;
        }
        else
        {
            float projectedNewVelocity = Vector3.Dot(newHVelocity, oldHVelocity) / oldHVelocity.sqrMagnitude;
            velocity = oldHVelocity * Mathf.Clamp01(projectedNewVelocity) + (Vector3.up * velocity.y);
        }

        if (velocity.y < velo.y - 0.001f)
        {
            if (velocity.y < 0f)
            {
                velocity.y = velo.y;
            }
        }

        if (pauseVelocity != Vector3.zero && Time.timeScale > 0f)
        {
            velocity     += pauseVelocity; //Apply saved velocity.
            pauseVelocity = Vector3.zero;
        }

        if (!controller.isGrounded)
        {
            isSlipping = false;
        }

        if ((grounded && !controller.isGrounded && groundNormal.y <= 0.01f) || didJump)
        {
            grounded = (controller.collisionFlags & CollisionFlags.Below) != 0;

            if (!grounded)
            {
                if (!didJump)
                {
                    velocity -= Vector3.up * movement.gravity * 0.1f;
                }

                if (!didJump && movingPlatform.movementTransfer == MovementTransferOnJump.InitTransfer || movingPlatform.movementTransfer == MovementTransferOnJump.PermaTransfer)
                {
                    frameVelocity = platformVelocity;
                    velocity     += platformVelocity;
                }

                if (sprinting)
                {
                    wasSprinting       = true;
                    sprintJumpRestrict = 0.15f;
                    sprinting          = false;
                }

                ia.FallAnimation();
                playerMeshAnim.CrossFade(animations.jumpAnim, 0.2f);
                didJump = false;
            }
        }
        else if (!grounded && controller.isGrounded && groundNormal.y > 0.01f)
        {
            grounded = true;
            StartCoroutine(SubtractNewPlatformVelocity());

            if (onLadder)
            {
                UnlatchLadder();
            }

            float impactVelo = Mathf.Abs(velo.y);
            if (impactVelo >= 0.5f)
            {
                footsteps.footstepPos.volume = 0.1f + Mathf.Clamp(0.023f * impactVelo, 0f, 0.64f);
                tss.UpdatePitch(Random.Range(0.88f, 0.95f));
                SelectFootstep();
                tss.GetComponent <AudioSource>().PlayOneShot(footSound);
                stepTimer = 0f;

                if (standingRigidbody != null)
                {
                    Vector3 rigidImpact = controller.velocity;
                    rigidImpact.y *= (0.05f * physics.mass);
                    rigidImpact.y  = Mathf.Max(-5f, rigidImpact.y);
                    standingRigidbody.AddForceAtPosition(rigidImpact, transform.position, ForceMode.Impulse);
                }

                impactMod = 1f - Mathf.Clamp((impactVelo - 0.5f) * 0.08f, 0f, 0.5f);
                pv.FallDamage(impactVelo);
                ia.DoImpactAnimation(impactVelo - 0.32f);
            }

            wasSprinting = false;
        }

        if (activePlatform != null && (grounded || movingPlatform.movementTransfer == MovementTransferOnJump.PermaLocked))
        {
            activeGlobalPoint = tr.position + Vector3.up * (controller.center.y - (controller.height * 0.5f) + controller.radius);
            activeLocalPoint  = activePlatform.InverseTransformPoint(activeGlobalPoint);

            activeGlobalRotation = tr.rotation;
            activeLocalRotation  = Quaternion.Inverse(activePlatform.rotation) * activeGlobalRotation;
        }

        Vector3 controllerVelo = controller.velocity;

        controllerVeloMagn = controllerVelo.magnitude;
        controllerVelo.y   = 0f;
        xyVelocity         = controllerVelo.magnitude;

        isMoving = (controllerVeloMagn > 0.25f);

        if (((grounded && controller.isGrounded) || onLadder) && footsteps.enabled && !isSliding)
        {
            if (sprinting)
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.sprintStepRate, Time.deltaTime * 8f);
            }
            else if (sprintReloadBoost > 1f)
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.runStepRate * 1.1f, Time.deltaTime * 8f);
            }
            else if (onLadder)
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.ladderStepRate, Time.deltaTime * 8f);
            }
            else
            {
                stepRate = Mathf.Lerp(stepRate, footsteps.runStepRate, Time.deltaTime * 8f);
            }

            if (Mathf.Abs(inputVector.x) + Mathf.Abs(inputVector.y) >= 0.05f)
            {
                stepTimer += controllerVeloMagn * Time.deltaTime;
            }

            if (stepTimer >= stepRate)
            {
                if (sprinting)
                {
                    footsteps.footstepPos.volume = 0.175f;
                }
                else if (crouching || walking)
                {
                    footsteps.footstepPos.volume = 0.07f;
                }
                else
                {
                    footsteps.footstepPos.volume = 0.12f;
                }

                tss.UpdatePitch(Random.Range(0.9f, 1.0f));
                SelectFootstep();
                footsteps.footstepPos.PlayOneShot(footSound);
                stepTimer -= stepRate;
            }
        }

        if (animations.enabled && xyVelocity > 0.5f && !isSliding)
        {
            if (sprinting)
            {
                playerMeshAnim[animations.runAnim].speed = xyVelocity * 0.18f;
                playerMeshAnim.CrossFade(animations.runAnim, 0.25f);
            }
            else
            {
                Vector3 moveDir = moveDirection.normalized;

                if (crouching)
                {
                    float animVeloSpeed = xyVelocity * 0.5f;

                    if (moveDir.z > 0.05f)
                    {
                        playerMeshAnim[animations.crouchForwardAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchForwardAnim, 0.25f);
                    }
                    else if (moveDir.z < -0.05f)
                    {
                        playerMeshAnim[animations.crouchForwardAnim].speed = -animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchForwardAnim, 0.25f);
                    }
                    else if (moveDir.x < -0.05f)
                    {
                        playerMeshAnim[animations.crouchLeftAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchLeftAnim, 0.25f);
                    }
                    else if (moveDir.x > 0.05f)
                    {
                        playerMeshAnim[animations.crouchRightAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.crouchRightAnim, 0.25f);
                    }
                }
                else
                {
                    float animVeloSpeed = xyVelocity * 0.25f;

                    if (moveDir.z > 0.05f)
                    {
                        playerMeshAnim[animations.runAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.runAnim, 0.25f);
                    }
                    else if (moveDir.z < -0.05f)
                    {
                        if (animations.runBackAnim != "")
                        {
                            playerMeshAnim[animations.runBackAnim].speed = animVeloSpeed;
                            playerMeshAnim.CrossFade(animations.runBackAnim, 0.25f);
                        }
                        else
                        {
                            playerMeshAnim[animations.runAnim].speed = -animVeloSpeed;
                            playerMeshAnim.CrossFade(animations.runAnim, 0.25f);
                        }
                    }
                    else if (moveDir.x < -0.05f)
                    {
                        playerMeshAnim[animations.runLeftAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.runLeftAnim, 0.25f);
                    }
                    else if (moveDir.x > 0.05f)
                    {
                        playerMeshAnim[animations.runRightAnim].speed = animVeloSpeed;
                        playerMeshAnim.CrossFade(animations.runRightAnim, 0.25f);
                    }
                }
            }
        }

        if (animations.enabled && xyVelocity <= 0.5f)
        {
            if (crouching && !isSliding)
            {
                playerMeshAnim.CrossFade(animations.crouchAnim, 0.25f);
            }
            else
            {
                playerMeshAnim.CrossFade(animations.idleAnim, 0.25f);
            }
        }

        if (activePlatform != null)
        {
            if (!newPlatform)
            {
                platformVelocity = ((Time.deltaTime > 0f) ? (activePlatform.localToWorldMatrix.MultiplyPoint3x4(activeLocalPoint) - lastMatrix.MultiplyPoint3x4(activeLocalPoint)) / Time.deltaTime : Vector3.zero);
            }

            lastMatrix  = activePlatform.localToWorldMatrix;
            newPlatform = false;
        }
        else
        {
            platformVelocity = Vector3.zero;
        }

        fDmgSpeedMult = Mathf.Clamp(fDmgSpeedMult, 0.5f, 1f);
        fDmgSpeedMult = Mathf.MoveTowards(fDmgSpeedMult, 1f, Time.deltaTime * 0.007f);

        if (pauseVelocity == Vector3.zero && Time.timeScale <= 0f)
        {
            pauseVelocity = velocity; //Maintain velocity until the next time you un-pause.
        }
    }
Exemplo n.º 16
0
    void Update()
    {
        int retrievedMaxHealth = AntiHackSystem.RetrieveInt("maxHealth");
        int retrievedMaxShield = AntiHackSystem.RetrieveInt("maxShield");

        if (GameManager.boundarySettings != null)
        {
            bool inMapBounds = GameManager.boundarySettings.mapBounds.Contains(transform.position);
            if (!inMapBounds)
            {
                ApplyDamageMain((curHealth + curShield) * 2, false);
            }
        }

        if (Input.GetKey(KeyCode.X))
        {
            if (Input.GetKeyDown(KeyCode.B))
            {
                ApplyDamageMain(Random.Range(10, 15), true);
                HitIndicator(transform.position + DarkRef.RandomVector3(Vector3.one * -5f, Vector3.one * 5f));
            }
            else if (Input.GetKeyDown(KeyCode.K))
            {
                ApplyDamageMain(retrievedMaxHealth + retrievedMaxShield + 1, false);
            }
        }

        AdjustGUISize();
        ManageIndicatorGUI();

        if (recovering && curHealth < retrievedMaxHealth)
        {
            timer += Time.deltaTime;
        }

        if (shRecovering)
        {
            if (curShield < retrievedMaxShield)
            {
                shTimer += Time.deltaTime;
            }

            shieldAlarmSource.volume = 0f;

            if (!shGlowRecover)
            {
                shieldTexture.color = shieldTexture.defaultColor;
                shieldAlpha         = 0.21f;
                shGlowRecover       = true;
            }
        }
        else
        {
            shGlowRecover = false;
            if (retrievedMaxShield > 0f)
            {
                if (pe.hasEMP)
                {
                    shieldAlarmSource.volume = 0f;
                }
                else
                {
                    shieldAlarmSource.volume = Mathf.Clamp01(0.5f - shPercent) * 0.12f;
                }
            }
        }

        if (Time.time - lastDamage > 0.3f)
        {
            Color lerpHurtColor = Color.Lerp(hurtColor, Color.white, Mathf.Clamp01((percent - 0.2f) * 3.5f));
            healthText.color = Color.Lerp(healthText.color, lerpHurtColor, Time.unscaledDeltaTime * 5f);
            Color lerpShieldColor = Color.Lerp(new Color(0.8f, 0.8f, 0.8f, 1f), Color.white, Mathf.Clamp01(shPercent * 5f));
            shieldText.color = Color.Lerp(shieldText.color, lerpShieldColor, Time.unscaledDeltaTime * 5f);
        }

        curShield = Mathf.Clamp(curShield, 0, retrievedMaxShield);
        float fallDmgMod = (fallDamageTotal > 0) ? 0.8f : 1f;

        if (retrievedMaxShield > 0)
        {
            shPercent = (float)curShield / (float)retrievedMaxShield;

            float shRecoverRate = (shieldRecoverySpeed * fallDmgMod);
            if (shTimer >= shRecoverRate && (curShield < retrievedMaxShield))
            {
                curShield += shieldRecoverAmount;

                if (fallDamageTotal > 0)
                {
                    fallDamageTotal--;
                }

                shTimer -= shRecoverRate;
            }
        }
        else
        {
            shPercent = 0f;
        }

        curHealth  = Mathf.Clamp(curHealth, 0, retrievedMaxHealth);
        maxHealth  = retrievedMaxHealth;
        maxShield  = retrievedMaxShield;
        curStamina = Mathf.Clamp(curStamina, 0, 100);

        float recoverRate = (healthRecoverySpeed * (1f + (percent * healthRecoverInfluence)) * fallDmgMod);

        if (timer >= recoverRate && (curHealth < retrievedMaxHealth))
        {
            curHealth += healthRecoverAmount;

            if (fallDamageTotal > 0)
            {
                fallDamageTotal--;
            }

            timer -= recoverRate;
        }

        if (!dead)
        {
            if (startRecoveryTimer)
            {
                rTimer += Time.deltaTime;
            }

            if (startShRecoveryTimer)
            {
                shrTimer += Time.deltaTime;
            }
        }

        if (rTimer >= healthRecoverDelay && !dead)
        {
            startRecoveryTimer = false;
            rTimer             = 0f;
            recovering         = true;
        }

        if (maxShield > 0 && shrTimer >= shieldRecoverDelay && !dead)
        {
            startShRecoveryTimer = false;
            shrTimer             = 0f;
            shRecovering         = true;

            fallDamageSource.GetComponent <TimeScaleSound>().pitchMod = 1f;
            fallDamageSource.PlayOneShot(shieldRegen, 0.1f);
        }

        float steepSlopeFactor = (pm.grounded) ? Mathf.Clamp01(pm.controller.velocity.normalized.y) : 0f;

        if (pm.grounded && (pm.sprinting || pm.sprintReloadBoost > 1f) && pm.xyVelocity >= 0.75f)
        {
            rattleTSS.pitchMod           = 1f;
            equipmentRattleSource.volume = Mathf.Lerp(equipmentRattleSource.volume, rattleVolumeSprint, Time.deltaTime * 9f);
            dTimer += Time.deltaTime * (pm.controllerVeloMagn / pm.movement.sprintSpeed);

            float requirement = staminaDepletionRate * (1f - (wc.weightPercentage * 0.8f)) * (1f - (steepSlopeFactor * 0.22f));
            if (dTimer >= requirement && curStamina > 0f)
            {
                curStamina -= 1 + Mathf.RoundToInt((1f / requirement) * Time.deltaTime);
                dTimer      = 0f;
            }
        }
        else
        {
            float velocityFactor = Mathf.Clamp01(pm.xyVelocity / pm.movement.runSpeed);
            if (jumpRattleEquip)
            {
                rattleTimer += Time.deltaTime;

                if (pm.xyVelocity < 0.75f)
                {
                    rattleTSS.pitchMod           = 1f;
                    equipmentRattleSource.volume = Mathf.Lerp(equipmentRattleSource.volume, Mathf.Lerp(rattleVolumeNormal, rattleVolumeSprint, 0.5f), Time.deltaTime * 11f);
                }

                if (rattleTimer >= 0.4f)
                {
                    rattleTimer     = 0f;
                    jumpRattleEquip = false;
                }
            }
            else
            {
                if (pm.grounded)
                {
                    if (pm.xyVelocity >= 0.75f)
                    {
                        rattleTSS.pitchMod           = (pm.crouching) ? 0.8f : 0.96f;
                        equipmentRattleSource.volume = Mathf.Lerp(equipmentRattleSource.volume, rattleVolumeNormal * velocityFactor, Time.deltaTime * 9f);
                    }
                    else
                    {
                        equipmentRattleSource.volume = Mathf.Lerp(equipmentRattleSource.volume, 0f, Time.deltaTime * 9f);
                    }
                }
                else
                {
                    equipmentRattleSource.volume = Mathf.Lerp(equipmentRattleSource.volume, 0f, Time.deltaTime * 9f);
                }
            }

            sTimer += Time.deltaTime;

            float requirement = (staminaRecoverySpeed * (2f - Mathf.Clamp(Time.time - lastDe, 0f, 1f)) * (1f + Mathf.Clamp01((pm.xyVelocity * 0.17f) / pm.movement.runSpeed)) + (steepSlopeFactor * 0.16f));
            if (sTimer >= requirement && curStamina < 100 && !staminaCooldown)
            {
                curStamina += 1 + Mathf.RoundToInt((1f / requirement) * Time.deltaTime);
                sTimer      = 0f;
            }
        }

        curStamina = Mathf.Clamp(curStamina, 0, 100);

        if (curStamina <= 1f && canSprint)
        {
            StartCoroutine(CalmingStage());
        }

        shieldAlpha  = Mathf.Clamp(shieldAlpha, 0f, 0.35f);
        shieldAlpha  = Mathf.MoveTowards(shieldAlpha, 0f, Time.deltaTime * 0.6f);
        finalShAlpha = Mathf.Lerp(finalShAlpha, shieldAlpha, Time.deltaTime * 8.5f);

        shieldTexture.alpha = finalShAlpha * ((shGlowRecover) ? 1f : (0.3f + (Mathf.PerlinNoise(Mathf.PingPong(Time.time * 22f, 250f), 0f) * 0.7f)));
        damageEffect        = Mathf.Lerp(damageEffect, 0f, (Time.time - lastDe) * 5f);
        chromAbb            = Mathf.Lerp(chromAbb, Mathf.Clamp(damageEffect, 0f, 30f) + ((0.3f - Mathf.Min(percent, 0.3f)) * 25f), Time.deltaTime * 5f);

        bloodEffect             = Mathf.Clamp01(Mathf.Lerp(bloodEffect, 0f, Time.deltaTime * 0.068f));
        uic.gManager.damageBlur = Mathf.Clamp(Mathf.Lerp(uic.gManager.damageBlur, 0f, Time.deltaTime * dmgBlurRestore) + ((percent <= 0.2f) ? 0.001f : 0f), 0f, 0.85f);

        foreach (FlickeringGUI fg in flickeringGUI)
        {
            if (pe.hasEMP)
            {
                fg.dimAlpha         = Random.Range(0.1f, 1f);
                fg.updateFrequency  = 0.03f;
                fg.flickerFrequency = 0.8f;
            }
            else
            {
                fg.dimAlpha         = Mathf.Clamp01(0.3f + flickerIntensity * 2f);
                fg.updateFrequency  = 0.05f;
                fg.flickerFrequency = 0.85f;
            }
        }

        float stPercent = Mathf.Clamp01((float)curStamina / 100f);
        float hbVolume  = Mathf.Clamp(0.5f - percent, 0f, 0.5f) * 0.3f;

        heartbeatSound.volume = hbVolume + ((1f - stPercent) * 0.05f);

        float nVolume = Mathf.Clamp(0.25f - percent, 0f, 0.25f) / 0.25f;

        noiseSource.volume = nVolume * 0.2f;

        if (Time.time - lastHeartTime >= 1f)
        {
            hbEffectTarget = 3.1f;
            lastHeartTime  = Time.time;
        }

        if (pe.hasEMP)
        {
            grainEMP   = Mathf.Lerp(grainEMP, 0.035f, Time.deltaTime * 1.3f);
            distortEMP = Mathf.Lerp(distortEMP, 0.15f, Time.deltaTime * 1.3f);
        }
        else
        {
            grainEMP   = Mathf.Lerp(grainEMP, 0f, Time.deltaTime * 3f);
            distortEMP = Mathf.Lerp(distortEMP, 0f, Time.deltaTime * 3f);
        }

        vignetteEMP  = Mathf.Lerp(vignetteEMP, 0f, Time.deltaTime * 4f);
        ne.empEffect = grainEMP;

        hbEffectTarget  = Mathf.MoveTowards(hbEffectTarget, 0f, Time.deltaTime * 4.3f);
        heartbeatEffect = Mathf.Lerp(heartbeatEffect, hbEffectTarget + 0.05f, Time.deltaTime * 11f);

        percent          = curHealth / (float)retrievedMaxHealth;
        flickerIntensity = Mathf.Lerp(flickerIntensity, percent, Time.deltaTime * 0.5f * Mathf.Clamp((Time.time - initTime) * 0.5f, 0f, 4f));
        hearingPenalty   = Mathf.Lerp(hearingPenalty, 1f, Time.deltaTime * 0.2f);

        if (percent <= 0.25f)
        {
            standardFreq      = Mathf.Lerp(standardFreq, (pe.hasEMP) ? empMuffle : Mathf.Lerp(muffleRange.x, muffleRange.y, Mathf.Clamp01(percent * 4f)), Time.deltaTime * 9f);
            ne.grainIntensity = Mathf.Lerp(0f, 0.0075f, 1f - Mathf.Clamp01(percent * 4f));
        }
        else
        {
            standardFreq      = Mathf.Lerp(standardFreq, (pe.hasEMP) ? empMuffle : 20000f, Time.deltaTime * ((pe.hasEMP) ? 3.5f : 0.7f));
            ne.grainIntensity = Mathf.Lerp(ne.grainIntensity, 0f, Time.deltaTime * 5f);
        }

        healthLowPass.cutoffFrequency = standardFreq * hearingPenalty;

        ne.enabled         = (ne.grainIntensity + grainEMP > 0f);
        disE.enabled       = (ne.enabled || distortEMP > 0f);
        disE.baseIntensity = (ne.grainIntensity * 4f) + distortEMP;
        disE.splitOffset   = (pe.hasEMP) ? 0.05f : 0f;

        if (staminaBlinking)
        {
            sBlinkTimer += Time.deltaTime * 6.75f;
            sBlinkValue  = Mathf.Sin(sBlinkTimer);

            Color redCol = defStaminaBGCol;
            redCol.r *= 3f;
            staminaBackground.color = Color.Lerp(defStaminaBGCol, redCol, sBlinkValue);
        }
        else
        {
            sBlinkTimer = 0f;
            sBlinkValue = 0f;

            staminaBackground.color = defStaminaBGCol;
        }

        damageBreathBoost     = Mathf.Clamp(Mathf.MoveTowards(damageBreathBoost, 0f, Time.deltaTime * 0.05f), 0f, 0.42f);
        dBreath               = Mathf.Lerp(dBreath, damageBreathBoost, Time.deltaTime * 7f);
        breathingSound.volume = (0.05f + (hbVolume * 0.11f) + (0.148f * (1f - stPercent)) + dBreath) * breathFactor;
        breathingSound.GetComponent <TimeScaleSound>().pitchMod = 1f + (hbVolume * 0.03f) + (0.145f * (1f - stPercent));

        imageEffect                    = Mathf.Lerp(imageEffect, Mathf.Clamp01(1f - (percent + 0.45f)) * effectIntensity, Time.deltaTime * 3f);
        vignetting.intensity           = imageEffect + vignetteEMP + (heartbeatEffect * Mathf.Clamp01(1f - (percent * 2f)));
        vignetting.blur                = (imageEffect * 0.2f) + aimEffect;
        vignetting.blurSpread          = aimEffect * 0.5f;
        vignetting.heartbeatBlur       = heartbeatEffect * Mathf.Clamp01(1f - (percent * 2f)) * 0.45f;
        vignetting.chromaticAberration = chromAbb * (1f + ((1 - percent) * 0.3f));

        float saturation = Mathf.Clamp01(0.45f + (percent * 0.88f));

        sa.saturationAmount = Mathf.Lerp(sa.saturationAmount, (pe.hasEMP) ? Random.value * Random.value : saturation, Time.deltaTime * 4f);
        sa.colorTint        = Vector4.Lerp(new Vector4(1.1f, 0.95f, 0.95f, 1f), Vector4.one, Mathf.Clamp01(percent * 2.5f));

        if (!dead)
        {
            alpha = Mathf.Lerp(alpha, bloodEffect + ((1 - percent) * 0.15f), Time.deltaTime * 8f);
            bloodyScreen.material.color = DarkRef.SetAlpha(bloodyScreen.material.color, alpha * 0.82f);
        }

        healthBar.value = Mathf.Lerp(healthBar.value, (pe.hasEMP) ? Random.value : percent, Time.unscaledDeltaTime * 7.5f);
        shieldBar.value = Mathf.Lerp(shieldBar.value, (pe.hasEMP) ? Random.value : shPercent, Time.unscaledDeltaTime * 7.5f);

        if (pe.hasEMP)
        {
            if (Time.time - lastUpdateTime >= 0.1f)
            {
                healthText.text = (dead) ? "INACTIVE" : (Random.Range(0, 999) + "/" + Random.Range(0, 999));
                lastUpdateTime  = Time.time;
            }
        }
        else
        {
            healthText.text = (dead) ? "INACTIVE" : (curHealth + "/" + retrievedMaxHealth);
        }

        if (shrTimer < 0f || maxShield <= 0)
        {
            shieldText.color = new Color(1f, 0.4f, 0.2f);
            shieldText.text  = "DISABLED";
        }
        else
        {
            shieldText.color = shieldText.defaultColor;
            shieldText.text  = curShield + "/" + retrievedMaxShield;
        }

        staminaBar.value = Mathf.Lerp(staminaBar.value, (pe.hasEMP) ? Random.value : stPercent, Time.deltaTime * 8f);
    }
Exemplo n.º 17
0
    void Start()
    {
        base.isLocalPlayer = true;
        GeneralVariables.cachedSpectCam = cachedSpectCam;
        uic       = GeneralVariables.uiController;
        rattleTSS = equipmentRattleSource.GetComponent <TimeScaleSound>();

        healthBar         = uic.healthBar;
        healthText        = uic.healthText;
        shieldBar         = uic.shieldBar;
        shieldText        = uic.shieldText;
        staminaBar        = uic.staminaBar;
        shieldTexture     = uic.shieldTexture;
        ne                = uic.guiCamera.GetComponent <NoiseEffect>();
        disE              = uic.guiCamera.GetComponent <DistortionEffect>();
        staminaBackground = staminaBar.backgroundWidget;
        defStaminaBGCol   = staminaBackground.color;
        bloodyScreen      = uic.bloodyScreen;
        flickeringGUI     = uic.flickeringPanels;
        sa                = uic.screenAdjustment;

        bloodyScreen.material.color = DarkRef.SetAlpha(bloodyScreen.material.color, 0f);

        PlayerReference pr = GeneralVariables.playerRef;

        pm         = GetComponent <PlayerMovement>();
        playerLook = GetComponent <PlayerLook>();
        vignetting = cam.GetComponent <VignettingC>();

        damageBreathBoost  = 0f;
        ne.grainIntensity  = 0f;
        disE.baseIntensity = 0f;
        guiSizeModH        = guiSizeModS = 1f;
        healthBar.value    = 0f;
        shieldBar.value    = 0f;
        breathFactor       = 1f;
        hearingPenalty     = 1f;
        standardFreq       = 5000f;

        wm = pr.wm;
        wc = pr.wc;

        shieldAlpha      = 0f;
        finalShAlpha     = 0f;
        flickerIntensity = 0.5f;
        percent          = 1f;
        shPercent        = 1f;
        recovering       = true;
        canSprint        = true;
        initTime         = Time.time;

        damageIDs       = new List <byte>();
        damageInflicted = new List <int>();
        killerID        = -1;
        headID          = -1;
        lastWeaponID    = -1;
        builtData       = "";

        //Initialize values.
        curHealth = maxHealth;
        curShield = maxShield;
        AntiHackSystem.ProtectInt("maxHealth", maxHealth);
        AntiHackSystem.ProtectInt("maxShield", maxShield);

        oldHealth = curHealth;
        oldShield = curShield;
    }
Exemplo n.º 18
0
    private IEnumerator SelectWeaponCoroutine(int weaponIndex, bool immediate)
    {
        prepareToSwitch = true;

        while (ac.aimTransition > 0.05f)
        {
            yield return(0);
        }

        prepareToSwitch = false;

        if (currentGC != null && currentGC.reloading)
        {
            currentGC.CancelReload();
        }

        int prevWeaponNum = curWeaponNum;

        if (Topan.Network.isConnected && rootNetView != null)
        {
            if (weaponIndex == 0 || weaponIndex == 1)
            {
                rootNetView.RPC(Topan.RPCMode.OthersBuffered, "RefreshWeapon", (byte)heldWeapons[weaponIndex].weaponID);

                if (heldWeapons[weaponIndex].gunVisuals != null && heldWeapons[weaponIndex].gunVisuals.flashlight != null)
                {
                    rootNetView.RPC(Topan.RPCMode.OthersBuffered, "SetFlashlight", heldWeapons[weaponIndex].flashlightOn);
                }
            }
            else
            {
                if (weaponIndex <= -1)
                {
                    rootNetView.RPC(Topan.RPCMode.OthersBuffered, "SetSpecialActive", (byte)0); //Hands
                }
                else if (weaponIndex == 2)
                {
                    rootNetView.RPC(Topan.RPCMode.OthersBuffered, "SetSpecialActive", (byte)1); //Melee
                }
                else if (weaponIndex == 3)
                {
                    grenadeManager.OnSelect(true);
                }
            }
        }

        if (!immediate)
        {
            if (!isQuickThrowState)
            {
                curAmmoDisplay.text  = "--";
                ammoLeftDisplay.text = "---";
            }

            float weightFactorTime = 0f;
            if (weaponIndex == 0 || weaponIndex == 1)
            {
                if (ignoreWeightDelayOnce)
                {
                    ignoreWeightDelayOnce = false;
                }
                else
                {
                    weightFactorTime = (heldWeapons[weaponIndex].weaponWeight * 0.05f);
                }
            }

            dm.Draw(drawTime + weightFactorTime);
            switching          = true;
            pv.jumpRattleEquip = true;

            float waitPeriod       = 0f;
            bool  cyclingGrenades  = false;
            bool  ignoreFirstPress = true;
            while (waitPeriod < drawTime + weightFactorTime)
            {
                if (weaponIndex == 3 && Input.GetKeyDown(KeyCode.Alpha4) && grenadeManager.availableGrenades.Count > 1)
                {
                    if (!ignoreFirstPress)
                    {
                        cyclingGrenades = true;

                        if (grenadeManager.grenadeIndex == 0 && gam.typeTwoGrenades > 0)
                        {
                            grenadeManager.grenadeIndex = 1;
                        }
                        else if (grenadeManager.grenadeIndex == 1 && gam.typeOneGrenades > 0)
                        {
                            grenadeManager.grenadeIndex = 0;
                        }

                        grenadeSelection.alpha     = grenadeSelection.defaultAlpha;
                        grenadeSelectionLabel.text = grenadeManager.grenadeInventory[grenadeManager.grenadeIndex].grenadeName;

                        dm.ExtendDrawTime(waitPeriod);
                        waitPeriod = 0f;
                    }
                    else
                    {
                        grenadeSelectionLabel.alpha = 0.4f;
                    }

                    ignoreFirstPress = false;
                }

                if (cyclingGrenades)
                {
                    grenadeSelectionLabel.alpha = Mathf.Lerp(grenadeSelectionLabel.alpha, 0.8f, Time.deltaTime * 18f);
                }

                waitPeriod += Time.deltaTime;
                yield return(null);
            }

            switching = false;
        }

        bool          sameWeapon = false;
        GunController gc1        = null;
        GunController gc2        = null;

        if (prevWeaponNum > -1 && prevWeaponNum >= 0 && prevWeaponNum <= 1 && weaponIndex >= 0 && weaponIndex <= 1)
        {
            gc1 = heldWeapons[prevWeaponNum];
            gc2 = heldWeapons[weaponIndex];

            if (gc1 != null && gc2 != null && gc1.weaponID == gc2.weaponID)
            {
                sameWeapon = true;
            }
        }

        if (weaponIndex > -2)
        {
            pv.jumpRattleEquip = true;
            GetComponent <AudioSource>().PlayOneShot(drawSound, 0.2f);
        }

        if (currentWeaponTransform == grenadeManager.transform)
        {
            grenadeManager.OnDeselect();
        }

        DeselectAll();

        curWeaponNum  = weaponIndex;
        curWeaponMode = (curWeaponNum == 0 || curWeaponNum == 1) ? CurrentWeaponMode.GenericWeapon : CurrentWeaponMode.AlternateWeapon;

        if (curWeaponMode == CurrentWeaponMode.GenericWeapon)
        {
            currentGC.gameObject.SetActive(true);
            currentGC.OnWeaponDraw();
            currentWeaponTransform = currentGC.transform;

            if (queuedAmmo > -1)
            {
                AntiHackSystem.ProtectInt("currentAmmo", queuedAmmo);
                queuedAmmo = -1;
            }

            if (queuedReserve > -1)
            {
                AntiHackSystem.ProtectInt("ammoLeft", queuedReserve);
                queuedReserve = -1;
            }

            currentGC.bulletInChamber = queuedChamber;
            queuedChamber             = false;

            curWepName = currentGC.gunName;

            if (!pe.hasEMP)
            {
                weaponIcon.mainTexture             = currentGC.iconTexture;
                weaponIcon.transform.localPosition = defaultIconPos + new Vector3(currentGC.iconOffset.x, currentGC.iconOffset.y, 0f);
                weaponIcon.SetDimensions((int)currentGC.iconScale.x, (int)currentGC.iconScale.y);
            }
        }
        else
        {
            if (curWeaponNum == 3)
            {
                grenadeManager.gameObject.SetActive(true);
                grenadeManager.OnSelect(false);

                if (pressedQuickThrow)
                {
                    grenadeManager.QuickThrow(prevWeaponNum);
                }

                currentWeaponTransform = grenadeManager.transform;
                pressedQuickThrow      = false;
            }
            else if (curWeaponNum == 2)
            {
                meleeController.gameObject.SetActive(true);
                currentWeaponTransform = meleeController.transform;

                weaponIcon.mainTexture             = meleeController.iconTexture;
                weaponIcon.transform.localPosition = defaultIconPos + new Vector3(meleeController.iconOffset.x, meleeController.iconOffset.y, 0f);
                weaponIcon.SetDimensions((int)meleeController.iconSize.x, (int)meleeController.iconSize.y);
            }
            else if (curWeaponNum <= -1)
            {
                if (curWeaponNum == -1)
                {
                    hands.SetActive(true);
                    currentWeaponTransform = hands.transform;
                }
                else
                {
                    currentWeaponTransform = null;
                }

                curWepName             = "Hands";
                weaponIcon.mainTexture = null;
                weaponIcon.SetDimensions(100, 50);

                curAmmoDisplay.color = Color.white;
                curAmmoDisplay.text  = "---";
                ammoLeftDisplay.text = "---";

                ammoBar.value = 1f;
            }
        }

        StartCoroutine(WeaponNameTransition());

        ReflectionUpdateGroup foundRUG = currentWeaponTransform.GetComponent <ReflectionUpdateGroup>();

        if (foundRUG != null)
        {
            foreach (Renderer r in foundRUG.allRenderers)
            {
                UpdateReflection(r);
            }
        }

        if (sameWeapon)
        {
            gc2.ammoLeft = gc1.ammoLeft;
            AntiHackSystem.ProtectInt("ammoLeft", gc1.ammoLeft);
        }

        if (curWeaponNum < 3 && curWeaponNum != -2)
        {
            dm.sao = currentWeaponTransform.GetComponent <SprintAnimOverride>();
        }

        grenadeSelectionLabel.alpha = 0.2f;
    }
Exemplo n.º 19
0
    void Update()
    {
        if (mpReferenceOnly || ownedByBot)
        {
            return;
        }

        int retrievedAmmo = AntiHackSystem.RetrieveInt("currentAmmo");

        CheckAmmo();
        WeaponGUI();

        float curTime = Time.time;

        if (curTime - timeSinceLastFire >= Mathf.Min(0.5f, (1f + Time.deltaTime) / GetFireRate()))
        {
            bsna = Mathf.MoveTowards(bsna, baseSpreadAmount, Time.deltaTime * recoverSpeed);
        }
        else
        {
            bsna = Mathf.MoveTowards(bsna, baseSpreadAmount, Time.deltaTime * recoverSpeed * 0.1f);
        }

        bsna = Mathf.Clamp(bsna, baseSpreadAmount, maxSpreadAmount);

        if (timer > 0f)
        {
            timer -= Time.deltaTime * GetFireRate();
        }

        if (curTime - initializeTime < 0.5f)
        {
            return;
        }

        if (cInput.GetButton("Fire Weapon") && currentAmmo > 0)
        {
            if (!startCounting)
            {
                startCounting = true;
            }
        }
        else
        {
            if (startCounting)
            {
                fireCount     = 0;
                startCounting = false;
            }
        }

        float cwm        = (pm.crouching || pm.walking) ? crouchWalkModifier : 1f;
        float veloFactor = Mathf.Clamp01(pm.controllerVeloMagn / pm.movement.runSpeed) * movementSpreadAmount * asm;
        float airFactor  = ((pm.grounded) ? 1f : (1f + (Mathf.Clamp01(Mathf.Max(0.1f, Mathf.Abs(pm.controller.velocity.y) - 2.5f) * 0.15f) * (ac.isAiming ? 32f : 1f))));

        spreadReal = (bsna * cwm * asm * airFactor) + veloFactor;

        if (!RestrictionManager.restricted && !RestrictionManager.mpMatchRestrict && timer <= 0f && retrievedAmmo > 0 && !reloading && !pm.sprinting && !switching && !acs.clipping && !pm.onLadder && !dm.animationIsPlaying && !dm.terminalVelocity && Time.time - endReload >= 0.15f && !ac.isTransitioning)
        {
            if (cInput.GetButtonDown("Fire Weapon") && currentFireMode == FireMode.SemiAuto)
            {
                Shoot(cwm, veloFactor, airFactor);
            }

            if (cInput.GetButton("Fire Weapon"))
            {
                if (currentFireMode == FireMode.FullAuto)
                {
                    Shoot(cwm, veloFactor, airFactor);
                }
                else if (currentFireMode == FireMode.BurstFire && !bursting)
                {
                    StartCoroutine(Burst(cwm, veloFactor, airFactor));
                }
            }
        }

        if (reloading)
        {
            if (reloadMethod == ReloadMethod.Magazine)
            {
                if (curTime - startReload >= curReloadDur)
                {
                    Reload();
                }
            }
            else if (reloadMethod == ReloadMethod.Singular)
            {
                if (cInput.GetButtonDown("Reload") || cInput.GetButtonDown("Fire Weapon"))
                {
                    forceStopReload = true;
                }

                if (rDelayDone)
                {
                    rIntervalTimer += Time.deltaTime;

                    if (rIntervalTimer >= reloadInterval)
                    {
                        InsertBullet();
                        rIntervalTimer -= reloadInterval;
                    }
                }
                else
                {
                    rDelayTimer += Time.deltaTime;
                    if (rDelayTimer >= reloadDelay)
                    {
                        rIntervalTimer = reloadInterval;
                        rDelayTimer    = 0f;
                        rDelayDone     = true;
                    }
                }
            }
        }

        if (ac.isAiming && !pm.onLadder)
        {
            asm = aimSpreadModifier;
            pl.aimMouseModifier = mouseSensitivityAim;
            pm.speedAimMod      = playerSpeedAim;
            if (sniperAimEffect)
            {
                ac.aimEffect = true;
            }
        }
        else
        {
            asm = 1f;
            pl.aimMouseModifier = 1f;
            pm.speedAimMod      = 1f;
            if (sniperAimEffect)
            {
                ac.aimEffect = false;
            }
        }

        if (!pm.onLadder && !RestrictionManager.restricted)
        {
            if (cInput.GetButtonDown("Fire Mode") && secondMode != FireMode.None && canSwitchModes && !switching)
            {
                SwitchFireModes();
            }

            if (!reloading && (Time.time - timeSinceLastFire > 0.2f) && AntiHackSystem.RetrieveInt("ammoLeft") > 0 && !pm.sprinting && ((cInput.GetButtonDown("Reload") && ammoDif > 0) || (retrievedAmmo <= 0 && reloadOnMouseClick && cInput.GetButtonDown("Fire Weapon"))))
            {
                if (reloadMethod == ReloadMethod.Magazine)
                {
                    StartMagazineReload();
                }
                else if (reloadMethod == ReloadMethod.Singular && !reloading)
                {
                    reloading = true;
                }
            }
        }
    }
Exemplo n.º 20
0
    private void Shoot(float cwm, float vf, float af)
    {
        for (int i = 0; i < bulletsPerShot; i++)
        {
            Vector2    randomTargetPoint = Random.insideUnitCircle * ((bsna * cwm * asm * af) + vf);
            Vector3    randomDir         = new Vector3(randomTargetPoint.x, randomTargetPoint.y, 0f);
            Quaternion randomRot         = Quaternion.Euler(firePos.eulerAngles) * Quaternion.Euler(randomDir);
            GameObject proj = PoolManager.Instance.RequestInstantiate(bulletInfo.poolIndex, firePos.position, randomRot, false);

            if (bulletInfo.bulletType == BulletInfo.BulletType.Bullet)
            {
                Bullet projBul = proj.GetComponent <Bullet>();
                projBul.BulletInfo(bulletInfo, weaponID, false, true, -1);
                projBul.noWhizSound = true;
                projBul.InstantiateStart();
            }
            else if (bulletInfo.bulletType == BulletInfo.BulletType.Rocket)
            {
                Rocket projRoc = proj.GetComponent <Rocket>();
                projRoc.RocketInfo(bulletInfo, weaponID, false, true, -1);
                projRoc.InstantiateStart();
            }

            if (Topan.Network.isConnected && wm.rootNetView)
            {
                Vector3 fwdRot = Quaternion.LookRotation(randomRot * Vector3.forward).eulerAngles;
                wm.rootNetView.UnreliableRPC(Topan.RPCMode.Others, "NetworkShoot", (TopanFloat)(fwdRot.x / 360f), (TopanFloat)(fwdRot.y / 360f), firePos.position);
            }
        }

        bsna += spreadSpeed * spreadAimFactor;

        if (countsAsOneBullet)
        {
            AntiHackSystem.ProtectInt("currentAmmo", currentAmmo - 1);
        }
        else
        {
            AntiHackSystem.ProtectInt("currentAmmo", currentAmmo - bulletsPerShot);
        }

        fireCount++;

        StopCoroutine("MuzzleControl");
        StartCoroutine(MuzzleControl());

        if (ejectionEnabled)
        {
            if (ejectionDelay > 0f)
            {
                StartCoroutine(EjectShell());
            }
            else
            {
                Rigidbody shell = PoolManager.Instance.RequestInstantiate(bulletShellIndex, ejectionPos.position, ejectionPos.rotation).GetComponent <Rigidbody>();
                shell.velocity        = (pm.controller.velocity * 0.7f) + pm.transform.TransformDirection(DarkRef.RandomVector3(ejectionMinForce, ejectionMaxForce));
                shell.angularVelocity = Random.rotation.eulerAngles * ejectionRotation;
            }
        }

        tss.pitchMod = Random.Range(0.95f, 1f);
        tss.GetComponent <AudioSource>().PlayOneShot(fireSound);

        if (pa != null)
        {
            pa.startAnimation = true;
        }

        float aimMod    = (ac.isAiming) ? aimUpkickModifier : 1f;
        float crouchMod = (pm.crouching) ? crouchUpkickModifier : 1f;
        float extraMod  = (fireCount > extraRecoilThreshold) ? 1f + Mathf.Clamp((fireCount - extraRecoilThreshold) * extraRecoilAmount, 0f, maxExtraRecoil) : 1f;

        pl.Recoil(recoilAmount * ((ac.isAiming) ? 0.56f : 1.0f), upKickAmount * aimMod * crouchMod * extraMod, sideKickAmount * aimMod * crouchMod * extraMod, kickInfluence, kickCameraTilt, camShakeAnim, autoReturn);
        dm.Kickback(kickBackAmount * 0.04f, kickSpeedFactor, kickGunTilt);

        shootImpulseGUI += 0.1f;
        ammoBar.value   += 0.01f;
        crosshair.JoltAnimation(spreadSpeed);

        timeSinceLastFire = Time.time;

        if (currentFireMode != FireMode.BurstFire)
        {
            timer += 1f;
        }
    }