| 01-27-2012, 05:17 PM | #1 | ||
Buff Generator version 3.1.7 This system allows rapid and easy buff development. System code: JASS:library BuffGen /* v3.1.7.0 ************************************************************************************************ * BUFF GENERATOR by Bills * * This system allows rapid and easy buff development. * ************************************************************************************************ * * */ uses /* * * */ UnitIndexer /* hiveworkshop.com/forums/jass-resources-412/system-unit-indexer-172090/ * */ Event /* hiveworkshop.com/forums/jass-resources-412/snippet-event-186555/ * */ CTL /* hiveworkshop.com/forums/jass-resources-412/snippet-constant-timer-loop-32-a-201381/ * */ TimerUtils /* hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/ * */ Table /* hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/ * *************************************************************************************************** * * Functions * * function AddBuff takes unit whichUnit, Buff whichBuff, real duration returns boolean * - returns true if added the buff * * function RemoveBuff takes unit wichUnit, Buff whichBuff returns boolean * - returns true if removed the buff * * function RemoveAllBuffs takes unit wichUnit returns nothing * - removes all buffs of unit * * function UnitHasBuff takes unit wichUnit, Buff whichBuff returns boolean * - returns true if unit has the buff * * function SetBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns nothing * - sets the duration of buff * * function AddBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns nothing * - increments the duration of buff * * function GetBuffDuration takes unit whichUnit, Buff whichBuff, real duration returns real * - returns the duration of buff * * function CountBuffs takes unit whichUnit returns real * - returns de amount of buffs that unit have * ******************************************************************************************* * * struct Buff extends array * * static Event START * - fires when a buff is added * static Event FINISH * - fires when a buff is removed * * Event Responses * - function GetEventBuff takes nothing returns Buff * - function GetBuffEventUnit takes nothing returns unit * - function GetBuffEventUnitId takes nothing returns integer * * function TriggerRegisterBuffEvent takes trigger t, Event e returns nothing * - Jass wrapper of EVENT.registerTrigger(trigger) * * function RegisterBuffEvent takes boolexpr b, Event e returns nothing * - Jass wrapper of EVENT.register(boolexpr) * ***************************************************************************** * * module BuffStruct * * static constant real TIMEOUT = 0.031250000 // useful to method onPeriodic * * static method operator buff takes nothing returns Buff * - returns the Buff generated by implementation of this module * * (interface) * * private static constant integer AURAID = 'AURA' * (required) - this is a tornado slow aura * private static constant integer BUFFID = 'BUFF' * (required) - this is the buff of aura * * private method onApply takes nothing returns nothing * (optional) - called all times that AddBuff is called * * private method onRemove takes nothing returns nothing * (optional) - called all times that RemoveBuff is called * * private method onFinish takes nothing returns nothing * (optional) - called only when the buff finish completely your duration * * private method onPeriodic takes nothing returns nothing * (optional) - called 32 times per second * * Notes: * - "thistype this" represents the index of buffed unit in all methods above. * - If you do not want to use AURAID or/and BUFFID, just set it with 0 (zero). * ******************************************************************************** * * ForEachBuff Modules * * allows the method ForEachBuff takes unit enumUnit returns nothing * * module ForEachBuff * - declare local variables here * module ForEachBuffLoop * - run loop code * module ForEachBuffNull * - null locals * module ForEachBuffEnd * * Exemple of ForEachBuff * - struct Test extends array * unit targ * implement ForEachBuff * local unit target=thistype(GetUnitUserData(enumUnit)).targ * implement ForEachBuffLoop * call UnitDamageTarget(enumUnit, target, 50, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS) * // deals 50 damage on target for each buff on enumUnit * implement ForEachBuffNull * set target=null * implement ForEachBuffEnd * * static method onCast takes nothing returns boolean * set thistype(GetUnitUserData(GetTriggerUnit())).targ=GetSpellTargetUnit() * call ForEachBuff(GetTriggerUnit()) * return false * endmethod * endstruct * ************************************************************************************/ globals private integer total=0 //Buff indexer and counter private integer array aid //ability id private integer array bid //buff id private integer array bc private Table array t private Event array e private integer array ed1 // event data private integer array ed2 // other event data private boolean ee=true private unit eu=null private Buff eb=0 endglobals private module M private static method onInit takes nothing returns nothing set START=Event.create() set FINISH=Event.create() endmethod endmodule struct Buff extends array readonly static Event START readonly static Event FINISH implement M endstruct private function InitBuff takes integer auraid, integer buffid, code func returns integer local integer id=total+1 set total=id set e[id]=Event.create() call e[id].register(Filter(func)) set t[id]=Table.create() set aid[id]=auraid set bid[id]=buffid return id endfunction function UnitHasBuff takes unit u, Buff b returns boolean return t[b].boolean[GetUnitUserData(u)] endfunction function RemoveBuff takes unit u, Buff b returns boolean debug if u==null or b<=0 or integer(b)>total then debug call BJDebugMsg("[Buff Generator] Error: invalid arguments on RemoveBuff") debug return false debug endif if UnitHasBuff(u,b) then set t[b].boolean[GetUnitUserData(u)]=false if UnitMakeAbilityPermanent(u,false,aid[b]) then call UnitRemoveAbility(u,aid[b]) call UnitRemoveAbility(u,bid[b]) endif set ed1[b]=GetUnitUserData(u) set ed2[b]=2 call e[b].fire() if ee then set eu=u set eb=b call Buff.FINISH.fire() endif return true endif return false endfunction function AddBuff takes unit u, Buff b, real dur returns boolean local integer i debug if u==null or b<=0 or integer(b)>total then debug call BJDebugMsg("[Buff Generator] Error: invalid arguments on AddBuff") debug return false debug endif if UnitHasBuff(u,b) then call RemoveBuff(u,b) call AddBuff(u,b,dur) else set i=GetUnitUserData(u) set t[b].boolean[i]=true if UnitAddAbility(u,aid[b]) then call UnitMakeAbilityPermanent(u,true,aid[b]) endif set t[b].real[i]=dur set ed1[b]=i set ed2[b]=1 call e[b].fire() if ee then set eu=u set eb=b call Buff.START.fire() endif return true endif return false endfunction function RemoveAllBuffs takes unit u returns nothing local Buff i=total loop exitwhen i==0 call RemoveBuff(u,i) set i=i-1 endloop endfunction function SetBuffDuration takes unit u, Buff b, real dur returns nothing if UnitHasBuff(u,b) then set t[b].real[GetUnitUserData(u)]=dur set ed1[b]=GetUnitUserData(u) set ed2[b]=3 call e[b].fire() endif endfunction function GetBuffDuration takes unit u, Buff b returns real if UnitHasBuff(u,b) then return t[b].real[GetUnitUserData(u)] endif return 0. endfunction function AddBuffDuration takes unit u, Buff b, real dur returns nothing call SetBuffDuration(u,b,GetBuffDuration(u,b)+dur) endfunction function CountBuffs takes unit u returns integer return bc[GetUnitUserData(u)] endfunction function TriggerRegisterBuffEvent takes trigger t, Event e returns nothing call e.registerTrigger(t) endfunction function RegisterBuffEvent takes boolexpr t, Event e returns nothing call e.register(t) endfunction function GetBuffEventUnit takes nothing returns unit return eu endfunction function GetBuffEventUnitId takes nothing returns integer return GetUnitUserData(eu) endfunction function GetEventBuff takes nothing returns Buff return eb endfunction module BuffStruct static constant real TIMEOUT=0.031250000 private static Buff id //id of this buff static method operator buff takes nothing returns Buff return id endmethod static if thistype.onPeriodic.exists then private integer index private thistype T implement CTL local real d implement CTLExpire set d=t[id].real[index]-TIMEOUT call thistype(index).onPeriodic() if d<=0.00 then call RemoveBuff(GetUnitById(index),id) static if thistype.onFinish.exists then call thistype(index).onFinish() endif else set t[id].real[index]=d endif implement CTLNull implement CTLEnd else private timer T private static method exp takes nothing returns nothing local integer i=GetTimerData(GetExpiredTimer()) call RemoveBuff(GetUnitById(i),id) static if thistype.onFinish.exists then call thistype(i).onFinish() endif endmethod endif private static method m takes nothing returns nothing local integer i=ed1[id] //unit id local integer j=ed2[id] //data local thistype this=thistype(i) if j==1 then static if thistype.onPeriodic.exists then set T=create() set T.index=i else set T=NewTimerEx(i) call TimerStart(T,t[id].real[i],false,function thistype.exp) endif static if thistype.onApply.exists then call onApply() endif set bc[i]=bc[i]+1 elseif j==2 then static if thistype.onPeriodic.exists then call T.destroy() else call ReleaseTimer(T) set T=null endif static if thistype.onRemove.exists then call onRemove() endif set bc[i]=bc[i]-1 elseif j==3 then static if not thistype.onPeriodic.exists then set T=NewTimerEx(ReleaseTimer(T)) call TimerStart(T,t[id].real[i],false,function thistype.exp) endif endif endmethod private static method onInit takes nothing returns nothing set id=InitBuff(AURAID,BUFFID,function thistype.m) endmethod endmodule // ForEachBuff Modules module ForEachBuff static method ForEachBuff takes unit enumUnit returns nothing local Buff this=total endmodule module ForEachBuffLoop loop exitwhen this==0 if UnitHasBuff(enumUnit,this) then endmodule module ForEachBuffNull endif set this=this-1 endloop endmodule module ForEachBuffEnd endmethod endmodule endlibrary
Important: The TimerUtils used on system is this > hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/ |
| 01-27-2012, 10:42 PM | #2 |
Unfortunately, your resource can not be approved as long as it uses libraries that have not gone through our review system and been accepted themselves. |
| 01-27-2012, 11:12 PM | #3 |
Attempting to submit a buff system to Anitarf is like trying to sell snow to Eskimos. ![]() see here: http://www.wc3c.net/showthread.php?t=95521 |
| 01-29-2012, 02:05 AM | #4 | |
Quote:
|
