Exemple #1
0
        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");

            trigger.Add(new TwoWayBinding <Vector3>(transform.Position, trigger.Position));
            trigger.Add(new CommandBinding(trigger.PlayerEntered, (Action)mapExit.Go));

            trigger.EditorProperties();
            entity.Add("OnEnter", trigger.PlayerEntered);
            entity.Add("Enable", trigger.Enable);
            entity.Add("Enabled", trigger.Enabled);
            entity.Add("Disable", trigger.Disable);
            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);
        }
Exemple #2
0
 /// <summary>
 /// Called whenever an entity moves to another tile
 /// </summary>
 public void OnEntityMoved(Entity entity)
 {
     if (entity == player && loadedLevel.map.exits.ContainsKey(entity.pos)) //Player stepped on an exit tile
     {
         MapExit exit = loadedLevel.map.exits[entity.pos];
         EnterLevel(exit.level, exit.entranceID);
     }
 }
Exemple #3
0
 public void OnEntityFailedToMove(Entity entity, IntVec attemptTilePos)
 {
     if (entity == player && loadedLevel.map.exits.ContainsKey(entity.pos)) //Player stepped in an invalid direction while on an exit tile - Activate exit
     {
         MapExit exit = loadedLevel.map.exits[entity.pos];
         EnterLevel(exit.level, exit.entranceID);
     }
 }
Exemple #4
0
    // EXIT ColourR,G,B,A Level entranceID
    static void AddExit(string[] args)
    {
        Color32 colour        = ParseColour(args[1]);
        string  toLevel       = ParseString(args[2]);
        int     entranceToUse = int.Parse(args[3]);
        MapExit exit          = new MapExit(toLevel, entranceToUse);

        colourBehaviours.Add(new KeyValuePair <Color32, IMapComponent>(colour, exit));
    }
Exemple #5
0
        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);
        }