/// <summary> /// Returns a list of recipes from selected skill /// </summary> /// <param name="skillLine"></param> /// <returns></returns> public static TradeSkill GetTradeSkill(SkillLine skillLine) { if (!ObjectManager.IsInGame) { throw new InvalidOperationException("Must Be in game to call GetTradeSkill()"); } if (skillLine == 0 || !SupportedSkills.Contains(skillLine)) { throw new InvalidOperationException(String.Format("The tradekill {0} can not be loaded", skillLine)); } // if HB is not running then we need to pulse objectmanger for item counts if (!TreeRoot.IsRunning) { ObjectManager.Update(); } //Stopwatch sw = new Stopwatch(); TradeSkill tradeSkill = null; try { //using (new FrameLock()) //{ WoWSkill wowSkill = ObjectManager.Me.GetSkill(skillLine); // sw.Start(); tradeSkill = new TradeSkill(wowSkill); List <SkillLineAbilityEntry> entries = tradeSkill.GetSkillLineAbilityEntries(); foreach (SkillLineAbilityEntry entry in entries) { // check if the entry is a recipe if (entry.NextSpellId == 0 && entry.GreySkillLevel > 0) { var recipe = new Recipe(tradeSkill, entry); recipe.UpdateHeader(); tradeSkill.AddRecipe(recipe); } //Logging.Write(entry.ToString()); } //} } catch (Exception ex) { Logging.WriteException(ex); } //Logging.Write("it took {0} ms to load {1}", sw.ElapsedMilliseconds, skillLine); return(tradeSkill); }
/// <summary> /// Returns a list of recipes from selected skill /// </summary> /// <param name="skillLine"></param> /// <param name="blockFrame">prevents tradeskill frame from showing</param> /// <returns></returns> public TradeSkill GetTradeSkill(SkillLine skillLine, bool blockFrame) { if (!ObjectManager.IsInGame) { throw new InvalidOperationException("Must Be in game to call GetTradeSkill()"); } if (skillLine == 0 || !SupportedSkills.Contains(skillLine)) { throw new InvalidOperationException(string.Format("The tradekill {0} can not be loaded", skillLine)); } // if HB is not running then we need to pulse objectmanger for item counts if (!TreeRoot.IsRunning) { ObjectManager.Update(); } WoWSkill wowSkill = ObjectManager.Me.GetSkill(skillLine); TradeSkill tradeSkill = new TradeSkill(wowSkill); //lets copy over to a local variable for performance bool _isVisible = IsVisible; bool loadSkill = Skill != skillLine || !_isVisible; string lua = string.Format("{0}{1}{2}{3}", blockFrame && loadSkill ? "if not TradeSkillFrame then LoadAddOn('Blizzard_TradeSkillUI') end local fs = {} local f = EnumerateFrames() while f do if f:IsEventRegistered('TRADE_SKILL_SHOW') == 1 and f:GetName() ~= 'UIParent' then f:UnregisterEvent('TRADE_SKILL_SHOW') table.insert (fs,f) end f = EnumerateFrames(f) end " : "", // have to hard code in mining since I need to cast 'Smelting' not 'Mining' XD // also using lua over SpellManager.Cast since its grabing name from DBC. one word, localization. loadSkill ? (skillLine == SkillLine.Mining ? "CastSpellByID(2656) " : string.Format("CastSpellByName('{0}') ", wowSkill.Name)) : "", // force cache load "for i=1, GetNumTradeSkills() do GetTradeSkillItemLink(i) for n=1,GetTradeSkillNumReagents(i) do GetTradeSkillReagentInfo(i,n) end end ", blockFrame && loadSkill ? "for k,v in pairs(fs) do v:RegisterEvent('TRADE_SKILL_SHOW') end CloseTradeSkill() " : "" ); using (new FrameLock()) { if (!string.IsNullOrEmpty(lua)) { Lua.DoString(lua); } int _recipeCount = RecipeCount; if (Skill != skillLine || _recipeCount <= 0) {// we failed to load tradeskill throw new Exception(string.Format("Unable to load {0}", skillLine)); } // array of pointers that point to each recipe structure. uint[] recipePtrArray = ObjectManager.Wow.ReadStructArray <uint>(RecipeOffset, RecipeCount); for (int index = 0; index < _recipeCount; index++) { uint[] recipeData = ObjectManager.Wow.ReadStructArray <uint>(recipePtrArray[index], 9); uint id = recipeData[(int)Recipe.RecipeIndex.RecipeID]; // check if its a header if (id == uint.MaxValue) { continue; // no further info to get for header } tradeSkill.Recipes.Add(id, new Recipe(recipeData, tradeSkill, skillLine)); } tradeSkill.InitIngredientList(); tradeSkill.InitToolList(); } return(tradeSkill); }
/// <summary> /// Updates the skill level, recipe difficulty and adds new recipes. /// </summary> /// <param name="tradeSkill"></param> public void UpdateTradeSkill(TradeSkill tradeSkill, bool blockFrame) { if (!ObjectManager.IsInGame || tradeSkill == null) { return; } // if HB is not running then we should maybe pulse objectmanger for item counts if (!TreeRoot.IsRunning) { ObjectManager.Update(); } tradeSkill.WoWSkill = ObjectManager.Me.GetSkill(tradeSkill.SkillLine); //lets copy over to a local variable for performance bool _isVisible = IsVisible; bool loadSkill = Skill != tradeSkill.SkillLine || !_isVisible; string lua = string.Format("{0}{1}{2}{3}", blockFrame && loadSkill ? "if not TradeSkillFrame then LoadAddOn('Blizzard_TradeSkillUI') end local fs = {} local f = EnumerateFrames() while f do if f:IsEventRegistered('TRADE_SKILL_SHOW') == 1 then f:UnregisterEvent('TRADE_SKILL_SHOW') table.insert (fs,f) end f = EnumerateFrames(f) end " : "", // have to hard code in mining since I need to cast 'Smelting' not 'Mining' XD // also using lua over SpellManager.Cast since its grabing name from DBC. one word, localization. loadSkill ? (tradeSkill.SkillLine == SkillLine.Mining ? "CastSpellByID(2656) " : string.Format("CastSpellByName('{0}') ", tradeSkill.Name)) : "", "for i=1, GetNumTradeSkills() do GetTradeSkillItemLink(i) for n=1,GetTradeSkillNumReagents(i) do GetTradeSkillReagentInfo(i,n) end end ", blockFrame && loadSkill ? "for k,v in pairs(fs) do v:RegisterEvent('TRADE_SKILL_SHOW') end CloseTradeSkill() " : "" ); // using framelock here to lock memory while I'm reading from it.. since it's changing constantly.. using (new FrameLock()) { if (!string.IsNullOrEmpty(lua)) { Lua.DoString(lua); } if (Skill != tradeSkill.SkillLine) {// we failed to load tradeskill throw new Exception("Fail to update Tradeskill " + tradeSkill.SkillLine.ToString()); } // array of pointers that point to each recipe structure. uint[] recipePtrArray = ObjectManager.Wow.ReadStructArray <uint>(RecipeOffset, RecipeCount); int _recipeCount = RecipeCount; for (int index = 0; index < _recipeCount; index++) { uint[] recipeData = ObjectManager.Wow.ReadStructArray <uint>(recipePtrArray[index], 9); uint id = recipeData[(int)Recipe.RecipeIndex.RecipeID]; // check if its a header if (id == uint.MaxValue) { continue; // no further info to get for header } if (tradeSkill.Recipes.ContainsKey(id)) { tradeSkill.Recipes[id].Update(recipeData); } else { tradeSkill.Recipes.Add(id, new Recipe(recipeData, tradeSkill, tradeSkill.SkillLine)); } } } }
public void LoadTradeSkills() { try { lock (TradeSkillList) { TradeSkillList.Clear(); foreach (WoWSkill skill in SupportedTradeSkills) { Log("Adding TradeSkill {0}", skill.Name); TradeSkill ts = TradeSkillFrame.Instance.GetTradeSkill((SkillLine)skill.Id, true); if (ts != null) { TradeSkillList.Add(ts); } else { IsTradeSkillsLoaded = false; Log("Unable to load tradeskill {0}", (SkillLine)skill.Id); return; } } } IsTradeSkillsLoaded = true; if (OnTradeSkillsLoaded != null) { OnTradeSkillsLoaded(this, null); } } catch (Exception ex) { Logging.Write(System.Drawing.Color.Red, ex.ToString()); } }
public void LoadTradeSkills() { new Timer(state => { try { lock (TradeSkillList) { TradeSkillList.Clear(); //IEnumerable<WoWSkill> skillList = from skill in TradeSkill.SupportedSkills // select Me.GetSkill(skill); //foreach (WoWSkill skill in skillList) //{ // Log("Adding TradeSkill {0}", skill.Name); // TradeSkill ts = TradeSkill.GetTradeSkill((SkillLine)skill.Id); // if (ts != null) // { // TradeSkillList.Add(ts); // } // else // { // IsTradeSkillsLoaded = false; // Log("Unable to load tradeskill {0}", (SkillLine)skill.Id); // return; // } //} foreach (WoWSkill skill in SupportedTradeSkills) { Log("Adding TradeSkill {0}", skill.Name); TradeSkill ts = TradeSkill.GetTradeSkill((SkillLine)skill.Id); if (ts != null) { TradeSkillList.Add(ts); } else { IsTradeSkillsLoaded = false; Log("Unable to load tradeskill {0}", (SkillLine)skill.Id); return; } } } Log("Done Loading Tradeskills."); IsTradeSkillsLoaded = true; if (OnTradeSkillsLoaded != null) { OnTradeSkillsLoaded(this, null); } } catch (Exception ex) { Logging.Write(Color.Red, ex.ToString()); } }, null, 0, Timeout.Infinite); }
internal Recipe(TradeSkill parent, SkillLineAbilityEntry skillLineAbilityEntry) { _parent = parent; SpellId = skillLineAbilityEntry.SpellId; OrangeSkillLevel = skillLineAbilityEntry.OrangeSkillLevel; YellowSkillLevel = skillLineAbilityEntry.YellowSkillLevel; GreenSkillLevel = (skillLineAbilityEntry.YellowSkillLevel + skillLineAbilityEntry.GreySkillLevel) / 2; GreySkillLevel = skillLineAbilityEntry.GreySkillLevel; OptimalSkillups = skillLineAbilityEntry.SkillPointsEarned; Skill = skillLineAbilityEntry.SkillLine; HasRecipe = TradeSkill.HasSpell(SpellId); }
internal Recipe(uint[] data, TradeSkill parent, SkillLine skill) { this.recipeData = data; this.Skill = skill; this.parent = parent; }
/// <summary> /// Returns a list of recipes from selected skill /// </summary> /// <param name="skillLine"></param> /// <returns></returns> public static TradeSkill GetTradeSkill(SkillLine skillLine) { if (!StyxWoW.IsInGame) throw new InvalidOperationException("Must Be in game to call GetTradeSkill()"); if (skillLine == 0 || !SupportedSkills.Contains(skillLine)) throw new InvalidOperationException(String.Format("The tradekill {0} can not be loaded", skillLine)); // if HB is not running then we need to pulse objectmanger for item counts if (!TreeRoot.IsRunning) ObjectManager.Update(); //Stopwatch sw = new Stopwatch(); TradeSkill tradeSkill = null; try { using (StyxWoW.Memory.AcquireFrame()) { WoWSkill wowSkill = StyxWoW.Me.GetSkill(skillLine); // sw.Start(); tradeSkill = new TradeSkill(wowSkill); List<SkillLineAbilityEntry> entries = tradeSkill.GetSkillLineAbilityEntries(); foreach (SkillLineAbilityEntry entry in entries) { // check if the entry is a recipe if (entry.NextSpellId == 0 && entry.GreySkillLevel > 0 && entry.TradeSkillCategoryIndex != 0) { var recipe = new Recipe(tradeSkill, entry); recipe.UpdateHeader(); tradeSkill.AddRecipe(recipe); } //Logging.Write(entry.ToString()); } } } catch (Exception ex) { Logging.WriteException(ex); } //Logging.Write("it took {0} ms to load {1}", sw.ElapsedMilliseconds, skillLine); return tradeSkill; }
public void Update() { HasRecipe = TradeSkill.HasSpell(SpellId); }
/// <summary> /// Updates the skill level, recipe difficulty and adds new recipes. /// </summary> /// <param name="tradeSkill"></param> public void UpdateTradeSkill(TradeSkill tradeSkill, bool blockFrame) { if (!ObjectManager.IsInGame || tradeSkill == null) { return; } // if HB is not running then we should maybe pulse objectmanger for item counts if (!TreeRoot.IsRunning) ObjectManager.Update(); tradeSkill.WoWSkill = ObjectManager.Me.GetSkill(tradeSkill.SkillLine); //lets copy over to a local variable for performance bool _isVisible = IsVisible; bool loadSkill = Skill != tradeSkill.SkillLine || !_isVisible; string lua = string.Format("{0}{1}{2}{3}", blockFrame && loadSkill ? "if not TradeSkillFrame then LoadAddOn('Blizzard_TradeSkillUI') end local fs = {} local f = EnumerateFrames() while f do if f:IsEventRegistered('TRADE_SKILL_SHOW') == 1 then f:UnregisterEvent('TRADE_SKILL_SHOW') table.insert (fs,f) end f = EnumerateFrames(f) end " : "", // have to hard code in mining since I need to cast 'Smelting' not 'Mining' XD // also using lua over SpellManager.Cast since its grabing name from DBC. one word, localization. loadSkill ? (tradeSkill.SkillLine == SkillLine.Mining ? "CastSpellByID(2656) " : string.Format("CastSpellByName('{0}') ", tradeSkill.Name)) : "", "for i=1, GetNumTradeSkills() do GetTradeSkillItemLink(i) for n=1,GetTradeSkillNumReagents(i) do GetTradeSkillReagentInfo(i,n) end end ", blockFrame && loadSkill ? "for k,v in pairs(fs) do v:RegisterEvent('TRADE_SKILL_SHOW') end CloseTradeSkill() " : "" ); // using framelock here to lock memory while I'm reading from it.. since it's changing constantly.. using (new FrameLock()) { if (!string.IsNullOrEmpty(lua)) Lua.DoString(lua); if (Skill != tradeSkill.SkillLine) {// we failed to load tradeskill throw new Exception("Fail to update Tradeskill " + tradeSkill.SkillLine.ToString()); } // array of pointers that point to each recipe structure. uint[] recipePtrArray = ObjectManager.Wow.ReadStructArray<uint>(RecipeOffset, RecipeCount); int _recipeCount = RecipeCount; for (int index = 0; index < _recipeCount; index++) { uint[] recipeData = ObjectManager.Wow.ReadStructArray<uint>(recipePtrArray[index], 9); uint id = recipeData[(int)Recipe.RecipeIndex.RecipeID]; // check if its a header if (id == uint.MaxValue) { continue; // no further info to get for header } if (tradeSkill.Recipes.ContainsKey(id)) { tradeSkill.Recipes[id].Update(recipeData); } else { tradeSkill.Recipes.Add(id, new Recipe(recipeData, tradeSkill, tradeSkill.SkillLine)); } } } }
/// <summary> /// Returns a list of recipes from selected skill /// </summary> /// <param name="skillLine"></param> /// <param name="blockFrame">prevents tradeskill frame from showing</param> /// <returns></returns> public TradeSkill GetTradeSkill(SkillLine skillLine, bool blockFrame) { if (!ObjectManager.IsInGame) throw new InvalidOperationException("Must Be in game to call GetTradeSkill()"); if (skillLine == 0 || !SupportedSkills.Contains(skillLine)) throw new InvalidOperationException(string.Format("The tradekill {0} can not be loaded", skillLine)); // if HB is not running then we need to pulse objectmanger for item counts if (!TreeRoot.IsRunning) ObjectManager.Update(); WoWSkill wowSkill = ObjectManager.Me.GetSkill(skillLine); TradeSkill tradeSkill = new TradeSkill(wowSkill); //lets copy over to a local variable for performance bool _isVisible = IsVisible; bool loadSkill = Skill != skillLine || !_isVisible; string lua = string.Format("{0}{1}{2}{3}", blockFrame && loadSkill ? "if not TradeSkillFrame then LoadAddOn('Blizzard_TradeSkillUI') end local fs = {} local f = EnumerateFrames() while f do if f:IsEventRegistered('TRADE_SKILL_SHOW') == 1 and f:GetName() ~= 'UIParent' then f:UnregisterEvent('TRADE_SKILL_SHOW') table.insert (fs,f) end f = EnumerateFrames(f) end " : "", // have to hard code in mining since I need to cast 'Smelting' not 'Mining' XD // also using lua over SpellManager.Cast since its grabing name from DBC. one word, localization. loadSkill ? (skillLine == SkillLine.Mining ? "CastSpellByID(2656) " : string.Format("CastSpellByName('{0}') ", wowSkill.Name)) : "", // force cache load "for i=1, GetNumTradeSkills() do GetTradeSkillItemLink(i) for n=1,GetTradeSkillNumReagents(i) do GetTradeSkillReagentInfo(i,n) end end ", blockFrame && loadSkill ? "for k,v in pairs(fs) do v:RegisterEvent('TRADE_SKILL_SHOW') end CloseTradeSkill() " : "" ); using (new FrameLock()) { if (!string.IsNullOrEmpty(lua)) Lua.DoString(lua); int _recipeCount = RecipeCount; if (Skill != skillLine || _recipeCount <= 0) {// we failed to load tradeskill throw new Exception(string.Format("Unable to load {0}", skillLine)); } // array of pointers that point to each recipe structure. uint[] recipePtrArray = ObjectManager.Wow.ReadStructArray<uint>(RecipeOffset, RecipeCount); for (int index = 0; index < _recipeCount; index++) { uint[] recipeData = ObjectManager.Wow.ReadStructArray<uint>(recipePtrArray[index], 9); uint id = recipeData[(int)Recipe.RecipeIndex.RecipeID]; // check if its a header if (id == uint.MaxValue) { continue; // no further info to get for header } tradeSkill.Recipes.Add(id, new Recipe(recipeData, tradeSkill, skillLine)); } tradeSkill.InitIngredientList(); tradeSkill.InitToolList(); } return tradeSkill; }
internal Recipe(uint[] data, TradeSkill parent, SkillLine skill) { _recipeData = data; Skill = skill; Parent = parent; }