Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Windows.Media;
- using CommonBehaviors.Actions;
- using Styx;
- using Styx.Common;
- using Styx.CommonBot.Coroutines;
- using Styx.WoWInternals;
- namespace NuokRealmHop
- {
- public class LfgList
- {
- private static IEnumerable<int> GetAvailableCategorieIds
- {
- get
- {
- using (new PerformanceLogger(NuokRealmHopSettings.Instance.DebugPerformace, "GetAvailableCategorieIds"))
- {
- using (StyxWoW.Memory.AcquireFrame())
- {
- const string getIdsLua = @"local categories = C_LFGList.GetAvailableCategories();
- local results = {}
- for i = 1, #categories do
- local id = categories[i]
- if (id ~= nil) then
- table.insert(results, id)
- end
- end
- return unpack(results)";
- var l = new List<int>();
- var getResultIds = Lua.GetReturnValues(getIdsLua);
- l.AddRange(getResultIds.Select(Lua.ParseLuaValue<int>));
- return l;
- }
- }
- }
- }
- public static List<CategoryInfo> GetAvailableCategories
- {
- get
- {
- using (new PerformanceLogger(NuokRealmHopSettings.Instance.DebugPerformace, "GetAvailableCategories"))
- {
- using (StyxWoW.Memory.AcquireFrame())
- {
- var x = GetAvailableCategorieIds.Select(GetCategoryInfo).ToList();
- return x;
- }
- }
- }
- }
- /// <summary>
- /// Retrieve the search information for the last search only
- /// </summary>
- public static List<SearchResultInfo> GetSearchResults
- {
- get
- {
- using (new PerformanceLogger(NuokRealmHopSettings.Instance.DebugPerformace, "GetSearchResults"))
- {
- const string getIdsLua = @"local numResults, resultIDTable = C_LFGList.GetSearchResults();
- local results = {}
- for i = 1, numResults do
- local id = resultIDTable[i]
- if (id ~= nil) then
- table.insert(results, id)
- end
- end
- return unpack(results)";
- var l = new List<int>();
- using (StyxWoW.Memory.AcquireFrame())
- {
- var getResultIds = Lua.GetReturnValues(getIdsLua);
- l.AddRange(getResultIds.Select(Lua.ParseLuaValue<int>));
- }
- return (from i in l where i != 0 select GetSearchResultInfo(i)).ToList();
- }
- }
- }
- public static int NumActiveAppliications => Lua.GetReturnVal<int>("return C_LFGList.GetNumApplications()", 1);
- /// <summary>
- /// Gets all the currently applied for groups
- /// </summary>
- public static List<ApplicationInfo> GetApplicationInfos
- {
- get
- {
- using (new PerformanceLogger(NuokRealmHopSettings.Instance.DebugPerformace, "GetApplicationInfos"))
- {
- var l = new List<ApplicationInfo>();
- using (StyxWoW.Memory.AcquireFrame())
- {
- var apps = GetApplicationIds;
- l.AddRange(apps.Select(GetApplicationInfo));
- }
- return l;
- }
- }
- }
- /// <summary>
- /// Gets the players current realm name
- /// </summary>
- public static string GetRealmName
- {
- get
- {
- using (new PerformanceLogger(NuokRealmHopSettings.Instance.DebugPerformace, "GetRealmName"))
- {
- var realm = "nil";
- using (StyxWoW.Memory.AcquireFrame())
- {
- string lua;
- var gi = StyxWoW.Me.GroupInfo;
- var meLeader = gi.GroupLeader == StyxWoW.Me;
- if (gi.IsInParty && !meLeader)
- lua =
- @"local index = GetNumGroupMembers();
- for i = 1, index do
- if UnitIsGroupLeader('party' ..i) then
- local name, realm = UnitName('party' ..i);
- return realm;
- end
- end";
- else if (gi.IsInRaid && !meLeader)
- lua = @"local index = GetNumGroupMembers();
- for i = 1, index do
- if UnitIsGroupLeader('raid' ..i) then
- local name, realm = UnitName('raid' ..i);
- return realm;
- end
- end";
- else lua = "return GetRealmName();";
- realm = Lua.GetReturnVal<string>(lua, 0);
- }
- return realm;
- }
- }
- }
- private static IEnumerable<int> GetApplicationIds
- {
- get
- {
- var l = new List<int>();
- const string lua = @"local apps = C_LFGList.GetApplications();
- local results = {}
- for i = 1, #apps do
- local id = apps[i]
- if (id ~= nil) then
- table.insert(results, id)
- end
- end
- return unpack(results)";
- var getResultIds = Lua.GetReturnValues(lua);
- l.AddRange(getResultIds.Select(Lua.ParseLuaValue<int>));
- return l;
- }
- }
- /// <summary>
- /// Opens the LFG Frame in game
- /// </summary>
- public static void LFGLiftFrame_Show()
- {
- Lua.DoString("PVEFrame_ShowFrame('GroupFinderFrame', LFGListPVEStub)");
- new SleepForLagDuration().ExecuteCoroutine();
- }
- private static void Log(string format, params object[] args)
- {
- Logging.WriteDiagnostic(Colors.Goldenrod, "LFGList: " + format, args);
- }
- /// <summary>
- /// Applies to join the group
- /// </summary>
- /// <param name="id">Group Id</param>
- public static void ApplyToGroup(int id)
- {
- Lua.DoString($"C_LFGList.ApplyToGroup({id}, '', false, false, true);");
- }
- /// <summary>
- /// Applies to join the group
- /// </summary>
- /// <param name="application"></param>
- public static void ApplyToGroup(SearchResultInfo application)
- {
- Log($"Applying to Group {application} on {application.Realm}");
- ApplyToGroup(application.Id);
- }
- /// <summary>
- /// Accepts group invite pop ups
- /// </summary>
- public static void AcceptPopUps()
- {
- Lua.DoString("LFGListInviteDialog.AcceptButton:Click(); LFGListInviteDialog.AcknowledgeButton:Click();");
- }
- private static CategoryInfo GetCategoryInfo(int categoryId)
- {
- var a = Lua.GetReturnValues($"return C_LFGList.GetCategoryInfo({categoryId});");
- var name = Lua.ParseLuaValue<string>(a[0]);
- var seperate = Lua.ParseLuaValue<bool>(a[1]);
- var auto = Lua.ParseLuaValue<bool>(a[2]);
- var prefer = Lua.ParseLuaValue<bool>(a[3]);
- return new CategoryInfo
- {
- CategoryId = categoryId,
- Name = name,
- SeparateRecommended = seperate,
- AutoChoose = auto,
- PreferCurrentArea = prefer
- };
- }
- /// <summary>
- /// Initializes a search for groups within the category
- /// </summary>
- /// <param name="categorieId">Category Id</param>
- public static void Search(int categorieId)
- {
- Lua.DoString(
- $"local languages = C_LFGList.GetLanguageSearchFilter(); C_LFGList.Search({categorieId}, '', 0, 0, languages)");
- }
- /// <summary>
- /// Initializes a search for groups within the category
- /// </summary>
- /// <param name="category">CategoryInfo</param>
- public static void Search(CategoryInfo category)
- {
- Log($"Starting a search of {category}");
- Search(category.CategoryId);
- }
- /// <summary>
- /// Starts the search for groups
- /// </summary>
- /// <param name="category">The category you wish to search</param>
- public static void Search(LFGCategory category)
- {
- Log($"Starting a search of {category}");
- Search((int) category);
- }
- private static ApplicationInfo GetApplicationInfo(int applicationId)
- {
- var info = Lua.GetReturnValues($"return C_LFGList.GetApplicationInfo({applicationId});");
- return new ApplicationInfo
- {
- Id = Lua.ParseLuaValue<int>(info[0]),
- Status = GetApplicationState(Lua.ParseLuaValue<string>(info[1])),
- PendingStatus = Lua.ParseLuaValue<bool>(info[2]),
- ApplicationDuration = TimeSpan.FromMinutes(Lua.ParseLuaValue<double>(info[3])),
- AccpetedRole = Lua.ParseLuaValue<string>(info[4])
- };
- }
- private static SearchResultInfo GetSearchResultInfo(int resultId)
- {
- var r = Lua.GetReturnValues($"return C_LFGList.GetSearchResultInfo({resultId});");
- //retrieve the realm & player name to see if they check out
- var s = Lua.ParseLuaValue<string>(r[11]);
- if (s == null)
- return new SearchResultInfo
- {
- Id = resultId,
- ActivityId = Lua.ParseLuaValue<int>(r[1]),
- Name = Lua.ParseLuaValue<string>(r[2]),
- Comment = Lua.ParseLuaValue<string>(r[3]),
- VoiceChat = Lua.ParseLuaValue<bool>(r[4]),
- iLevel = Lua.ParseLuaValue<int>(r[5]),
- Age = TimeSpan.FromSeconds(Lua.ParseLuaValue<int>(r[6])),
- NumBNetFriends = Lua.ParseLuaValue<int>(r[7]),
- NumCharFriends = Lua.ParseLuaValue<int>(r[8]),
- NumGuildMates = Lua.ParseLuaValue<int>(r[9]),
- IsDelisted = Lua.ParseLuaValue<bool>(r[10]),
- PlayerCount = Lua.ParseLuaValue<int>(r[12]),
- AutoInvite = Lua.ParseLuaValue<bool>(r[13]),
- Realm = "null",
- LeaderName = "null"
- };
- char[] sep = {'-'};
- var wowSplit = s.Split(sep, 2);
- var l = wowSplit.Length < 1 ? "null" : wowSplit[0];
- var ra = wowSplit.Length < 2 ? "null" : wowSplit[1];
- return new SearchResultInfo
- {
- Id = resultId,
- ActivityId = Lua.ParseLuaValue<int>(r[1]),
- Name = Lua.ParseLuaValue<string>(r[2]),
- Comment = Lua.ParseLuaValue<string>(r[3]),
- VoiceChat = Lua.ParseLuaValue<bool>(r[4]),
- iLevel = Lua.ParseLuaValue<int>(r[5]),
- Age = TimeSpan.FromSeconds(Lua.ParseLuaValue<int>(r[6])),
- NumBNetFriends = Lua.ParseLuaValue<int>(r[7]),
- NumCharFriends = Lua.ParseLuaValue<int>(r[8]),
- NumGuildMates = Lua.ParseLuaValue<int>(r[9]),
- IsDelisted = Lua.ParseLuaValue<bool>(r[10]),
- PlayerCount = Lua.ParseLuaValue<int>(r[12]),
- AutoInvite = Lua.ParseLuaValue<bool>(r[13]),
- LeaderName = l,
- Realm = ra
- };
- }
- public static bool LeaveGroup()
- {
- Log("Leaving Current Group");
- Lua.DoString("LeaveParty();");
- var s = new SleepForLagDuration();
- s.ExecuteCoroutine();
- return StyxWoW.Me.GroupInfo.IsInParty || StyxWoW.Me.GroupInfo.IsInRaid;
- }
- private static ApplicationState GetApplicationState(string application)
- {
- switch (application)
- {
- case "invited":
- return ApplicationState.Invited;
- case "failed":
- return ApplicationState.Failed;
- case "cancelled":
- return ApplicationState.Cancelled;
- case "applied":
- return ApplicationState.Applied;
- }
- Log($"{application} not listed as a state");
- return ApplicationState.Failed;
- }
- }
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- public enum LFGCategory
- {
- Questing = 1,
- Dungeons = 2,
- Raids = 3,
- Arenas = 4,
- Scenarios = 5,
- Custom = 6,
- Skirmishes = 7,
- Battlegrounds = 8,
- RatedBGs = 9,
- Ashran = 10
- }
- [Flags]
- public enum ApplicationState
- {
- Invited,
- Failed,
- Cancelled,
- Applied
- }
- public class CategoryInfo
- {
- public bool AutoChoose;
- public int CategoryId;
- public string Name;
- public bool PreferCurrentArea;
- public bool SeparateRecommended;
- public LFGCategory Category => (LFGCategory) CategoryId;
- public override string ToString()
- {
- return $"{Name}";
- }
- }
- public class ApplicationInfo
- {
- public string AccpetedRole;
- public TimeSpan ApplicationDuration;
- public int Id;
- public bool PendingStatus;
- public ApplicationState Status;
- public override string ToString()
- {
- return $"ApplicationId {Id}";
- }
- }
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- public class SearchResultInfo
- {
- public int ActivityId;
- public TimeSpan Age;
- public bool AutoInvite;
- public string Comment;
- public int Id;
- public int iLevel;
- public bool IsDelisted;
- public string LeaderName;
- public string Name;
- public int NumBNetFriends;
- public int NumCharFriends;
- public int NumGuildMates;
- public int PlayerCount;
- public string Realm;
- public bool VoiceChat;
- public void ApplyToGroup()
- {
- LfgList.ApplyToGroup(this);
- }
- public override string ToString()
- {
- return $"{Name} ({Id})";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement