diff options
| author | Michael <[email protected]> | 2017-06-03 09:16:44 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-06-03 09:16:44 -0400 |
| commit | cc55af0c8b4d14053bfb46ec14c3e1887d375f7d (patch) | |
| tree | 37231db5ce31a1e18b49ccb4d027f64393830820 /ShiftOS_TheReturn | |
| parent | 719f2e4170e0a42ca372ff142e5b9613177db1be (diff) | |
| download | shiftos_thereturn-cc55af0c8b4d14053bfb46ec14c3e1887d375f7d.tar.gz shiftos_thereturn-cc55af0c8b4d14053bfb46ec14c3e1887d375f7d.tar.bz2 shiftos_thereturn-cc55af0c8b4d14053bfb46ec14c3e1887d375f7d.zip | |
story objectives system
Diffstat (limited to 'ShiftOS_TheReturn')
| -rw-r--r-- | ShiftOS_TheReturn/Commands.cs | 15 | ||||
| -rw-r--r-- | ShiftOS_TheReturn/Story.cs | 104 |
2 files changed, 115 insertions, 4 deletions
diff --git a/ShiftOS_TheReturn/Commands.cs b/ShiftOS_TheReturn/Commands.cs index e379a50..72bccb1 100644 --- a/ShiftOS_TheReturn/Commands.cs +++ b/ShiftOS_TheReturn/Commands.cs @@ -533,11 +533,20 @@ namespace ShiftOS.Engine Codepoints: {SaveSystem.CurrentSave.Codepoints} Upgrades: {SaveSystem.CurrentSave.CountUpgrades()} installed, - {Shiftorium.GetAvailable().Length} available"; + {Shiftorium.GetAvailable().Length} available + +"; - if (Shiftorium.UpgradeInstalled("mud_control_centre")) - status += Environment.NewLine + $"Reputation: {SaveSystem.CurrentSave.RawReputation} ({SaveSystem.CurrentSave.Reputation})"; Console.WriteLine(status); + + if(Story.CurrentObjective != null) + { + Console.WriteLine("CURRENT OBJECTIVE: " + Story.CurrentObjective.Name); + Console.WriteLine("-------------------------------"); + Console.WriteLine(); + Console.WriteLine(Story.CurrentObjective.Description); + } + return true; } } diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs index d62dae4..848c757 100644 --- a/ShiftOS_TheReturn/Story.cs +++ b/ShiftOS_TheReturn/Story.cs @@ -35,11 +35,100 @@ using Newtonsoft.Json; namespace ShiftOS.Engine { + public class StoryContext + { + public string Id { get; set; } + public MethodInfo Method { get; set; } + public bool AutoComplete = false; + + public StoryContext() + { + AutoComplete = true; + } + + public void MarkComplete() + { + SaveSystem.CurrentSave.StoriesExperienced.Add(Id); + OnComplete?.Invoke(); + } + + public event Action OnComplete; + } + + public class Objective + { + private Func<bool> _completeFunc = null; + + public string Name { get; set; } + public string Description { get; set; } + + public bool IsComplete + { + get + { + return (bool)_completeFunc?.Invoke(); + } + } + + public Objective(string name, string desc, Func<bool> completeFunc, Action onComplete) + { + _completeFunc = completeFunc; + Name = name; + Description = desc; + this.onComplete = onComplete; + } + + private Action onComplete = null; + + public void Complete() + { + onComplete?.Invoke(); + } + } + /// <summary> /// Storyline management class. /// </summary> public static class Story { + public static StoryContext Context { get; private set; } + public static event Action<string> StoryComplete; + public static Objective CurrentObjective { get; private set; } + + public static void PushObjective(string name, string desc, Func<bool> completeFunc, Action onComplete) + { + if (CurrentObjective != null) + { + if (CurrentObjective.IsComplete == false) + { + throw new Exception("Cannot start objective - an objective is already running."); + } + else + { + CurrentObjective = null; + } + } + + CurrentObjective = new Objective(name, desc, completeFunc, onComplete); + + var t = new Thread(() => + { + var obj = CurrentObjective; + while (!obj.IsComplete) + { + Thread.Sleep(5000); + } + obj.Complete(); + CurrentObjective = null; + }); + t.IsBackground = true; + t.Start(); + + Console.WriteLine("NEW OBJECTIVE:"); + Console.WriteLine("A new objective has been added to your system. Run sos.status to find out what you need to do."); + } + + /// <summary> /// Starts the storyline with the specified Storyline ID. /// </summary> @@ -68,8 +157,21 @@ namespace ShiftOS.Engine { new Thread(() => { + Context = new Engine.StoryContext + { + Id = stid, + Method = mth, + AutoComplete = true, + }; + Context.OnComplete += () => + { + StoryComplete?.Invoke(stid); + }; mth.Invoke(null, null); - SaveSystem.CurrentSave.StoriesExperienced.Add(stid); + if (Context.AutoComplete) + { + Context.MarkComplete(); + } }).Start(); return; } |
