Advertisement
Guest User

TemporaryHeroAttribute

a guest
Jun 9th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  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 attribDat array attribDB
  16.         private integer dbIndex=-1
  17.         private timer time=CreateTimer()
  18.     endglobals
  19.    
  20.     private function p takes nothing returns nothing
  21.         local attribDat tempDat
  22.         local integer index=0
  23.         loop
  24.             exitwhen index>dbIndex
  25.             set tempDat=attribDB[index]
  26.             set tempDat.duration=tempDat.duration-TIMER_FIDELITY
  27.             if tempDat.duration<=0. then
  28.                 if tempDat.attribute==AGILITY then
  29.                     call SetHeroAgi(tempDat.hero,GetHeroAgi(tempDat.hero,false)-tempDat.value,true)
  30.                 elseif tempDat.attribute==STRENGTH then
  31.                     call SetHeroStr(tempDat.hero,GetHeroStr(tempDat.hero,false)-tempDat.value,true)
  32.                 elseif tempDat.attribute==INTELLIGENCE then
  33.                     call SetHeroInt(tempDat.hero,GetHeroInt(tempDat.hero,false)-tempDat.value,true)
  34.                 endif
  35.                 call tempDat.destroy()
  36.                 set attribDB[index]=attribDB[dbIndex]
  37.                 set dbIndex=dbIndex-1
  38.                 set index=index-1
  39.                 if dbIndex==-1 then
  40.                     call PauseTimer(time)
  41.                 endif
  42.             endif
  43.             set index=index+1
  44.         endloop
  45.     endfunction
  46.    
  47.     public function add takes unit hero, integer attribute, integer value, real duration returns nothing
  48.         local attribDat tempDat
  49.         if attribute==AGILITY then
  50.             call SetHeroAgi(hero,GetHeroAgi(hero,false)+value,true)
  51.         elseif attribute==STRENGTH then
  52.             call SetHeroStr(hero,GetHeroStr(hero,false)+value,true)
  53.         elseif attribute==INTELLIGENCE then
  54.             call SetHeroInt(hero,GetHeroInt(hero,false)+value,true)
  55.         else
  56.             debug call BJDebugMsg("|cff990000tempModifyHeroAttrib:|r Unrecognized attribute integer!")
  57.             return
  58.         endif
  59.         set tempDat=attribDat.create()
  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