private IEnumerator LoadSequence(List <SaveData> saveData)
        {
            Processing = true;
            yield return(new WaitForSecondsRealtime(0.5f));

            yield return(new WaitForSecondsRealtime(loadDelay));

            for (int i = 0; i < saveData.Count; i++)
            {
                SaveData  data     = saveData[i];
                ISaveable saveable = saveables.SingleOrDefault(x => x.Id == data.id);
                if (saveable != null && saveable.ToString() != "null")
                {
                    saveable.Load(data);
                }
            }

            Processing = false;

            ClearTrash();
            List <ISaveable> redundant = saveables.Where(x => !saveData.Any(y => y.id == x.Id)).ToList();

            for (int i = redundant.Count - 1; i >= 0; i--)
            {
                Destroy(redundant[i].GO);
            }

            DevTools.Instance().DisableAll();
            yield return(new WaitForEndOfFrame());

            onLoad?.Invoke();
        }
Beispiel #2
0
        /// <summary>
        /// Is this weapon can fire?
        /// </summary>
        public virtual bool CanFire()
        {
            if (team == Teams.Player && DevTools.Instance().God)
            {
                return(Time.time >= nextFire);
            }

            return(Time.time >= nextFire && ammo > 0);
        }
Beispiel #3
0
        /// <summary>
        /// Fire the weapon.
        /// </summary>
        protected virtual bool FireWeapon(Ray ray)
        {
            //Do not fire if the weapon not ready
            if (!CanFire())
            {
                return(false);
            }

            ray.direction = Quaternion.Euler(muzzle.right * Random.Range(-spread, spread) + muzzle.up * Random.Range(-spread, spread)) * ray.direction;

            Transform  effect;
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, maxDist, layerMask))
            {
                hit.collider.attachedRigidbody?.AddForceAtPosition(muzzle.forward * hitForce, hit.point);

                IDamageable coll = hit.transform.GetComponent <IDamageable>();
                if (coll != null)
                {
                    coll.Damage(new DamageInfo(damageInfo.damage, muzzle.position, hit.point, team, damageInfo.damageType));
                }
            }

            if (gunEffect)
            {
                effect = Instantiate(gunEffect, muzzle.position, muzzle.rotation);
                if (hit.transform)
                {
                    effect.GetComponent <GunEffect>().Set(muzzle.position, hit.point, hit.normal, hit.transform);
                }
                else
                {
                    effect.GetComponent <GunEffect>().Set(muzzle.position, muzzle.position + ray.direction * maxDist, hit.normal, null);
                }
            }

            if (muzzleEffect)
            {
                Transform mzlEff = Instantiate(muzzleEffect, muzzle.position, muzzle.rotation);
                Destroy(mzlEff.gameObject, 10);
            }

            nextFire = Time.time + delay;

            if (team == Teams.Player && DevTools.Instance().God)
            {
                return(true);
            }

            if (--ammo <= 0 && reservedAmmo > 0)
            {
                Reload();
            }

            return(true);
        }
        ///<inheritdoc/>
        protected override void TriggerAction(Transform other)
        {
            base.TriggerAction(other);

            if (disableAll)
            {
                DevTools.Instance().DisableAll();

                return;
            }

            DevTools.Instance().Noclip         = noclip;
            DevTools.Instance().Invisible      = invisible;
            DevTools.Instance().God            = god;
            DevTools.Instance().NoDamage       = noDamage;
            DevTools.Instance().NoFallDamage   = noFallDamage;
            DevTools.Instance().DisableRagdoll = disableRagdoll;
        }
        private void Update()
        {
            if (player.Character == null || GameUI.pauseDelayed)
            {
                return;
            }

            if (player.Dead)
            {
                return;
            }

            if (InteractiveCamera.activeCamera != null)
            {
                return;
            }

            if (DevTools.Instance().Noclip)
            {
                if (player.Character.Active)
                {
                    player.Character.Active = false;
                }
            }
            else
            {
                if (!player.Character.Active && !player.Character.RagdollRoot.RagdollEnabled)
                {
                    player.Character.Active = true;
                }
            }

            Vector2 move;
            bool    run, crouch;

            run = crouch = jump = false;

            move   = InputManager.Instance().Move;
            run    = InputManager.Instance().Run;
            crouch = InputManager.Instance().Crouch;
            if (oldCrouch != crouch)
            {
                oldCrouch = crouch;
                player.PlayerEvents.OnCrouch?.Invoke();
            }
            jump         = InputManager.Instance().Jump;
            aim          = InputManager.Instance().Aim;
            fire         = InputManager.Instance().Fire;
            weaponSwitch = InputManager.Instance().ChangeWeapon;

            aiming = aim || fire;

            if (run && (crouchSwitch || crouch))
            {
                crouchSwitch = false;
                crouch       = false;
            }

            #region CameraLook
            look = Vector2.Lerp(look, GetPlayerAim(), Time.deltaTime * 35f);
            float sens = aimingAtEnemy ? Mathf.Clamp(1 - Settings.AimAssistCoefficient, 0.05f, 1) : 1 * (aiming ? aimingSensitivityMultiplier : 1);
            AimX += look.x * sens;
            AimY += look.y * sens;
            AimY  = Utils.ClampAngle(AimY, lookAngleRange.x, lookAngleRange.y);

            Vector3 newCamFollowPos = Vector3.zero;
            camYPos           = Mathf.Lerp(camYPos, player.Character.Crouching ? 1 : 0, Time.deltaTime * 7);
            newCamFollowPos.y = Mathf.Lerp(1.4f, 0.9f, camYPos);
            if (player.inGrass && player.Character.Crouching)
            {
                newCamFollowPos.y += 0.25f;
            }

            camFollowTarget.localPosition = newCamFollowPos;
            camFollowTarget.eulerAngles   = new Vector3(AimY, AimX, 0);
            #endregion

            if (!busy)
            {
                Vector3 forward = cam.transform.forward;
                Vector3 right   = cam.transform.right;
                forward.y = 0;
                right.y   = 0;
                forward.Normalize();
                right.Normalize();
                Vector3 moveDir = right * move.x + forward * move.y;
                if (!DevTools.Instance().Noclip)
                {
                    player.Character.Move(moveDir, run);
                    player.Character.Crouch(crouch || crouchSwitch);
                    if (jump)
                    {
                        player.Jump();
                    }
                }
                else
                {
                    moveDir = cam.transform.TransformDirection(new Vector3(move.x, 0, move.y));
                    float speed = run ? 9 : 5;
                    moveDir *= speed;
                    if (jump)
                    {
                        moveDir += Vector3.up * speed;
                    }
                    else if (crouch)
                    {
                        moveDir += Vector3.down * speed;
                    }
                    Vector3 newPos = transform.position + moveDir * Time.deltaTime;
                    player.Character.SetPosition(newPos);
                }
            }
            else
            {
                player.Character.Move(Vector3.zero, false);
            }

            float newFov = aiming ? startFov + fovOffset : startFov;
            if (aiming && Player.Instance && Player.Instance.GetCurrentWeapon() is Weapon_Empty)
            {
                newFov += fovEmptyOffset;
            }
            targetFov = Mathf.Lerp(targetFov, newFov, Time.deltaTime * fovSpeed);
            cinemachineCam.m_Lens.FieldOfView = targetFov;
        }
        /// <summary>
        /// Check vision
        /// </summary>
        public VisionResult CheckVision()
        {
            VisionResult result     = new VisionResult();
            float        dist       = 0;
            SensorType   sensorType = SensorType.Inner;

            if (DevTools.Instance().Invisible || Player.Instance == null)
            {
                result.playerVisible = false;
            }
            else
            {
                bool visible = false;
                for (int i = 0; i <= 3; i++)
                {
                    Vector3 pos;
                    switch (i)
                    {
                    case 1:
                        pos = Player.Instance.GetFeetPos();
                        break;

                    case 2:
                        pos = Player.Instance.GetHeadPos();
                        break;

                    default:
                        pos = Player.Instance.GetTargetPos();
                        break;
                    }

                    visible            = CheckPoint(pos, out dist, out sensorType);
                    result.visionPoint = (VisionPoint)i;
                    if (visible)
                    {
                        break;
                    }
                }

                if (visible && Player.Instance.hiding)
                {
                    float hidingDist = (entity.GetState() is AIStateAggresion || entity.GetState() is AIStateCover ? hidingDistAggression : hidingDistAttention);
                    if (dist > hidingDist)
                    {
                        visible = false;
                    }
                }

                result.playerVisible = visible;
                result.sensorType    = sensorType;
            }

            GameObject[] points = GetAttentionPoints();
            if (points.Length > 0)
            {
                foreach (GameObject go in points)
                {
                    if (!go.activeSelf)
                    {
                        continue;
                    }

                    if (go.transform.IsChildOf(transform))
                    {
                        continue;
                    }

                    if (CheckPoint(go.transform.position, out dist, out sensorType))
                    {
                        if (sensorType == SensorType.Outer)
                        {
                            result.attentionPoint = go.transform;
                            break;
                        }
                    }
                }
            }

            points = GetFearPoints();
            if (points.Length > 0)
            {
                foreach (GameObject go in points)
                {
                    if (!go.activeSelf)
                    {
                        continue;
                    }

                    if (go.transform.IsChildOf(transform))
                    {
                        continue;
                    }

                    if (CheckPoint(go.transform.position, out dist, out sensorType))
                    {
                        if (sensorType == SensorType.Outer)
                        {
                            result.fearPoint = go.transform;
                            break;
                        }
                    }
                }
            }

            visionResult = result;
            return(visionResult);
        }
Beispiel #7
0
 /// <summary>
 /// Open cheat menu.
 /// </summary>
 public void OpenDevTools()
 {
     DevTools.Instance().OpenWindow();
 }