Advertisement
mikeyy

HEMA01_AIActions.lua - TB Build Mode Check

Jun 24th, 2011
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --Get TB's skill build mode - hybrid, fire, or ice
  2. function GetBuildAbilityMode(unit)
  3.     if not unit.BuildAbilityMode then
  4.         local build = string.lower(unit:GetAIBrain().SkillBuild or 'none')
  5.         local fire = string.find(build, 'fire')
  6.         local ice = string.find(build, 'ice')
  7.         local hybrid = string.find(build, 'hybrid')
  8.         if hybrid or (ice and fire) then
  9.             unit.BuildAbilityMode = 'hybrid'
  10.         elseif ice then
  11.             unit.BuildAbilityMode = 'ice'
  12.         elseif fire then
  13.             unit.BuildAbilityMode = 'fire'
  14.         end
  15.         LOG("GetBuildAbilityMode: Setting mode: "..repr(unit.BuildAbilityMode))
  16.     end
  17.     return unit.BuildAbilityMode or 'unknown'
  18. end
  19.  
  20. --Add a skill-build mode check to the mode-switch InstantStatusFunctions and ActionFunctions
  21. local prevFireAction = HeroAIActionTemplates['Burn Alive'].ActionFunction
  22. HeroAIActionTemplates['Burn Alive'].ActionFunction = function(unit, action)
  23.     if GetBuildAbilityMode(unit) ~= 'ice' then
  24.         return prevFireAction(unit, action)
  25.     else
  26.         return false
  27.     end
  28. end
  29.  
  30. local prevFireStatus = HeroAIActionTemplates['Burn Alive'].InstantStatusFunction
  31. HeroAIActionTemplates['Burn Alive'].InstantStatusFunction = function(unit, action)
  32.     if GetBuildAbilityMode(unit) ~= 'ice' then
  33.         return prevFireStatus(unit, action)
  34.     else
  35.         return false
  36.     end
  37. end
  38.  
  39. local prevIceAction = HeroAIActionTemplates['Frozen Heart'].ActionFunction
  40. HeroAIActionTemplates['Frozen Heart'].ActionFunction = function(unit, action)
  41.     if GetBuildAbilityMode(unit) ~= 'fire' then
  42.         return prevIceAction(unit, action)
  43.     else
  44.         return false
  45.     end
  46. end
  47.  
  48. local prevIceStatus = HeroAIActionTemplates['Frozen Heart'].InstantStatusFunction
  49. HeroAIActionTemplates['Frozen Heart'].InstantStatusFunction = function(unit, action)
  50.     if GetBuildAbilityMode(unit) ~= 'fire' then
  51.         return prevIceStatus(unit, action)
  52.     else
  53.         return false
  54.     end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement