Example #1
0
        //Neat way of making a pseudo auto script for automatic wheather messages
        private static Func <BsonArray, Tuple <string, int>, string, string, bool> GetScript(List <string> zones)
        {
            int step = 0;

            Func <BsonArray, Tuple <string, int>, string, string, bool> result = delegate(BsonArray sequence, Tuple <string, int> tuple, string type, string message) {
                Rooms.Room room = null;
                //the sequence has ended nothing left to do here
                if (step >= sequence.Count)
                {
                    foreach (string zone in zones)           //loop through each zone
                    {
                        for (int low = 0; low <= 999; low++) //apply to it to rooms in zone Todo: get the number of rooms in the zone and use that as the low, high numbers
                        {
                            room                = Rooms.Room.GetRoom(zone + low);
                            room.Weather        = type;
                            room.WeatherMessage = message;
                        }
                    }
                    return(false);
                }

                foreach (string zone in zones)
                {
                    for (int low = 0; low <= 999; low++)  //Todo: get low/high numbers from room count in zone from database
                    {
                        room = Rooms.Room.GetRoom(zone + low);
                        if (room.IsOutdoors)
                        {
                            //ok if the tuple is not null then we are going to process it first. As of now it is just one single message with a wait time
                            //this can be modified to include more steps easily by making item1 a list and using steps to keep track
                            if (tuple != null)
                            {
                                room.InformPlayersInRoom(tuple.Item1, new List <string>(new string[] { }));
                                System.Threading.Thread.Sleep(tuple.Item2 * 1000);
                                return(true); //we still want the other sequence to execute we will set the tuple to null in the body of the while loop
                            }
                            //run the main sequence script
                            room.InformPlayersInRoom(sequence[step]["Step"].AsString, new List <string>(new string[] { }));
                        }
                    }
                }

                System.Threading.Thread.Sleep(sequence[step]["Wait"].AsInt32 * 1000);
                step++;
                return(true);
            };

            return(result);
        }