protected async override Task Run() { try { if ( Lua.GetReturnVal <int>( "if AuctionFrame and AuctionFrame:IsVisible() == 1 then return 1 else return 0 end ", 0) == 0) { MoveToAh(); } else if ( Lua.GetReturnVal <int>( "if CanSendAuctionQuery('owner') == 1 then return 1 else return 0 end ", 0) == 1) { if (_toScanItemList == null) { _toScanItemList = BuildScanItemList(); _toCancelItemList = new List <AuctionEntry>(); } if (_toScanItemList.Count > 0) { AuctionEntry ae = _toScanItemList[0]; bool scanDone = ScanAh(ref ae); _toScanItemList[0] = ae; // update if (scanDone) { _toCancelItemList.Add(ae); _toScanItemList.RemoveAt(0); } if (_toScanItemList.Count == 0) { ProfessionbuddyBot.Debug("Finished scanning for items"); } } else { if (_toCancelItemList.Count == 0) { _toScanItemList = null; IsDone = true; return; } if (CancelAuction(_toCancelItemList[0])) { _toCancelItemList.RemoveAt(0); } } } } catch (Exception ex) { PBLog.Warn(ex.ToString()); } }
void Finished(string reason = null) { if (StyxWoW.Me.IsCasting && StyxWoW.Me.CastingSpell.Id == Entry) { SpellManager.StopCasting(); } Lua.Events.DetachEvent("UNIT_SPELLCAST_SUCCEEDED", OnUnitSpellCastSucceeded); var reasonString = !string.IsNullOrEmpty(reason) ? string.Format(" Reason: {0}", reason) : ""; ProfessionbuddyBot.Debug("Done crafting {0}.{1}", IsRecipe ? SpellName : Entry.Value.ToString(CultureInfo.InvariantCulture), reasonString); IsDone = true; }
//indexs are {0}=ItemsCounter,NumOfItemToBuy, {1}=ItemID, {2}=maxBuyout, {3}=BidOnItem ? 1 : 0 private bool BuyFromAH(BuyItemEntry bie) { bool done = false; if (!_queueTimer.IsRunning) { string lua = string.Format("QueryAuctionItems(\"{0}\" ,nil,nil,nil,nil,nil,{1}) return 1", bie.Name.ToFormatedUTF8(), _page); Lua.GetReturnVal <int>(lua, 0); ProfessionbuddyBot.Debug("Searching AH for {0}", bie.Name); _queueTimer.Start(); } else if (_queueTimer.ElapsedMilliseconds <= 10000) { if (Lua.GetReturnVal <int>("if CanSendAuctionQuery('list') == 1 then return 1 else return 0 end ", 0) == 1) { _totalAuctions = Lua.GetReturnVal <int>("return GetNumAuctionItems('list')", 1); _queueTimer.Stop(); _queueTimer.Reset(); if (_totalAuctions > 0) { string lua = string.Format(BuyFromAHLuaFormat, _counter, bie.BuyAmount, bie.Id, MaxBuyout.TotalCopper, BidOnItem ? 1 : 0); _counter = Lua.GetReturnVal <int>(lua, 0); if (_counter == -1 || ++_page >= (int)Math.Ceiling((double)_totalAuctions / 50)) { done = true; } } else { done = true; } } } else { done = true; } if (done) { _queueTimer = new Stopwatch(); _totalAuctions = 0; _counter = 0; _page = 0; } return(done); }
private bool ScanAh(ref AuctionEntry ae) { bool scanned = false; if (!_queueTimer.IsRunning) { string lua = string.Format("QueryAuctionItems(\"{0}\" ,nil,nil,nil,nil,nil,{1}) return 1", ae.Name.ToFormatedUTF8(), _page); Lua.GetReturnVal <int>(lua, 0); ProfessionbuddyBot.Debug("Searching AH for {0}", ae.Name); _queueTimer.Start(); } else if (_queueTimer.ElapsedMilliseconds <= 10000) { using (StyxWoW.Memory.AcquireFrame()) { if ( Lua.GetReturnVal <int>("if CanSendAuctionQuery('list') == 1 then return 1 else return 0 end ", 0) == 1) { _queueTimer.Reset(); _totalAuctions = Lua.GetReturnVal <int>("return GetNumAuctionItems('list')", 1); string lua = string.Format(SellItemOnAhAction.ScanAhFormatLua, ae.LowestBo, ae.MyAuctions, ae.Id, IgnoreStackSizeBelow, int.MaxValue); List <string> retVals = Lua.GetReturnValues(lua); uint.TryParse(retVals[0], out ae.LowestBo); uint.TryParse(retVals[1], out ae.MyAuctions); if (++_page >= (int)Math.Ceiling((double)_totalAuctions / 50)) { scanned = true; } } } } else { scanned = true; } // reset to default values in preparations for next scan if (scanned) { ProfessionbuddyBot.Debug("lowest buyout {0}", ae.LowestBo); _queueTimer.Reset(); _totalAuctions = 0; _page = 0; } return(scanned); }
protected override async Task Run() { try { if (_changeBotTimer == null) { _changeBotTimer = new WaitTimer(TimeSpan.FromSeconds(10)); _changeBotTimer.Reset(); _bot = Util.GetBotByName(BotName); if (_bot != null) { if (ProfessionbuddyBot.Instance.SecondaryBot == _bot) { IsDone = true; return; } ProfessionbuddyBot.ChangeSecondaryBot(BotName); } } } finally { // Wait until bot change completes or fails if (_bot == null || _changeBotTimer != null && (_changeBotTimer.IsFinished || ProfessionbuddyBot.Instance.SecondaryBot == _bot)) { IsDone = true; _changeBotTimer = null; } } if (IsDone) { if (_bot == null) { PBLog.Warn("No bot with name: {0} could be found", BotName); } else if (ProfessionbuddyBot.Instance.SecondaryBot == _bot) { PBLog.Log("Successfuly changed secondary bot to: {0}", BotName); } else { PBLog.Warn("Unable to switch secondary bot to: {0}", BotName); } } }
protected async override Task Run() { if (!_timeout.IsRunning) { _timeout.Start(); } try { if (_timeout.ElapsedMilliseconds >= Timeout || CanRunDelegate(this)) { _timeout.Reset(); ProfessionbuddyBot.Debug("Wait for {0} or until {1} Completed", TimeSpan.FromMilliseconds(Timeout), Condition); IsDone = true; } } catch (Exception ex) { if (ex.GetType() != typeof(ThreadAbortException)) { PBLog.Warn("{0}:({1})\n{2}", Strings["Action_WaitAction_Name"], Condition, ex); } } }
protected async override Task Run() { if (_loadingProfile) { return; } var absPath = GetAbsolutePath(); bool emptyProfile = string.IsNullOrEmpty(Path); if (IsLocal) { // check if profile is already loaded. if (!string.IsNullOrEmpty(ProfileManager.XmlLocation) && ProfileManager.XmlLocation.Equals(absPath, StringComparison.CurrentCultureIgnoreCase)) { IsDone = true; return; } // check if profile exists if (!emptyProfile && !File.Exists(absPath)) { PBLog.Warn("{0}: {1}", ProfessionbuddyBot.Instance.Strings["Error_UnableToFindProfile"], Path); IsDone = true; return; } } ProfessionbuddyBot.Debug( "Loading Profile: {0}, previous profile was {1}", emptyProfile ? "(Empty Profile)" : Path, ProfileManager.XmlLocation ?? "[No Profile]"); var path = emptyProfile || !IsLocal ? Path : absPath; Util.ExecuteActionWhileBotIsStopped( () => { try { if (string.IsNullOrEmpty(path)) { ProfileManager.LoadEmpty(); } else if (!IsLocal) { var req = WebRequest.Create(path); req.Proxy = null; using (WebResponse res = req.GetResponse()) { using (var stream = res.GetResponseStream()) { ProfileManager.LoadNew(stream); } } } else if (File.Exists(path)) { ProfileManager.LoadNew(path); } IsDone = true; ProfessionbuddyBot.Debug("Successfully loaded profile:{0}", emptyProfile ? "(Empty Profile)" : Path); } catch (Exception ex) { // if ex is not null there was a problem loading profile. ProfessionbuddyBot.Fatal("Failed to load profile.\n{0}", ex); } }, "Loading a new profile"); _loadingProfile = true; }
protected async override Task Run() { if ((Bank == BankType.Guild && !Util.IsGBankFrameOpen) || (Bank == BankType.Personal && !Util.IsBankFrameOpen)) { MoveToBanker(); } else { if (_itemsSW == null) { _itemsSW = new Stopwatch(); _itemsSW.Start(); } else if (_itemsSW.ElapsedMilliseconds < Util.WowWorldLatency * 3) { return; } if (_itemList == null) { _itemList = BuildItemList(); } // no bag space... if (_itemList.Count == 0) { IsDone = true; } else { uint itemID = _itemList.Keys.FirstOrDefault(); bool done; if (Bank == BankType.Personal) { done = PutItemInBank(itemID, _itemList[itemID]); } else { // throttle the amount of items being withdrawn from gbank per sec if (!_gbankItemThrottleSW.IsRunning) { _gbankItemThrottleSW.Start(); } if (_gbankItemThrottleSW.ElapsedMilliseconds < GbankItemThrottle) { return; } _gbankItemThrottleSW.Reset(); _gbankItemThrottleSW.Start(); int ret = PutItemInGBank(itemID, _itemList[itemID], GuildTab); _itemList[itemID] = ret < 0 ? 0 : _itemList[itemID] - ret; done = _itemList[itemID] <= 0; } if (done) { ProfessionbuddyBot.Debug("Done Depositing Item:{0} to bank", itemID); _itemList.Remove(itemID); } _itemsSW.Reset(); _itemsSW.Start(); } } if (IsDone) { PBLog.Log("Deposited Items:[{0}] to {1} Bank", ItemID, Bank); } }
private string GetLocalName(uint id) { ProfessionbuddyBot.Debug("Queueing server for Item: {0}", id); return(Util.GetItemCacheName(id)); }
protected async override Task Run() { if (Lua.GetReturnVal <int>("if AuctionFrame and AuctionFrame:IsVisible() then return 1 else return 0 end ", 0) == 0) { MoveToAh(); } else { if (_toScanItemList == null) { _toScanItemList = BuildScanItemList(); _toSellItemList = new List <AuctionEntry>(); } if (_toScanItemList.Count == 0 && _toSellItemList.Count == 0) { _toScanItemList = null; IsDone = true; return; } if (_toScanItemList.Count > 0) { AuctionEntry ae = _toScanItemList[0]; bool scanDone = ScanAh(ref ae); _toScanItemList[0] = ae; // update if (scanDone) { uint lowestBo = ae.LowestBo; if (lowestBo > MaxBuyout.TotalCopper) { ae.Buyout = MaxBuyout.TotalCopper; } else if (lowestBo < MinBuyout.TotalCopper) { ae.Buyout = MinBuyout.TotalCopper; } else { ae.Buyout = lowestBo - (uint)Math.Ceiling((lowestBo * UndercutPrecent / 100d)); } ae.Bid = (uint)(ae.Buyout * BidPrecent / 100d); bool enoughItemsPosted = AmountType == AmountBasedType.Amount && ae.MyAuctions >= Amount; bool tooLowBuyout = !PostIfBelowMinBuyout && lowestBo < MinBuyout.TotalCopper; ProfessionbuddyBot.Debug("Post If Below MinBuyout:{0} ", PostIfBelowMinBuyout, MinBuyout.TotalCopper); ProfessionbuddyBot.Debug( "Lowest Buyout on AH: {0}, My Minimum Bouyout: {1}", AuctionEntry.GoldString(lowestBo), AuctionEntry.GoldString(MinBuyout.TotalCopper)); if (!enoughItemsPosted && !tooLowBuyout) { _toSellItemList.Add(ae); } else { PBLog.Log( "Skipping {0} since {1}", ae.Name, tooLowBuyout ? string.Format("lowest buyout:{0} is below my MinBuyout:{1}", AuctionEntry.GoldString(lowestBo), MinBuyout) : string.Format("{0} items from me are already posted. Max amount is {1}", ae.MyAuctions, Amount)); } _toScanItemList.RemoveAt(0); } if (_toScanItemList.Count == 0) { ProfessionbuddyBot.Debug("Finished scanning for items"); } } if (_toSellItemList.Count > 0) { if (SellOnAh(_toSellItemList[0])) { PBLog.Log( "Selling {0} for {1}. {2}", _toSellItemList[0].Name, AuctionEntry.GoldString(_toSellItemList[0].Buyout), _toSellItemList[0].LowestBo == uint.MaxValue ? "There is no competition" : string.Format("Competition is at {0}", AuctionEntry.GoldString(_toSellItemList[0].LowestBo))); _toSellItemList.RemoveAt(0); } } } }
protected async override Task Run() { if (Me.IsFlying && await CommonCoroutines.Dismount("Crafting an item")) { return; } if (!IsRecipe) { CheckTradeskillList(); } if (Casted >= CalculatedRepeat) { Finished(); return; } // can't make recipe so stop trying. if (IsRecipe && Recipe.CanRepeatNum2 <= 0) { Finished("Not enough material."); return; } if (Me.IsCasting && Me.CastingSpellId != Entry) { SpellManager.StopCasting(); } // we should confirm the last recipe in list so we don't make an axtra if (Casted + 1 < CalculatedRepeat || (Casted + 1 == CalculatedRepeat && (Confimed || !_spamControl.IsRunning || (_spamControl.ElapsedMilliseconds >= (_recastTime + (_recastTime / 2)) + _waitTime && !StyxWoW.Me.IsCasting)))) { if (!_spamControl.IsRunning || Me.IsCasting && Me.CurrentCastTimeLeft <= TimeSpan.FromMilliseconds(250) || (!StyxWoW.Me.IsCasting && _spamControl.ElapsedMilliseconds >= _waitTime)) { if (StyxWoW.Me.IsMoving) { WoWMovement.MoveStop(); } if (!QueueIsRunning) { Lua.Events.AttachEvent("UNIT_SPELLCAST_SUCCEEDED", OnUnitSpellCastSucceeded); QueueIsRunning = true; TreeRoot.StatusText = string.Format("Casting: {0}", IsRecipe ? Recipe.Name : Entry.ToString()); } WoWSpell spell = WoWSpell.FromId((int)Entry.Value); if (spell == null) { PBLog.Warn("{0}: {1}", Strings["Error_UnableToFindSpellWithEntry"], Entry.Value.ToString(CultureInfo.InvariantCulture)); return; } _recastTime = spell.CastTime; ProfessionbuddyBot.Debug("Casting {0}, recast :{1}", spell.Name, _recastTime); if (CastOnItem) { WoWItem item = TargetedItem; if (item != null) { spell.CastOnItem(item); } else { PBLog.Warn( "{0}: {1}", Strings["Error_UnableToFindItemToCastOn"], IsRecipe ? Recipe.Name : Entry.Value.ToString(CultureInfo.InvariantCulture)); IsDone = true; } } else { spell.Cast(); } _waitTime = Util.WowWorldLatency * 3 + 50; Confimed = false; _spamControl.Reset(); _spamControl.Start(); } } }