- Joined
- Sep 12, 2008
- Messages
- 657
Recycling Groups?
I didnt use 1 group yet.. except the 1 i forgot to uncall.. heres a better code:
JASS:
library ShieldSystem initializer OnInit requires IntuitiveDamageSystem
function interface ShieldTakesDamage takes unit wielder, real shieldLifeLeft, real dealtDamage returns nothing
globals
public constant real loopSpeed = 0.032
endglobals
struct ShieldSystemData
public unit wielder
public string shieldSFX
public effect sEffect
public real shieldCurrentLife
public real shieldMaximumLife
public real damageReduction
public real currentDamage
public real damageHoldoff
public real explosionDamageReduction
public real explosionRadius
public boolexpr explosionBer
public group explosionGroup
public ShieldTakesDamage eventFunction
public static method create takes unit shieldWielder, string shieldSFX, real shieldMaxLife, real damageReduction returns thistype
local thistype t = allocate()
set t.wielder = shieldWielder
set t.shieldSFX = shieldSFX
set t.shieldCurrentLife = shieldMaxLife
set t.shieldMaximumLife = shieldMaxLife
set t.damageReduction = damageReduction
set t.currentDamage = 0
set t.explosionRadius = 0
set t.sEffect = AddSpecialEffectTarget(t.shieldSFX, t.wielder, "origin")
//set t.explosionGroup = CreateGroup()
return t
endmethod
public method allowExplosion takes real explosionDamageReduction, real explosionRange, boolexpr groupFilter returns nothing
set this.explosionDamageReduction = damageReduction
set this.explosionRadius = explosionRange
set this.explosionBer = groupFilter
endmethod
public method registerDamageEvent takes ShieldTakesDamage func returns nothing
set eventFunction = func
endmethod
public method isShieldAlive takes nothing returns boolean
return .shieldCurrentLife > 0
endmethod
public method damage takes real damage returns nothing
if isShieldAlive() then
set shieldCurrentLife = shieldCurrentLife - damage
set currentDamage = currentDamage + damage
call eventFunction.execute(wielder, shieldCurrentLife, currentDamage)
if isShieldAlive() == false then
call DestroyEffect(sEffect)
//Explode It Here
//call DestroyGroup(explosionGroup)
endif
endif
endmethod
endstruct
globals
public trigger sTrigger = CreateTrigger()
public ShieldSystemData array shieldData
public integer ShieldSystemCount = 0
endglobals
function createShield takes ShieldSystemData data returns integer
set ShieldSystemCount = ShieldSystemCount + 1
set shieldData[ShieldSystemCount] = data
return ShieldSystemCount
endfunction
public function UnitUnderAttack takes nothing returns nothing
local integer count = 0
local real equation = 0
loop
set count = count + 1
if GetTriggerUnit() == shieldData[count].wielder then
if shieldData[count].isShieldAlive() then
set equation = (GetEventDamage() * (shieldData[count].damageReduction / 100))
call shieldData[count].damage(equation)
call SetWidgetLife(GetTriggerUnit(), GetWidgetLife(GetTriggerUnit()) + (GetEventDamage() - equation))
endif
endif
exitwhen count >= ShieldSystemCount
endloop
endfunction
public function OnInit takes nothing returns nothing
call TriggerRegisterDamageEvent(sTrigger, 1)
call TriggerAddAction(sTrigger, function UnitUnderAttack)
endfunction
endlibrary
tell me what i can improve before i go into the explosion equations plz =]