Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library TemporaryHeroAttribute
- private struct attribDat
- integer attribute
- integer value
- real duration
- unit hero
- endstruct
- globals
- public constant integer AGILITY='A'
- public constant integer STRENGTH='S'
- public constant integer INTELLIGENCE='I'
- private constant real TIMER_FIDELITY=1./10.
- private constant string ERROR_MESSAGE="|cff990000tempModifyHeroAttrib:|r Unrecognized attribute integer!"
- private attribDat array attribDB
- private integer dbIndex=-1
- private timer time=CreateTimer()
- endglobals
- private function p takes nothing returns nothing
- local attribDat tempDat
- local integer index=0
- loop
- exitwhen index>dbIndex
- set tempDat=attribDB[index]
- set tempDat.duration=tempDat.duration-TIMER_FIDELITY
- if tempDat.duration<0. then
- if tempDat.attribute==AGILITY then
- call SetHeroAgi(tempDat.hero,GetHeroAgi(tempDat.hero,false)-tempDat.value,true)
- elseif tempDat.attribute==STRENGTH then
- call SetHeroStr(tempDat.hero,GetHeroStr(tempDat.hero,false)-tempDat.value,true)
- elseif tempDat.attribute==INTELLIGENCE then
- call SetHeroInt(tempDat.hero,GetHeroInt(tempDat.hero,false)-tempDat.value,true)
- debug else
- debug call BJDebugMsg(ERROR_MESSAGE)
- endif
- call tempDat.destroy()
- set attribDB[index]=attribDB[dbIndex]
- set dbIndex=dbIndex-1
- set index=index-1
- if dbIndex==-1 then
- call PauseTimer(time)
- endif
- endif
- set index=index+1
- endloop
- endfunction
- public function add takes unit hero, integer attribute, integer value, real duration returns nothing
- local attribDat tempDat=attribDat.create()
- if attribute==AGILITY then
- call SetHeroAgi(hero,GetHeroAgi(hero,false)+value,true)
- elseif attribute==STRENGTH then
- call SetHeroStr(hero,GetHeroStr(hero,false)+value,true)
- elseif attribute==INTELLIGENCE then
- call SetHeroInt(hero,GetHeroInt(hero,false)+value,true)
- debug else
- debug call BJDebugMsg(ERROR_MESSAGE)
- endif
- set tempDat.attribute=attribute
- set tempDat.value=value
- set tempDat.duration=duration
- set tempDat.hero=hero
- set dbIndex=dbIndex+1
- set attribDB[dbIndex]=tempDat
- if dbIndex==0 then
- call TimerStart(time,TIMER_FIDELITY,true,function p)
- endif
- endfunction
- endlibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement