Exemplo n.º 1
0
 private void CmdDown_Click(object sender, RoutedEventArgs e)
 {
     if (lstLights.SelectedItems.Count == 1)
     {
         LightEntity light = (LightEntity)lstLights.SelectedItems[0];
         AdjustBrightness(Int32.Parse(txtOffset.Text) * -1, light.id);
     }
 }
Exemplo n.º 2
0
 private void updateSelectedLight(LightEntity light)
 {
     if (light != null)
     {
         cmdUp.IsEnabled      = light.state.reachable;
         cmdDown.IsEnabled    = light.state.reachable;
         lblReachable.Content = light.state.reachable ? "Light is reachable!" : "Light NOT reachable";
     }
     else
     {
         cmdUp.IsEnabled      = false;
         cmdDown.IsEnabled    = false;
         lblReachable.Content = "";
     }
 }
Exemplo n.º 3
0
    void Start()
    {
        _lightEntity = new LightEntity(entityId);

        if (_lightEntity != null) // found?
        {
            // grab current state
            _lightEntity.IsOn(on =>
            {
                if (sceneLight != null)
                {
                    sceneLight.SetActive(on);
                }
            });
        }
    }
Exemplo n.º 4
0
 public static IObservable <StateChange <LightEntity, EntityState <LightAttributes> > > StateAllChangesWithCurrent(this LightEntity entity)
 {
     return(entity.StateAllChangesWithCurrent <LightEntity, EntityState <LightAttributes>, LightAttributes>());
 }
Exemplo n.º 5
0
        public override void OnPlayerControlTick()
        {
            if (!Host.IsServer)
            {
                return;
            }

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

                bool useRope = input.Pressed(InputButton.Attack1);
                if (!useRope && !input.Pressed(InputButton.Attack2))
                {
                    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 LightEntity)
                {
                    // TODO: Set properties

                    return;
                }

                var light = new LightEntity
                {
                    Enabled              = true,
                    DynamicShadows       = false,
                    Range                = 128,
                    Falloff              = 1.0f,
                    LinearAttenuation    = 0.0f,
                    QuadraticAttenuation = 1.0f,
                    Brightness           = 1,
                    Color                = Color.Random,
                };

                light.UseFogNoShadows();
                light.SetModel(Model);
                light.SetupPhysicsFromModel(PhysicsMotionType.Dynamic, false);
                light.WorldPos = tr.EndPos + -light.CollisionBounds.Center + tr.Normal * light.CollisionBounds.Size * 0.5f;

                if (!useRope)
                {
                    return;
                }

                var rope = Particles.Create("particles/rope.vpcf");
                rope.SetEntity(0, light, Vector3.Down * 6.5f);                   // Should be an attachment point

                var attachEnt      = tr.Body.IsValid() ? tr.Body.Entity : tr.Entity;
                var attachLocalPos = tr.Body.Transform.PointToLocal(tr.EndPos);

                if (attachEnt.IsWorld)
                {
                    rope.SetPos(1, attachLocalPos);
                }
                else
                {
                    rope.SetEntityBone(1, attachEnt, tr.Bone, new Transform(attachLocalPos));
                }

                light.AttachRope = rope;

                light.AttachJoint = PhysicsJoint.Spring
                                    .From(light.PhysicsBody)
                                    .To(tr.Body)
                                    .WithPivot(light.WorldPos + Vector3.Down * 6.5f)
                                    .WithFrequency(5.0f)
                                    .WithDampingRatio(0.7f)
                                    .WithReferenceMass(0)
                                    .WithMinRestLength(0)
                                    .WithMaxRestLength(100)
                                    .WithCollisionsEnabled()
                                    .Create();
            }
        }
Exemplo n.º 6
0
        protected bool RunCubeBlockReflectionTests()
        {
            bool result = true;

            if (!CubeBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CubeBlockEntity reflection validation failed!");
            }

            if (!TerminalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TerminalBlockEntity reflection validation failed!");
            }

            if (!FunctionalBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("FunctionalBlockEntity reflection validation failed!");
            }

            if (!ProductionBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ProductionBlockEntity reflection validation failed!");
            }

            if (!LightEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LightEntity reflection validation failed!");
            }

            if (!BatteryBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BatteryBlockEntity reflection validation failed!");
            }

            if (!BatteryBlockNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BatteryBlockNetworkManager reflection validation failed!");
            }

            if (!DoorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("DoorEntity reflection validation failed!");
            }

            if (!GravityBaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravityBaseEntity reflection validation failed!");
            }

            if (!GravityGeneratorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravityGeneratorEntity reflection validation failed!");
            }

            if (!GravitySphereEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravitySphereEntity reflection validation failed!");
            }

            if (!BeaconEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BeaconEntity reflection validation failed!");
            }

            if (!AntennaEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("AntennaEntity reflection validation failed!");
            }

            if (!ThrustEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ThrustEntity reflection validation failed!");
            }

            if (!ThrustNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ThrustNetworkManager reflection validation failed!");
            }

            if (!GyroEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GyroEntity reflection validation failed!");
            }

            if (!GyroNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GyroNetworkManager reflection validation failed!");
            }

            if (!CockpitEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CockpitEntity reflection validation failed!");
            }

            if (!TurretBaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TurretBaseEntity reflection validation failed!");
            }

            if (!TurretNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("TurretNetworkManager reflection validation failed!");
            }

            if (!LandingGearEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LandingGearEntity reflection validation failed!");
            }

            if (!LandingGearNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LandingGearNetworkManager reflection validation failed!");
            }

            if (!ReactorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ReactorEntity reflection validation failed!");
            }

            if (!SolarPanelEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SolarPanelEntity reflection validation failed!");
            }

            if (!SmallGatlingGunEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("SmallGatlingGunEntity reflection validation failed!");
            }

            if (!MergeBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("MergeBlockEntity reflection validation failed!");
            }

            if (!PistonEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PistonEntity reflection validation failed!");
            }

            if (!PistonNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("PistonNetworkManager reflection validation failed!");
            }

            if (!RotorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("RotorEntity reflection validation failed!");
            }

            if (!VirtualMassEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("VirtualMassEntity reflection validation failed!");
            }

            if (!CameraBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("CameraBlockEntity reflection validation failed!");
            }

            if (!OreDetectorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("OreDetectorEntity reflection validation failed!");
            }

            if (!ButtonPanelEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ButtonPanelEntity reflection validation failed!");
            }

            if (!ShipControllerEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ShipControllerEntity reflection validation failed!");
            }

            if (!ShipControllerNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ShipControllerNetworkManager reflection validation failed!");
            }

            if (result)
            {
                Console.WriteLine("All block types passed reflection unit tests!");
            }

            return(result);
        }
Exemplo n.º 7
0
        protected bool RunCubeBlockReflectionTests()
        {
            bool result = true;

            if (!LightEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("LightEntity reflection validation failed!");
            }

            if (!BatteryBlockEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BatteryBlockEntity reflection validation failed!");
            }

            if (!DoorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("DoorEntity reflection validation failed!");
            }

            if (!GravityBaseEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravityBaseEntity reflection validation failed!");
            }

            if (!GravityGeneratorEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravityGeneratorEntity reflection validation failed!");
            }

            if (!GravitySphereEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GravitySphereEntity reflection validation failed!");
            }

            if (!BeaconEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("BeaconEntity reflection validation failed!");
            }

            if (!AntennaEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("AntennaEntity reflection validation failed!");
            }

            if (!ThrustEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ThrustEntity reflection validation failed!");
            }

            if (!ThrustNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("ThrustNetworkManager reflection validation failed!");
            }

            if (!GyroEntity.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GyroEntity reflection validation failed!");
            }

            if (!GyroNetworkManager.ReflectionUnitTest())
            {
                result = false;
                Console.WriteLine("GyroNetworkManager reflection validation failed!");
            }

            if (result)
            {
                Console.WriteLine("All block types passed reflection unit tests!");
            }

            return(result);
        }
Exemplo n.º 8
0
        public override void Simulate()
        {
            if (!Host.IsServer)
            {
                return;
            }

            using (Prediction.Off())
            {
                bool useRope = Input.Pressed(InputButton.Attack1);
                if (!useRope && !Input.Pressed(InputButton.Attack2))
                {
                    return;
                }

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

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

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

                CreateHitEffects(tr.EndPosition);

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

                    return;
                }

                var light = new LightEntity
                {
                    Enabled              = true,
                    DynamicShadows       = false,
                    Range                = 128,
                    Falloff              = 1.0f,
                    LinearAttenuation    = 0.0f,
                    QuadraticAttenuation = 1.0f,
                    Brightness           = 1,
                    Color                = Color.Random,
                    //LightCookie = Texture.Load( "materials/effects/lightcookie.vtex" )
                };

                light.UseFogNoShadows();
                light.SetModel(Model);
                light.SetupPhysicsFromModel(PhysicsMotionType.Dynamic, false);
                light.Position = tr.EndPosition + -light.CollisionBounds.Center + tr.Normal * light.CollisionBounds.Size * 0.5f;

                if (!useRope)
                {
                    return;
                }

                var rope = Particles.Create("particles/rope.vpcf");
                rope.SetEntity(0, light, Vector3.Down * 6.5f);                   // Should be an attachment point

                var attachEnt      = tr.Body.IsValid() ? tr.Body.GetEntity() : tr.Entity;
                var attachLocalPos = tr.Body.Transform.PointToLocal(tr.EndPosition) * (1.0f / tr.Entity.Scale);

                if (attachEnt.IsWorld)
                {
                    rope.SetPosition(1, attachLocalPos);
                }
                else
                {
                    rope.SetEntityBone(1, attachEnt, tr.Bone, new Transform(attachLocalPos));
                }

                var spring = PhysicsJoint.CreateLength(PhysicsPoint.Local(light.PhysicsBody, Vector3.Down * 6.5f), PhysicsPoint.World(tr.Body, tr.EndPosition), 100);
                spring.SpringLinear            = new(5, 0.7f);
                spring.Collisions              = true;
                spring.EnableAngularConstraint = false;
                spring.OnBreak += () =>
                {
                    rope?.Destroy(true);
                    spring.Remove();
                };
            }
        }