Exemplo n.º 1
0
        private string ReadEquitmentSlot(EquipmentSlot equipmentSlot)
        {
            string command = $"abotItemSlot={(int)equipmentSlot};abotItemInfoResult='noItem';abId=GetInventoryItemID('player',abotItemSlot);abCount=GetInventoryItemCount('player',abotItemSlot);abQuality=GetInventoryItemQuality('player',abotItemSlot);abCurrentDurability,abMaxDurability=GetInventoryItemDurability(abotItemSlot);abCooldownStart,abCooldownEnd=GetInventoryItemCooldown('player',abotItemSlot);abName,abLink,abRarity,abLevel,abMinLevel,abType,abSubType,abStackCount,abEquipLoc,abIcon,abSellPrice=GetItemInfo(GetInventoryItemLink('player',abotItemSlot));abotItemInfoResult='{{'..'\"id\": \"'..tostring(abId or 0)..'\",'..'\"count\": \"'..tostring(abCount or 0)..'\",'..'\"quality\": \"'..tostring(abQuality or 0)..'\",'..'\"curDurability\": \"'..tostring(abCurrentDurability or 0)..'\",'..'\"maxDurability\": \"'..tostring(abMaxDurability or 0)..'\",'..'\"cooldownStart\": \"'..tostring(abCooldownStart or 0)..'\",'..'\"cooldownEnd\": '..tostring(abCooldownEnd or 0)..','..'\"name\": \"'..tostring(abName or 0)..'\",'..'\"link\": \"'..tostring(abLink or 0)..'\",'..'\"level\": \"'..tostring(abLevel or 0)..'\",'..'\"minLevel\": \"'..tostring(abMinLevel or 0)..'\",'..'\"type\": \"'..tostring(abType or 0)..'\",'..'\"subtype\": \"'..tostring(abSubType or 0)..'\",'..'\"maxStack\": \"'..tostring(abStackCount or 0)..'\",'..'\"equiplocation\": \"'..tostring(abEquipLoc or 0)..'\",'..'\"sellprice\": \"'..tostring(abSellPrice or 0)..'\"'..'}}';";

            WowActionExecutor?.LuaDoString(command);
            return(WowActionExecutor?.GetLocalizedText("abotItemInfoResult"));
        }
Exemplo n.º 2
0
        private string ReadInventoryItems()
        {
            string command = $"abotInventoryResult='['for b=0,4 do containerSlots=GetContainerNumSlots(b); for a=1,containerSlots do abItemLink=GetContainerItemLink(b,a)if abItemLink then abCurrentDurability,abMaxDurability=GetContainerItemDurability(b,a)abCooldownStart,abCooldownEnd=GetContainerItemCooldown(b,a)abIcon,abItemCount,abLocked,abQuality,abReadable,abLootable,abItemLink,isFiltered=GetContainerItemInfo(b,a)abName,abLink,abRarity,abLevel,abMinLevel,abType,abSubType,abStackCount,abEquipLoc,abIcon,abSellPrice=GetItemInfo(abItemLink)abotInventoryResult=abotInventoryResult..'{{'..'\"id\": \"'..tostring(abId or 0)..'\",'..'\"count\": \"'..tostring(abItemCount or 0)..'\",'..'\"quality\": \"'..tostring(abQuality or 0)..'\",'..'\"curDurability\": \"'..tostring(abCurrentDurability or 0)..'\",'..'\"maxDurability\": \"'..tostring(abMaxDurability or 0)..'\",'..'\"cooldownStart\": \"'..tostring(abCooldownStart or 0)..'\",'..'\"cooldownEnd\": \"'..tostring(abCooldownEnd or 0)..'\",'..'\"name\": \"'..tostring(abName or 0)..'\",'..'\"lootable\": \"'..tostring(abLootable or 0)..'\",'..'\"readable\": \"'..tostring(abReadable or 0)..'\",'..'\"link\": \"'..tostring(abItemLink or 0)..'\",'..'\"level\": \"'..tostring(abLevel or 0)..'\",'..'\"minLevel\": \"'..tostring(abMinLevel or 0)..'\",'..'\"type\": \"'..tostring(abType or 0)..'\",'..'\"subtype\": \"'..tostring(abSubType or 0)..'\",'..'\"maxStack\": \"'..tostring(abStackCount or 0)..'\",'..'\"equiplocation\": \"'..tostring(abEquipLoc or 0)..'\",'..'\"sellprice\": \"'..tostring(abSellPrice or 0)..'\"'..'}}'if b<4 or a<containerSlots then abotInventoryResult=abotInventoryResult..','end end end end;abotInventoryResult=abotInventoryResult..']'";

            WowActionExecutor?.LuaDoString(command);
            return(WowActionExecutor?.GetLocalizedText("abotInventoryResult"));
        }
        private bool CastSpell(Spell spell, bool onSelf = false)
        {
            if (spell == null)
            {
                return(false);
            }

            AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X" , CultureInfo.InvariantCulture.NumberFormat)}]\tCasting spell \"{spell}\" [onSelf = {onSelf}]", LogLevel.Verbose);
            WowUnit player = ((WowUnit)WowDataAdapter.ObjectManager.GetWowObjectByGuid(WowDataAdapter.PlayerGuid));

            WowActionExecutor?.CastSpell(spell.name, onSelf);

            int casttime = 0;

            while (IsMeCasting())
            {
                Thread.Sleep(100);
                casttime += 100;
            }

            if (player.IsConfused ||
                player.IsDazed ||
                player.IsDisarmed ||
                player.IsFleeing ||
                player.IsSilenced ||
                (casttime < spell.castTime - 100))
            {
                AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X" , CultureInfo.InvariantCulture.NumberFormat)}]\tCast interrupted [casttime = {casttime}, spell.castTime = {spell.castTime}, IsConfused = {player.IsConfused}, IsDazed = {player.IsDazed}, IsDisarmed = {player.IsDisarmed}, IsFleeing = {player.IsFleeing}, IsSilenced = {player.IsSilenced}]", LogLevel.Verbose);
                //we got interrupted, TODO: need to handle casttime buffs
                return(false);
            }

            return(true);
        }
        private void CEventReader()
        {
            while (Enabled)
            {
                try
                {
                    if (!IsSetUp)
                    {
                        SetupEventHook();
                        continue;
                    }

                    // Unminified lua code can be found im my github repo "WowLuaStuff"
                    WowActionExecutor.LuaDoString("abEventJson='['for a,b in pairs(abEventTable)do abEventJson=abEventJson..'{'for c,d in pairs(b)do if type(d)==\"table\"then abEventJson=abEventJson..'\"args\": ['for e,f in pairs(d)do abEventJson=abEventJson..'\"'..f..'\"'if e<=table.getn(d)then abEventJson=abEventJson..','end end;abEventJson=abEventJson..']}'if a<table.getn(abEventTable)then abEventJson=abEventJson..','end else if type(d)==\"string\"then abEventJson=abEventJson..'\"event\": \"'..d..'\",'else abEventJson=abEventJson..'\"time\": \"'..d..'\",'end end end end;abEventJson=abEventJson..']'abEventTable={}");
                    string eventJson = WowActionExecutor.GetLocalizedText("abEventJson");

                    HandlEvents(eventJson);
                }
                catch (Exception ex)
                {
                    AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tCrash at StateMachine: \n{ex}");
                }

                Thread.Sleep(1000);
            }
        }
Exemplo n.º 5
0
 public void Detach()
 {
     StateMachine?.Stop();
     WowEventAdapter?.Stop();
     WowActionExecutor?.Stop();
     WowPathfindingClient?.Disconnect();
     WowDataAdapter?.StopObjectUpdates();
     Attached = false;
 }
 private void CStateMachineUpdate(object sender, ElapsedEventArgs e)
 {
     try
     {
         CurrentState.Execute();
         WowActionExecutor.AntiAfk();
     }
     catch (Exception ex)
     {
         AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X" , CultureInfo.InvariantCulture.NumberFormat)}]\tCrash at StateMachine: \n{ex}");
     }
 }
        public void Stop()
        {
            AmeisenBotLogger.Instance.Log($"[{WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tStopping EventHook...");
            WowActionExecutor.LuaDoString($"abFrame:UnregisterAllEvents();");
            WowActionExecutor.LuaDoString($"abFrame:SetScript(\"OnEvent\", nil);");

            Enabled = false;

            if (EventReaderThread?.IsAlive == true)
            {
                EventReaderThread.Join();
            }
        }
        private void SetupEventHook()
        {
            AmeisenBotLogger.Instance.Log($"[{WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tPreparing EventHook...");
            StringBuilder luaStuff = new StringBuilder();

            luaStuff.Append("abFrame = CreateFrame(\"FRAME\", \"AbotEventFrame\") ");
            luaStuff.Append("abEventTable = {} ");
            luaStuff.Append("function abEventHandler(self, event, ...) ");
            luaStuff.Append("table.insert(abEventTable, {time(), event, {...}}) end ");
            luaStuff.Append("if abFrame:GetScript(\"OnEvent\") == nil then ");
            luaStuff.Append("abFrame:SetScript(\"OnEvent\", abEventHandler) end");
            WowActionExecutor.LuaDoString(luaStuff.ToString());
            IsSetUp = true;
        }
        private List <Spell> ReadAvaiableSpells()
        {
            AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tReading Spellbok...", LogLevel.Verbose);
            WowActionExecutor?.LuaDoString("abotSpellResult='['tabCount=GetNumSpellTabs()for a=1,tabCount do tabName,tabTexture,tabOffset,numEntries=GetSpellTabInfo(a)for b=tabOffset+1,tabOffset+numEntries do abSpellName,abSpellRank=GetSpellName(b,\"BOOKTYPE_SPELL\")if abSpellName then abName,abRank,_,abCosts,_,_,abCastTime,abMinRange,abMaxRange=GetSpellInfo(abSpellName,abSpellRank)abotSpellResult=abotSpellResult..'{'..'\"spellbookName\": \"'..tostring(tabName or 0)..'\",'..'\"spellbookId\": \"'..tostring(a or 0)..'\",'..'\"name\": \"'..tostring(abSpellName or 0)..'\",'..'\"rank\": \"'..tostring(abRank or 0)..'\",'..'\"castTime\": \"'..tostring(abCastTime or 0)..'\",'..'\"minRange\": \"'..tostring(abMinRange or 0)..'\",'..'\"maxRange\": \"'..tostring(abMaxRange or 0)..'\",'..'\"costs\": \"'..tostring(abCosts or 0)..'\"'..'}'if a<tabCount or b<tabOffset+numEntries then abotSpellResult=abotSpellResult..','end end end end;abotSpellResult=abotSpellResult..']'");
            string result = WowActionExecutor?.GetLocalizedText("abotSpellResult");

            AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X" , CultureInfo.InvariantCulture.NumberFormat)}]\tAvailable spells: {result}", LogLevel.Verbose);

            List <Spell> spells;

            try
            {
                spells = JsonConvert.DeserializeObject <List <Spell> >(result);
            }
            catch { spells = new List <Spell>(); }

            return(spells);
        }
