/// <summary> /// Render USSD menu and redirect to appropriate user's choice. /// </summary> /// <param name="ussdMenu"></param> /// <returns></returns> public async Task <UssdResponse> RenderMenu(UssdMenu ussdMenu) { var json = JsonConvert.SerializeObject(ussdMenu); await DataBag.Set(MenuProcessorDataKey, json); return(Render(ussdMenu.Render(), "MenuProcessor")); }
/// <summary> /// Render a form (series of inputs). /// </summary> /// <param name="form"></param> /// <returns></returns> public async Task <UssdResponse> RenderForm(UssdForm form) { var json = JsonConvert.SerializeObject(form); await DataBag.Set(FormProcessorDataKey, json); return(Redirect("FormInputDisplay")); }
public void Test_SingleEntranceTimer_OnlyOneRunningInstance() { int parallism = 3; DataBag db = new DataBag(); Action action = db.RunUntilCancelled; SingleEntranceTimer timer = new SingleEntranceTimer(action, TimeSpan.FromMilliseconds(2)); Assert.IsFalse(timer.Started); List <Task> tasks = Enumerable.Range(0, parallism).Select(i => timer.ForceFire()).ToList(); SpinWait spinWait = new SpinWait(); while (timer.NumFired < parallism || db.NumRun == 0) { spinWait.SpinOnce(); } db.Cancelled = true; Task.WhenAll(tasks).Wait(); Assert.AreEqual(1, db.NumRun); Assert.AreEqual(1, timer.NumExecuted); Assert.AreEqual(parallism, timer.NumFired); timer.Dispose(); }
public static string SpellAreaTriggersData() { var spellareatriggers = Storage.Objects.IsEmpty() ? new Dictionary <WowGuid, SpellAreaTrigger>() // empty dict if there are no objects : Storage.Objects.Where( obj => obj.Value.Item1.Type == ObjectType.AreaTrigger && !obj.Value.Item1.IsTemporarySpawn()) // remove temporary spawns .OrderBy(pair => pair.Value.Item2) // order by spawn time .ToDictionary(obj => obj.Key, obj => obj.Value.Item1 as SpellAreaTrigger); if (spellareatriggers.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.spell_areatrigger)) { return(string.Empty); } var spellareatriggersData = new DataBag <SpellAreaTrigger>(); foreach (var spellareatrigger in spellareatriggers) { spellareatriggersData.Add(spellareatrigger.Value); } var templateDb = SQLDatabase.Get(spellareatriggersData); return(SQLUtil.Compare(Settings.SQLOrderByKey ? spellareatriggersData.OrderBy(x => x.Item1.AreaTriggerId).ToArray() : spellareatriggersData.ToArray(), templateDb, x => "SpellId : " + x.spellId.ToString())); }
public async Task <ProgrammableServiceResponse> MenuProcessor() { var json = await DataBag.Get(MenuProcessorDataKey); var menu = JsonConvert.DeserializeObject <Menu>(json); MenuItem item; try { var choice = Convert.ToInt16(Request.TrimmedMessage); if (choice == 0 && menu.ZeroItem != null) { return(Redirect(menu.ZeroItem.Action, menu.ZeroItem.Controller)); } item = menu.Items[choice - 1]; } catch (Exception ex) { return(Render(string.Format("Menu choice {0} does not exist.", Request.TrimmedMessage), null, null)); } await DataBag.Delete(MenuProcessorDataKey); return(Redirect(item.Action, item.Controller)); }
public async Task <ProgrammableServiceResponse> Start() { _logger.LogDebug("Initial request: {request}", Request); try { if (Request.IsUssd()) { var header = "Buy my awesome product"; var item1 = "Buy for myself"; var item2 = "Buy for a different number"; var menu = Menu.New(header) .AddItem(item1, $"{nameof(EnterAmountForm)}") .AddItem(item2, $"{nameof(RecipientForm)}"); await DataBag.Set("mobileNumber", Request.Mobile); // setup rich ux for web and mobile return(await RenderMenu(menu, new List <ProgrammableServicesResponseData> { new ProgrammableServicesResponseData(item1, "1", decimal.Zero), new ProgrammableServicesResponseData(item2, "2", decimal.Zero), }, null, header, ProgrammableServiceDataTypes.Menu)); } return(Redirect($"{nameof(RecipientForm)}")); } catch (Exception e) { _logger.LogError(e, e.Message); return(await Error()); } }
public static string ConversationTemplateData() { var conversations = Storage.Objects.IsEmpty() ? new Dictionary <WowGuid, ConversationTemplate>() // empty dict if there are no objects : Storage.Objects.Where( obj => obj.Value.Item1.Type == ObjectType.Conversation) .OrderBy(pair => pair.Value.Item2) // order by spawn time .ToDictionary(obj => obj.Key, obj => obj.Value.Item1 as ConversationTemplate); if (conversations.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.conversation_template)) { return(string.Empty); } var conversationsData = new DataBag <ConversationTemplate>(); foreach (var conversation in conversations) { conversationsData.Add(conversation.Value); } var templateDb = SQLDatabase.Get(conversationsData); return(SQLUtil.Compare(Settings.SQLOrderByKey ? conversationsData.OrderBy(x => x.Item1.Id).ToArray() : conversationsData.ToArray(), templateDb, x => string.Empty)); }
/// <summary> /// Render USSD menu and redirect to appropriate user's choice. /// </summary> /// <param name="ussdMenu"></param> /// <returns></returns> public async Task <ProgrammableServiceResponse> RenderMenu(Menu ussdMenu, List <ProgrammableServicesResponseData> dataItems = null, ProgrammableServicesResponseCartData cartItem = null, string label = null, string dataType = null, bool persistAsFavoriteStep = false) { var json = JsonConvert.SerializeObject(ussdMenu); await DataBag.Set(MenuProcessorDataKey, json); return(Render(ussdMenu.Render(), dataItems, cartItem, label, dataType, "", "", persistAsFavoriteStep, nameof(MenuProcessor))); }
/// <summary> /// Render a form (series of inputs). /// </summary> /// <param name="form"></param> /// <returns></returns> public async Task <ProgrammableServiceResponse> RenderForm(Form form, List <ProgrammableServicesResponseData> dataItems = null, ProgrammableServicesResponseCartData cartItem = null, string label = null, string dataType = null, string fieldType = "text", string fieldName = "", bool persistAsFavoriteStep = false) { var json = JsonConvert.SerializeObject(form); await DataBag.Set(FormProcessorDataKey, json); //return Redirect("FormInputDisplay"); return(await RichFormInputDisplay(dataItems, cartItem, label, dataType, fieldType, fieldName, persistAsFavoriteStep)); }
internal async Task <Form> GetForm() { var json = await DataBag.Get(FormProcessorDataKey); var form = JsonConvert.DeserializeObject <Form>(json); return(form); }
public static RowList <T> Get <T>(DataBag <T> conditionList, string database = null) where T : IDataModel, new() { var cond = new RowList <T>(); cond.AddRange(conditionList.Select(c => c.Item1)); return(Get(cond, database)); }
public async Task <ProgrammableServiceResponse> Confirmation() { try { var mobileNumber = await DataBag.Get("mobileNumber"); var amountStr = FormData["amount"]; // you may want to validate amount if (!decimal.TryParse(amountStr, out var amount)) { return(await RenderResponse("Amount is not valid")); } if (amount <= decimal.Zero) { return(await RenderResponse($"Amount is not valid")); } if (amount < 1) { return(await RenderResponse($"Sorry, minimum amount is GHS 1.00")); } if (amount > 100) { return(await RenderResponse($"Sorry, maximum amount is GHS 100.00")); } await DataBag.Set("amount", amount.ToString()); var header = $"Confirmation\nService: MTN Airtime for {mobileNumber}\nAmount: {amount}"; var menu = Menu.New(header) .AddItem("Confirm", $"{nameof(ProcessAddToCart)}") .AddZeroItem("Cancel", $"{nameof(Exit)}"); var dataItems = new List <ProgrammableServicesResponseData> { new ProgrammableServicesResponseData("Confirm", "1") , new ProgrammableServicesResponseData("Cancel", "0") }; if (Request.IsUssd()) { return(await RenderMenu(menu, dataItems, null, header, ProgrammableServiceDataTypes.Confirm)); } return(await ProcessAddToCart()); } catch (Exception e) { _logger.LogError(e, e.Message); return(await Error()); } }
public void Test_SingleEntranceTimer_AutoStart() { DataBag db = new DataBag(); Action action = db.RunIfNotCancelled; SingleEntranceTimer timer = new SingleEntranceTimer(action, TimeSpan.FromMilliseconds(2), autoStart: true); Assert.IsTrue(timer.Started); timer.Dispose(); }
public void ReferencePassingTest() { var data = new DataBag(); ThreadingHelpers.ExecuteOnThread( () => data.X++, 10); Assert.Equal(10, data.X); }
public async Task OpenFilePickerSrcAsync() { try { FileData fileData = await CrossFilePicker.Current.PickFile(); if (fileData == null) { return; // user canceled file picking } MemoryStream ms = new MemoryStream(fileData.DataArray); StreamReader reader = new StreamReader(ms, System.Text.Encoding.ASCII); string line; byte[] mem = new byte[80]; int index = 0; while (true) { line = reader.ReadLine(); if (line == null) { break; } try { int j = 0; while ((2 * j < line.Length) && (line[2 * j] != ' ') && (line[2 * j] != '\t') && (index < 80)) { mem[index++] = byte.Parse(line.Substring(2 * j++, 2), NumberStyles.HexNumber); } } catch { Console.WriteLine("Error: unknown line format: {0}", line); } } nPause = PauseDuration.GetSliderTicks(256 * mem[48] + mem[49]); SetControlsVisibility(mem[41]); DataBag.SetData(mem); MessagingCenter.Send(this, "DataChanged", DataBag.GetData()); } catch (Exception ex) { Console.WriteLine("Exception choosing file: " + ex.ToString()); }; return; }
public void RoastProfileSelChanged() { // if changed manually in picker (this function is also called, if we programmatically change RoastProfileSel)m // we want to remove formerly selected special (id >= 100) entry, so it connot be choosen manually in the picker again if (RoastProfileSel.isManualChoiceAllowed || // manually template choosen or (RoastProfileSel.Id != lastSelectedRoastProfile.Id)) // programmatically other special entry choosen { if ((lastSelectedRoastProfile?.Id > 100) || (lastSelectedRoastProfile?.Id == 0)) { RoastProfiles.Remove(lastSelectedRoastProfile); OnPropertyChanged(nameof(RoastProfiles)); } } if (!string.IsNullOrEmpty(RoastProfileSel.Data)) { // if (manually) template choosen -> load template byte[] mem = new byte[80]; int index = 16; string line = RoastProfileSel.Data; if (string.IsNullOrEmpty(line)) { return; } try { int j = 0; while ((j < line.Length) && (index < 80)) { if ((line[j] == ' ') || (line[j] == '\t')) { j++; continue; } mem[index++] = byte.Parse(line.Substring(j, 2), NumberStyles.HexNumber); j += 2; } } catch { Console.WriteLine("Error: unknown line format: {0}", line); } nPause = PauseDuration.GetSliderTicks(256 * mem[48] + mem[49]); SetControlsVisibility(mem[41], false); DataBag.SetData(mem); MessagingCenter.Send(this, "DataChanged", DataBag.GetData()); } lastSelectedRoastProfile = RoastProfileSel; }
internal BagProperties ToBag(DataBag dtBag) { var bagProperties = new BagProperties(null , dtBag.Name, dtBag.Description , new Vector3D(dtBag.Dimensions[0], dtBag.Dimensions[1], dtBag.Dimensions[2]) , dtBag.RoundingRadius); bagProperties.SetWeight(dtBag.Weight); bagProperties.SetNetWeight(new OptDouble(dtBag.NetWeight > 0, dtBag.NetWeight)); return(bagProperties); }
public static string PointsOfInterest() { if (Storage.GossipPOIs.IsEmpty()) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.points_of_interest)) { return(string.Empty); } string result = string.Empty; if (!Storage.GossipSelects.IsEmpty()) { var gossipPOIsTable = new Dictionary <Tuple <uint, uint>, uint>(); foreach (var poi in Storage.GossipPOIs) { foreach (var gossipSelect in Storage.GossipSelects) { var tuple = Tuple.Create(gossipSelect.Key.Item1, gossipSelect.Key.Item2); if (gossipPOIsTable.ContainsKey(tuple)) { continue; } var timeSpan = poi.Item2 - gossipSelect.Value.Item2; if (timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1)) { gossipPOIsTable.Add(tuple, poi.Item1.ID.GetValueOrDefault()); } } } var menuOptions = new DataBag <GossipMenuOption>(); foreach (var u in gossipPOIsTable) { menuOptions.Add(new GossipMenuOption { ID = u.Key.Item2, MenuID = u.Key.Item1, ActionPoiID = u.Value }); } result += SQLUtil.Compare(menuOptions, SQLDatabase.Get(menuOptions), StoreNameType.None); } result += SQLUtil.Compare(Storage.GossipPOIs, SQLDatabase.Get(Storage.GossipPOIs), StoreNameType.None); return(result); }
public static string GameObjectTemplateAddon(Dictionary<WowGuid, GameObject> gameobjects) { if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.gameobject_template_addon)) return string.Empty; if (gameobjects.Count == 0) return string.Empty; var addons = new DataBag<GameObjectTemplateAddon>(); foreach (var obj in gameobjects) { var goT = Storage.GameObjectTemplates.FirstOrDefault(p => p.Item1.Entry == obj.Key.GetEntry()); if (goT == null) continue; var go = obj.Value; if (Settings.AreaFilters.Length > 0) if (!(go.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(go.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; var addon = new GameObjectTemplateAddon { Entry = obj.Key.GetEntry() }; HashSet<uint> playerFactions = new HashSet<uint> { 1, 2, 3, 4, 5, 6, 115, 116, 1610, 1629, 2203, 2204 }; addon.Faction = go.Faction.GetValueOrDefault(0); if (playerFactions.Contains(go.Faction.GetValueOrDefault())) addon.Faction = 0; addon.Flags = go.Flags.GetValueOrDefault(GameObjectFlag.None); addon.Flags &= ~GameObjectFlag.Triggered; addon.Flags &= ~GameObjectFlag.Damaged; addon.Flags &= ~GameObjectFlag.Destroyed; if (addons.ContainsKey(addon)) continue; if (addon.Flags == GameObjectFlag.None && addon.Faction == 0) continue; addons.Add(addon); } var addonsDb = SQLDatabase.Get(addons); return SQLUtil.Compare(addons, addonsDb, StoreNameType.GameObject); }
/// <summary> /// Get Form's response data. /// </summary> /// <returns></returns> internal async Task <Dictionary <string, string> > GetFormData() { var json = await DataBag.Get(FormDataKey); try { var data = JsonConvert.DeserializeObject <Dictionary <string, string> >(json); return(data); } catch (Exception ex) { return(new Dictionary <string, string>()); } }
public static string CreatureEquip(Dictionary<WowGuid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template)) return string.Empty; var equips = new DataBag<CreatureEquipment>(); foreach (KeyValuePair<WowGuid, Unit> npc in units) { if (Settings.AreaFilters.Length > 0) if (!(npc.Value.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(npc.Value.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; if (npc.Value.Equipment == null || npc.Value.Equipment.Length != 3) continue; if (npc.Value.Equipment[0] == 0 && npc.Value.Equipment[1] == 0 && npc.Value.Equipment[2] == 0) continue; CreatureEquipment equip = new CreatureEquipment { CreatureID = npc.Key.GetEntry(), ItemID1 = npc.Value.Equipment[0], ItemID2 = npc.Value.Equipment[1], ItemID3 = npc.Value.Equipment[2] }; if (equips.Contains(equip)) continue; for (uint i = 1;; i++) { equip.ID = i; if (!equips.ContainsKey(equip)) break; } equips.Add(equip); } var equipsDb = SQLDatabase.Get(equips); return SQLUtil.Compare(equips, equipsDb, StoreNameType.Unit); }
/// <summary> /// Must be used only for USSD. /// </summary> /// <param name="collection">Must be valid and not null. Dictionary's key should be the display text.</param> /// <param name="paginationOptions"></param> /// <returns></returns> public async Task <ProgrammableServiceResponse> PaginateForUssd(Dictionary <string, string> collection, PaginationOptions paginationOptions) { if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (paginationOptions == null) { throw new ArgumentNullException(nameof(paginationOptions)); } if (string.IsNullOrEmpty(paginationOptions.NextPageKey)) { throw new ArgumentNullException(nameof(paginationOptions.NextPageKey)); } if (string.IsNullOrEmpty(paginationOptions.PreviousPageKey)) { throw new ArgumentNullException(nameof(paginationOptions.PreviousPageKey)); } if (paginationOptions.PreviousPageKey.Equals(paginationOptions.NextPageKey)) { throw new Exception($"{nameof(paginationOptions.NextPageKey)} should not be the same as {nameof(paginationOptions.PreviousPageKey)}"); } if (FormData == null) { FormData = new Dictionary <string, string>(); } if (!Request.IsUssd()) { throw new InvalidOperationException("this method is meant for USSD context only :|"); } await DataBag.Set(PaginationOptionsKey, JsonConvert.SerializeObject(paginationOptions)); await DataBag.Set(PaginationCollectionKey, JsonConvert.SerializeObject(collection)); await DataBag.Set(OnPaginationItemSelectedName, OnPaginationItemSelectedValue); var form = (await PaginateCollection(collection, paginationOptions))[0]; form.Data = FormData; return(await RenderForm(form)); }
public async Task <ProgrammableServiceResponse> ProcessAddToCart() { try { var mobileNumber = await DataBag.Get("mobileNumber"); var accountId = await DataBag.Get("mobileNumber"); var rawAmount = await DataBag.Get("amount"); var rawQuantity = "1"; var country = "GH"; decimal amount = decimal.Parse(rawAmount); int quantity = int.Parse(rawQuantity); //save your data into Storage so that when you get callback from Hubtel, you can //compare and render service var cartItem = new ProgrammableServicesResponseCartData($"MTN Airtime Topup for {mobileNumber}", quantity, amount, Guid.NewGuid().ToString("N")) { ServiceData = { ["destination"] = mobileNumber, ["amount"] = $"{2m}" } }; cartItem.ServiceData["destination"] = mobileNumber; cartItem.ServiceData["amount"] = rawAmount; var checkoutMsg = $"Please authorize payment for GHs {amount} as MTN Airtime Topup to {mobileNumber}"; //any of these methods can work for redirecting a user to another controller //return Redirect(nameof(TestController.Index), nameof(TestController)); // return Redirect("Index", nameof(TestController)); //return Redirect("Index", "Test"); // return Redirect("Index", nameof(TestController)); return(AddToCart(checkoutMsg, cartItem)); } catch (Exception e) { _logger.LogError(e, e.Message); return(await Error()); } }
public static string AreaTriggerCreatePropertiesData() { var spellareatriggers = Storage.Objects.IsEmpty() ? new Dictionary <WowGuid, AreaTriggerCreateProperties>() // empty dict if there are no objects : Storage.Objects.Where( obj => obj.Value.Item1.Type == ObjectType.AreaTrigger && !obj.Value.Item1.IsTemporarySpawn()) // remove temporary spawns .OrderBy(pair => pair.Value.Item2) // order by spawn time .ToDictionary(obj => obj.Key, obj => obj.Value.Item1 as AreaTriggerCreateProperties); if (spellareatriggers.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.areatrigger_create_properties)) { return(string.Empty); } var spellareatriggersData = new DataBag <AreaTriggerCreateProperties>(); foreach (var spellareatrigger in spellareatriggers) { spellareatriggersData.Add(spellareatrigger.Value); } var templateDb = SQLDatabase.Get(spellareatriggersData); return(SQLUtil.Compare(Settings.SQLOrderByKey ? spellareatriggersData.OrderBy(x => x.Item1.AreaTriggerId).ToArray() : spellareatriggersData.ToArray(), templateDb, x => { var comment = "SpellId : " + x.spellId.ToString(); if ((x.AreaTriggerCreatePropertiesId & 0x80000000) != 0) { comment += " CANNOT FIND PROPERTIES ID, USED SPELL ID AS KEY (NEEDS MANUAL CORRECTION)"; } return comment; })); }
public async Task <UssdResponse> FormInputProcessor() { var form = await GetForm(); var input = form.Inputs[form.ProcessingPosition]; var key = input.Name; string value = null; if (!input.HasOptions) { value = Request.TrimmedMessage; } else { try { var choice = Convert.ToInt16(Request.TrimmedMessage); value = input.Options[choice - 1].Value; } catch (Exception exception) { return(Render(string.Format("Option {0} does not exist.", Request.TrimmedMessage))); } } form.Data.Add(key, value); if (form.ProcessingPosition == (form.Inputs.Count - 1)) { await DataBag.Delete(FormProcessorDataKey); var jsonData = JsonConvert.SerializeObject(form.Data); await DataBag.Set(FormDataKey, jsonData); return(Redirect(form.Action, form.Controller)); } ++form.ProcessingPosition; var json = JsonConvert.SerializeObject(form); await DataBag.Set(FormProcessorDataKey, json); return(Redirect("FormInputDisplay")); }
public void Test_SingleEntranceTimer_MaxRunTimeLimitation() { int parallism = 10; int runLimit = 3; DataBag db = new DataBag(); Action action = db.RunIfNotCancelled; SingleEntranceTimer timer = new SingleEntranceTimer(action, TimeSpan.FromMilliseconds(2), maxExecutionLimit: runLimit); Assert.IsFalse(timer.Started); for (int i = 0; i < parallism; i++) { timer.ForceFire().Wait(); } db.Cancelled = true; Assert.AreEqual(runLimit, db.NumRun); Assert.AreEqual(runLimit, timer.NumExecuted); Assert.AreEqual(parallism, timer.NumFired); timer.Dispose(); }
public async Task <ProgrammableServiceResponse> ProcessRecipientForm() { try { var mobileNumber = FormData["mobileNumber"]; if (string.IsNullOrEmpty(mobileNumber)) // check if the input phone number is invalid { return(Redirect($"{nameof(RecipientForm)}")); } await DataBag.Set("mobileNumber", mobileNumber); return(Redirect($"{nameof(EnterAmountForm)}")); } catch (Exception e) { _logger.LogError(e, e.Message); return(await Error()); } }
public static string PointsOfInterest() { if (Storage.GossipPOIs.IsEmpty()) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.points_of_interest)) return string.Empty; var result = string.Empty; if (!Storage.GossipSelects.IsEmpty()) { var gossipPOIsTable = new Dictionary<Tuple<uint, uint>, uint>(); foreach (var poi in Storage.GossipPOIs) { foreach (var gossipSelect in Storage.GossipSelects) { var tuple = Tuple.Create(gossipSelect.Key.Item1, gossipSelect.Key.Item2); if (gossipPOIsTable.ContainsKey(tuple)) continue; var timeSpan = poi.Item2 - gossipSelect.Value.Item2; if (timeSpan != null && timeSpan.Value.Duration() <= TimeSpan.FromSeconds(1)) gossipPOIsTable.Add(tuple, poi.Item1.ID.GetValueOrDefault()); } } var menuOptions = new DataBag<GossipMenuOption>(); foreach (var u in gossipPOIsTable) menuOptions.Add(new GossipMenuOption {ID = u.Key.Item2, MenuID = u.Key.Item1, ActionPoiID = u.Value}); result += SQLUtil.Compare(menuOptions, SQLDatabase.Get(menuOptions), StoreNameType.None); } result += SQLUtil.Compare(Storage.GossipPOIs, SQLDatabase.Get(Storage.GossipPOIs), StoreNameType.None); return result; }
public static string ModelData(Dictionary<WowGuid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info)) return string.Empty; var models = new DataBag<ModelData>(); foreach (var npc in units.Select(unit => unit.Value)) { if (Settings.AreaFilters.Length > 0) if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; uint modelId; if (npc.Model.HasValue) modelId = npc.Model.Value; else continue; var model = new ModelData { DisplayID = modelId }; if (models.ContainsKey(model)) continue; var scale = npc.Size.GetValueOrDefault(1.0f); model.BoundingRadius = npc.BoundingRadius.GetValueOrDefault(0.306f) / scale; model.CombatReach = npc.CombatReach.GetValueOrDefault(1.5f) / scale; model.Gender = npc.Gender.GetValueOrDefault(Gender.Male); models.Add(model); } var modelsDb = SQLDatabase.Get(models); return SQLUtil.Compare(models, modelsDb, StoreNameType.None); }
public static string CreatureTemplateAddon(Dictionary<WowGuid, Unit> units) { if (units.Count == 0) return string.Empty; if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template_addon)) return string.Empty; var addons = new DataBag<CreatureTemplateAddon>(); foreach (var unit in units) { var npc = unit.Value; if (Settings.AreaFilters.Length > 0) if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) continue; if (Settings.MapFilters.Length > 0) if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) continue; var auras = string.Empty; var commentAuras = string.Empty; if (npc.Auras != null && npc.Auras.Count != 0) { foreach (var aura in npc.Auras.Where(aura => aura != null && (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster)))) { auras += aura.SpellId + " "; commentAuras += StoreGetters.GetName(StoreNameType.Spell, (int) aura.SpellId, false) + ", "; } auras = auras.TrimEnd(' '); commentAuras = commentAuras.TrimEnd(',', ' '); } var addon = new CreatureTemplateAddon { Entry = unit.Key.GetEntry(), MountID = npc.Mount.GetValueOrDefault(), Bytes1 = npc.Bytes1.GetValueOrDefault(), Bytes2 = npc.Bytes2.GetValueOrDefault(), Auras = auras, CommentAuras = commentAuras }; if (addons.ContainsKey(addon)) continue; addons.Add(addon); } var addonsDb = SQLDatabase.Get(addons); return SQLUtil.Compare(addons, addonsDb, addon => { var comment = StoreGetters.GetName(StoreNameType.Unit, (int)addon.Entry.GetValueOrDefault()); if (!string.IsNullOrEmpty(addon.CommentAuras)) comment += " - " + addon.CommentAuras; return comment; }); }
public static string CreatureTemplateAddon(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template_addon)) { return(string.Empty); } var addons = new DataBag <CreatureTemplateAddon>(); foreach (var unit in units) { Unit npc = unit.Value; if (Settings.AreaFilters.Length > 0) { if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) { continue; } } if (Settings.MapFilters.Length > 0) { if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) { continue; } } string auras = string.Empty; string commentAuras = string.Empty; if (npc.Auras != null && npc.Auras.Count != 0) { foreach (Aura aura in npc.Auras) { if (aura == null) { continue; } // usually "template auras" do not have caster if (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? !aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : !aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster)) { continue; } auras += aura.SpellId + " "; commentAuras += StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", "; } auras = auras.TrimEnd(' '); commentAuras = commentAuras.TrimEnd(',', ' '); } CreatureTemplateAddon addon = new CreatureTemplateAddon { Entry = unit.Key.GetEntry(), MountID = npc.Mount.GetValueOrDefault(), Bytes1 = npc.Bytes1.GetValueOrDefault(), Bytes2 = npc.Bytes2.GetValueOrDefault(), Auras = auras, CommentAuras = commentAuras }; if (addons.ContainsKey(addon)) { continue; } addons.Add(addon); } var addonsDb = SQLDatabase.Get(addons); return(SQLUtil.Compare(addons, addonsDb, addon => { string comment = StoreGetters.GetName(StoreNameType.Unit, (int)addon.Entry.GetValueOrDefault()); if (!string.IsNullOrEmpty(addon.CommentAuras)) { comment += " - " + addon.CommentAuras; } return comment; })); }
public static string CreatureEquip(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template)) { return(string.Empty); } var equips = new DataBag <CreatureEquipment>(); foreach (var npc in units) { if (Settings.AreaFilters.Length > 0) { if (!(npc.Value.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) { continue; } } if (Settings.MapFilters.Length > 0) { if (!(npc.Value.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) { continue; } } var equipment = npc.Value.UnitData.VirtualItems; if (equipment.Length != 3) { continue; } if (equipment[0].ItemID == 0 && equipment[1].ItemID == 0 && equipment[2].ItemID == 0) { continue; } var equip = new CreatureEquipment { CreatureID = npc.Key.GetEntry(), ItemID1 = (uint)equipment[0].ItemID, ItemID2 = (uint)equipment[1].ItemID, ItemID3 = (uint)equipment[2].ItemID, AppearanceModID1 = equipment[0].ItemAppearanceModID, AppearanceModID2 = equipment[1].ItemAppearanceModID, AppearanceModID3 = equipment[2].ItemAppearanceModID, ItemVisual1 = equipment[0].ItemVisual, ItemVisual2 = equipment[1].ItemVisual, ItemVisual3 = equipment[2].ItemVisual }; if (equips.Contains(equip)) { continue; } for (uint i = 1;; i++) { equip.ID = i; if (!equips.ContainsKey(equip)) { break; } } equips.Add(equip); } var equipsDb = SQLDatabase.Get(equips); return(SQLUtil.Compare(equips, equipsDb, StoreNameType.Unit)); }
public static string ModelData(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_model_info)) { return(string.Empty); } var models = new DataBag <ModelData>(); foreach (var npc in units.Select(unit => unit.Value)) { if (Settings.AreaFilters.Length > 0) { if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) { continue; } } if (Settings.MapFilters.Length > 0) { if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) { continue; } } uint modelId = (uint)npc.UnitData.DisplayID; if (modelId == 0) { continue; } var model = new ModelData { DisplayID = modelId }; //if (models.ContainsKey(model)) if (models.Any(modelInfo => modelInfo.Item1.DisplayID == modelId)) { continue; } var scale = npc.ObjectData.Scale; model.BoundingRadius = npc.UnitData.BoundingRadius / scale; model.CombatReach = npc.UnitData.CombatReach / scale; model.Gender = (Gender)npc.UnitData.Sex; models.Add(model); } var modelsDb = SQLDatabase.Get(models); return(SQLUtil.Compare(models, modelsDb, StoreNameType.None)); }
public static string CreatureTemplateAddon(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_template_addon)) { return(string.Empty); } CreatureTemplateAddon templateAddonDefault = null; if (Settings.DBEnabled && Settings.SkipRowsWithFallbackValues) { templateAddonDefault = SQLUtil.GetDefaultObject <CreatureTemplateAddon>(); } var dbFields = SQLUtil.GetDBFields <CreatureTemplateAddon>(false); var addons = new DataBag <CreatureTemplateAddon>(); foreach (var unit in units) { var npc = unit.Value; if (Settings.AreaFilters.Length > 0) { if (!(npc.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) { continue; } } if (Settings.MapFilters.Length > 0) { if (!(npc.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) { continue; } } var auras = string.Empty; var commentAuras = string.Empty; if (npc.Auras != null && npc.Auras.Count != 0) { foreach (var aura in npc.Auras.Where(aura => aura != null && (ClientVersion.AddedInVersion(ClientType.MistsOfPandaria) ? aura.AuraFlags.HasAnyFlag(AuraFlagMoP.NoCaster) : aura.AuraFlags.HasAnyFlag(AuraFlag.NotCaster)))) { auras += aura.SpellId + " "; commentAuras += StoreGetters.GetName(StoreNameType.Spell, (int)aura.SpellId, false) + ", "; } auras = auras.TrimEnd(' '); commentAuras = commentAuras.TrimEnd(',', ' '); } var addon = new CreatureTemplateAddon { Entry = unit.Key.GetEntry(), PathID = 0, MountID = (uint)npc.UnitData.MountDisplayID, Bytes1 = npc.Bytes1, Bytes2 = npc.Bytes2, Emote = 0, AIAnimKit = npc.AIAnimKit.GetValueOrDefault(0), MovementAnimKit = npc.MovementAnimKit.GetValueOrDefault(0), MeleeAnimKit = npc.MeleeAnimKit.GetValueOrDefault(0), Auras = auras, CommentAuras = commentAuras }; if (templateAddonDefault != null && SQLUtil.AreDBFieldsEqual(addon, templateAddonDefault, dbFields)) { continue; } if (addons.ContainsKey(addon)) { continue; } addons.Add(addon); } var addonsDb = SQLDatabase.Get(addons); return(SQLUtil.Compare(addons, addonsDb, addon => { var comment = StoreGetters.GetName(StoreNameType.Unit, (int)addon.Entry.GetValueOrDefault()); if (!string.IsNullOrEmpty(addon.CommentAuras)) { comment += " - " + addon.CommentAuras; } return comment; })); }
public static string CreatureEquip(Dictionary <WowGuid, Unit> units) { if (units.Count == 0) { return(string.Empty); } if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_equip_template)) { return(string.Empty); } var equips = new DataBag <CreatureEquipment>(); foreach (KeyValuePair <WowGuid, Unit> npc in units) { if (Settings.AreaFilters.Length > 0) { if (!(npc.Value.Area.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.AreaFilters))) { continue; } } if (Settings.MapFilters.Length > 0) { if (!(npc.Value.Map.ToString(CultureInfo.InvariantCulture).MatchesFilters(Settings.MapFilters))) { continue; } } if (npc.Value.Equipment == null || npc.Value.Equipment.Length != 3) { continue; } if (npc.Value.Equipment[0] == 0 && npc.Value.Equipment[1] == 0 && npc.Value.Equipment[2] == 0) { continue; } CreatureEquipment equip = new CreatureEquipment { CreatureID = npc.Key.GetEntry(), ItemID1 = npc.Value.Equipment[0], ItemID2 = npc.Value.Equipment[1], ItemID3 = npc.Value.Equipment[2] }; if (equips.Contains(equip)) { continue; } for (uint i = 1;; i++) { equip.ID = i; if (!equips.ContainsKey(equip)) { break; } } equips.Add(equip); } var equipsDb = SQLDatabase.Get(equips); return(SQLUtil.Compare(equips, equipsDb, StoreNameType.Unit)); }