Advertisement
Guest User

temporaryHeroAttribute

a guest
May 30th, 2012
45
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.                 else
  36.                     debug call BJDebugMsg(ERROR_MESSAGE)
  37.                 endif
  38.                 call tempDat.destroy()
  39.                 set attribDB[index]=attribDB[dbIndex]
  40.                 set dbIndex=dbIndex-1
  41.                 if dbIndex==-1 then
  42.                     call PauseTimer(time)
  43.                 endif
  44.             endif
  45.             set index=index+1
  46.         endloop
  47.     endfunction
  48.    
  49.     public function add takes unit hero, integer attribute, integer value, real duration returns nothing
  50.         local attribDat tempDat=attribDat.create()
  51.         if attribute==AGILITY then
  52.             call SetHeroAgi(hero,GetHeroAgi(hero,false)+value,true)
  53.         elseif attribute==STRENGTH then
  54.             call SetHeroStr(hero,GetHeroStr(hero,false)+value,true)
  55.         elseif attribute==INTELLIGENCE then
  56.             call SetHeroInt(hero,GetHeroInt(hero,false)+value,true)
  57.         else
  58.             debug call BJDebugMsg(ERROR_MESSAGE)
  59.         endif
  60.         set tempDat.attribute=attribute
  61.         set tempDat.value=value
  62.         set tempDat.duration=duration
  63.         set tempDat.hero=hero
  64.         set dbIndex=dbIndex+1
  65.         set attribDB[dbIndex]=tempDat
  66.         if dbIndex==0 then
  67.             call TimerStart(time,TIMER_FIDELITY,true,function p)
  68.         endif
  69.     endfunction
  70. endlibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement