File src/abla.j added (mode: 100644) (index 0000000..64a83d8) |
|
1 |
|
// src/abla.j |
|
2 |
|
// requires src/spell.j |
|
3 |
|
|
|
4 |
|
// Spell Arcane blast. |
|
5 |
|
// Deal damage to units in target area. |
|
6 |
|
// Given unit that is immune to magic, heal the unit instead. |
|
7 |
|
// This spell may heal enemies. |
|
8 |
|
// This spell may harm allies. |
|
9 |
|
|
|
10 |
|
globals |
|
11 |
|
|
|
12 |
|
// src/abla.j fields |
|
13 |
|
|
|
14 |
|
constant integer ABLA_ABILITY_ID = 'A000' |
|
15 |
|
|
|
16 |
|
constant integer ABLA_GROUP_LIMIT = 12 |
|
17 |
|
constant real ABLA_AREA_MAX = 8192.0 |
|
18 |
|
constant real ABLA_AREA_MIN = 64.0 |
|
19 |
|
constant real ABLA_DAMAGE_AMOUNT_MAX = 100000.0 |
|
20 |
|
constant real ABLA_DAMAGE_AMOUNT_MIN = 0.0 |
|
21 |
|
constant real ABLA_HEAL_AMOUNT_MAX = 100000.0 |
|
22 |
|
constant real ABLA_HEAL_AMOUNT_MIN = 0.0 |
|
23 |
|
integer abla_super_abilityid = 0 |
|
24 |
|
real abla_super_damage = 0.0 |
|
25 |
|
real abla_super_heal = 0.0 |
|
26 |
|
unit abla_super_caster = null |
|
27 |
|
endglobals |
|
28 |
|
|
|
29 |
|
// src/abla.j functions |
|
30 |
|
|
|
31 |
|
function abla_harm_check takes unit u returns boolean |
|
32 |
|
local boolean flag = true |
|
33 |
|
//local player p = null |
|
34 |
|
|
|
35 |
|
if null == u then |
|
36 |
|
return false |
|
37 |
|
endif |
|
38 |
|
|
|
39 |
|
set flag = not IsUnitType(u, UNIT_TYPE_DEAD) and flag |
|
40 |
|
set flag = GetUnitState(u, UNIT_STATE_LIFE) > 0 and flag |
|
41 |
|
set flag = not IsUnitType(u, UNIT_TYPE_STRUCTURE) and flag |
|
42 |
|
set flag = not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) and flag |
|
43 |
|
// TODO Consider making Arcane Blast to never harm allies, but allow it to heal enemies. |
|
44 |
|
//set p = GetOwningPlayer(abla_super_caster) |
|
45 |
|
//set flag = IsUnitEnemy(u, p) and flag |
|
46 |
|
|
|
47 |
|
return flag |
|
48 |
|
endfunction |
|
49 |
|
|
|
50 |
|
function abla_heal_check takes unit u returns boolean |
|
51 |
|
local boolean flag = true |
|
52 |
|
|
|
53 |
|
if null == u then |
|
54 |
|
return false |
|
55 |
|
endif |
|
56 |
|
|
|
57 |
|
set flag = not IsUnitType(u, UNIT_TYPE_DEAD) and flag |
|
58 |
|
set flag = GetUnitState(u, UNIT_STATE_LIFE) > 0 and flag |
|
59 |
|
set flag = not IsUnitType(u, UNIT_TYPE_STRUCTURE) and flag |
|
60 |
|
set flag = IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) and flag |
|
61 |
|
|
|
62 |
|
return flag |
|
63 |
|
endfunction |
|
64 |
|
|
|
65 |
|
function abla_harm_group_filter takes nothing returns boolean |
|
66 |
|
local unit u = GetFilterUnit() |
|
67 |
|
return abla_harm_check(u) and not abla_heal_check(u) |
|
68 |
|
endfunction |
|
69 |
|
|
|
70 |
|
function abla_heal_group_filter takes nothing returns boolean |
|
71 |
|
local unit u = GetFilterUnit() |
|
72 |
|
return abla_heal_check(u) and not abla_harm_check(u) |
|
73 |
|
endfunction |
|
74 |
|
|
|
75 |
|
function abla_harm_group_callback takes nothing returns nothing |
|
76 |
|
local integer abilityid = 0 |
|
77 |
|
local unit caster = null |
|
78 |
|
local unit u = null |
|
79 |
|
local real damage = 0.0 |
|
80 |
|
local boolean attack = true |
|
81 |
|
local boolean ranged = true |
|
82 |
|
local effect e = null |
|
83 |
|
|
|
84 |
|
set u = GetEnumUnit() |
|
85 |
|
if null == u then |
|
86 |
|
return |
|
87 |
|
endif |
|
88 |
|
|
|
89 |
|
set caster = abla_super_caster |
|
90 |
|
set damage = RMinBJ(RMaxBJ(ABLA_DAMAGE_AMOUNT_MIN, abla_super_damage), ABLA_DAMAGE_AMOUNT_MAX) |
|
91 |
|
|
|
92 |
|
call UnitDamageTarget(caster, u, damage, attack, ranged, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS) |
|
93 |
|
|
|
94 |
|
set abilityid = abla_super_abilityid |
|
95 |
|
set e = AddSpellEffectTargetById(abilityid, EFFECT_TYPE_TARGET, u, "origin") |
|
96 |
|
call DestroyEffect(e) |
|
97 |
|
endfunction |
|
98 |
|
|
|
99 |
|
function abla_heal_group_callback takes nothing returns nothing |
|
100 |
|
local unit caster = null |
|
101 |
|
local unit u = null |
|
102 |
|
local real heal = 0.0 |
|
103 |
|
local real a = 0.0 |
|
104 |
|
local real b = 0.0 |
|
105 |
|
local effect e = null |
|
106 |
|
|
|
107 |
|
set u = GetEnumUnit() |
|
108 |
|
if null == u then |
|
109 |
|
return |
|
110 |
|
endif |
|
111 |
|
|
|
112 |
|
set heal = RMinBJ(RMaxBJ(ABLA_HEAL_AMOUNT_MIN, abla_super_heal), ABLA_HEAL_AMOUNT_MAX) |
|
113 |
|
set a = GetUnitState(u, UNIT_STATE_LIFE) |
|
114 |
|
call SetUnitState(u, UNIT_STATE_LIFE, a + heal) |
|
115 |
|
set b = GetUnitState(u, UNIT_STATE_LIFE) |
|
116 |
|
|
|
117 |
|
// Only show healing graphics when the amount of health effectively changed. |
|
118 |
|
if b > a then |
|
119 |
|
set e = AddSpellEffectTargetById('AIhx', EFFECT_TYPE_TARGET, u, "origin") |
|
120 |
|
call DestroyEffect(e) |
|
121 |
|
endif |
|
122 |
|
endfunction |
|
123 |
|
|
|
124 |
|
function abla_apply takes integer abilityid, unit caster, location destination, real area, real damage, real healing returns nothing |
|
125 |
|
local group g = null |
|
126 |
|
local real radius = 0.0 |
|
127 |
|
local filterfunc filter = null |
|
128 |
|
local integer limit = 1 |
|
129 |
|
local effect e = null |
|
130 |
|
|
|
131 |
|
if null == destination then |
|
132 |
|
return |
|
133 |
|
endif |
|
134 |
|
|
|
135 |
|
set area = RMinBJ(RMaxBJ(ABLA_AREA_MIN, area), ABLA_AREA_MAX) |
|
136 |
|
set radius = area * 0.5 |
|
137 |
|
set damage = RMinBJ(RMaxBJ(ABLA_DAMAGE_AMOUNT_MIN, damage), ABLA_DAMAGE_AMOUNT_MAX) |
|
138 |
|
set healing = RMinBJ(RMaxBJ(ABLA_HEAL_AMOUNT_MIN, healing), ABLA_HEAL_AMOUNT_MAX) |
|
139 |
|
set limit = ABLA_GROUP_LIMIT |
|
140 |
|
|
|
141 |
|
// Implicit arguments (upvalues) for group callbacks. |
|
142 |
|
set abla_super_abilityid = abilityid |
|
143 |
|
set abla_super_caster = caster |
|
144 |
|
set abla_super_damage = damage |
|
145 |
|
set abla_super_heal = healing |
|
146 |
|
|
|
147 |
|
set g = CreateGroup() |
|
148 |
|
|
|
149 |
|
call GroupClear(g) |
|
150 |
|
set filter = Filter(function abla_harm_group_filter) |
|
151 |
|
call GroupEnumUnitsInRangeOfLocCounted(g, destination, radius, filter, limit) |
|
152 |
|
call ForGroup(g, function abla_harm_group_callback) |
|
153 |
|
call DestroyFilter(filter) |
|
154 |
|
|
|
155 |
|
call GroupClear(g) |
|
156 |
|
set filter = Filter(function abla_heal_group_filter) |
|
157 |
|
call GroupEnumUnitsInRangeOfLocCounted(g, destination, radius, filter, limit) |
|
158 |
|
call ForGroup(g, function abla_heal_group_callback) |
|
159 |
|
call DestroyFilter(filter) |
|
160 |
|
|
|
161 |
|
set abla_super_abilityid = 0 |
|
162 |
|
set abla_super_caster = null |
|
163 |
|
set abla_super_damage = 0.0 |
|
164 |
|
set abla_super_heal = 0.0 |
|
165 |
|
call DestroyGroup(g) |
|
166 |
|
|
|
167 |
|
set e = AddSpellEffectByIdLoc(abilityid, EFFECT_TYPE_SPECIAL, destination) |
|
168 |
|
call DestroyEffect(e) |
|
169 |
|
endfunction |
|
170 |
|
|
|
171 |
|
function abla_trig_filter takes nothing returns boolean |
|
172 |
|
return ABLA_ABILITY_ID == GetSpellAbilityId() |
|
173 |
|
endfunction |
|
174 |
|
|
|
175 |
|
function abla_trig_action takes nothing returns nothing |
|
176 |
|
local integer abilityid = 0 |
|
177 |
|
local unit caster = null |
|
178 |
|
local location destination = null |
|
179 |
|
local real area = 0.0 |
|
180 |
|
local real damage = 0.0 |
|
181 |
|
local real healing = 0.0 |
|
182 |
|
local integer level = 0 |
|
183 |
|
|
|
184 |
|
set abilityid = GetSpellAbilityId() |
|
185 |
|
set caster = GetSpellAbilityUnit() |
|
186 |
|
set level = GetUnitAbilityLevel(caster, abilityid) |
|
187 |
|
set destination = GetSpellTargetLoc() |
|
188 |
|
set area = 512.0 |
|
189 |
|
set damage = 50.0 + 50 * level |
|
190 |
|
set healing = 50.0 * level |
|
191 |
|
|
|
192 |
|
call abla_apply(abilityid, caster, destination, area, damage, healing) |
|
193 |
|
|
|
194 |
|
call RemoveLocation(destination) |
|
195 |
|
endfunction |
|
196 |
|
|
|
197 |
|
function abla_init takes nothing returns nothing |
|
198 |
|
local conditionfunc filter = Condition(function abla_trig_filter) |
|
199 |
|
call spell_trig_init(filter, function abla_trig_action) |
|
200 |
|
endfunction |