Exemplo n.º 1
0
        public void FireRocket(TankPlayer player, Vector3 cannonEnd)
        {
            timeSinceCannonFire = 0;
            if (!Host.IsServer)
            {
                return;
            }
            var rocket = new Rocket {
                Position    = cannonEnd,
                Rotation    = Rotation,
                Shooter     = player,
                RenderColor = player.GetClientOwner().GetScore("mtk_customcolor", Vector3.Zero).ToColor().ToColor32()
            };

            rocket.SetupPhysicsFromModel(PhysicsMotionType.Keyframed);

            using (Prediction.Off()) {
                Particles.Create("particles/tank_shoot.vpcf", cannonEnd).SetForward(0, Rotation.Forward);
                Sound.FromWorld("shoot", cannonEnd);
            }
        }
Exemplo n.º 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();*/
        }