Advertisement
Guest User

TemporaryHeroAttribute

a guest
Jun 1st, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. library TemporaryHeroAttribute
  3.     private struct attribDat
  4.         integer attribute
  5.         integer value
  6.         real duration
  7.         unit hero
  8.     endstruct
  9.    
  10.     globals
  11.         public constant integer AGILITY='A'
  12.         public constant integer STRENGTH='S'
  13.         public constant integer INTELLIGENCE='I'
  14.         private constant real TIMER_FIDELITY=1./10.
  15.         private constant string ERROR_MESSAGE="|cff990000tempModifyHeroAttrib:|r Unrecognized attribute integer!"
  16.         private attribDat array attribDB
  17.         private integer dbIndex=-1
  18.         private timer time=CreateTimer()
  19.     endglobals
  20.    
  21.     private function p takes nothing returns nothing
  22.         local attribDat tempDat
  23.         local integer index=0
  24.         loop
  25.             exitwhen index>dbIndex
  26.             set tempDat=attribDB[index]
  27.             set tempDat.duration=tempDat.duration-TIMER_FIDELITY
  28.             if tempDat.duration<0. then
  29.                 if tempDat.attribute==AGILITY then
  30.                     call SetHeroAgi(tempDat.hero,GetHeroAgi(tempDat.hero,false)-tempDat.value,true)
  31.                 elseif tempDat.attribute==STRENGTH then
  32.                     call SetHeroStr(tempDat.hero,GetHeroStr(tempDat.hero,false)-tempDat.value,true)
  33.                 elseif tempDat.attribute==INTELLIGENCE then
  34.                     call SetHeroInt(tempDat.hero,GetHeroInt(tempDat.hero,false)-tempDat.value,true)
  35.                 debug else
  36.                     debug call BJDebugMsg(ERROR_MESSAGE)
  37.                 endif
  38.                 call tempDat.destroy()
  39.                 set index=index-1
  40.                 set attribDB[index]=attribDB[dbIndex]
  41.                 set dbIndex=dbIndex-1
  42.                 if dbIndex==-1 then
  43.                     call PauseTimer(time)
  44.                 endif
  45.             endif
  46.             set index=index+1
  47.         endloop
  48.     endfunction
  49.    
  50.     public function add takes unit hero, integer attribute, integer value, real duration returns nothing
  51.         local attribDat tempDat=attribDat.create()
  52.         if attribute==AGILITY then
  53.             call SetHeroAgi(hero,GetHeroAgi(hero,false)+value,true)
  54.         elseif attribute==STRENGTH then
  55.             call SetHeroStr(hero,GetHeroStr(hero,false)+value,true)
  56.         elseif attribute==INTELLIGENCE then
  57.             call SetHeroInt(hero,GetHeroInt(hero,false)+value,true)
  58.         debug else
  59.             debug call BJDebugMsg(ERROR_MESSAGE)
  60.         endif
  61.         set tempDat.attribute=attribute
  62.         set tempDat.value=value
  63.         set tempDat.duration=duration
  64.         set tempDat.hero=hero
  65.         set dbIndex=dbIndex+1
  66.         set attribDB[dbIndex]=tempDat
  67.         if dbIndex==0 then
  68.             call TimerStart(time,TIMER_FIDELITY,true,function p)
  69.         endif
  70.     endfunction
  71. endlibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement