Dirac
22710180
- Reaction score
- 147
JASS:
library RawDamage /* v1.0.5
*/uses/*
*/ DamageMod /* thehelper.net/forums/showthread.php/168198-Damage-Mod
A useful tool to handle raw damage from units.
**********************************************************************/
globals
constant integer RAW_DAMAGE_PRIORITY =1
//The priority sets before and after which damage mods the raw damage
//is dealt.
endglobals
/**********************************************************************
*
* struct RawDamage
*
* - Modifies unit damage by exact values.
* - Takes the unit's custom value as an instance.
*
* real input
* - Determines how much extra damage the unit receives when
* - it takes damage.
* real output
* - Determines how much extra damage the unit deals when
* - it deals damage.
* readonly static DamageMod MOD
* - The mod used for this code.
* method addOutputFilter takes code func returns triggercondition
* method addInputFilter takes code func returns triggercondition
* - If the filter returns false then it skips damage
* - modification.
* method removeOutputFilter takes triggercondition whichCondition returns nothing
* method removeInputFilter takes triggercondition whichCondition returns nothing
* - Disables the filter
*
*********************************************************************/
private module RawDamageModule
readonly static DamageMod MOD
private trigger outputTrig
private trigger inputTrig
real output
real input
method addOutputFilter takes code func returns triggercondition
if null==this.outputTrig then
set this.outputTrig=CreateTrigger()
endif
return TriggerAddCondition(this.outputTrig,Filter(func))
endmethod
method removeOutputFilter takes triggercondition whichCondition returns nothing
call TriggerRemoveCondition(this.outputTrig,whichCondition)
endmethod
method addInputFilter takes code func returns triggercondition
if null==this.inputTrig then
set this.inputTrig=CreateTrigger()
endif
return TriggerAddCondition(this.inputTrig,Filter(func))
endmethod
method removeInputFilter takes triggercondition whichCondition returns nothing
call TriggerRemoveCondition(this.inputTrig,whichCondition)
endmethod
private static method onDamage takes nothing returns boolean
local real result=thistype(Damage.sourceId).output-thistype(Damage.targetId).input
if result>0 then
if not(null==thistype(Damage.sourceId).outputTrig) then
if not(TriggerEvaluate(thistype(Damage.targetId).outputTrig)) then
return false
endif
endif
call Damage.add(result)
elseif result<0 then
if not(null==thistype(Damage.targetId).inputTrig) then
if not(TriggerEvaluate(thistype(Damage.targetId).inputTrig)) then
return false
endif
endif
call Damage.prevent(result)
endif
return false
endmethod
private static method onInit takes nothing returns nothing
set MOD=DamageMod.create(function thistype.onDamage,RAW_DAMAGE_PRIORITY)
endmethod
endmodule
struct RawDamage extends array
implement RawDamageModule
endstruct
endlibrary