Exemplo n.º 10
0
        private WowUnit SelectNewTarget()
        {
            List <WowUnit> aliveTargets = GetAvaiableTargets().Where(unit => unit.Health > 0 && unit.MaxHealth > 0).ToList();

            if (aliveTargets.Count == 0)
            {
                return(null);
            }

            WowUnit player = (WowUnit)WowDataAdapter.ObjectManager.GetWowObjectByGuid(WowDataAdapter.PlayerGuid);

            // get the one with the lowest HealthPercentage
            foreach (WowUnit unit in aliveTargets.OrderByDescending(unit => (unit.Health / unit.MaxHealth) * 100))
            {
                if (WowActionExecutor?.GetUnitReaction(unit, player) != UnitReaction.Friendly)
                {
                    return(unit);
                }
            }

            return(null);
        }
Exemplo n.º 11
0
        public void Execute()
        {
            if (!IsUnitValid(ActiveTarget))
            {
                ActiveTarget = SelectNewTarget();
                AmeisenBotLogger.Instance.Log($"[{WowActionExecutor?.ProcessId.ToString("X" , CultureInfo.InvariantCulture.NumberFormat)}]\tNew ActiveTarget is: {ActiveTarget?.Name}");
                return;
            }

            WowPosition positionToMoveTo = MovementProvider?.GetPositionToMoveTo(WowDataAdapter.ActivePlayerPosition, WowDataAdapter.GetPosition(ActiveTarget.BaseAddress)) ?? new WowPosition();

            WowActionExecutor.MoveToPosition(positionToMoveTo);

            WowUnit player = (WowUnit)WowDataAdapter.ObjectManager.GetWowObjectByGuid(WowDataAdapter.PlayerGuid);

            if (ActiveTarget?.Guid != 0 &&
                player.TargetGuid != ActiveTarget.Guid)
            {
                WowActionExecutor.TargetGuid(ActiveTarget.Guid);
            }

            WowActionExecutor.AttackUnit(ActiveTarget);
            /*SpellStrategy?.GetSpellToCast(player, ActiveTarget);*/
        }
Exemplo n.º 12
0
 private void OnResurrectRequest(long timestamp, List <string> args)
 {
     WowActionExecutor.AcceptResurrect();
 }
 public void Unsubscribe(string eventName)
 {
     AmeisenBotLogger.Instance.Log($"[{WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tUnsubscribed from \"{eventName}\"");
     WowActionExecutor.LuaDoString($"abFrame:UnregisterEvent(\"{eventName}\");");
     EventDictionary.Remove(eventName);
 }
 public void Subscribe(string eventName, OnEventFired onEventFired)
 {
     AmeisenBotLogger.Instance.Log($"[{WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tSubscribed to \"{eventName}\"");
     WowActionExecutor.LuaDoString($"abFrame:RegisterEvent(\"{eventName}\");");
     EventDictionary.Add(eventName, onEventFired);
 }
Exemplo n.º 15
0
 private void OnReadyCheck(long timestamp, List <string> args)
 {
     WowActionExecutor.CofirmReadyCheck(true);
 }
Exemplo n.º 16
0
 private void OnConfirmBindOnPickup(long timestamp, List <string> args)
 {
     WowActionExecutor.CofirmBop();
 }
Exemplo n.º 17
0
 private void OnPartyInvitation(long timestamp, List <string> args)
 {
     WowActionExecutor.AcceptPartyInvite();
 }
Exemplo n.º 18
0
 private void OnLootWindowOpened(long timestamp, List <string> args)
 {
     WowActionExecutor.LootEveryThing();
 }
Exemplo n.º 19
0
 private void OnSummonRequest(long timestamp, List <string> args)
 {
     WowActionExecutor.AcceptSummon();
 }