scope PutridExplosion
globals
public constant integer spellid1 = 'A02E'
public constant integer manacost1 = 80
public constant integer manacostperlvl1 = 0
public constant integer chance1 = 100
unit array PutridExplosionUnit
constant integer PESTILENCECLOUD = 'uplg'
endglobals
public function Conditions1 takes nothing returns boolean
return GetSpellAbilityId()==spellid1
endfunction
public function GetNearestCorpse takes unit U, player J returns unit
local location position = GetUnitLoc(U)
local group groupe = GetUnitsInRangeOfLocMatching(900,position,null)
local unit un = null
local real dist = 1000
set PutridExplosionUnit[GetPlayerId(J)]=null
loop
set un = GroupPickRandomUnit(groupe)
exitwhen un == null
if(IsUnitEnemy(un,J) and IsDead(un) and DistUnits(U,un)<dist and not IsMech(un) and IsUnitVisible(un,GetOwningPlayer(U)) and not IsHero(un) and not IsEffect(un)) then
set dist = DistUnits(U,un)
set PutridExplosionUnit[GetPlayerId(GetOwningPlayer(U))]=un
endif
call GroupRemoveUnit(groupe,un)
endloop
call DestroyGroup(groupe)
call RemoveLocation(position)
set position = null
set groupe = null
set un = null
return PutridExplosionUnit[GetPlayerId(J)]
endfunction
public function GetNearestCorpseAoE takes unit U, player J, location P returns unit
local group groupe = GetUnitsInRangeOfLocMatching(350,P,null)
local unit un = null
local real dist = 450
set PutridExplosionUnit[GetPlayerId(J)]=null
loop
set un = GroupPickRandomUnit(groupe)
exitwhen un == null
if(IsUnitEnemy(un,J) and IsDead(un) and DistCoord(GetUnitX(un),GetUnitY(un),GetLocationX(P),GetLocationY(P))<dist and not IsMech(un) and IsUnitVisible(un,GetOwningPlayer(U)) and not IsHero(un) and not IsEffect(un)) then
set dist = DistCoord(GetUnitX(un),GetUnitY(un),GetLocationX(P),GetLocationY(P))
set PutridExplosionUnit[GetPlayerId(GetOwningPlayer(U))]=un
endif
call GroupRemoveUnit(groupe,un)
endloop
call DestroyGroup(groupe)
set groupe = null
set un = null
return PutridExplosionUnit[GetPlayerId(J)]
endfunction
public function Conditions2 takes nothing returns boolean
return GetUnitAbilityLevel(GetAttacker(),'A018')>0 and GetUnitAbilityLevel(GetAttacker(),spellid1)>0 and IsUnitEnemy(GetAttacker(),GetOwningPlayer(GetTriggerUnit())) and IsDead(GetTriggerUnit())==false and IsIllusion(GetAttacker())==false and EnableAI[GetPlayerId(GetOwningPlayer(GetAttacker()))]==true
endfunction
public function SpellEffect1 takes nothing returns nothing
local unit lanceur = GetSpellAbilityUnit()
local integer lvl = GetUnitAbilityLevel(lanceur,spellid1)
local location position = GetSpellTargetLoc()
local unit cible = GetNearestCorpseAoE(lanceur, GetOwningPlayer(lanceur),position)
local group groupe = GetUnitsInRangeOfLocAll(250,position)
local real dmg = GetUnitState(cible,UNIT_STATE_MAX_LIFE)*GetRandomReal(0.30,0.70)
local unit un = null
local unit cloud = null
if cible==null then
call UnitResetAbility(lanceur,spellid1,lvl)
call Error(GetOwningPlayer(lanceur),"There are no usable corpses nearby.")
call RegenManaStat(lanceur,manacost1+manacostperlvl1*lvl)
else
call RemoveLocation(position)
set position = GetUnitLoc(cible)
call DestroyEffect(AddSpecialEffectLoc("PutridExplosion.mdx",position))
call DestroyEffect(AddSpecialEffectLoc("Objects\\Spawnmodels\\Human\\HumanLargeDeathExplode\\HumanLargeDeathExplode.mdl",position))
call RemoveUnit(cible)
set cloud = CreateUnitAtLoc(GetOwningPlayer(lanceur),PESTILENCECLOUD,position,0)
call UnitApplyTimedLife(cloud, 'BTLF',15)
loop
set un = FirstOfGroup(groupe)
exitwhen un == null
if (IsUnitEnemy(un,GetOwningPlayer(lanceur)) and not IsInvulnerable(un) and not IsEffect(un) and not IsDead(un)) then
call UnitDamageTarget(lanceur, un,dmg/2, false,true, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
if not IsMagicImmune(un) then
call UnitDamageTarget(lanceur, un,dmg/2, false,true, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS)
endif
endif
call GroupRemoveUnit(groupe,un)
endloop
endif
if position!=null then
call RemoveLocation(position)
endif
call DestroyGroup(groupe)
set PutridExplosionUnit[GetPlayerId(GetOwningPlayer(lanceur))]=null
set lanceur = null
set position = null
set groupe = null
set un = null
set cible = null
set cloud = null
endfunction
public function Attack takes nothing returns nothing
local unit lanceur = GetAttacker()
local unit cible = GetTriggerUnit()
local integer lvl = GetUnitAbilityLevel(lanceur,spellid1)
local unit corpse = GetNearestCorpse(lanceur,GetOwningPlayer(lanceur))
if Chance(chance1,1) and corpse!=null and GetUnitState(lanceur,UNIT_STATE_MANA)>=manacost1+manacostperlvl1*lvl then
if IssuePointOrderById(lanceur,OrderId("blizzard"),GetUnitX(corpse),GetUnitY(corpse))==true then
call ReOrderDelayed(lanceur,0)
endif
endif
set PutridExplosionUnit[GetPlayerId(GetOwningPlayer(lanceur))]=null
set corpse = null
set lanceur = null
set cible = null
endfunction
public function Init takes nothing returns nothing
local trigger declo = CreateTrigger()
call TriggerAddCondition(declo,Condition(function Conditions2))
call TriggerRegisterAnyUnitEventBJ(declo, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddAction(declo, function Attack)
set declo = CreateTrigger()
call TriggerAddCondition(declo,Condition(function Conditions1))
call TriggerRegisterAnyUnitEventBJ(declo,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddAction(declo,function SpellEffect1)
set declo = null
call LoadSkill(spellid1)
endfunction
endscope