Example #1
0
        /// <summary>
        /// Starts the storyline with the specified Storyline ID.
        /// </summary>
        /// <param name="stid">The storyline ID to start.</param>
        public static void Start(string stid)
        {
            if (SaveSystem.CurrentSave.StoriesExperienced == null)
            {
                SaveSystem.CurrentSave.StoriesExperienced = new List <string>();
            }
            foreach (var type in ReflectMan.Types)
            {
                foreach (var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
                {
                    foreach (var attrib in Array.FindAll(mth.GetCustomAttributes(false), a => a is StoryAttribute || a is MissionAttribute))
                    {
                        var story = attrib as StoryAttribute;
                        if (story.StoryID == stid)
                        {
                            new Thread(() =>
                            {
                                Context = new Engine.StoryContext
                                {
                                    Id           = stid,
                                    Method       = mth,
                                    AutoComplete = true,
                                };
                                SaveSystem.CurrentSave.PickupPoint = Context.Id;
                                Context.OnComplete += () =>
                                {
                                    if (story is MissionAttribute)
                                    {
                                        var mission = story as MissionAttribute;
                                        ConsoleEx.ForegroundColor = ConsoleColor.Yellow;
                                        ConsoleEx.Bold            = true;
                                        Console.WriteLine(" - mission complete - ");
                                        ConsoleEx.Bold            = false;
                                        ConsoleEx.ForegroundColor = ConsoleColor.White;
                                        Console.WriteLine($"{mission.Name} successfully finished. You have earned {mission.CodepointAward} Codepoints for your efforts.");
                                        SaveSystem.CurrentSave.Codepoints += mission.CodepointAward;
                                        TerminalBackend.PrintPrompt();
                                        TerminalBackend.PrefixEnabled = true;
                                    }
                                    StoryComplete?.Invoke(stid);
                                    SaveSystem.CurrentSave.PickupPoint = null;
                                };
                                mth.Invoke(null, null);
                                if (Context.AutoComplete)
                                {
                                    Context.MarkComplete();
                                }
                            }).Start();
                            return;
                        }
                    }
                }
            }
#if DEBUG
            throw new ArgumentException("Story ID not found: " + stid + " - Talk to Michael. NOW.");
#else
            Debug.Print("No such story: " + stid);
#endif
        }
Example #2
0
        public static void PushObjective(string name, string desc, Func <bool> completeFunc, Action onComplete)
        {
            if (CurrentObjectives == null)
            {
                CurrentObjectives = new List <Objective>();
            }

            var currentObjective = new Objective(name, desc, completeFunc, onComplete);

            CurrentObjectives.Add(currentObjective);
            var t = new Thread(() =>
            {
                var obj = currentObjective;
                while (!obj.IsComplete)
                {
                    Thread.Sleep(5000);
                }
                Thread.Sleep(500);
                CurrentObjectives.Remove(obj);
                obj.Complete();
            });

            t.IsBackground = true;
            t.Start();

            Console.WriteLine();
            ConsoleEx.ForegroundColor = ConsoleColor.Red;
            ConsoleEx.Bold            = true;
            Console.WriteLine("NEW OBJECTIVE:");
            Console.WriteLine();

            ConsoleEx.ForegroundColor = ConsoleColor.White;
            ConsoleEx.Bold            = false;
            Console.WriteLine("A new objective has been added to your system.");
            ConsoleEx.Bold = true;
            Console.WriteLine(name);
            ConsoleEx.Bold = false;
            Console.WriteLine();
            Console.WriteLine(desc);
            Console.WriteLine();
            Console.WriteLine("Run 'status' at any time to view your current objectives.");
            TerminalBackend.PrintPrompt();
        }
Example #3
0
        /// <summary>
        /// Initiate a new Digital Society connection.
        /// </summary>
        /// <param name="mud_address">The IP address or hostname of the target server</param>
        /// <param name="port">The target port.</param>
        public static void Initiate(string mud_address, int port)
        {
            client = new NetObjectClient();
            client.OnDisconnected += (o, a) =>
            {
                if (!UserDisconnect)
                {
                    Desktop.PushNotification("digital_society_connection", "Disconnected from Digital Society.", "The ShiftOS kernel has been disconnected from the Digital Society. We are attempting to re-connect you.");
                    TerminalBackend.PrefixEnabled = true;
                    ConsoleEx.ForegroundColor     = ConsoleColor.Red;
                    ConsoleEx.Bold = true;
                    Console.Write($@"Disconnected from MUD: ");
                    ConsoleEx.Bold            = false;
                    ConsoleEx.Italic          = true;
                    ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("You have been disconnected from the multi-user domain for an unknown reason. Your save data is preserved within the kernel and you will be reconnected shortly.");
                    TerminalBackend.PrefixEnabled = true;
                    TerminalBackend.PrintPrompt();
                    Initiate(mud_address, port);
                }
            };
            client.OnReceived += (o, a) =>
            {
                if (PingTimer.IsRunning)
                {
                    DigitalSocietyPing = PingTimer.ElapsedMilliseconds;
                    PingTimer.Reset();
                }
                var msg = a.Data.Object as ServerMessage;
                if (msg.Name == "Welcome")
                {
                    thisGuid = new Guid(msg.Contents);
                    GUIDReceived?.Invoke(msg.Contents);
                    guidReceiveARE.Set();
                    TerminalBackend.PrefixEnabled = true;
                    TerminalBackend.PrintPrompt();
                }
                else if (msg.Name == "allusers")
                {
                    foreach (var acc in JsonConvert.DeserializeObject <string[]>(msg.Contents))
                    {
                        Console.WriteLine(acc);
                    }
                    TerminalBackend.PrintPrompt();
                }
                else if (msg.Name == "update_your_cp")
                {
                    var args = JsonConvert.DeserializeObject <Dictionary <string, object> >(msg.Contents);
                    if (args["username"] as string == SaveSystem.CurrentUser.Username)
                    {
                        SaveSystem.CurrentSave.Codepoints += (ulong)args["amount"];
                        Desktop.InvokeOnWorkerThread(new Action(() =>
                        {
                            Infobox.Show($"MUD Control Centre", $"Someone bought an item in your shop, and they have paid {args["amount"]}, and as such, you have been granted these Codepoints.");
                        }));
                        SaveSystem.SaveGame();
                    }
                }
                else if (msg.Name == "broadcast")
                {
                    Console.WriteLine(msg.Contents);
                }
                else if (msg.Name == "forward")
                {
                    MessageReceived?.Invoke(JsonConvert.DeserializeObject <ServerMessage>(msg.Contents));
                }
                else if (msg.Name == "Error")
                {
                    var ex = JsonConvert.DeserializeObject <Exception>(msg.Contents);
                    TerminalBackend.PrefixEnabled = true;
                    ConsoleEx.ForegroundColor     = ConsoleColor.Red;
                    ConsoleEx.Bold = true;
                    Console.Write($@"{{MUD_ERROR}}: ");
                    ConsoleEx.Bold            = false;
                    ConsoleEx.Italic          = true;
                    ConsoleEx.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine(ex.Message);
                    TerminalBackend.PrefixEnabled = true;
                    TerminalBackend.PrintPrompt();
                }
                else
                {
                    MessageReceived?.Invoke(msg);
                }
            };

            try
            {
                client.Connect(mud_address, port);
            }
            catch (SocketException ex)
            {
                System.Diagnostics.Debug.Print(ex.ToString());
                Initiate(mud_address, port);
            }
        }