mirror of
https://git.alee14.me/shiftos-archive/ShiftOS_TheReturn.git
synced 2025-01-22 18:02:16 +00:00
Modular stories
This commit is contained in:
parent
4e52b93912
commit
081b59d749
2 changed files with 64 additions and 0 deletions
|
@ -68,6 +68,7 @@ namespace ShiftOS.Objects
|
|||
}
|
||||
|
||||
public int LastMonthPaid { get; set; }
|
||||
public List<string> StoriesExperienced { get; set; }
|
||||
|
||||
public int CountUpgrades()
|
||||
{
|
||||
|
|
|
@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue