Modular stories

This commit is contained in:
Michael 2017-03-06 20:05:24 -05:00
parent 4e52b93912
commit 081b59d749
2 changed files with 64 additions and 0 deletions

View file

@ -68,6 +68,7 @@ namespace ShiftOS.Objects
}
public int LastMonthPaid { get; set; }
public List<string> StoriesExperienced { get; set; }
public int CountUpgrades()
{

View file

@ -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<string>();
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
{
/// <summary>
/// Creates a new instance of the <see cref="StoryAttribute"/> attribute.
/// </summary>
/// <param name="id">The ID of this story plot.</param>
/// <remarks>
/// <para>
/// The <see cref="StoryAttribute"/> is used to turn a static, public method into a story element. Using the specified <paramref name="id"/> argument, the ShiftOS Engine can determine whether this plot has already been experienced, and using the <see cref="Shiftorium"/> classes, the ID is treated as a special Shiftorium upgrade, and you can use the <see cref="RequiresUpgradeAttribute"/> attribute as well as the various other ways of determining whether a Shiftorium upgrade is installed to determine if this plot has been experienced.
/// </para>
/// </remarks>
public StoryAttribute(string id)
{
StoryID = id;
}
public string StoryID { get; private set; }
}
}