From 081b59d749a11737b6465aacf2288d5be365cbfa Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 6 Mar 2017 20:05:24 -0500 Subject: [PATCH] Modular stories --- ShiftOS.Objects/Save.cs | 1 + ShiftOS_TheReturn/Story.cs | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/ShiftOS.Objects/Save.cs b/ShiftOS.Objects/Save.cs index 35bfdc2..d5faa78 100644 --- a/ShiftOS.Objects/Save.cs +++ b/ShiftOS.Objects/Save.cs @@ -68,6 +68,7 @@ namespace ShiftOS.Objects } public int LastMonthPaid { get; set; } + public List StoriesExperienced { get; set; } public int CountUpgrades() { diff --git a/ShiftOS_TheReturn/Story.cs b/ShiftOS_TheReturn/Story.cs index 9d8078e..ecd04f4 100644 --- a/ShiftOS_TheReturn/Story.cs +++ b/ShiftOS_TheReturn/Story.cs @@ -37,6 +37,48 @@ namespace ShiftOS.Engine { public class Story { + public static void Start(string stid) + { + foreach (var exec in System.IO.Directory.GetFiles(Environment.CurrentDirectory)) + { + if(exec.EndsWith(".exe") || exec.EndsWith(".dll")) + { + try + { + if (SaveSystem.CurrentSave.StoriesExperienced == null) + SaveSystem.CurrentSave.StoriesExperienced = new List(); + var asm = Assembly.LoadFile(exec); + foreach(var type in asm.GetTypes()) + { + foreach(var mth in type.GetMethods(BindingFlags.Public | BindingFlags.Static)) + { + foreach(var attrib in mth.GetCustomAttributes(false)) + { + if(attrib is StoryAttribute) + { + var story = attrib as StoryAttribute; + if(story.StoryID == stid) + { + mth.Invoke(null, null); + SaveSystem.CurrentSave.StoriesExperienced.Add(stid); + return; + } + } + } + } + } + } + catch { } + } + } +#if DEBUG + throw new ArgumentException("Story ID not found: " + stid + " - Talk to Michael. NOW."); +#else + Debug.Print("No such story: " + stid); +#endif + } + + public static void RunFromInternalResource(string resource_id) { var t = typeof(Properties.Resources); @@ -262,4 +304,25 @@ namespace ShiftOS.Engine thread.Start(); } } + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] + public class StoryAttribute : Attribute + { + /// + /// Creates a new instance of the attribute. + /// + /// The ID of this story plot. + /// + /// + /// The is used to turn a static, public method into a story element. Using the specified argument, the ShiftOS Engine can determine whether this plot has already been experienced, and using the classes, the ID is treated as a special Shiftorium upgrade, and you can use the attribute as well as the various other ways of determining whether a Shiftorium upgrade is installed to determine if this plot has been experienced. + /// + /// + public StoryAttribute(string id) + { + StoryID = id; + } + + public string StoryID { get; private set; } + + } }