Advertisement
Shuraken007

BAS.lua

Oct 18th, 2016
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.84 KB | None | 0 0
  1. BAS={}
  2.  
  3. function BAS.GetWeaponSpeed()
  4.     local WeaponSpeed = nil
  5.     BASScannerTooltip:SetOwner(UIParent, "ANCHOR_NONE")
  6.     BASScannerTooltip:SetInventoryItem("player", 18)
  7.     for i=1,10 do
  8.         text = getglobal("BASScannerTooltipTextRight"..i)
  9.         if text:IsVisible() then
  10.             _, _, WeaponSpeed = string.find(text:GetText(), "([%,%.%d]+)")
  11.             if speedmax then
  12.                 if not tonumber(WeaponSpeed) then
  13.                     WeaponSpeed = string.gsub(WeaponSpeed, "%,", "%.")
  14.                 end
  15.                 break
  16.             end
  17.         end
  18.     end
  19.     return WeaponSpeed
  20. end
  21.  
  22. function BAS.CheckQuiver()
  23.     local tmpTxt, line, result;
  24.     local lines = BASScannerTooltip:NumLines();
  25.     for i=1, lines do
  26.         tmpText = getglobal("BASScannerTooltipTextLeft"..i);
  27.         val = nil;
  28.         if (tmpText:GetText()) then
  29.             line = tmpText:GetText();
  30.             if string.find(line, "speed by") then
  31.                 _, _,result = string.find(line, "speed by (%d+)")
  32.             end
  33.         end
  34.     end
  35.     return result
  36. end
  37.  
  38.  
  39. function BAS.GetBagSpeed()
  40.     local result
  41.     for i = 1,4 do
  42.         local invID = ContainerIDToInventoryID(i)  
  43.         if invID then
  44.             local bagLink = GetInventoryItemLink("player",invID)
  45.             if bagLink then
  46.                 _, _, Color, Ltype, Id, Enchant, Suffix, Unique, Name = string.find(bagLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d*):?(%d*):?(%d*):?(%d*)|?h?%[(.+)%]")
  47.                 bagHyperLink = Ltype..":"..Id..":"..Enchant..":"..Suffix
  48.                 BASScannerTooltip:SetOwner(UIParent, "ANCHOR_NONE")
  49.                 BASScannerTooltip:SetHyperlink(bagHyperLink)
  50.                 result = BAS.CheckQuiver()
  51.                 if result then
  52.                     break
  53.                 end
  54.             end
  55.         end    
  56.     end
  57.     return result
  58. end
  59.  
  60. function BAS.GetBaseSpeed()
  61.     local W_Speed, B_Speed = BAS.GetWeaponSpeed(), BAS.GetBagSpeed()
  62.     if W_Speed then
  63.         if B_Speed then
  64.             W_Speed = W_Speed / (1 + B_Speed/100)
  65.             W_Speed = floor(W_Speed*100)/100
  66.         end
  67.     end
  68.     return W_Speed
  69. end
  70.  
  71. function BAS.GetKoefSpeed()
  72.     local un_mode_speed, mode_speed, result
  73.     un_mode_speed = BAS.GetBaseSpeed()
  74.     mode_speed = floor(UnitRangedDamage("player")*100)/100
  75.     if un_mode_speed and mode_speed and mode_speed~=0 then
  76.         result = un_mode_speed/mode_speed
  77.     end
  78.     return result
  79. end
  80.  
  81. function BAS.CheckCastSpeed()
  82.     local tmpTxt, line, result;
  83.     local lines = BASScannerTooltip:NumLines();
  84.     for i=1, lines do
  85.         tmpText = getglobal("BASScannerTooltipTextLeft"..i);
  86.         val = nil;
  87.         if (tmpText:GetText()) then
  88.             line = tmpText:GetText();
  89.             if string.find(line, "sec cast") then
  90.                 _, _,result = string.find(line, "(%d+) sec cast")
  91.             end
  92.         end
  93.     end
  94.     return result
  95. end
  96.  
  97. function BAS.FindInBook(spell)
  98.     spell = gsub(spell, "%-", "%%%-")
  99.     local i = 1
  100.     local SPELLNUM = nil
  101.     while true do
  102.         local spellName, spellRank = GetSpellName(i, BOOKTYPE_SPELL)
  103.         if not spellName then
  104.             break
  105.         end
  106.         if string.find(spellName .. '(Rank ' .. spellRank .. ')', spell) then
  107.             SPELLNUM = i
  108.         end
  109.         i = i + 1
  110.     end
  111.     return SPELLNUM
  112. end
  113.  
  114. function BAS.GetCD(spell)
  115.     local SPELLNUM = BAS.FindInBook(spell)
  116.     if not SPELLNUM then
  117.         return nil
  118.     end
  119.     start, duration = GetSpellCooldown(SPELLNUM, BOOKTYPE_SPELL)
  120.     if duration ~= 0 then
  121.         return duration - GetTime() + start
  122.     else
  123.         return 0
  124.     end
  125. end
  126.  
  127. local BAS_CastSpell = CastSpell
  128. function CastSpell(spell, tab, a, b, c, d, e)
  129.     local name = GetSpellName(spell, tab)
  130.     BAS.LastCastName = name
  131.     BAS.LastCastTime = GetTime()
  132.     if name == "Aimed Shot" then
  133.         BAS.CastBarCastSpell(name)
  134.     end
  135.     return BAS_CastSpell(spell, tab, a, b, c, d, e)
  136. end
  137.  
  138. local BAS_UseAction = UseAction
  139. function UseAction(slot, checkCursor, onSelf, a, b, c, d, e)
  140.     BASScannerTooltip:SetOwner(UIParent, "ANCHOR_NONE")
  141.     BASScannerTooltip:SetAction(slot)
  142.     local name = BASScannerTooltipTextLeft1:GetText()
  143.     BAS.LastCastName = name
  144.     BAS.LastCastTime = GetTime()
  145.     if name == "Aimed Shot" then
  146.         BAS.CastBarCastSpell(name)
  147.     end
  148.     return BAS_UseAction(slot, checkCursor, onSelf, a, b, c, d, e)
  149. end
  150.  
  151. local BAS_CastSpellByName = CastSpellByName
  152. function CastSpellByName(spell, onSelf, a, b, c, d, e)
  153.     local _, _, name = string.find(spell or "", "([%w%'%s]+)")
  154.     BAS.LastCastName = name
  155.     BAS.LastCastTime = GetTime()
  156.     if name == "Aimed Shot" then
  157.         BAS.CastBarCastSpell(name)
  158.     end
  159.     return BAS_CastSpellByName(spell, onSelf, a, b, c, d, e)
  160. end
  161.  
  162. BAS.Ping = 0.2
  163.  
  164. function BAS.CastBarCastSpell(name)
  165.     if CastingBarText:GetText() ~= name then
  166.         local cast_time = nil
  167.         local SPELLNUM = BAS.FindInBook(name)
  168.         if SPELLNUM then
  169.             BASScannerTooltip:SetOwner(UIParent, "ANCHOR_NONE")
  170.             BASScannerTooltip:SetSpell(SPELLNUM, BOOKTYPE_SPELL)
  171.             cast_time = BAS.CheckCastSpeed()
  172.         else
  173.             cast_time = 3
  174.         end
  175.         cast_time = cast_time + BAS.Ping
  176.         cast_time = cast_time*1000
  177.         cast_time = cast_time/BAS.GetKoefSpeed()
  178.         CastingBarFrameStatusBar:SetStatusBarColor(1.0, 0.7, 0.0);
  179.         CastingBarSpark:Show();
  180.         CastingBarFrame.startTime = GetTime();
  181.         CastingBarFrame.maxValue = CastingBarFrame.startTime + (cast_time / 1000);
  182.         CastingBarFrameStatusBar:SetMinMaxValues(CastingBarFrame.startTime, CastingBarFrame.maxValue);
  183.         CastingBarFrameStatusBar:SetValue(CastingBarFrame.startTime);
  184.         CastingBarText:SetText(name);
  185.         CastingBarFrame:SetAlpha(1.0);
  186.         CastingBarFrame.holdTime = 0;
  187.         CastingBarFrame.casting = 1;
  188.         CastingBarFrame.fadeOut = nil;
  189.         CastingBarFrame:Show();
  190.  
  191.         CastingBarFrame.mode = "casting";  
  192.     end
  193. end
  194.  
  195. BAS.autoshot = nil
  196. BAS.time_shoot = 0
  197. BAS.LastCastTime = 0
  198. BAS.LastCastName = ""
  199.    
  200. function BAS.GetTimeToShoot()
  201.     local speed = UnitRangedDamage("player")
  202.     local result = speed - (GetTime() - BAS.time_shoot)
  203.     if result < 0 then
  204.         result = 0
  205.     end
  206.     return result
  207. end
  208.  
  209. function BAS.OnLoad()
  210.     this:RegisterEvent("START_AUTOREPEAT_SPELL")
  211.     this:RegisterEvent("STOP_AUTOREPEAT_SPELL")
  212.     this:RegisterEvent("ITEM_LOCK_CHANGED")
  213.     this:RegisterEvent("SPELLCAST_STOP")
  214. end
  215.  
  216. BAS.ShotCount = 0
  217. function BAS.OnEvent(event)
  218.     if event == "START_AUTOREPEAT_SPELL" then
  219.         BAS.autoshot = true
  220.         local ammoSlot = GetInventorySlotInfo("AmmoSlot")
  221.         BAS.ammoCount = GetInventoryItemCount("player", ammoSlot)
  222.         if ((BAS.ammoCount == 1) and (not GetInventoryItemTexture("player", ammoSlot))) then
  223.             BAS.ammoCount = 0
  224.         end
  225.     elseif event == "STOP_AUTOREPEAT_SPELL" then
  226.         BAS.autoshot = false
  227.     elseif event == "ITEM_LOCK_CHANGED" then
  228.         if BAS.autoshot then
  229.             local ammoSlot = GetInventorySlotInfo("AmmoSlot")
  230.             local ammoCount = GetInventoryItemCount("player", ammoSlot)
  231.             if ((ammoCount == 1) and (not GetInventoryItemTexture("player", ammoSlot))) then
  232.                 ammoCount = 0
  233.             end
  234.             if ammoCount == BAS.ammoCount - 1 then
  235.                 BAS.time_shoot = GetTime()
  236.                 BAS.ammoCount = ammoCount
  237.                 Printd(BAS.LastCastName.."| "..(GetTime() - BAS.LastCastTime).."| "..BAS.GetCD(BAS.LastCastName))
  238.                 if not (BAS.LastCastName ~= "Auto Shot" and (GetTime() - BAS.LastCastTime) < 0.6 and BAS.GetCD(BAS.LastCastName) < 1.5) then
  239.                     BAS.ShotCount = BAS.ShotCount + 1
  240.                     Printd(BAS.ShotCount)
  241.                 end
  242.             end
  243.         end
  244.     end
  245. end
  246.  
  247. function BAS.OnUpdate()
  248. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement