예제 #1
0
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                var input    = Owner.Input;
                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                int resizeDir;
                if (input.Down(InputButton.Attack1))
                {
                    resizeDir = 1;
                }
                else if (input.Down(InputButton.Attack2))
                {
                    resizeDir = -1;
                }
                else
                {
                    return;
                }

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .UseHitboxes()
                         .HitLayer(CollisionLayer.Debris)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid() || tr.Entity.PhysicsGroup == null)
                {
                    return;
                }

                // Disable resizing lights for now
                if (tr.Entity is LightEntity || tr.Entity is LampEntity)
                {
                    return;
                }

                var scale = Math.Clamp(tr.Entity.Scale + ((0.5f * Time.Delta) * resizeDir), 0.4f, 4.0f);

                if (tr.Entity.Scale != scale)
                {
                    tr.Entity.Scale = scale;
                    tr.Entity.PhysicsGroup.RebuildMass();
                    tr.Entity.PhysicsGroup.Wake();
                }

                if (input.Pressed(InputButton.Attack1) ||
                    input.Pressed(InputButton.Attack2))
                {
                    CreateHitEffects(tr.EndPos);
                }
            }
        }
예제 #2
0
파일: DmWeapon.cs 프로젝트: UAVXP/dm98
    public override void Reload(Player owner)
    {
        if (IsClient || IsReloading)
        {
            return;
        }

        if (AmmoClip >= ClipSize)
        {
            return;
        }

        TimeSinceReload = 0;

        using (Prediction.Off())
        {
            if (Owner  is DeathmatchPlayer player)
            {
                if (player.AmmoCount(AmmoType) <= 0)
                {
                    return;
                }

                StartReloadEffects();
            }

            IsReloading = true;
            Owner.SetAnimParam("b_reload", true);
            StartReloadEffects();
        }
    }
예제 #3
0
        public virtual void ShootBullet(float spread, float force, float damage, float bulletSize)
        {
            var forward = Owner.EyeRot.Forward;

            forward += (Vector3.Random + Vector3.Random + Vector3.Random + Vector3.Random) * spread * 0.25f;
            forward  = forward.Normal;

            foreach (var tr in TraceBullet(Owner.EyePos, Owner.EyePos + forward * 5000, bulletSize))
            {
                tr.Surface.DoBulletImpact(tr);

                if (!IsServer)
                {
                    continue;
                }
                if (!tr.Entity.IsValid())
                {
                    continue;
                }

                using (Prediction.Off())
                {
                    var damageInfo = DamageInfo.FromBullet(tr.EndPos, forward * 100 * force, damage)
                                     .UsingTraceResult(tr)
                                     .WithAttacker(Owner)
                                     .WithWeapon(this);

                    tr.Entity.TakeDamage(damageInfo);
                }
            }
        }
예제 #4
0
        public override void OnPlayerControlTick()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                if (this.prop.IsValid())
                {
                    this.prop.Delete();
                    this.prop = null;

                    return;
                }

                if (this.removable != null)
                {
                    this.removable.Remove();
                    this.removable = null;

                    return;
                }

                var input = Owner.Input;

                if (!input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid() || tr.Entity.IsWorld)
                {
                    return;
                }

                if (tr.Entity is IRemovable removable)
                {
                    this.removable = removable;

                    return;
                }

                if (tr.Entity is Prop prop)
                {
                    prop.PhysicsGroup?.Wake();
                    this.prop = prop;

                    return;
                }
            }
        }
예제 #5
0
    private void Shoot(Vector3 pos, Vector3 dir, Vector3 force)
    {
        //
        // Tell the clients to play the shoot effects
        //
        ShootEffects();

        if (IsServer)
        {
            using (Prediction.Off())
            {
                var ent = ((DeathmatchPlayer)Owner).grenadePooler.GetPooledObject();
                ent.ResetInterpolation();
                ent.Position = Owner.EyePos + (Owner.EyeRot.Forward * 50);
                ent.Rotation = Owner.EyeRot;
                ent.Velocity = Owner.EyeRot.Forward * force;
                ent.PhysicsBody.GravityScale = ent.GravityScale;
                ent.RenderColor         = Color.Random;
                ent.EnableAllCollisions = true;
                ent.EnableDrawing       = true;
                ent.AttachTrail();
                ent.Owner   = Local.Pawn;
                ent.OwnedBy = Owner;
                ent.StartDestroy();
            }
        }
    }
예제 #6
0
        public override void Spawn()
        {
            SetModel("models/tank_rocket.vmdl");
            timeSinceLaunched = 0;
            Transmit          = TransmitType.Always;
            Tags.Add("rocket");

            using (Prediction.Off()) {
                TrailEffect = Particles.Create("particles/rocket_trail.vpcf");
                TrailEffect.SetEntity(0, this, CollisionBounds.Mins.WithZ(0).WithY(0));
            }
            Light = new SpotLightEntity {
                Position       = Position + Rotation.Forward * (CollisionBounds.Mins.x - 1),
                Rotation       = Rotation.LookAt(Rotation.Backward),
                DynamicShadows = true,
                Color          = new(1, 0.5f, 0),
                Brightness     = 2,
                Parent         = this,
                Range          = 96,
                InnerConeAngle = 15,
                OuterConeAngle = 70
            };

            //timeAlive = Rand.Float();
        }
예제 #7
0
    public void OnPlayerControlTick(Player owner)
    {
        if (owner == null)
        {
            return;
        }

        var input  = owner.Input;
        var eyePos = owner.EyePos;
        var eyeDir = owner.EyeRot.Forward;
        var eyeRot = Rotation.From(new Angles(0.0f, owner.EyeAng.yaw, 0.0f));

        if (!grabbing && input.Pressed(InputButton.Attack1))
        {
            grabbing = true;
        }

        bool grabEnabled   = grabbing && input.Down(InputButton.Attack1);
        bool wantsToFreeze = input.Pressed(InputButton.Attack2);

        if (IsClient && wantsToFreeze)
        {
            grabEnabled = false;
            grabbing    = false;
        }

        BeamActive = grabEnabled;

        if (IsServer)
        {
            using (Prediction.Off())
            {
                if (!holdBody.IsValid())
                {
                    return;
                }

                if (grabEnabled)
                {
                    if (heldBody.IsValid())
                    {
                        UpdateGrab(input, eyePos, eyeRot, eyeDir, wantsToFreeze);
                    }
                    else
                    {
                        TryStartGrab(owner, eyePos, eyeRot, eyeDir);
                    }
                }
                else if (grabbing)
                {
                    GrabEnd();
                }
            }
        }

        if (BeamActive)
        {
            owner.Input.MouseWheel = 0;
        }
    }
예제 #8
0
        public override void StartTouch(Entity other)
        {
            base.StartTouch(other);

            WaterController.StartTouch(other);

            Action task = async() =>
            {
                await Task.DelaySeconds(2);

                if (!other.IsValid())
                {
                    return;
                }

                // TODO: check if other is still in water

                using (Prediction.Off())
                {
                    if (other is GolfBall ball)
                    {
                        (Game.Current as GolfGame).BallOutOfBounds(ball, GolfGame.OutOfBoundsType.Water);
                    }
                }
            };

            task.Invoke();
        }
예제 #9
0
        public virtual void MeleeStrike(float damage, float force)
        {
            Vector3 forward = Owner.EyeRotation.Forward;

            forward = forward.Normal;

            foreach (TraceResult tr in TraceBullet(Owner.EyePosition, Owner.EyePosition + forward * MeleeDistance, 10f))
            {
                if (!tr.Entity.IsValid())
                {
                    continue;
                }

                tr.Surface.DoBulletImpact(tr);

                if (!IsServer)
                {
                    continue;
                }

                using (Prediction.Off())
                {
                    DamageInfo damageInfo = DamageInfo.FromBullet(tr.EndPosition, forward * 100 * force, damage)
                                            .UsingTraceResult(tr)
                                            .WithAttacker(Owner)
                                            .WithWeapon(this);

                    tr.Entity.TakeDamage(damageInfo);
                }
            }
        }
예제 #10
0
        public virtual void ShootBullet(float spread, float force, float damage, float bulletSize, string impactEffect = null, DamageFlags damageType = DamageFlags.Bullet)
        {
            Vector3 forward = Owner.EyeRotation.Forward;

            forward += (Vector3.Random + Vector3.Random + Vector3.Random + Vector3.Random) * spread * 0.25f;
            forward  = forward.Normal;

            foreach (TraceResult trace in TraceBullet(Owner.EyePosition, Owner.EyePosition + forward * BulletRange, bulletSize))
            {
                Vector3 endPos = trace.EndPosition + trace.Direction * bulletSize;

                if (string.IsNullOrEmpty(impactEffect))
                {
                    trace.Surface.DoBulletImpact(trace);
                }
                else
                {
                    Particles.Create(impactEffect, endPos)?.SetForward(0, trace.Normal);
                }

                if (!IsServer || !trace.Entity.IsValid())
                {
                    continue;
                }

                using (Prediction.Off())
                {
                    DealDamage(trace.Entity, trace.EndPosition, forward * 100f * force, damage, damageType, trace);
                }
            }
        }
예제 #11
0
        public override void AttackPrimary(Sandbox.Player owner)
        {
            TimeSincePrimaryAttack   = 0;
            TimeSinceSecondaryAttack = 0;

            ShootEffects();

            foreach (var tr in TraceBullet(owner.EyePos, owner.EyePos + owner.EyeRot.Forward * 5000))
            {
                tr.Surface.DoBulletImpact(tr);

                if (!IsServer)
                {
                    continue;
                }
                if (!tr.Entity.IsValid())
                {
                    continue;
                }

                using (Prediction.Off())
                {
                    var damage = DamageInfo.FromBullet(tr.EndPos, owner.EyeRot.Forward * 100, 15)
                                 .UsingTraceResult(tr)
                                 .WithAttacker(owner)
                                 .WithWeapon(this);

                    tr.Entity.TakeDamage(damage);
                }
            }
        }
예제 #12
0
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                var input = Owner.Input;

                bool push = input.Down(InputButton.Attack1);
                if (!push && !input.Down(InputButton.Attack2))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .HitLayer(CollisionLayer.Debris)
                         .Run();

                if (!tr.Hit)
                {
                    return;
                }

                if (!tr.Entity.IsValid())
                {
                    return;
                }

                if (tr.Entity.IsWorld)
                {
                    return;
                }

                var body = tr.Body;

                if (!body.IsValid())
                {
                    return;
                }

                var direction = tr.EndPos - tr.StartPos;
                var distance  = direction.Length;
                var ratio     = (1.0f - (distance / MaxDistance)).Clamp(0, 1) * (push ? 1.0f : -1.0f);
                var force     = direction * (Force * ratio);

                if (Massless)
                {
                    force *= body.Mass;
                }

                body.ApplyForceAt(tr.EndPos, force);
            }
        }
예제 #13
0
파일: Lamp.cs 프로젝트: Exer0s/flood
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                var input = Owner.Input;

                if (!input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid())
                {
                    return;
                }

                CreateHitEffects(tr.EndPos);

                if (tr.Entity is LampEntity lamp)
                {
                    // TODO: Set properties

                    lamp.Flicker = !lamp.Flicker;

                    return;
                }

                lamp = new LampEntity
                {
                    Enabled              = true,
                    DynamicShadows       = true,
                    Range                = 512,
                    Falloff              = 1.0f,
                    LinearAttenuation    = 0.0f,
                    QuadraticAttenuation = 1.0f,
                    InnerConeAngle       = 25,
                    OuterConeAngle       = 45,
                    Brightness           = 10,
                    Color                = Color.Random,
                    Rotation             = Rotation.Identity
                };

                lamp.SetModel(Model);
                lamp.SetupPhysicsFromModel(PhysicsMotionType.Dynamic, false);
                lamp.Position = tr.EndPos + -lamp.CollisionBounds.Center + tr.Normal * lamp.CollisionBounds.Size * 0.5f;
            }
        }
