Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Reflection;
- using LSPD_First_Response.Mod.API;
- using LSPD_First_Response.Mod.Callouts;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Rage;
- namespace ForceACallout.Utils
- {
- internal static class RandomCallouts
- {
- internal static List<string> RandomCalloutCache = new List<string>();
- internal static int[] CalloutProbabilityRegistrationCount =
- {
- 95, 80, 70, 50, 30, 15, 0
- };
- static RandomCallouts()
- {
- GameFiber.StartNew(delegate
- {
- GameFiber.WaitWhile(() => !Globals.Application.SettingsLoaded);
- CacheCallouts();
- }, "CalloutCacheLoader");
- }
- internal static void CacheCallouts()
- {
- foreach (Assembly Assem in Functions.GetAllUserPlugins())
- {
- AssemblyName AssemName = Assem.GetName();
- List<Type> AssemCallouts = (from Callout in Assem.GetTypes()
- where Callout.IsClass && Callout.BaseType == typeof(LSPD_First_Response.Mod.Callouts.Callout)
- select Callout).ToList();
- if (AssemCallouts.Count() < 1)
- {
- Logger.Log(Assem.GetName().Name + " No callouts detected.");
- }
- else
- {
- int AddCount = 0;
- foreach (Type Callout in AssemCallouts)
- {
- object[] CalloutAttributes = Callout.GetCustomAttributes(typeof(CalloutInfoAttribute), true);
- if (CalloutAttributes.Count() > 0)
- {
- CalloutInfoAttribute CalloutAttribute = (CalloutInfoAttribute)(from a in CalloutAttributes select a).FirstOrDefault();
- if (CalloutAttribute != null)
- {
- if (Globals.Config.CalloutProbability == false)
- RandomCalloutCache.Add(CalloutAttribute.Name);
- else
- {
- for (int LoopCount = 0; LoopCount < CalloutProbabilityRegistrationCount[(int)CalloutAttribute.CalloutProbability] * Globals.Config.CalloutProbabilityModifier; LoopCount++)
- {
- RandomCalloutCache.Add(CalloutAttribute.Name);
- }
- }
- AddCount++;
- }
- }
- }
- Logger.Log(Assem.GetName().Name + $" detected {AddCount} callouts and added them to the ForceACallout cache.");
- }
- }
- if (Globals.Config.CalloutProbability == true)
- {
- Logger.Log($"{RandomCalloutCache.Count} total probabilities registered in ForceACallout.");
- }
- }
- internal static string StartRandomCallout()
- {
- Logger.DebugLog("StartRandomCallout() Started");
- Random RandomValue = new Random();
- try
- {
- string RandomCallout = RandomCalloutCache[RandomValue.Next(0, RandomCalloutCache.Count)];
- Functions.StartCallout(RandomCallout);
- Logger.Log($"Starting callout {RandomCallout}");
- return RandomCallout;
- }
- catch
- {
- Logger.Log("Could not start callout!");
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement