aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS_TheReturn/Story.cs
diff options
context:
space:
mode:
authorwilliam341 <[email protected]>2017-06-18 16:43:30 -0700
committerGitHub <[email protected]>2017-06-18 16:43:30 -0700
commitba80dcf3f80018cbb041b62ad8a40268427d1311 (patch)
treef0bd18b2355d34c07c744c3cd82a4725a799eecd /ShiftOS_TheReturn/Story.cs
parent771c20cfb3a703e0f1550fdcf9eb07b78298c944 (diff)
parent12acff8742f4c64976bfabee1b70dc515190fc7c (diff)
downloadshiftos_thereturn-ba80dcf3f80018cbb041b62ad8a40268427d1311.tar.gz
shiftos_thereturn-ba80dcf3f80018cbb041b62ad8a40268427d1311.tar.bz2
shiftos_thereturn-ba80dcf3f80018cbb041b62ad8a40268427d1311.zip
Merge pull request #2 from shiftos-game/master
wew
Diffstat (limited to 'ShiftOS_TheReturn/Story.cs')
-rw-r--r--ShiftOS_TheReturn/Story.cs139
1 files changed, 115 insertions, 24 deletions
diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs
index d62dae4..2b00686 100644
--- a/ShiftOS_TheReturn/Story.cs
+++ b/ShiftOS_TheReturn/Story.cs
@@ -35,51 +35,142 @@ 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 List<Objective> CurrentObjectives { get; private set; }
+
+ 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. Run sos.status to find out what you need to do.");
+ TerminalBackend.PrintPrompt();
+ }
+
+
/// <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)
{
- foreach (var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory))
+ if (SaveSystem.CurrentSave.StoriesExperienced == null)
+ SaveSystem.CurrentSave.StoriesExperienced = new List<string>();
+ foreach (var type in ReflectMan.Types)
{
- if(exec.EndsWith(".exe") || exec.EndsWith(".dll"))
+ foreach (var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
{
- try
+ foreach (var attrib in Array.FindAll(mth.GetCustomAttributes(false), a => a is StoryAttribute))
{
- if (SaveSystem.CurrentSave.StoriesExperienced == null)
- SaveSystem.CurrentSave.StoriesExperienced = new List<string>();
- var asm = Assembly.LoadFile(exec);
- foreach(var type in asm.GetTypes())
+ var story = attrib as StoryAttribute;
+ if (story.StoryID == stid)
{
- foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static))
+ new Thread(() =>
{
- foreach(var attrib in mth.GetCustomAttributes(false))
+ Context = new Engine.StoryContext
+ {
+ Id = stid,
+ Method = mth,
+ AutoComplete = true,
+ };
+ SaveSystem.CurrentSave.PickupPoint = Context.Id;
+ Context.OnComplete += () =>
{
- if(attrib is StoryAttribute)
- {
- var story = attrib as StoryAttribute;
- if(story.StoryID == stid)
- {
- new Thread(() =>
- {
- mth.Invoke(null, null);
- SaveSystem.CurrentSave.StoriesExperienced.Add(stid);
- }).Start();
- return;
- }
- }
+ StoryComplete?.Invoke(stid);
+ SaveSystem.CurrentSave.PickupPoint = null;
+ };
+ mth.Invoke(null, null);
+ if (Context.AutoComplete)
+ {
+ Context.MarkComplete();
}
- }
+ }).Start();
+ return;
}
}
- catch (Exception ex) { throw ex; }
}
+
}
#if DEBUG
throw new ArgumentException("Story ID not found: " + stid + " - Talk to Michael. NOW.");