예제 #14
0
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                if (!Input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePosition;
                var dir      = Owner.EyeRotation.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .Run();

                if (!tr.Hit)
                {
                    return;
                }

                if (!tr.Entity.IsValid())
                {
                    return;
                }

                var attached = !tr.Entity.IsWorld && tr.Body.IsValid() && tr.Body.PhysicsGroup != null && tr.Body.GetEntity().IsValid();

                if (attached && tr.Entity is not Prop)
                {
                    return;
                }

                CreateHitEffects(tr.EndPosition);

                if (tr.Entity is WheelEntity)
                {
                    // TODO: Set properties

                    return;
                }

                var ent = new WheelEntity
                {
                    Position = tr.EndPosition,
                    Rotation = Rotation.LookAt(tr.Normal) * Rotation.From(new Angles(0, 90, 0)),
                };

                ent.SetModel("models/citizen_props/wheel01.vmdl");

                ent.PhysicsBody.Mass = tr.Body.Mass;
                ent.Joint            = PhysicsJoint.CreateHinge(ent.PhysicsBody, tr.Body, tr.EndPosition, tr.Normal);
            }
        }
예제 #15
0
파일: Remover.cs 프로젝트: anthrax3/sandbox
        public override void OnPlayerControlTick()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                if (target.IsValid())
                {
                    target.Delete();
                    target = null;

                    return;
                }

                var input = Owner.Input;

                if (!input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .Run();

                if (!tr.Hit)
                {
                    return;
                }

                if (!tr.Entity.IsValid())
                {
                    return;
                }

                if (tr.Entity.IsWorld)
                {
                    return;
                }

                if (tr.Entity is not Prop prop)
                {
                    return;
                }

                prop.PhysicsGroup?.Wake();

                target = prop;
            }
        }
예제 #16
0
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                if (!Input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid())
                {
                    return;
                }

                var attached = !tr.Entity.IsWorld && tr.Body.IsValid() && tr.Body.PhysicsGroup != null && tr.Body.Entity.IsValid();

                if (attached && tr.Entity is not Prop)
                {
                    return;
                }

                CreateHitEffects(tr.EndPos);

                if (tr.Entity is StarfallProcessor)
                {
                    return;
                }

                var ent = new StarfallProcessor
                {
                    Position              = tr.EndPos,
                    Rotation              = Rotation.LookAt(tr.Normal, dir) * Rotation.From(new Angles(90, 0, 0)),
                    PhysicsEnabled        = !attached,
                    EnableSolidCollisions = !attached,
                };

                if (attached)
                {
                    ent.SetParent(tr.Body.Entity, tr.Body.PhysicsGroup.GetBodyBoneName(tr.Body));
                }

                ent.SetModel("models/starfall_processor.vmdl");
            }
        }
예제 #17
0
 public void TakeDmg()
 {
     using (Prediction.Off())
     {
         var info = DealDamageBasedOnVelocityZ();
         if (info.Damage > 0)
         {
             Pawn.TakeDamage(info);
         }
     }
 }
예제 #18
0
        protected async Task pulseIndicator()
        {
            await GameTask.Delay(100);

            while (!IsCollected)
            {
                using (Prediction.Off()) {
                    Particles.Create(indicator, Position + Vector3.Up * 0.5f);
                }
                await GameTask.DelaySeconds(timeBetweenIndicators);
            }
        }
예제 #19
0
        public override void OnCollected(TankPlayer player)
        {
            timeSinceCollected = 0;
            startClientMeter(To.Single(player.GetClientOwner()));             // This RPC only works if inheriting from ModelEntity

            if (!string.IsNullOrEmpty(active))
            {
                using (Prediction.Off()) {
                    activeEffect = Particles.Create(active, player.Base, "");
                }
            }
            base.OnCollected(player);
        }
예제 #20
0
파일: DmWeapon.cs 프로젝트: UAVXP/dm98
    public override void OnPlayerControlTick(Player owner)
    {
        if (!IsReloading)
        {
            base.OnPlayerControlTick(owner);
        }

        if (IsServer && IsReloading && TimeSinceReload > ReloadTime)
        {
            using (Prediction.Off())
            {
                OnReloadFinish();
            }
        }
    }
예제 #21
0
        public void PlayFootstep(int foot = 0, float volume = 1)
        {
            using (Prediction.Off())
            {
                var trBegin = new Transform(Position.WithZ(Position.z + 5), Rotation.Identity);
                var trEnd   = new Transform(Position.WithZ(Position.z - 10), Rotation.Identity);
                var tr      = Trace.Sweep(PhysicsBody, trBegin, trEnd)
                              .Ignore(this)
                              .Run();

                if (tr.Hit)
                {
                    tr.Surface.DoFootstep(this, tr, foot, volume);
                }
            }
        }
예제 #22
0
        private void TickPlayerFlashlight()
        {
            using (Prediction.Off())
            {
                if (Input.Released(InputButton.Flashlight))
                {
                    ToggleFlashlight();
                }
            }

            if (IsFlashlightOn)
            {
                _worldFlashlight.Rotation = Rotation.Slerp(_worldFlashlight.Rotation, Input.Rotation, SMOOTH_SPEED);
                _worldFlashlight.Position = Vector3.Lerp(_worldFlashlight.Position, EyePosition + Input.Rotation.Forward * FLASHLIGHT_DISTANCE, SMOOTH_SPEED);
            }
        }
예제 #23
0
        protected async Task startEmitting()
        {
            await GameTask.Delay(100);

            if (!ShouldEmitEffects)
            {
                return;
            }
            using (Prediction.Off()) {
                mainParticles    = Particles.Create(main, Position + Vector3.Up * 32);
                fieldUpParticles = Particles.Create(field, Position);
                fieldUpParticles.SetForward(0, Vector3.Up);
                fieldDownParticles = Particles.Create(field, Position + Vector3.Up * 80);
                fieldDownParticles.SetForward(0, Vector3.Down);
            }
        }
예제 #24
0
    protected override void Tick()
    {
        base.Tick();

        //
        // Input requested a weapon switch
        //
        if (Input.ActiveChild != null)
        {
            ActiveChild = Input.ActiveChild;
        }

        if (LifeState != LifeState.Alive)
        {
            return;
        }

        if (Input.Pressed(InputButton.View))
        {
            if (Camera is ThirdPersonCamera)
            {
                Camera = new FirstPersonCamera();
            }
            else
            {
                Camera = new ThirdPersonCamera();
            }
        }

        if (Input.Pressed(InputButton.Drop))
        {
            var dropped = Inventory.DropActive();
            if (dropped != null)
            {
                dropped.PhysicsGroup.Velocity = Velocity + (EyeRot.Forward + EyeRot.Up) * 300;
                timeSinceDropped = 0;
            }
        }

        if (Input.Pressed(InputButton.Use))
        {
            using (Prediction.Off())
            {
                TookDamage(this, WorldPos + Vector3.Random * 100);
            }
        }
    }
예제 #25
0
        public override void AttackPrimary()
        {
            TimeSincePrimaryAttack           = 0;
            TimeSinceSuccessfulPrimaryAttack = 0;
            TimeSinceSecondaryAttack         = 0;

            //
            // Tell the clients to play the shoot effects
            //
            ShootEffects();

            //
            // Do recoil
            //
            PerformRecoil();

            //
            // ShootBullet is coded in a way where we can have bullets pass through shit
            // or bounce off shit, in which case it'll return multiple results
            //
            foreach (var tr in TraceBullet(Owner.EyePos, Owner.EyePos + Owner.EyeRot.Forward * 5000))
            {
                tr.Surface.DoBulletImpact(tr);

                if (!IsServer)
                {
                    continue;
                }
                if (!tr.Entity.IsValid())
                {
                    continue;
                }

                //
                // We turn predictiuon off for this, so aany exploding effects don't get culled etc
                //
                using (Prediction.Off())
                {
                    var damage = DamageInfo.FromBullet(tr.EndPos, Owner.EyeRot.Forward * 100, 15)
                                 .UsingTraceResult(tr)
                                 .WithAttacker(Owner)
                                 .WithWeapon(this);

                    tr.Entity.TakeDamage(damage);
                }
            }
        }
예제 #26
0
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                var input = Owner.Input;

                if (!input.Pressed(InputButton.Attack1))
                {
                    return;
                }

                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .HitLayer(CollisionLayer.Debris)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid())
                {
                    return;
                }

                if (tr.Entity is Player)
                {
                    return;
                }

                CreateHitEffects(tr.EndPos);

                if (tr.Entity.IsWorld)
                {
                    return;
                }

                tr.Entity.Delete();

                var particle = Particles.Create("particles/physgun_freeze.vpcf");
                particle.SetPos(0, tr.Entity.Position);
            }
        }
예제 #27
0
파일: Resizer.cs 프로젝트: geferon/sandbox
        public override void OnPlayerControlTick()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                var input    = Owner.Input;
                var startPos = Owner.EyePos;
                var dir      = Owner.EyeRot.Forward;

                int resizeDir;
                if (input.Pressed(InputButton.Attack1))
                {
                    resizeDir = 1;
                }
                else if (input.Pressed(InputButton.Attack2))
                {
                    resizeDir = -1;
                }
                else
                {
                    return;
                }

                var tr = Trace.Ray(startPos, startPos + dir * MaxTraceDistance)
                         .Ignore(Owner)
                         .UseHitboxes()
                         .HitLayer(CollisionLayer.Debris)
                         .Run();

                if (!tr.Hit || !tr.Entity.IsValid() || tr.Entity.PhysicsGroup == null)
                {
                    return;
                }

                var scale = Math.Clamp(tr.Entity.WorldScale + (0.1f * resizeDir), 0.4f, 4.0f);

                tr.Entity.WorldScale = scale;
                tr.Entity.PhysicsGroup.RebuildMass();
                tr.Entity.PhysicsGroup.Wake();
            }
        }
예제 #28
0
    public override void AttackPrimary()
    {
        TimeSincePrimaryAttack   = 0;
        TimeSinceSecondaryAttack = 0;

        //
        // Tell the clients to play the shoot effects
        //
        ShootEffects();


        bool InWater = Physics.TestPointContents(Owner.EyePos, CollisionLayer.Water);
        var  forward = Owner.EyeRot.Forward * (InWater ? 500 : 4000);

        //
        // ShootBullet is coded in a way where we can have bullets pass through shit
        // or bounce off shit, in which case it'll return multiple results
        //
        foreach (var tr in TraceBullet(Owner.EyePos, Owner.EyePos + Owner.EyeRot.Forward * 4000))
        {
            tr.Surface.DoBulletImpact(tr);

            if (!IsServer)
            {
                continue;
            }
            if (!tr.Entity.IsValid())
            {
                continue;
            }

            //
            // We turn predictiuon off for this, so aany exploding effects
            //
            using (Prediction.Off())
            {
                var damage = DamageInfo.FromBullet(tr.EndPos, forward.Normal * 100, 15)
                             .UsingTraceResult(tr)
                             .WithAttacker(Owner)
                             .WithWeapon(this);

                tr.Entity.TakeDamage(damage);
            }
        }
    }
예제 #29
0
        protected override void OnPostCategorizePosition(bool stayOnGround, TraceResult trace)
        {
            if (Host.IsServer && trace.Hit && _fallVelocity < -FallDamageVelocity)
            {
                var damage = (MathF.Abs(_fallVelocity) - FallDamageVelocity) * FallDamageScale;

                using (Prediction.Off())
                {
                    var damageInfo = new DamageInfo()
                                     .WithAttacker(Player)
                                     .WithFlag(DamageFlags.Fall);

                    damageInfo.Damage = damage;

                    Player.TakeDamage(damageInfo);
                }
            }
        }
예제 #30
0
        public virtual void OnPostCategorizePosition(bool stayOnGround, TraceResult trace)
        {
            if (Host.IsServer && trace.Hit && _fallVelocity < -FALL_DAMAGE_VELOCITY)
            {
                using (Prediction.Off())
                {
                    DamageInfo damageInfo = new()
                    {
                        Attacker    = Pawn,
                        Flags       = DamageFlags.Fall,
                        HitboxIndex = (int)HitboxIndex.LeftFoot,
                        Position    = Position,
                        Damage      = (MathF.Abs(_fallVelocity) - FALL_DAMAGE_VELOCITY) * FALL_DAMAGE_SCALE
                    };

                    Pawn.TakeDamage(damageInfo);
                }
            }
        }