public override void Bind(Entity entity, Main main, bool creating = false) { Transform transform = entity.GetOrCreate <Transform>("Transform"); PlayerTrigger trigger = entity.GetOrCreate <PlayerTrigger>("PlayerTrigger"); this.SetMain(entity, main); VoxelAttachable.MakeAttachable(entity, main).EditorProperties(); MapExit mapExit = entity.GetOrCreate <MapExit>("MapExit"); AmbientSound sound = entity.GetOrCreate <AmbientSound>(); sound.Add(new Binding <Vector3>(sound.Position, transform.Position)); sound.PlayCue.Value = AK.EVENTS.PLAY_DOOR_AMBIENCE; sound.StopCue.Value = AK.EVENTS.STOP_DOOR_AMBIENCE; sound.Add(new Binding <bool>(sound.Enabled, trigger.Enabled)); trigger.Add(new TwoWayBinding <Vector3>(transform.Position, trigger.Position)); trigger.Add(new CommandBinding(trigger.PlayerEntered, (Action)mapExit.Go)); trigger.EditorProperties(); entity.Add("Enable", trigger.Enable); entity.Add("Disable", trigger.Disable); entity.Add("OnEnter", trigger.PlayerEntered); entity.Add("Enabled", trigger.Enabled); entity.Add("NextMap", mapExit.NextMap, new PropertyEntry.EditorData { Options = FileFilter.Get(main, main.MapDirectory, null, MapLoader.MapExtension, delegate() { return(new[] { Main.MenuMap }); }), }); entity.Add("StartSpawnPoint", mapExit.StartSpawnPoint); }
public static void Run(Entity script) { Updater updater = script.Create <Updater>(); Command enable = command(script, "Enable"); Command disable = command(script, "Disable"); Property <bool> enabled = property <bool>(script, "Enabled"); updater.Add(new Binding <bool>(updater.Enabled, enabled)); script.Add(new CommandBinding(enable, () => !enabled, delegate() { enabled.Value = true; })); script.Add(new CommandBinding(disable, () => enabled, delegate() { enabled.Value = false; })); AmbientSound sound = script.Create <AmbientSound>(); sound.PlayCue.Value = AK.EVENTS.PLAY_MONOLITH_LOOP; sound.StopCue.Value = AK.EVENTS.STOP_ALL_OBJECT; sound.Add(new Binding <bool>(sound.Enabled, enabled)); script.Add(new Binding <float, bool>(WorldFactory.Instance.Get <World>().CameraShakeAmount, x => x ? 0.02f : 0.0f, enabled)); script.Add(new ChangeBinding <bool>(enabled, delegate(bool old, bool value) { if (!old && value) { enable.Execute(); } else if (old && !value) { disable.Execute(); } })); RiftFactory riftFactory = Factory.Get <RiftFactory>(); const float minInterval = 3.0f; const float maxInterval = 8.0f; float interval = minInterval + (float)random.NextDouble() * (maxInterval - minInterval); updater.Action = delegate(float dt) { Entity player = PlayerFactory.Instance; if (player != null) { interval -= dt; if (interval < 0.0f) { Vector3 pos = player.Get <Transform>().Position; Vector3 dir = Vector3.Normalize(new Vector3((float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f)); Voxel.GlobalRaycastResult hit = default(Voxel.GlobalRaycastResult); int radius = random.Next(4, 10); int tries = 30; bool success = false; while (tries > 0) { hit = Voxel.GlobalRaycast(pos, dir, 50.0f); if (hit.Voxel != null && hit.Distance > radius && Rift.Query(hit.Position) == null && Zone.CanSpawnRift(hit.Position) && MapExit.Query(hit.Position, 5 + radius) == null) { success = true; break; } tries--; } if (success) { Entity rift = riftFactory.CreateAndBind(main); rift.Get <Transform>().Position.Value = hit.Position; VoxelAttachable attachment = rift.Get <VoxelAttachable>(); attachment.AttachedVoxel.Value = hit.Voxel.Entity; attachment.Coord.Value = hit.Coordinate.Value; Rift riftComponent = rift.Get <Rift>(); riftComponent.Radius.Value = radius; main.Add(rift); riftComponent.Enabled.Value = true; interval = minInterval + (float)random.NextDouble() * (maxInterval - minInterval); } } } }; script.Add(updater); }