Пример #1
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (Me.IsFlying)
         {
             return(RunStatus.Failure);
         }
         if (_lootSw.IsRunning && _lootSw.ElapsedMilliseconds < 1000)
         {
             return(RunStatus.Success);
         }
         if (LootFrame.Instance != null && LootFrame.Instance.IsVisible)
         {
             LootFrame.Instance.LootAll();
             _lootSw.Reset();
             _lootSw.Start();
             return(RunStatus.Success);
         }
         uint timeToWait = ((uint)ActionType * 1000) + 2500;
         if (!Me.IsCasting && (!_castTimer.IsRunning || _castTimer.ElapsedMilliseconds >= timeToWait))
         {
             List <WoWItem> itemList = BuildItemList();
             if (itemList == null || itemList.Count == 0)
             {
                 IsDone = true;
                 Professionbuddy.Log("Done {0}ing", ActionType);
             }
             else
             { // skip 'locked' items
                 int index = 0;
                 for (; index <= itemList.Count; index++)
                 {
                     if (!itemList[index].IsDisabled)
                     {
                         break;
                     }
                 }
                 if (index < itemList.Count)
                 {
                     if (itemList[index].Guid == _lastItemGuid && _lastStackSize == itemList[index].StackCount)
                     {
                         if (++_tries >= 3)
                         {
                             Professionbuddy.Log("Unable to {0} {1}, BlackListing", Name, itemList[index].Name);
                             if (!_blacklistedItems.Contains(_lastItemGuid))
                             {
                                 _blacklistedItems.Add(_lastItemGuid);
                             }
                             return(RunStatus.Success);
                         }
                     }
                     else
                     {
                         _tries = 0;
                     }
                     WoWSpell spell = WoWSpell.FromId(SpellId);
                     if (spell != null)
                     {
                         TreeRoot.GoalText = string.Format("{0}ing {1}", ActionType, itemList[index].Name);
                         Professionbuddy.Log(TreeRoot.GoalText);
                         //Lua.DoString("CastSpellByID({0}) UseContainerItem({1}, {2})",
                         //    spellId, ItemList[index].BagIndex + 1, ItemList[index].BagSlot + 1);
                         spell.CastOnItem(itemList[index]);
                         _lastItemGuid  = itemList[index].Guid;
                         _lastStackSize = itemList[index].StackCount;
                         _castTimer.Reset();
                         _castTimer.Start();
                     }
                     else
                     {
                         IsDone = true;
                     }
                 }
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Success);
         }
     }
     return(RunStatus.Failure);
 }
Пример #2
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (!IsRecipe)
         {
             CheckTradeskillList();
         }
         if (Casted >= CalculatedRepeat)
         {
             if (ObjectManager.Me.IsCasting && ObjectManager.Me.CastingSpell.Id == Entry)
             {
                 SpellManager.StopCasting();
             }
             _spamControl.Stop();
             _spamControl.Reset();
             Lua.Events.DetachEvent("UNIT_SPELLCAST_SUCCEEDED", OnUnitSpellCastSucceeded);
             IsDone = true;
             return(RunStatus.Failure);
         }
         // can't make recipe so stop trying.
         if (IsRecipe && Recipe.CanRepeatNum2 <= 0)
         {
             Professionbuddy.Debug("{0} doesn't have enough material to craft.", SpellName);
             IsDone = true;
             return(RunStatus.Failure);
         }
         if (Me.IsCasting && Me.CastingSpellId != Entry)
         {
             SpellManager.StopCasting();
         }
         // we should confirm the last recipe in list so we don't make an axtra
         if (!Me.IsFlying && Casted + 1 < CalculatedRepeat || (Casted + 1 == CalculatedRepeat &&
                                                               (Confimed || !_spamControl.IsRunning ||
                                                                (_spamControl.ElapsedMilliseconds >=
                                                                 (_recastTime + (_recastTime / 2)) + _waitTime &&
                                                                 !ObjectManager.Me.IsCasting))))
         {
             if (!_spamControl.IsRunning || _spamControl.ElapsedMilliseconds >= _recastTime ||
                 (!ObjectManager.Me.IsCasting && _spamControl.ElapsedMilliseconds >= _waitTime))
             {
                 if (ObjectManager.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(CultureInfo.InvariantCulture));
                 }
                 WoWSpell spell = WoWSpell.FromId((int)Entry);
                 if (spell == null)
                 {
                     Professionbuddy.Err("{0}: {1}", Pb.Strings["Error_UnableToFindSpellWithEntry"], Entry);
                     return(RunStatus.Failure);
                 }
                 _recastTime = spell.CastTime;
                 Professionbuddy.Debug("Casting {0}, recast :{1}", spell.Name, _recastTime);
                 if (CastOnItem)
                 {
                     WoWItem item = TargetedItem;
                     if (item != null)
                     {
                         spell.CastOnItem(item);
                     }
                     else
                     {
                         Professionbuddy.Err("{0}: {1}",
                                             Pb.Strings["Error_UnableToFindItemToCastOn"],
                                             IsRecipe
                                                 ? Recipe.Name
                                                 : Entry.ToString(CultureInfo.InvariantCulture));
                         IsDone = true;
                     }
                 }
                 else
                 {
                     spell.Cast();
                 }
                 _waitTime = StyxWoW.WoWClient.Latency * 2;
                 Confimed  = false;
                 _spamControl.Reset();
                 _spamControl.Start();
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Success);
         }
     }
     return(RunStatus.Failure);
 }
Пример #3
0
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                if (me.IsFlying)
                {
                    return(RunStatus.Failure);
                }
                if (LootFrame.Instance != null && LootFrame.Instance.IsVisible)
                {
                    LootFrame.Instance.LootAll();
                    return(RunStatus.Running);
                }
                if (!me.IsCasting && (!castTimer.IsRunning || castTimer.ElapsedMilliseconds >= timeToWait))
                {
                    List <WoWItem> ItemList = BuildItemList();
                    if (ItemList == null || ItemList.Count == 0)
                    {
                        IsDone = true;
                        Professionbuddy.Log("Done {0}ing", ActionType);
                    }
                    else
                    { // skip 'locked' items
                        int index = 0;
                        for (; index <= ItemList.Count; index++)
                        {
                            if (!ItemList[index].IsDisabled)
                            {
                                break;
                            }
                        }
                        if (index < ItemList.Count)
                        {
                            if (ItemList[index].Guid == lastItemGuid && lastStackSize == ItemList[index].StackCount)
                            {
                                if (++tries >= 3)
                                {
                                    Professionbuddy.Log("Unable to {0} {1}, BlackListing", Name, ItemList[index].Name);
                                    if (!blacklistedItems.Contains(lastItemGuid))
                                    {
                                        blacklistedItems.Add(lastItemGuid);
                                    }
                                    return(RunStatus.Running);
                                }
                            }
                            else
                            {
                                tries = 0;
                            }
                            WoWSpell spell = WoWSpell.FromId(spellId);
                            if (spell != null)
                            {
                                TreeRoot.GoalText = string.Format("{0}ing {1}", ActionType, ItemList[index].Name);

                                //Lua.DoString("CastSpellByID({0}) UseContainerItem({1}, {2})",
                                //    spellId, ItemList[index].BagIndex + 1, ItemList[index].BagSlot + 1);
                                spell.CastOnItem(ItemList[index]);
                                lastItemGuid  = ItemList[index].Guid;
                                lastStackSize = ItemList[index].StackCount;
                                castTimer.Reset();
                                castTimer.Start();
                            }
                            else
                            {
                                IsDone = true;
                            }
                        }
                    }
                }
                if (!IsDone)
                {
                    return(RunStatus.Running);
                }
            }
            return(RunStatus.Failure);
        }
Пример #4
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();
                }
            }
        }