Guest User

iSAC

a guest
Aug 23rd, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 43.76 KB | None | 0 0
  1. --[[    iSAC Library by Apple
  2.  
  3.         iSAC is based upon Sida's Auto Carry and offers a base for champion scripts.
  4.         Credits to Sida, SAC has been a great source of inspiration and some logic has been taken from SAC.
  5.  
  6.         Note: Class names are prefixed with 'i' to prevent multiple similar classes from interfering with eachother. (And because I love being me.)
  7.  
  8.         Special thanks to:
  9.         HeX - For giving me a lot of ideas and being an awesome mate to talk to while working.
  10.         Mom - For giving birth to me.
  11.         My psychiatrist - For prescribing me pills.
  12.         ]]--
  13.  
  14. if VIP_USER then require "Collision" end
  15. local _customValues = FileExist(LIB_PATH.."iSAC - Custom Values.lua") and assert(loadfile(LIB_PATH.."iSAC - Custom Values.lua"))()
  16.  
  17. --[[    iOrbWalker Class
  18.    
  19.     Methods:
  20.         local Orbwalker = iOrbWalker(AARange)
  21.  
  22.     Functions:
  23.         OrbWalker:addAA([AAName])               -> Add autoattack spellname to iOrbWalker, uses most common logic if omitted or equals "attack"
  24.         OrbWalker:addReset(resetName)           -> Add spellname with AA-timer reset.
  25.         OrbWalker:removeAA(AAName)              -> Removes an autoattack from the list or adds the autoattack to the list of ignored attacks.
  26.         OrbWalker:GetStage()                    -> Returns current stage of AA: STAGE_WINDUP, STAGE_ORBWALK, STAGE_NONE
  27.         OrbWalker:GetDPS(unit, [target])        -> Returns basic DPS a unit will deal to the target, will calculate base DPS if target is omitted.
  28.  
  29.         OrbWalker:OrbWalk(movePos, target)      -> Orbwalks, attacks target if possible, otherwise moves to movePos.
  30.         OrbWalker:Attack(target)                -> Attacks target if possible.
  31.         OrbWalker:Move(movePos)             -> Moves to movePos if possible.
  32.         OrbWalker:ManualOrbwalk(packet)     -> (VIP Only) Put in OnSendPacket, enables manual orbwalking with assistance.
  33.         OrbWalker:ManualBlock(packet)           -> (VIP Only) Put in OnSendPacket, blocks movement that will cancel AA's prematurely.
  34.  
  35.     Members:
  36.         OrbWalker.AARange       -> Autoattack range
  37.         OrbWalker.ShotCast      -> Returns the tick when the windup of the last AA ends.
  38.         OrbWalker.NextShot      -> Returns the tick when the next AA is ready.
  39.  
  40.     Example:
  41.         local OrbWalker = iOrbWalker(myHero.range)
  42.         local ts = TargetSelector(TARGET_LOW_HP, myHero.range)
  43.         OrbWalker:addAA()
  44.  
  45.         function OnTick()
  46.             ts:update()
  47.             OrbWalker:OrbWalk(mousePos, ts.target)
  48.         end
  49.  
  50.         function OnProcessSpell(unit, spell)
  51.             OrbWalker:OnProcessSpell(unit, spell)
  52.         end
  53.  
  54.     ]]--
  55.  
  56. class 'iOrbWalker'
  57.  
  58. STAGE_WINDUP = 1
  59. STAGE_ORBWALK = 2
  60. STAGE_NONE = 3
  61.  
  62. local iOWInstances = {}
  63.  
  64. function iOrbWalker:__init(AARange, useDefaultValues, addDelay)
  65.     self.AARange = AARange or (myHero.range + GetDistance(myHero.minBBox))
  66.     self.addDelay = addDelay or 20
  67.     self.ShotCast = 0
  68.     self.NextShot = 0
  69.     self.windUpTime = 0
  70.     self.animationTime = 0
  71.     if useDefaultValues then
  72.         self:addAA()
  73.         self:addReset()
  74.     end
  75.     iOWInstances[#iOWInstances+1] = self
  76.     if not iOW_OnProcessSpell then
  77.         function iOW_OnProcessSpell(unit, spell)
  78.             for _, iOWInstance in ipairs(iOWInstances) do
  79.                 iOWInstance:OnProcessSpell(unit, spell)
  80.             end
  81.         end
  82.         function iOW_OnAnimation(unit, animation)
  83.             for _, iOWInstance in ipairs(iOWInstances) do
  84.                 iOWInstance:OnAnimation(unit, animation)
  85.             end
  86.         end
  87.         AddProcessSpellCallback(iOW_OnProcessSpell)
  88.         AddAnimationCallback(iOW_OnAnimation)
  89.     end
  90. end
  91.  
  92. function iOrbWalker:__type()
  93.     return "iOrbWalker"
  94. end
  95.  
  96. --[[ Main Functions ]]--
  97.  
  98. function iOrbWalker:Orbwalk(movePos, target)
  99.     assert(movePos and movePos.x and movePos.z, "Error: iOrbWalker:Orbwalk(movePos, target), invalid movePos.")
  100.     if self:GetStage() == STAGE_NONE and ValidTarget(target, self.AARange) then
  101.         myHero:Attack(target)
  102.     elseif self:GetStage() ~= STAGE_WINDUP then
  103.         myHero:MoveTo(movePos.x, movePos.z)
  104.     end
  105. end
  106.  
  107. function iOrbWalker:Attack(target)
  108.     assert(not target or ValidTarget(target), "Error: iOrbWalker:Attack(target), invalid target.")
  109.     if self:GetStage() == STAGE_NONE and ValidTarget(target, self.AARange) then
  110.         myHero:Attack(target)
  111.         return true
  112.     end
  113.     return false
  114. end
  115.  
  116. function iOrbWalker:Move(movePos)
  117.     assert(movePos and movePos.x and movePos.z, "Error: iOrbWalker:Move(movePos), invalid movePos.")
  118.     if self:GetStage() ~= STAGE_WINDUP then
  119.         myHero:MoveTo(movePos.x, movePos.z)
  120.         return true
  121.     end
  122.     return false
  123. end
  124.  
  125. --[[ Manual Orbwalking (Placed in OnSendPacket) ]]--
  126.  
  127. function iOrbWalker:ManualOrbwalk(packet, rangeFromMouse)
  128.     assert(rangeFromMouse == nil or type(rangeFromMouse) == "number", "Error: iOrbWalker:ManualOrbwalk(packet, rangeFromMouse) -> <packet><number> expected.")
  129.     if packet.header == 0x71 then
  130.         if self:GetStage() == STAGE_WINDUP then
  131.             packet:Block()
  132.         elseif self:GetStage() == STAGE_ORBWALK then
  133.             local pPacket = Packet(packet)
  134.             packet:Block()
  135.             myHero:Move(pPacket.values.x, pPacket.values.z)
  136.             return {x = pPacket.values.x, z = pPacket.values.z}
  137.         else
  138.             local pPacket = Packet(packet)
  139.             packet:Block()
  140.             for _, enemy in ipairs(GetEnemyHeroes()) do
  141.                 if GetDistance(pPacket.values, enemy) < (rangeFromMouse or 50) then
  142.                     myHero:Attack(enemy)
  143.                     return enemy
  144.                 end
  145.             end
  146.         end
  147.     end
  148. end
  149.  
  150. function iOrbWalker:ManualBlock(packet)
  151.     if pack.header == 0x71 then
  152.         if self:GetStage() == STAGE_WINDUP then
  153.             packet:Block()
  154.         end
  155.     end
  156. end
  157.  
  158. --[[ Information ]]--
  159.  
  160. function iOrbWalker:GetStage()
  161.     if GetTickCount() > self.NextShot then return STAGE_NONE end
  162.     if GetTickCount() > self.ShotCast then return STAGE_ORBWALK end
  163.     return STAGE_WINDUP
  164. end
  165.  
  166. function iOrbWalker:GetDPS(unit, target)
  167.     local unit = unit or myHero
  168.     if target then
  169.         return unit.totalDamage and unit.attackSpeed and unit:CalcDamage(target, (1/(unit.attackSpeed * 0.625))*unit.totalDamage) or 0
  170.     else
  171.         return unit.totalDamage and unit.attackSpeed and (1/(unit.attackSpeed * 0.625))*unit.totalDamage or 0
  172.     end
  173. end
  174.  
  175. --[[ Configuration Functions ]]--
  176.  
  177. function iOrbWalker:addAA(AAName, isAnimation) -- Add AA spell
  178.     assert(AAName == nil or type(AAName) == "string", "Error: iOrbWalker:addAA(AAName, isAnimation), <string> or nil expected.")
  179.     if isAnimation then
  180.         if AAName then
  181.             if not self.AASpellsAnim then self.AASpellsAnim = {} end
  182.             self.AASpellsAnim[#self.AASpellsAnim+1] = AAName
  183.         end
  184.     else
  185.         if not self.AASpells then self.AASpells = {} end
  186.         if not AAName then
  187.             self.AASpells[#self.AASpells+1] = "attack"
  188.             if _customValues and _customValues.AASpells then
  189.                 if type(_customValues.AASpells[myHero.charName]) == "string" then
  190.                     self.AASpells[#self.AASpells+1] = _customValues.AASpells[myHero.charName]
  191.                 elseif type(_customValues.AASpells[myHero.charName]) == "table" then
  192.                     for _, AAName in ipairs(_customValues.AASpells[myHero.charName]) do
  193.                         self.AASpells[#self.AASpells+1] = AAName
  194.                     end
  195.                 end
  196.             end
  197.         else
  198.             self.AASpells[#self.AASpells+1] = AAName
  199.         end
  200.     end
  201. end
  202.  
  203. function iOrbWalker:removeAA(AAName, isAnimation) -- Remove AA spell
  204.     if isAnimation then
  205.         if self.AASpellsAnim then
  206.             for i, AAName2 in ipairs(self.AASpellsAnim) do
  207.                 if AAName2 == AAName then
  208.                     table.remove(self.AASpellsAnim, i)
  209.                     return
  210.                 end
  211.             end
  212.         end
  213.     elseif self.AASpells then
  214.         for i, AAName2 in ipairs(self.AASpells) do
  215.             if AAName2 == AAName then
  216.                 table.remove(self.AASpells, i)
  217.                 return
  218.             end
  219.         end
  220.     end
  221. end
  222.  
  223. function iOrbWalker:ignoreAA(AAName, isAnimation)
  224.     assert(type(resetName) == "string", "Error: iOrbWalker:ignoreAA(AAName), <string> expected.")
  225.     if isAnimation then
  226.         if not self.AASpellsIgnoreAnim then
  227.             self.AASpellsIgnoreAnim = {AAName}
  228.         else
  229.             self.AASpellsIgnoreAnim[#self.AASpellsIgnoreAnim+1] = AAName
  230.         end
  231.     elseif not self.AASpellsIgnore then
  232.         self.AASpellsIgnore = {AAName}
  233.     else
  234.         self.AASpellsIgnore[#self.AASpellsIgnore+1] = AAName
  235.     end
  236. end
  237.  
  238. function iOrbWalker:addReset(resetName, isAnimation) -- Add AA-timer resetting spell
  239.     --assert(type(resetName) == "string", "Error: iOrbWalker:addReset(resetName), <string> expected.")
  240.     if isAnimation then
  241.         if resetName then
  242.             if not self.ResetSpellsAnim then self.ResetSpellsAnim = {} end
  243.             self.ResetSpellsAnim[#self.ResetSpellsAnim+1] = resetName
  244.         end
  245.     else
  246.         if not self.ResetSpells then self.ResetSpells = {} end
  247.         if not resetName then
  248.             if _customValues and _customValues.ResetSpells then
  249.                 if type(_customValues.ResetSpells[myHero.charName]) == "string" then
  250.                     self.ResetSpells[#self.ResetSpells+1] = _customValues.ResetSpells[myHero.charName]
  251.                 elseif type(_customValues.ResetSpells[myHero.charName]) == "table" then
  252.                     for _, resetName in ipairs(_customValues.ResetSpells[myHero.charName]) do
  253.                         self.ResetSpells[#self.ResetSpells+1] = resetName
  254.                     end
  255.                 end
  256.             end
  257.         else
  258.             self.ResetSpells[#self.ResetSpells+1] = resetName
  259.         end
  260.     end
  261. end
  262.  
  263. function iOrbWalker:OnProcessSpell(unit, spell)
  264.     if unit.isMe then
  265.         if self.AASpellsIgnore then
  266.             for _, AAName in ipairs(self.AASpellsIgnore) do
  267.                 if spell.name:find(AAName) then return end
  268.             end
  269.         end
  270.         if self.ResetSpells then
  271.             for _, resetName in ipairs(self.ResetSpells) do
  272.                 if spell.name:find(resetName) then
  273.                     self.ShotCast = GetTickCount()
  274.                     self.NextShot = GetTickCount()
  275.                     return
  276.                 end
  277.             end
  278.         end
  279.         if self.AASpells and spell.windUpTime and spell.animationTime then
  280.             for _, AAName in ipairs(self.AASpells) do
  281.                 if AAName == "attack" and spell.name:lower():find("attack") then -- Simple lowercase checking for "attack" for the lazy people who don't want to search for all the basic attack names (like me)
  282.                     self.ShotCast = GetTickCount() + spell.windUpTime * 1000 - GetLatency() / 2 + self.addDelay
  283.                     self.NextShot = GetTickCount() + spell.animationTime * 1000
  284.                     self.windUpTime = spell.windUpTime
  285.                     self.animationTime = spell.animationTime
  286.                     return
  287.                 elseif spell.name:find(AAName) then
  288.                     self.ShotCast = GetTickCount() + spell.windUpTime * 1000 - GetLatency() / 2 + self.addDelay
  289.                     self.NextShot = GetTickCount() + spell.animationTime * 1000
  290.                     self.windUpTime = spell.windUpTime
  291.                     self.animationTime = spell.animationTime
  292.                     return
  293.                 end
  294.             end
  295.         end
  296.     end
  297. end
  298.  
  299. function iOrbWalker:OnAnimation(unit, animation)
  300.     if unit.isMe then
  301.         if self.AASpellsIgnoreAnim then
  302.             for _, AAName in ipairs(self.AASpellsIgnoreAnim) do
  303.                 if animation:find(AAName) then return end
  304.             end
  305.         end
  306.         if self.ResetSpellsAnim then
  307.             for _, resetName in ipairs(self.ResetSpellsAnim) do
  308.                 if animation:find(resetName) then
  309.                     self.ShotCast = GetTickCount()
  310.                     self.NextShot = GetTickCount()
  311.                     return
  312.                 end
  313.             end
  314.         end
  315.         if self.AASpellsAnim and self.windUpTime and self.animationTime then
  316.             for _, AAName in ipairs(self.AASpellsAnim) do
  317.                 if animation:find(AAName) then
  318.                     self.ShotCast = GetTickCount() + self.windUpTime * 1000 - GetLatency() / 2 + self.addDelay
  319.                     self.NextShot = GetTickCount() + self.animationTime * 1000
  320.                     return
  321.                 end
  322.             end
  323.         end
  324.     end
  325. end
  326.  
  327. --[[    iCaster Class
  328.    
  329.     Methods:
  330.         local Spell = iCaster(spell, range, spellType, [speed, delay, width, useCollisionLib])
  331.  
  332.         local Spell = iCaster(spell, range, SPELL_TARGETED)
  333.         local Spell = iCaster(spell, range, SPELL_LINEAR, speed, delay, [width])
  334.         local Spell = iCaster(spell, range, SPELL_CIRCLE, speed, delay, [width])
  335.         local Spell = iCaster(spell, range, SPELL_CONE)
  336.         local Spell = iCaster(spell, range, SPELL_LINEAR_COL, speed, delay, width, [useCollisionLib])
  337.         local Spell = iCaster(spell, range, SPELL_SELF)
  338.  
  339.     Functions:
  340.         Spell:Cast(target, [minHitChance])      -> Casts spell at target. minHitChance is for skillshots, will use 0 if omitted.
  341.         Spell:CastMouse(spellPos, [nearestTarget])      -> Casts spell at spellPos. nearestTarget is for SPELL_TARGETED to target the nearest enemy champion to spellPos.
  342.         Spell:AACast(iOrbWalker, target, [minHitChance])        -> Casts spell right after autoattack. Requires an iOrbWalker instance.
  343.         Spell:AACastMouse(iOrbWalker, spellPos, [nearestTarget])        -> Casts spell right after autoattack at spellPos. Requires an iOrbWalker instance.
  344.         Spell:Ready()       -> Returns true/false
  345.         Spell:GetPrediction(target)     -> Returns the prediction for target
  346.         Spell:GetCollision(spellPos)        -> Returns if the spell will collide.
  347.  
  348.     Members:
  349.         Spell.spell
  350.         Spell.range
  351.         Spell.spellType
  352.         Spell.speed
  353.         Spell.delay
  354.         Spell.width
  355.         Spell.spellData     -> Same information as myHero:GetSpellData(spell) at the time the instance was initiated.
  356.         Spell.pred          -> Prediction
  357.         Spell.coll          -> Collision lib
  358.  
  359.     Example:
  360.         local QSpell = iCaster(_Q, nil, SPELL_SELF)
  361.         local Orbwalker = iOrbWalker(myHero.range)
  362.  
  363.         function OnTick()
  364.             QSpell:AACast(Orbwalker)
  365.         end
  366.  
  367.     ]]--
  368.  
  369. class 'iCaster'
  370.  
  371. SPELL_TARGETED = 1
  372. SPELL_LINEAR = 2
  373. SPELL_CIRCLE = 3
  374. SPELL_CONE = 4
  375. SPELL_LINEAR_COL = 5
  376. SPELL_SELF = 6
  377.  
  378. function iCaster:__init(spell, range, spellType, speed, delay, width, useCollisionLib)
  379.     --assert(spell and (range or spellType == SPELL_SELF), "Error: iCaster:__init(spell, range, spellType, [speed, delay, width, useCollisionLib]), invalid arguments.")
  380.     self.spell = spell
  381.     self.range = range or 0
  382.     self.spellType = spellType or SPELL_SELF
  383.     self.speed = speed or math.huge
  384.     self.delay = delay or 0
  385.     self.width = width
  386.     self.spellData = myHero:GetSpellData(spell)
  387.     if spellType == SPELL_LINEAR or spellType == SPELL_CIRCLE or spellType == SPELL_LINEAR_COL then
  388.         --if type(range) == "number" and (not speed or type(speed) == "number") and (not delay type(delay) == "number" and (type(width) == "number" or not width) then
  389.             --assert(type(range) == "number" and type(speed) == "number" and type(delay) == "number" and (type(width) == "number" or not width), "Error: iCaster:__init(spell, range, [spellType, speed, delay, width, useCollisionLib]), invalid arguments for skillshot-type.")
  390.             self.pred = VIP_USER and TargetPredictionVIP(range, speed, delay, width) or TargetPrediction(range, speed/1000, delay*1000, width)
  391.             if spellType == SPELL_LINEAR_COL then
  392.                 self.coll = VIP_USER and useCollisionLib ~= false and Collision(range, (speed or math.huge), delay, width) or nil
  393.             end
  394.         --end
  395.     end
  396. end
  397.  
  398. function iCaster:__type()
  399.     return "iCaster"
  400. end
  401.  
  402. function iCaster:Data()
  403.     return myHero:GetSpellData(self.spell)
  404. end
  405.  
  406. function iCaster:Cast(target, minHitChance)
  407.     if myHero:CanUseSpell(self.spell) ~= READY then return false end
  408.     if self.spellType == SPELL_SELF then
  409.         CastSpell(self.spell)
  410.         return true
  411.     elseif self.spellType == SPELL_TARGETED then
  412.         if ValidTarget(target, self.range) then
  413.             CastSpell(self.spell, target)
  414.             return true
  415.         end
  416.     elseif self.spellType == SPELL_TARGETED_FRIENDLY then
  417.         if target ~= nil and not target.dead and GetDistance(target) < self.range and target.team == myHero.team then
  418.             CastSpell(self.spell, target)
  419.             return true
  420.         end
  421.     elseif self.spellType == SPELL_CONE then
  422.         if ValidTarget(target, self.range) then
  423.             CastSpell(self.spell, target.x, target.z)
  424.             return true
  425.         end
  426.     elseif self.spellType == SPELL_LINEAR or self.spellType == SPELL_CIRCLE then
  427.         if self.pred and ValidTarget(target) then
  428.             local spellPos,_ = self.pred:GetPrediction(target)
  429.             if spellPos and (not VIP_USER or not minHitChance or self.pred:GetHitChance(target) > minHitChance) then
  430.                 CastSpell(self.spell, spellPos.x, spellPos.z)
  431.                 return true
  432.             end
  433.         end
  434.     elseif self.spellType == SPELL_LINEAR_COL then
  435.         if self.pred and ValidTarget(target) then
  436.             local spellPos,_ = self.pred:GetPrediction(target)
  437.             if spellPos and (not VIP_USER or not minHitChance or self.pred:GetHitChance(target) > minHitChance) then
  438.                 if self.coll then
  439.                     local willCollide,_ = self.coll:GetMinionCollision(myHero, spellPos)
  440.                     if not willCollide then
  441.                         CastSpell(self.spell, spellPos.x, spellPos.z)
  442.                         return true
  443.                     end
  444.                 elseif not iCollision(spellPos, self.width) then
  445.                     CastSpell(self.spell, spellPos.x, spellPos.z)
  446.                     return true
  447.                 end
  448.             end
  449.         end
  450.     end
  451.     return false
  452. end
  453.  
  454. function iCaster:CastMouse(spellPos, nearestTarget)
  455.     assert(spellPos and spellPos.x and spellPos.z, "Error: iCaster:CastMouse(spellPos, nearestTarget), invalid spellPos.")
  456.     assert(self.spellType ~= SPELL_TARGETED or (nearestTarget == nil or type(nearestTarget) == "boolean"), "Error: iCaster:CastMouse(spellPos, nearestTarget), <boolean> or nil expected for nearestTarget.")
  457.     if myHero:CanUseSpell(self.spell) ~= READY then return false end
  458.     if self.spellType == SPELL_SELF then
  459.         CastSpell(self.spell)
  460.         return true
  461.     elseif self.spellType == SPELL_TARGETED then
  462.         if nearestTarget ~= false then
  463.             local targetEnemy
  464.             for _, enemy in ipairs(GetEnemyHeroes()) do
  465.                 if ValidTarget(targetEnemy, self.range) and (targetEnemy == nil or GetDistanceFromMouse(enemy) < GetDistanceFromMouse(targetEnemy)) then
  466.                     targetEnemy = enemy
  467.                 end
  468.             end
  469.             if targetEnemy then
  470.                 CastSpell(self.spell, targetEnemy)
  471.                 return true
  472.             end
  473.         end
  474.     elseif self.spellType == SPELL_LINEAR_COL or self.spellType == SPELL_LINEAR or self.spellType == SPELL_CIRCLE or self.spellType == SPELL_CONE then
  475.         CastSpell(self.spell, spellPos.x, spellPos.z)
  476.         return true
  477.     end
  478. end
  479.  
  480. function iCaster:AACast(iOW, target, minHitChance) -- Cast after AA
  481.     if not iOW then return false end
  482.     if iOW:GetStage() == STAGE_ORBWALK then
  483.         return self:Cast(target, minHitChance)
  484.     end
  485. end
  486.  
  487. function iCaster:AACastMouse(iOW, spellPos, nearestTarget)
  488.     if not iOW then return false end
  489.     if iOW:GetStage() == STAGE_ORBWALK then
  490.         return self:CastMouse(spellPos, nearestTarget)
  491.     end
  492. end
  493.  
  494. function iCaster:Ready()
  495.     return myHero:CanUseSpell(self.spell) == READY
  496. end
  497.  
  498. function iCaster:GetPrediction(target)
  499.     if self.pred and ValidTarget(target) then return self.pred:GetPrediction(target) end
  500. end
  501.  
  502. function iCaster:GetCollision(spellPos)
  503.     if spellPos and spellPos.x and spellPos.z then
  504.         if self.coll then
  505.             return self.coll:GetMinionCollision(myHero, spellPos)
  506.         else
  507.             return iCollision(spellPos, self.width)
  508.         end
  509.     end
  510. end
  511.  
  512. --[[ iSummoners Class - Credits to LoLZinga for the base
  513.  
  514.     Methods:
  515.         local Summoners = iSummoners()
  516.  
  517.     Functions
  518.         Summoners:Ready(spell)      -> Returns true/false
  519.         Summoners:AutoAll()         -> Automatically uses all summoner spells.
  520.         Summoners:AutoIgnite([dmgMultiplier])       -> Auto ignites killable enemies. dmgMultiplier is in percentages between 1 and 100, can be left omitted.
  521.         Summoners:AutoBarrier([maxHPPerc, procRate])        -> Auto barriers on high damage. maxHPPerc and procRate are in percentages. Will only use barrier if your health is below maxHPPerc%.
  522.         Summoners:AutoRevive([condition])       -> Auto revives you. Condition can be left omitted or should be a function returning true or false.
  523.         Summoners:AutoClarity([maxManaPerc, condition])     -> Auto uses clarity if your mana is below maxManaPerc%. Condition can be left omitted or should be a function returning a value.
  524.         Summoners:AutoHeal([maxHPPerc, procRate, useForTeam])       -> Auto heals you and your team. Works the same as AutoBarrier logically.
  525.         Summoners:Exhaust(target)       -> Exhausts the target.
  526.  
  527.     Members:
  528.         Summoners.SUMMONER_1
  529.         Summoners.SUMMONER_2
  530.         Summoners.Clarity
  531.         Summoners.Garrison
  532.         Summoners.Ghost
  533.         Summoners.Heal
  534.         Summoners.Revive
  535.         Summoners.Smite
  536.         Summoners.Cleanse
  537.         Summoners.Teleport
  538.         Summoners.Barrier
  539.         Summoners.Exhaust
  540.         Summoners.Ignite
  541.         Summoners.Clairvoyance
  542.         Summoners.Flash
  543.  
  544.         Sub-Members:
  545.             Summoners.<InsertSpellHere>.name
  546.             Summoners.<InsertSpellHere>.shortName
  547.             Summoners.<InsertSpellHere>.range
  548.             Summoners.<InsertSpellHere>.slot
  549.  
  550.     Example:
  551.         local Summoners = iSummoners()
  552.  
  553.         function OnTick()
  554.             Summoners:AutoAll()
  555.         end
  556.  
  557.     ]]--
  558.  
  559. class 'iSummoners'
  560. local _SummonerSpells = {
  561.     SummonerMana = {name = "SummonerMana", shortName = "Clarity", range = 600},
  562.     SummonerOdinGarrison = {name = "SummonerOdinGarrison", shortName = "Garrison", range = 1000},
  563.     SummonerHaste = {name = "SummonerHaste", shortName = "Ghost", range = nil},
  564.     SummonerHeal = {name = "SummonerHeal", shortName = "Heal", range = 300},
  565.     SummonerRevive = {name = "SummonerRevive", shortName = "Revive", range = nil},
  566.     SummonerSmite = {name = "SummonerSmite", shortName = "Smite", range = 625},
  567.     SummonerBoost = {name = "SummonerBoost", shortName = "Cleanse", range = nil},
  568.     SummonerTeleport = {name = "SummonerTeleport", shortName = "Teleport", range = nil},
  569.     SummonerBarrier = {name = "SummonerBarrier", shortName = "Barrier", range = nil},
  570.     SummonerExhaust = {name = "SummonerExhaust", shortName = "Exhaust", range = 550},
  571.     SummonerDot = {name = "SummonerDot", shortName = "Ignite", range = 600},
  572.     SummonerClairvoyance = {name = "SummonerClairvoyance", shortName = "Clairvoyance", range = nil},
  573.     SummonerFlash = {name = "SummonerFlash", shortName = "Flash", range = 400}
  574. }
  575.  
  576. function iSummoners:__init()
  577.     self.SUMMONER_1 = _SummonerSpells[myHero:GetSpellData(SUMMONER_1).name]
  578.     self.SUMMONER_1.slot = SUMMONER_1
  579.     self.SUMMONER_2 = _SummonerSpells[myHero:GetSpellData(SUMMONER_2).name]
  580.     self.SUMMONER_2.slot = SUMMONER_2
  581.     self[self.SUMMONER_1.shortName] = self.SUMMONER_1
  582.     self[self.SUMMONER_2.shortName] = self.SUMMONER_2
  583. end
  584.  
  585. function iSummoners:__type()
  586.     return "iSummoners"
  587. end
  588.  
  589. function iSummoners:Ready(spell)
  590.     if type(spell) == "number" then
  591.         if spell == 1 or spell == 2 then
  592.             return myHero:CanUseSpell(self["SUMMONER_"..spell].slot) == READY
  593.         elseif spell == SUMMONER_1 or spell == SUMMONER_2 then
  594.             return myHero:CanUseSpell(spell) == READY
  595.         end
  596.     elseif type(spell) == "string" then
  597.         if self[spell] then
  598.             return myHero:CanUseSpell(self[spell].slot) == READY
  599.         end
  600.     end
  601.     return false
  602. end
  603.  
  604. function iSummoners:AutoAll()
  605.     self:AutoIgnite()
  606.     self:AutoBarrier()
  607.     self:AutoRevive()
  608.     self:AutoClarity()
  609.     self:AutoHeal()
  610. end
  611.  
  612. function iSummoners:AutoIgnite(dmgMultiplier)
  613.     assert(not dmgMultiplier or (type(dmgMultiplier) == "number" and dmgMultiplier <= 100 and dmgMultiplier > 0), "Error: iSummoners:AutoIgnite(dmgMultiplier, invalid dmgMultiplier.")
  614.     if self.Ignite and not myHero.dead and myHero:CanUseSpell(self.Ignite.slot) == READY then
  615.         local dmgMultiplier = dmgMultiplier and dmgMultiplier / 100 or 1
  616.         for _, enemy in ipairs(GetEnemyHeroes()) do
  617.             if ValidTarget(enemy, self.Ignite.range) and getDmg("IGNITE", enemy, myHero) * dmgMultiplier > enemy.health then
  618.                 CastSpell(self.Ignite.slot, enemy)
  619.             end
  620.         end
  621.     end
  622. end
  623.  
  624. function iSummoners:AutoBarrier(maxHPPerc, procRate)
  625.     assert(not maxHPPerc or (type(maxHPPerc) == "number" and maxHPPerc <= 100 and maxHPPerc > 0), "Error: iSummoners:AutoBarrier(maxHPPerc, procRate), invalid maxHPPerc.")
  626.     assert(not procRate or (type(procRate) == "number" and procRate <= 100 and procRate > 0), "Error: iSummoners:AutoBarrier(maxHPPerc, procRate), invalid procRate.")
  627.     if self.Barrier then
  628.         local maxHPPerc = maxHPPerc and maxHPPerc / 100 or 0.3
  629.         local procRate = procRate and procRate / 100 or 0.3
  630.         if not self.Barrier.nextCheck then self.Barrier.nextCheck = 0 end
  631.         if not self.Barrier.healthBefore then
  632.             self.Barrier.healthBefore = {}
  633.         elseif GetTickCount() >= self.Barrier.nextCheck then
  634.             if myHero:CanUseSpell(self.Barrier.slot) == READY and #self.Barrier.healthBefore > 1 then
  635.                 local HPRatio = myHero.health / myHero.maxHealth
  636.                 local procHP = self.Barrier.healthBefore[1] * procRate
  637.                 if myHero.health < procHP and maxHPPerc < HPRatio then
  638.                     CastSpell(self.Barrier.slot)
  639.                 end
  640.             end
  641.             self.Barrier.nextCheck = GetTickCount() + 100
  642.             self.Barrier.healthBefore[#self.Barrier.healthBefore+1] = myHero.health
  643.             if #self.Barrier.healthBefore > 10 then
  644.                 table.remove(self.Barrier.healthBefore, 1)
  645.             end
  646.         end
  647.     end
  648. end
  649.  
  650. function iSummoners:AutoRevive(condition)
  651.     assert(not condition or type(condition) == "function", "Error: iSummoners:AutoRevive(condition), invalid condition.")
  652.     if self.Revive and myHero.dead and myHero:CanUseSpell(self.Revive.slot) == READY and (not condition or condition()) then
  653.         CastSpell(self.Revive.slot)
  654.     end
  655. end
  656.  
  657. function iSummoners:AutoClarity(maxManaPerc, condition)
  658.     assert(not maxManaPerc or (type(maxManaPerc) == "number" and maxManaPerc <= 100 and maxManaPerc > 0), "Error: iSummoners:AutoClarity(maxManaPerc), invalid maxManaPerc.")
  659.     if self.Clarity then
  660.         local maxManaPerc = maxManaPerc and maxManaPerc / 100 or 0.3
  661.         if myHero:CanUseSpell(self.Clarity.slot) == READY and myHero.mana / myHero.maxMana < maxManaPerc and (not condition or condition()) then
  662.             CastSpell(self.Clarity.slot)
  663.         end
  664.     end
  665. end
  666.  
  667. function iSummoners:AutoHeal(maxHPPerc, procRate, useForTeam)
  668.     assert(not maxHPPerc or (type(maxHPPerc) == "number" and maxHPPerc <= 100 and maxHPPerc > 0), "Error: iSummoners:AutoHeal(maxHPPerc, procRate, useForTeam), invalid maxHPPerc.")
  669.     assert(not procRate or (type(procRate) == "number" and procRate <= 100 and procRate > 0), "Error: iSummoners:AutoHeal(maxHPPerc, procRate, useForTeam), invalid procRate.")
  670.     assert(useForTeam == nil or type(useForTeam) == "boolean", "Error: iSummoners:AutoHeal(maxHPPerc, procRate, useForTeam), invalid useForTeam")
  671.     if self.Heal then
  672.         local maxHPPerc = maxHPPerc and maxHPPerc / 100 or 0.3
  673.         local procRate = procRate and procRate / 100 or 0.3
  674.         local useForTeam = useForTeam ~= false
  675.         if not self.Heal.nextCheck then self.Heal.nextCheck = 0 end
  676.         if not self.Heal.healthBefore then
  677.             self.Heal.healthBefore = {}
  678.             for _, ally in ipairs(GetAllyHeroes()) do
  679.                 self.Heal.healthBefore[ally.charName] = {}
  680.             end
  681.             self.Heal.healthBefore[myHero.charName] = {}
  682.         elseif GetTickCount() >= self.Heal.nextCheck then
  683.             if myHero:CanUseSpell(self.Heal.slot) == READY and #self.Heal.healthBefore[myHero.charName] > 1then
  684.                 local HPRatio = myHero.health / myHero.maxHealth
  685.                 local procHP = self.Heal.healthBefore[myHero.charName][1] * procRate
  686.                 if myHero.health < procHP and maxHPPerc < HPRatio then
  687.                     CastSpell(self.Heal.slot)
  688.                 end
  689.                 if useForTeam then
  690.                     for _, ally in ipairs(GetAllyHeroes()) do
  691.                         if GetDistance(ally) < self.Heal.range and not ally.dead then
  692.                             local HPRatio = ally.health / ally.maxHealth
  693.                             local procHP = self.Heal.healthBefore[ally.charName][1] * procRate
  694.                             if ally.health < procHP and maxHPPerc < HPRatio then
  695.                                 CastSpell(self.Heal.slot)
  696.                             end
  697.                         end
  698.                     end
  699.                 end
  700.             end
  701.             self.Heal.nextCheck = GetTickCount() + 100
  702.             self.Heal.healthBefore[myHero.charName][#self.Heal.healthBefore[myHero.charName]+1] = myHero.health
  703.             if #self.Heal.healthBefore[myHero.charName] > 10 then
  704.                 table.remove(self.Heal.healthBefore[myHero.charName], 1)
  705.             end
  706.             for _, ally in ipairs(GetAllyHeroes()) do
  707.                 self.Heal.healthBefore[ally.charName][#self.Heal.healthBefore[ally.charName]+1] = ally.health
  708.                 if #self.Heal.healthBefore[ally.charName] > 10 then
  709.                     table.remove(self.Heal.healthBefore[ally.charName], 1)
  710.                 end
  711.             end
  712.         end
  713.     end
  714. end
  715.  
  716. function iSummoners:Exhaust(target) -- No AutoExhaust until I find a reliable logic. (No, AutoExhaust anyone below 50% HP is NOT reliable...)
  717.     if self.Exhaust and ValidTarget(target, self.Exhaust.range) and myHero:CanUseSpell(self.Exhaust.slot) then
  718.         CastSpell(self.Exhaust.slot, target)
  719.     end
  720. end
  721.  
  722. --[[ iTems Class
  723.  
  724.     Methods:
  725.         local Items = iTems()
  726.  
  727.     Functions:
  728.         Items:add(name, ID, [range, extraOptions])  -> Adds an item to the instance. Name and ID required, range and extraOptions optional.
  729.         Items:update()                              -> Update the instance. Item ready statusses and slots.
  730.         Items:Have(itemID, [unit])                  -> Check if the unit has the item. Returns true/false.
  731.         Items:Slot(itemID, [unit])                  -> Check if the unit has the item. Returns true/false.
  732.         Items:Dmg(itemID, target, [source])         -> Returns the damage the item will deal on the target. Source optional, uses myHero if omitted.
  733.         Items:InRange(itemID, target, [source])     -> Check if the target is within range. Returns true/false.
  734.        
  735.         Items:Use(itemID, [nil, nil, condition])    -> Use the item(s). Condition is optional, should be a function returning a boolean if used.
  736.         Items:Use(itemID, target, [nil, condition]) -> itemID can be "all" if you wish to use all items.
  737.         Items:Use(itemID, pos.x, pos.z,[condition]) ->
  738.  
  739.     Members:
  740.         Items.items     -- Returns the table with all added items.
  741.    
  742.     Example Usage:
  743.         local items = iTems()
  744.        
  745.         function OnLoad()
  746.             items:add("DFG", 3128, 600, {onlyOnKill = true})
  747.         end
  748.  
  749.         function OnTick()
  750.             if ValidTarget(GetTarget()) then
  751.                 items:Use("DFG", GetTarget(), nil, (function(item, target) return (target.health / target.maxHealth > 0.5) end))
  752.             end
  753.         end
  754.  
  755.     ]]--
  756.  
  757. class 'iTems'
  758.  
  759. local itemsAliasForDmgCalc = { -- Item Aliases for spellDmg lib, including their corresponding itemID's.
  760.     ["DFG"] = 3128,
  761.     ["HXG"] = 3146,
  762.     ["BWC"] = 3144,
  763.     ["HYDRA"] = 3074,
  764.     ["SHEEN"] = 3057,
  765.     ["KITAES"] = 3186,
  766.     ["TIAMAT"] = 3077,
  767.     ["NTOOTH"] = 3115,
  768.     ["SUNFIRE"] = 3068,
  769.     ["WITSEND"] = 3091,
  770.     ["TRINITY"] = 3078,
  771.     ["STATIKK"] = 3087,
  772.     ["ICEBORN"] = 3025,
  773.     ["MURAMANA"] = 3042,
  774.     ["LICHBANE"] = 3100,
  775.     ["LIANDRYS"] = 3151,
  776.     ["BLACKFIRE"] = 3188,
  777.     ["HURRICANE"] = 3085,
  778.     ["RUINEDKING"] = 3153,
  779.     ["LIGHTBRINGER"] = 3185,
  780.     ["SPIRITLIZARD"] = 3209,
  781.     --["ENTROPY"] = 3184,
  782. }
  783.  
  784. function iTems:__init()
  785.     self.items = {}
  786. end
  787.  
  788. function iTems:__type()
  789.     return "iTems"
  790. end
  791.  
  792.  
  793. function iTems:add(name, ID, range, extraOptions)
  794.     assert(type(name) == "string" and type(ID) == "number" and (not range or range == math.huge or type(range) == "number") and (extraOptions == nil or type(extraOptions) == "table"))
  795.     self.items[name] = {ID = ID, range = range or math.huge, slot = nil, ready = false}
  796.     if extraOptions then
  797.         for key, value in pairs(extraOptions) do
  798.             self.items[name][key] = value
  799.         end
  800.     end
  801. end
  802.  
  803. function iTems:update()
  804.     for _, item in pairs(self.items) do
  805.         item.slot = GetInventorySlotItem(item.ID)
  806.         item.ready = (item.slot and myHero:CanUseSpell(item.slot) == READY or false)
  807.     end
  808. end
  809.  
  810. function iTems:Ready(itemID)
  811.     if type(itemID) == "string" then return (self.items[itemID] and self.items[itemID].ready) end
  812.     if type(itemID) == "number" then
  813.         for _, item in pairs(self.items) do
  814.             if itemID == item.ID then
  815.                 return item.ready
  816.             end
  817.         end
  818.     end    
  819. end
  820.  
  821. function iTems:Have(itemID, unit)
  822.     return GetInventorySlotItem(type(itemID) == "string" and self.items[itemID].ID or type(itemID) == "number" and itemID, unit) ~= nil
  823. end
  824.  
  825. function iTems:Slot(itemID, unit)
  826.     return GetInventorySlotItem(type(itemID) == "string" and self.items[itemID].ID or type(itemID) == "number" and itemID, unit)
  827. end
  828.  
  829. function iTems:Dmg(itemID, target, source)
  830.     if type(itemID) == "string" then
  831.         if itemsAliasForDmgCalc[itemID] ~= nil then return getDmg(itemID, target, source or myHero) end
  832.         if self.items[itemID] then
  833.             for itemName, aliasID in pairs(itemsAliasForDmgCalc) do
  834.                 if self.items[itemID].ID == aliasID then return getDmg(itemName, target, source or myHero) end
  835.             end
  836.         end
  837.     elseif type(itemID) == "number" then
  838.         for itemName, aliasID in pairs(itemsAliasForDmgCalc) do
  839.             if itemID == aliasID then return getDmg(itemName, target, source or myHero) end
  840.         end
  841.     end
  842.     return 0
  843. end
  844.  
  845. function iTems:InRange(itemID, enemy, source)
  846.     if type(itemID) == "string" then return (self.items[itemID] and (not self.items[itemID].range or self.items[itemID].range > GetDistance(enemy, source or myHero))) end
  847.     if type(itemID) == "number" then
  848.         for _, item in pairs(self.items) do
  849.             if itemID == item.ID then
  850.                 return (not item.range or item.range > GetDistance(enemy, source or myHero))
  851.             end
  852.         end
  853.     end    
  854. end
  855.  
  856. function iTems:Use(itemID, arg1, arg2, condition) -- Condition could be a function, such as (function(item) return item.slot ~= ITEM_6 end) or perhaps (function(item, target) return (target.health / target.maxHealth > 0.5) end)
  857.     for itemName, item in pairs(self.items) do
  858.         if type(itemID) == "string" and (itemID == "all" or itemID == itemName) or type(itemID) == "number" and itemID == item.ID then
  859.             if item.ready and (condition == nil or condition(item, arg1, arg2)) then
  860.                 if arg2 then
  861.                     CastSpell(item.slot, arg1, arg2)
  862.                 elseif arg1 then
  863.                     if self:InRange(itemName, arg1) then
  864.                         CastSpell(item.slot, arg1)
  865.                     end
  866.                 else
  867.                     CastSpell(item.slot)
  868.                 end
  869.             end
  870.         end
  871.     end
  872. end
  873.  
  874. --[[    iMinionsOLD Class
  875.    
  876.     Methods:
  877.         local Minions = iMinionsOLD(range, [includeAD])     -> Include AA damage if true or omitted. Set to false if you wish to use an instance for spells and not include AA damage.
  878.  
  879.     Functions:
  880.         Minions:update()        -> Update the iMinions instance.
  881.         Minions:setADDmg(damage)        -> Set additional on-hit AD damage
  882.         Minions:setAPDmg(damage)        -> Set additional on-hit AP damage
  883.         Minions:setTrueDmg(damage)      -> Set additional on-hit True damage
  884.         Minions:marker(radius, colour, [thickness])     -> Draws circles around the killable minions. Place in OnDraw.
  885.         Minions:LastHit(range, [condition])         -> Last hits the killable minions. (Very basic) Use condition for more advanced configurability. condition must be a function or left omitted.
  886.         Minions:LastHitMove(movePos, range, [condition])        -> Same as Minions:LastHit, will move to movePos if no target.
  887.  
  888.     Example:
  889.         local Minions = iMinionsOLD(1000)
  890.  
  891.         function OnDraw()
  892.             Minions:update()
  893.             Minions:marker(50, 0xFF80FF00, 10)
  894.         end
  895.  
  896. ]]--
  897.  
  898. class 'iMinionsOLD'
  899.  
  900. function iMinionsOLD:__init(range, includeAD) -- includeAD adds myHero.totalDamage for AA's. Set to false if you wish to use iMinions for spells.
  901.     enemyMinions_update(range)
  902.     self.includeAD = includeAD ~= false
  903.     self.ADDmg, self.APDmg, self.TrueDmg = 0, 0, 0
  904.     self.killable = {}
  905. end
  906.  
  907. function iMinionsOLD:setADDmg(damage) -- For additional on-hit AD damage
  908.     self.ADDmg = damage or 0
  909. end
  910.  
  911. function iMinionsOLD:setAPDmg(damage) -- For additional on-hit AP damage
  912.     self.APDmg = damage or 0
  913. end
  914.  
  915. function iMinionsOLD:setTrueDmg(damage) -- For additional on-hit True damage
  916.     self.TrueDmg = damage or 0
  917. end
  918.  
  919. function iMinionsOLD:update()
  920.     enemyMinions_update()
  921.     self.killable = {}
  922.     for _, minion in ipairs(_enemyMinions.objects) do
  923.         if ValidTarget(minion) then
  924.             local damage = ((self.includeAD or self.ADDmg ~= 0) and (myHero:CalcDamage(minion, (self.includeAD and myHero.totalDamage or 0) + self.ADDmg)) or 0) + (self.APDmg ~= 0 and myHero:CalcMagicDamage(minion, self.APDmg) or 0) + self.TrueDmg
  925.             if damage > minion.health then
  926.                 self.killable[#self.killable+1] = minion
  927.             end
  928.         end
  929.     end
  930.     return self.killable
  931. end
  932.  
  933. function iMinionsOLD:marker(radius, colour, thickness)
  934.     if self.killable then
  935.         for _, minion in ipairs(self.killable) do
  936.             if thickness and thickness > 1 then
  937.                 for i = 1, thickness do
  938.                     DrawCircle(minion.x, minion.y, minion.z, radius+i, colour)
  939.                 end
  940.             else
  941.                 DrawCircle(minion.x, minion.y, minion.z, radius, colour)
  942.             end
  943.         end
  944.     end
  945. end
  946.  
  947. function iMinionsOLD:LastHit(range, condition) -- Very basic, too tired to expand now.
  948.     if self.killable then
  949.         for _, minion in ipairs(self.killable) do
  950.             if GetDistance(minion) < range and (not condition or condition(minion)) then
  951.                 myHero:Attack(minion)
  952.                 return minion
  953.             end
  954.         end
  955.     end
  956.     return nil
  957. end
  958.  
  959. function iMinionsOLD:LastHitMove(movePos, range, condition)
  960.     assert(movePos and movePos.x and movePos.z, "Error: iMinions:LastHitMove(movePos, range, condition), invalid movePos.")
  961.     if self.killable then
  962.         for _, minion in ipairs(self.killable) do
  963.             if GetDistance(minion) < range and (not condition or condition(minion)) then
  964.                 myHero:Attack(minion)
  965.                 return minion
  966.             end
  967.         end
  968.     end
  969.     myHero:MoveTo(movePos.x, movePos.z)
  970. end
  971.  
  972. --[[ Other General Functions ]]--
  973.  
  974. local _enemyMinions, _enemyMinionsUpdateDelay, _lastMinionsUpdate = nil, 0, 0
  975. function enemyMinions_update(range)
  976.     if not _enemyMinions then
  977.         _enemyMinions = minionManager(MINION_ENEMY, (range or 2000), myHero, MINION_SORT_HEALTH_ASC)
  978.     elseif range and range > _enemyMinions.range then
  979.         _enemyMinions.range = range
  980.     end
  981.     if _lastMinionsUpdate + _enemyMinionsUpdateDelay < GetTickCount() then
  982.         _enemyMinions:update()
  983.         _lastMinionsUpdate = GetTickCount()
  984.     end
  985. end
  986.  
  987. function enemyMinions_setDelay(delay)
  988.     _enemyMinionsUpdateDelay = delay or 0
  989. end
  990.  
  991. function getEnemyMinions()
  992.     enemyMinions_update()
  993.     return _enemyMinions.objects
  994. end
  995.  
  996. local jungleCamps = {
  997.     ["TT_Spiderboss7.1.1"] = true,
  998.     ["Worm12.1.1"] = true,
  999.     ["Dragon6.1.1"] = true,
  1000.     ["AncientGolem1.1.1"] = true,
  1001.     ["AncientGolem7.1.1"] =  true,
  1002.     ["LizardElder4.1.1"] =  true,
  1003.     ["LizardElder10.1.1"] = true,
  1004.     ["GiantWolf2.1.3"] = true,
  1005.     ["GiantWolf8.1.3"] = true,
  1006.     ["Wraith3.1.3"] = true,
  1007.     ["Wraith9.1.3"] = true,
  1008.     ["Golem5.1.2"] = true,
  1009.     ["Golem11.1.2"] = true,
  1010. }
  1011. local _jungleMinions = nil
  1012. function getJungleMinions()
  1013.     if not _jungleMinions then
  1014.         _jungleMinions = {}
  1015.         for i = 1, objManager.maxObjects do
  1016.             local object = objManager:getObject(i)
  1017.             if object and object.type == "obj_AI_Minion" and object.name and jungleCamps[object.name] then
  1018.                 _jungleMinions[#_jungleMinions+1] = object
  1019.             end
  1020.         end
  1021.         function jungleMinions_OnCreateObj(object)
  1022.             if object and object.type == "obj_AI_Minion" and object.name and jungleCamps[object.name] then
  1023.                 _jungleMinions[#_jungleMinions+1] = object
  1024.             end
  1025.         end
  1026.         function jungleMinions_OnDeleteObj(object)
  1027.             if object and object.type == "obj_AI_Minion" and object.name and jungleCamps[object.name] then
  1028.                 for i, minion in ipairs(_jungleMinions) do
  1029.                     if minion.name == object.name then
  1030.                         table.remove(_jungleMinions, i)
  1031.                     end
  1032.                 end
  1033.             end
  1034.         end
  1035.         AddCreateObjCallback(jungleMinions_OnCreateObj)
  1036.         AddDeleteObjCallback(jungleMinions_OnDeleteObj)
  1037.     end
  1038.     return _jungleMinions
  1039. end
  1040.  
  1041. function iCollision(endPos, width) -- Derp collision, altered a bit for own readability.
  1042.     enemyMinions_update()
  1043.     if not endPos or not width then return end
  1044.     for _, minion in pairs(_enemyMinions.objects) do
  1045.         if ValidTarget(minion) and myHero.x ~= minion.x then
  1046.             local myX = myHero.x
  1047.             local myZ = myHero.z
  1048.             local tarX = endPos.x
  1049.             local tarZ = endPos.z
  1050.             local deltaX = myX - tarX
  1051.             local deltaZ = myZ - tarZ
  1052.             local m = deltaZ/deltaX
  1053.             local c = myX - m*myX
  1054.             local minionX = minion.x
  1055.             local minionZ = minion.z
  1056.             local distanc = (math.abs(minionZ - m*minionX - c))/(math.sqrt(m*m+1))
  1057.             if distanc < width and ((tarX - myX)*(tarX - myX) + (tarZ - myZ)*(tarZ - myZ)) > ((tarX - minionX)*(tarX - minionX) + (tarZ - minionZ)*(tarZ - minionZ)) then
  1058.                 return true
  1059.             end
  1060.         end
  1061.    end
  1062.    return false
  1063. end
  1064.  
  1065. --[[ iMinions Class - Rewritten - Credits to Sida, logic is taken from Sida's Auto Carry ]]--
  1066.  
  1067. class 'iMinions'
  1068.  
  1069. local _minionAttacks, _incomingDamage = {obj_AI_Turret = {aaDelay = 150, projSpeed = 1.14}}, {}
  1070. _minionAttacks[(myHero.team == TEAM_BLUE and "Blue" or "Red").."_Minion_Basic"] = {aaDelay = 400, projSpeed = math.huge}
  1071. _minionAttacks[(myHero.team == TEAM_BLUE and "Blue" or "Red").."_Minion_Caster"] = {aaDelay = 484, projSpeed = 0.68}
  1072. _minionAttacks[(myHero.team == TEAM_BLUE and "Blue" or "Red").."_Minion_Wizard"] = {aaDelay = 484, projSpeed = 0.68}
  1073. _minionAttacks[(myHero.team == TEAM_BLUE and "Blue" or "Red").."_Minion_MechCannon"] = {aaDelay = 365, projSpeed = 1.18}
  1074.  
  1075. function iMinions:__init(range, iOW, projSpeed)
  1076.     local range = range or 1000
  1077.     enemyMinions_update(range)
  1078.     self.range = range
  1079.     self.projSpeed = projSpeed or (_customValues and _customValues.projSpeeds and _customValues.projSpeeds[myHero.charName]) or math.huge
  1080.     self.ADDmg, self.APDmg, self.TrueDmg = 0, 0, 0
  1081.     self.iOW = iOW or iOrbWalker(myHero.range)
  1082.     iMinions_AddProcSpell()
  1083. end
  1084.  
  1085. function iMinions:__type()
  1086.     return "iMinions"
  1087. end
  1088.  
  1089. function iMinions:AddSpell(iSpell)
  1090.     assert(iSpell:__type() == "iCaster", "Error: iMinions:AddSpell(iSpell), <iCaster> expected.")
  1091.  
  1092. end
  1093.  
  1094. function iMinions:SetBonusDmg(PhysDamage, MagicDamage, TrueDamage)
  1095.     self.ADDmg = PhysDamage or self.ADDmg
  1096.     self.APDmg = MagicDamage or self.APDmg
  1097.     self.TrueDmg = TrueDamage or self.TrueDmg
  1098. end
  1099.  
  1100. function iMinions:SimpleLastHit(range)
  1101.     enemyMinions_update()
  1102.     for _, minion in ipairs(_enemyMinions.objects) do
  1103.         if ValidTarget(minion, range) then
  1104.             local AADamage = getDmg("AD", minion, myHero) + (self.ADDmg > 0 and myHero:CalcDamage(minion, self.ADDmg) or 0)+ (self.APDmg > 0 and myHero:CalcMagicDamage(minion, self.APDmg) or 0) + self.TrueDmg
  1105.             if AADamage > minion.health then
  1106.                 myHero:Attack(minion)
  1107.                 return minion
  1108.             end
  1109.         end
  1110.     end
  1111. end
  1112.  
  1113. function iMinions:Marker(range, radius, colour, thickness)
  1114.     enemyMinions_update()
  1115.     for _, minion in ipairs(_enemyMinions.objects) do
  1116.         if ValidTarget(minion, range) then
  1117.             local AADamage = getDmg("AD", minion, myHero) + (self.ADDmg > 0 and myHero:CalcDamage(minion, self.ADDmg) or 0)+ (self.APDmg > 0 and myHero:CalcMagicDamage(minion, self.APDmg) or 0) + self.TrueDmg
  1118.             if AADamage > minion.health then
  1119.                 if thickness and thickness > 1 then
  1120.                     for i = 1, thickness do
  1121.                         DrawCircle(minion.x, minion.y, minion.z, radius+i, colour)
  1122.                     end
  1123.                 else
  1124.                     DrawCircle(minion.x, minion.y, minion.z, radius, colour)
  1125.                 end
  1126.             end
  1127.         end
  1128.     end
  1129. end
  1130.  
  1131. function iMinions:LastHit(range, movePos, iOW)
  1132.     assert(range == nil or type(range) == "number", "Error: iMinions:LastHit(range, movePos), <number> or nil expected for range.")
  1133.     assert(movePos == nil or (movePos.x and movePos.z), "Error: iMinions:LastHit(range, movePos), invalid movePos.")
  1134.     --assert(Orbwalker and Orbwalker:__type() == "iOrbWalker", "Error: iMinions:LastHit(Orbwalker, range, movePos), invalid Orbwalker.")
  1135.     enemyMinions_update()
  1136.     if not ValidTarget(self.target) then self.target = self:GetNewCreep(1, range) end
  1137.     if movePos then iOW:Orbwalk(movePos, self.target) else iOW:Attack(self.target) end
  1138. end
  1139.  
  1140. function iMinions:GetNewCreep(index, range)
  1141.     if not index then return end
  1142.     local minion = _enemyMinions.objects[index]
  1143.     if ValidTarget(minion, range) then
  1144.         local predictedDamage = self:GetPredictedDamage(minion)
  1145.         local AADamage = getDmg("AD", minion, myHero) + myHero:CalcDamage(minion, self.ADDmg) + myHero:CalcMagicDamage(minion, self.APDmg) + self.TrueDmg
  1146.         if minion.health > predictedDamage and AADamage + predictedDamage > minion.health then
  1147.             return minion
  1148.         end
  1149.     end
  1150.     if index < #_enemyMinions.objects then
  1151.         return self:GetNewCreep(index + 1, range)
  1152.     end
  1153.     return nil
  1154. end
  1155.  
  1156. function iMinions:GetPredictedDamage(minion)
  1157.     local predictedDamage = 0
  1158.     for i, attack in ipairs(_incomingDamage) do
  1159.         if not attack.target or not attack.source or attack.target.dead or attack.source.dead or GetDistanceSqr(attack.source, attack.origin) > 9 then
  1160.             table.remove(_incomingDamage, i)
  1161.         elseif minion.networkID == attack.target.networkID then
  1162.             local myTimeToHit = (self.projSpeed < math.huge and GetDistance(minion) / self.projSpeed or 0) + GetLatency() / 2 + (self.iOW and self.iOW.windUpTime or 500 / (myHero.attackSpeed * 0.625))
  1163.             local minionTimeToHit = attack.delay + GetDistance(attack.source, minion) / attack.speed
  1164.             if attack.started + minionTimeToHit < GetTickCount() then
  1165.                 table.remove(_incomingDamage, i)
  1166.             elseif GetTickCount() + myTimeToHit > attack.started + minionTimeToHit then
  1167.                 predictedDamage = predictedDamage + attack.damage
  1168.             end
  1169.         end
  1170.     end
  1171.     return predictedDamage
  1172. end
  1173.  
  1174. function iMinions_AddProcSpell()
  1175.     if not iMinions_OnProcessSpell then
  1176.         function iMinions_OnProcessSpell(unit, spell)
  1177.             enemyMinions_update()
  1178.             if unit and (unit.type == "obj_AI_Minion" or unit.type == "obj_AI_Turret") and unit.team == myHero.team then
  1179.                 for _, minion in ipairs(_enemyMinions.objects) do
  1180.                     if ValidTarget(minion) and GetDistanceSqr(minion, spell.endPos) < 9 then
  1181.                         if _minionAttacks[unit.charName] or unit.type == "obj_AI_turret" then
  1182.                             _incomingDamage[#_incomingDamage+1] = iMinions_getNewAttackDetails(unit, minion)
  1183.                         end
  1184.                     end
  1185.                 end
  1186.             end
  1187.         end
  1188.         AddProcessSpellCallback(iMinions_OnProcessSpell)
  1189.     end
  1190. end
  1191.  
  1192. function iMinions_getNewAttackDetails(source, target)
  1193.     return  {
  1194.         source = source,
  1195.         target = target,
  1196.         damage = source:CalcDamage(target),
  1197.         started = GetTickCount(),
  1198.         origin = {x = source.x, z = source.z},
  1199.         delay = source.type == "obj_AI_Turret" and minionAttacks.obj_AI_Turret.aaDelay or minionAttacks[source.charName].aaDelay,
  1200.         speed = source.type == "obj_AI_Turret" and minionAttacks.obj_AI_Turret.projSpeed or minionAttacks[source.charName].projSpeed,
  1201.         --sourceType = source.type,
  1202.     }
  1203. end
  1204.  
  1205. --[[ To do:
  1206.    
  1207.     - Add spell support to iMinions
  1208.  
  1209. ]]--
Advertisement
Add Comment
Please, Sign In to add comment