Continued business system

This commit is contained in:
hydrant
2018-11-18 22:21:02 +01:00
parent 52d8a74498
commit 53b9acab8b
8 changed files with 89 additions and 15 deletions

View File

@@ -0,0 +1,41 @@
using GTANetworkAPI;
using reallife_gamemode.Server.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace reallife_gamemode.Server.Managers
{
class BusinessManager : Script
{
private static List<BusinessBase> businesses;
public static void LoadBusinesses()
{
businesses = new List<BusinessBase>();
IEnumerable<Type> allTypes = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(BusinessBase)));
foreach (Type item in allTypes)
{
NAPI.Util.ConsoleOutput($"Loading Business {item.Name}");
if (Activator.CreateInstance(item) is BusinessBase o)
{
if (businesses.Find(b => b.GetType() == item) != null)
{
throw new InvalidOperationException($"Double Business found: {o.Id} | {o.Name}");
}
businesses.Add(o);
o.Load();
}
}
}
public static T GetBusiness<T>() where T : BusinessBase
{
return (T)businesses.Find(b => b.GetType() == typeof(T));
}
}
}