示例#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
        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
        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);
                }
            }
        }
        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);
                }
            }
        }