コード例 #1
0
    /// <summary>
    /// Called when a player has died, or been killed
    /// </summary>
    public override void PlayerKilled(Player player)
    {
        Log.Info($"{player.Name} was killed");

        if (player.LastAttacker != null)
        {
            if (player.LastAttacker is Player attackPlayer)
            {
                KillFeed.AddEntry(attackPlayer.SteamId, attackPlayer.Name, player.SteamId, player.Name, player.LastAttackerWeapon?.ClassInfo?.Name);
            }
            else
            {
                KillFeed.AddEntry((ulong)player.LastAttacker.NetworkIdent, player.LastAttacker.ToString(), player.SteamId, player.Name, "killed");
            }
        }
        else
        {
            KillFeed.AddEntry((ulong)0, "", player.SteamId, player.Name, "died");
        }
    }
コード例 #2
0
        public void MovementLogic()
        {
            if (!IsServer)
            {
                return;
            }
            if (!Shooter.IsValid())
            {
                explode(false); return;
            }

            var trace = Trace.Ray(Position, Position + Rotation.Forward * MoveSpeed * Time.Delta).Size(Vector3.One * 2).HitLayer(CollisionLayer.Player).Ignore(this);

            if (timeSinceLaunched < 0.1f)
            {
                trace.Ignore(Shooter.Head);
            }
            var tr = trace.Run();

            if (tr.Hit)
            {
                Bounces++;

                if (tr.Entity is Rocket other)                   // Hit rocket
                {
                    if (Shooter != other.Shooter)
                    {
                        if (timeSinceLaunched < other.timeSinceLaunched)                           // Whoever shot second gets credit
                        {
                            Shooter.AddPoints(1, "Blocked Shot");
                        }
                        else
                        {
                            other.Shooter.AddPoints(1, "Blocked Shot");
                        }
                    }

                    other.explode(false);
                    explode(true);
                }
                else if (tr.Entity is PlayerEntity)                     // Hit player
                {
                    if (tr.Entity.GetClientOwner().Pawn is TankPlayer hitPlayer)
                    {
                        var damage = new DamageInfo {
                            Attacker = Shooter, Damage = 1
                        };
                        hitPlayer.TakeDamage(damage);

                        bool isSelfDamage = hitPlayer == Shooter;
                        if (!isSelfDamage)
                        {
                            if (Bounces == 1)
                            {
                                Shooter.AddPoints(1, $"Hit {hitPlayer.GetClientOwner().Name}");
                            }
                            else
                            {
                                Shooter.AddPoints(2, $"Bounce Hit {hitPlayer.GetClientOwner().Name}", true);
                            }
                        }

                        if (hitPlayer.LifeState != LifeState.Alive)
                        {
                            if (!isSelfDamage)
                            {
                                Shooter.GetClientOwner().SetScore("kills", Shooter.GetClientOwner().GetScore <int>("kills") + 1);
                                if (Bounces == 1)
                                {
                                    Shooter.AddPoints(2, $"Exploded {hitPlayer.GetClientOwner().Name}");
                                }
                                else
                                {
                                    Shooter.AddPoints(4, $"Bounce Exploded {hitPlayer.GetClientOwner().Name}", true);
                                }
                            }
                            KillFeed.AddEntry(Shooter.GetClientOwner().SteamId, Shooter.GetClientOwner().Name, hitPlayer.GetClientOwner().SteamId, hitPlayer.GetClientOwner().Name, "rocket");
                        }
                        explode(true);
                    }
                }
                else if (Bounces > MaxBounces)                     // Out of bounces
                {
                    explode(true);
                }
                else                     // Bounce off
                {
                    Vector3 dir = Rotation.Forward;
                    //DebugOverlay.Line(tr.EndPos, tr.EndPos + tr.Normal * 16, Color.Cyan, 1, false);
                    if (tr.Normal.z != 0)                       // Fix the bounce direction so we don't move up or down
                    //DebugOverlay.Sphere(tr.EndPos, 8, Color.Red, false, 1);
                    {
                        tr.Normal.z = 0;
                        tr.Normal   = tr.Normal.Normal;
                    }

                    dir      = Vector3.Reflect(dir, tr.Normal);
                    Rotation = Rotation.LookAt(dir, Vector3.Up);
                    using (Prediction.Off()) {
                        Particles.Create("particles/rocket_bounce.vpcf", tr.EndPos).SetForward(0, tr.Normal);
                        Sound.FromWorld("bounce", Position);
                    }
                }
            }

            Position += Rotation.Forward * MoveSpeed * Time.Delta;

            /*timeAlive += dt;
             * Light.Color = ((double) timeAlive).ToHSV();*/
        }