Advertisement
Guest User

TemporaryHeroAttribute

a guest
Jun 1st, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library TemporaryHeroAttribute
  2.     private struct attribDat
  3.         integer attribute
  4.         integer value
  5.         real duration
  6.         unit hero
  7.     endstruct
  8.    
  9.     globals
  10.         public constant integer AGILITY='A'
  11.         public constant integer STRENGTH='S'
  12.         public constant integer INTELLIGENCE='I'
  13.         private constant real TIMER_FIDELITY=1./10.
  14.         private constant string ERROR_MESSAGE="|cff990000tempModifyHeroAttrib:|r Unrecognized attribute integer!"
  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.                 debug else
  35.                     debug call BJDebugMsg(ERROR_MESSAGE)
  36.                 endif
  37.                 call tempDat.destroy()
  38.                 set attribDB[index]=attribDB[dbIndex]
  39.                 set dbIndex=dbIndex-1
  40.                 set index=index-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.         debug 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