public EmoteManagerResult RemoveAll(IEnumerable <String> emotes, EmoteCategory category, String channel) { using var context = ContextFactory.GetContext(); IQueryable <String> databaseEmotes = context .Emotes .Where(x => x.TwitchDisplayName == channel && x.Category == category) .Select(x => x.Name); List <String> succeeded = new(); List <String> failed = new(); foreach (String emote in emotes) { if (context.Emotes.TryGetFirst(x => x.Name == emote && x.Category == category, out Emote found)) { context.Emotes.Remove(found); succeeded.Add(emote); } else { failed.Add(emote); } } if (succeeded.Any()) { context.SaveChanges(); TryGetAndCacheDatabaseEmoteList(channel, category, context); } return(new EmoteManagerResult(succeeded, failed)); }
public static Dictionary <EmoteSetField, string> ParseFieldDictionary(EmoteCategory category, Dictionary <string, string> dict) { var fieldDict = new Dictionary <EmoteSetField, string>(); foreach (var kvp in dict) { var key = kvp.Key; var val = kvp.Value; if (key.Equals(string.Empty)) { ParseOptionalFields(category, val, fieldDict); continue; } var field = GetField(key); if (field == null) { Console.WriteLine($"EmoteSet_Line.ParseFieldDictionary: unknown emote set field \"{key}\""); continue; } fieldDict.Add(field.Value, val); } return(fieldDict); }
public static void ParseOptionalFields(EmoteCategory category, string fields, Dictionary <EmoteSetField, string> fieldDict) { DefaultFields.TryGetValue(category, out var defaultFields); if (defaultFields == null) { Console.WriteLine($"EmoteSet_Line.ParseOptionalFields({category}): couldn't find default field for {category}"); return; } // custom parsers var tokens = new List <string>() { fields }; if (defaultFields.Count > 1) { tokens = GetSubTokens(fields); if (tokens.Count > defaultFields.Count) { Console.WriteLine($"Warning: EmoteSet_LineParseOptionalFields({category}): {fields} contains more than default # of fields"); } } for (var i = 0; i < tokens.Count && i < defaultFields.Count; i++) { var token = tokens[i]; var defaultField = defaultFields[i]; switch (defaultField) { case EmoteSetField.WeenieClassId: var wcid = Parser.TryParseWeenieClassId(token); if (wcid != null) { fieldDict.Add(EmoteSetField.WeenieClassId, wcid.ToString()); } break; case EmoteSetField.VendorType: var vendorType = Parser.TryParseVendorType(token); if (vendorType != null) { fieldDict.Add(EmoteSetField.VendorType, ((int)vendorType).ToString()); } break; default: fieldDict.Add(defaultField, token); break; } } }
public void ShouldReturnNothingOnEmptyCachedEmotes( String channelName, EmoteCategory category) { var result = Sut.TryGetCachedEmoteList(channelName, category)(); Assert.False(result.HasValue); }
public EmoteSet(EmoteCategory category, Emote parent = null) { Category = category; if (parent != null) { AddLink(parent); } }
public static EmoteSet BuildEmoteSet(EmoteCategory category, Dictionary <string, string> dict) { var emoteSet = new EmoteSet(category); var kvps = ParseFieldDictionary(category, dict); foreach (var kvp in kvps) { if (!FieldTypes.ContainsKey(kvp.Key)) { Console.WriteLine($"EmoteSet_Line.BuldEmote({kvp.Key}) - skipping"); continue; } var val = kvp.Value; switch (kvp.Key) { case EmoteSetField.Probability: emoteSet.Probability = Parser.TryParsePercent(val, out _); break; case EmoteSetField.WeenieClassId: emoteSet.WeenieClassId = Parser.TryParseUInt(val); break; case EmoteSetField.Style: emoteSet.Style = Parser.TryParseMotionStance(val); break; case EmoteSetField.Substyle: emoteSet.Substyle = Parser.TryParseMotionCommand(val); break; case EmoteSetField.Quest: emoteSet.Quest = val; break; case EmoteSetField.VendorType: emoteSet.VendorType = Parser.TryParseVendorType(val); break; case EmoteSetField.MinHealth: emoteSet.MinHealth = Parser.TryParsePercent(val, out _); break; case EmoteSetField.MaxHealth: emoteSet.MaxHealth = Parser.TryParsePercent(val, out _); break; } } return(emoteSet); }
/// <summary> /// checks the EmoteType attributes of the requested property to determine whether or not /// it should be shown /// </summary> public static bool IsPropertyVisible(string propertyName, EmoteCategory category) { var property = typeof(EmoteSet).GetProperty(propertyName); var attribs = property.GetCustomAttributes(typeof(EmoteCategoryAttribute), false).Cast <EmoteCategoryAttribute>().ToList(); if (attribs == null || attribs.Count < 1) { return(true); } // because the lists are long and could get unwieldy, we'll allow for multiple on the same property return(attribs.Any(a => a.CategoryList.Contains(category))); }
public IReadOnlyList <String> Get(String channel, EmoteCategory category) { return(TryGetCachedEmoteList(channel, category) .Match( Just: cachedEmoteList => cachedEmoteList, Nothing: () => TryGetAndCacheDatabaseEmoteList(channel, category) .Match( Just: databaseEmoteList => databaseEmoteList, Nothing: () => DefaultEmotes[category]) .Invoke()) .Invoke()); }
public void InqCategory(EmoteCategory categoryId, Emote emote) { var category = WorldObject.Biota.GetEmotes((uint)categoryId); if (category == null) { return; } foreach (var entry in category) { if (!emote.Message.Equals(entry.Quest)) { continue; } //ExecuteSet(entry, target); break; } }
public void InqCategory(EmoteCategory categoryId, BiotaPropertiesEmoteAction emoteAction, WorldObject sourceObject, WorldObject targetObject, ActionChain actionChain, bool useRNG = false) { var rng = useRNG ? Physics.Common.Random.RollDice(0.0f, 1.0f) : 0.0f; var result = sourceObject.Biota.BiotaPropertiesEmote.FirstOrDefault(e => e.Category == (uint)categoryId && e.Quest == emoteAction.Message && rng <= e.Probability); if (result == null) { return; } foreach (var action in result.BiotaPropertiesEmoteAction) { actionChain.AddAction(sourceObject, () => { ExecuteEmote(result, action, actionChain, sourceObject, targetObject); }); } }
public void ShouldReturnEmoteList( String channelName, EmoteCategory category) { ConcurrentDictionary <EmoteCategory, List <String> > categoryList = new(); String name = Guid.NewGuid().ToString(); List <String> emoteList = new(); emoteList.Add(name); categoryList[category] = emoteList; Sut.CachedEmotes.TryAdd(channelName, categoryList); var result = Sut.TryGetCachedEmoteList(channelName, category)(); Assert.True(result.HasValue); Assert.Equal(emoteList, result.Value); }
public EmoteSet_Line(EmoteCategory category, Dictionary <string, string> dict) { EmoteSet = BuildEmoteSet(category, dict); }
public EmoteCategoryAttribute(EmoteCategory emoteCategory) { CategoryList.Add(emoteCategory); }
public Option <IReadOnlyList <String> > TryGetAndCacheDatabaseEmoteList(String channelName, EmoteCategory category, IApplicationContext context = default) { if (context is null) { context = ContextFactory.GetContext(); } var categoryList = CachedEmotes.GetOrAdd(channelName, _ => new ConcurrentDictionary <EmoteCategory, List <String> >()); IQueryable <String> emotes = context .Emotes .Where(x => x.TwitchDisplayName == channelName && x.Category == category) .Select(x => x.Name); categoryList.Remove(category, out _); if (emotes.Any()) { var databaseEmoteList = emotes.ToList().AsReadOnly(); var categoryEmotes = categoryList.GetOrAdd(category, _ => new List <String>()); foreach (var emote in databaseEmoteList) { categoryEmotes.Add(emote); } return(() => databaseEmoteList); } return(Option.Nothing <IReadOnlyList <String> >()); }
public Option <IReadOnlyList <String> > TryGetCachedEmoteList(String channelName, EmoteCategory category) { if (CachedEmotes.TryGetValue(channelName, out var categoryList)) { if (categoryList.TryGetValue(category, out List <String> emoteList)) { return(() => emoteList.AsReadOnly()); } } return(Option.Nothing <IReadOnlyList <String> >()); }
public IEnumerable <BiotaPropertiesEmote> Emotes(EmoteCategory emoteCategory) { return(WorldObject.Biota.BiotaPropertiesEmote.Where(x => x.Category == (int)emoteCategory)); }
public static string GetName(this EmoteCategory prop) { var description = EnumHelper.GetAttributeOfType <DisplayAttribute>(prop); return(description?.Name ?? prop.ToString() ?? ""); }