5 SOUND(MageSpike_FIRE, W_Sound("electro_fire"));
6 void M_Mage_Attack_Spike(entity this, vector dir);
7 void M_Mage_Attack_Push(entity this);
8 METHOD(MageSpike, wr_think, void(MageSpike thiswep, entity actor, .entity weaponentity, int fire))
10 TC(MageSpike, thiswep);
12 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) {
13 if (!actor.target_range) actor.target_range = autocvar_g_monsters_target_range;
14 actor.enemy = Monster_FindTarget(actor);
15 monster_makevectors(actor, actor.enemy);
16 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MageSpike_FIRE, CH_WEAPON_B, 0, DEATH_MONSTER_MAGE.m_id);
17 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
18 M_Mage_Attack_Spike(actor, w_shotdir);
19 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
22 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
23 M_Mage_Attack_Push(actor);
24 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
28 void M_Mage_Attack_Teleport(entity this, entity targ);
30 CLASS(OffhandMageTeleport, OffhandWeapon)
31 .bool OffhandMageTeleport_key_pressed;
32 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
34 TC(OffhandMageTeleport, this);
35 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
36 M_Mage_Attack_Teleport(player, player.enemy);
37 player.OffhandMageTeleport_key_pressed = key_pressed;
39 ENDCLASS(OffhandMageTeleport)
40 OffhandMageTeleport OFFHAND_MAGE_TELEPORT;
41 STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
43 float autocvar_g_monster_mage_health;
44 float autocvar_g_monster_mage_damageforcescale = 0.5;
45 float autocvar_g_monster_mage_attack_spike_damage;
46 float autocvar_g_monster_mage_attack_spike_radius;
47 float autocvar_g_monster_mage_attack_spike_delay;
48 float autocvar_g_monster_mage_attack_spike_accel;
49 float autocvar_g_monster_mage_attack_spike_decel;
50 float autocvar_g_monster_mage_attack_spike_chance = 0.45;
51 float autocvar_g_monster_mage_attack_spike_turnrate;
52 float autocvar_g_monster_mage_attack_spike_speed_max;
53 float autocvar_g_monster_mage_attack_spike_smart;
54 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
55 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
56 float autocvar_g_monster_mage_attack_spike_smart_mindist;
57 float autocvar_g_monster_mage_attack_push_chance = 0.7;
58 float autocvar_g_monster_mage_attack_push_damage;
59 float autocvar_g_monster_mage_attack_push_radius;
60 float autocvar_g_monster_mage_attack_push_delay;
61 float autocvar_g_monster_mage_attack_push_force;
62 float autocvar_g_monster_mage_attack_teleport_chance = 0.2;
63 float autocvar_g_monster_mage_attack_teleport_delay = 2;
64 float autocvar_g_monster_mage_attack_teleport_random = 0.4;
65 float autocvar_g_monster_mage_attack_teleport_random_range = 1200;
66 float autocvar_g_monster_mage_heal_self;
67 float autocvar_g_monster_mage_heal_allies;
68 float autocvar_g_monster_mage_heal_minhealth;
69 float autocvar_g_monster_mage_heal_range;
70 float autocvar_g_monster_mage_heal_delay;
71 float autocvar_g_monster_mage_shield_time;
72 float autocvar_g_monster_mage_shield_delay;
73 float autocvar_g_monster_mage_shield_blockpercent;
74 float autocvar_g_monster_mage_speed_stop;
75 float autocvar_g_monster_mage_speed_run;
76 float autocvar_g_monster_mage_speed_walk;
79 const float mage_anim_idle = 0;
80 const float mage_anim_walk = 1;
81 const float mage_anim_attack = 2;
82 const float mage_anim_pain = 3;
83 const float mage_anim_death = 4;
84 const float mage_anim_run = 5;
87 void M_Mage_Defend_Heal(entity this);
88 void M_Mage_Defend_Shield(entity this);
91 .float mage_shield_delay;
93 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
97 if(GetResource(targ, RES_HEALTH) <= 0)
99 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
101 if(STAT(FROZEN, targ))
104 return (IS_MONSTER(targ) && GetResource(targ, RES_HEALTH) < targ.max_health);
105 if(StatusEffects_active(STATUSEFFECT_Shield, targ))
110 case 0: return (GetResource(targ, RES_HEALTH) < autocvar_g_balance_health_regenstable);
113 return ((GetResource(targ, RES_CELLS) && GetResource(targ, RES_CELLS) < g_pickup_cells_max)
114 || (GetResource(targ, RES_PLASMA) && GetResource(targ, RES_PLASMA) < g_pickup_plasma_max)
115 || (GetResource(targ, RES_ROCKETS) && GetResource(targ, RES_ROCKETS) < g_pickup_rockets_max)
116 || (GetResource(targ, RES_BULLETS) && GetResource(targ, RES_BULLETS) < g_pickup_nails_max)
117 || (GetResource(targ, RES_SHELLS) && GetResource(targ, RES_SHELLS) < g_pickup_shells_max)
120 case 2: return (GetResource(targ, RES_ARMOR) < autocvar_g_balance_armor_regenstable);
121 case 3: return (GetResource(targ, RES_HEALTH) > 0);
127 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
129 this.event_damage = func_null;
131 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
133 this.realowner.mage_spike = NULL;
135 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
136 RadiusDamage (this, this.realowner, (autocvar_g_monster_mage_attack_spike_damage), (autocvar_g_monster_mage_attack_spike_damage) * 0.5, (autocvar_g_monster_mage_attack_spike_radius),
137 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
142 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
144 PROJECTILE_TOUCH(this, toucher);
146 M_Mage_Attack_Spike_Explode(this, toucher);
151 // copied from W_Seeker_Think
152 void M_Mage_Attack_Spike_Think(entity this)
154 if (time > this.ltime || (this.enemy && GetResource(this.enemy, RES_HEALTH) <= 0) || GetResource(this.owner, RES_HEALTH) <= 0) {
155 this.projectiledeathtype |= HITTYPE_SPLASH;
156 M_Mage_Attack_Spike_Explode(this, NULL);
159 float spd = vlen(this.velocity);
161 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
162 (autocvar_g_monster_mage_attack_spike_speed_max),
163 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
166 if (this.enemy != NULL)
167 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
170 if (this.enemy != NULL)
172 entity e = this.enemy;
173 vector eorg = 0.5 * (e.absmin + e.absmax);
174 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
175 vector desireddir = normalize(eorg - this.origin);
176 vector olddir = normalize(this.velocity); // get my current direction
178 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
179 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
181 // Is it a better idea (shorter distance) to trace to the target itself?
182 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
183 traceline(this.origin, this.origin + olddir * this.wait, false, this);
185 traceline(this.origin, eorg, false, this);
187 // Setup adaptive tracelength
188 this.wait = bound((autocvar_g_monster_mage_attack_spike_smart_trace_min), vlen(this.origin - trace_endpos), this.wait = (autocvar_g_monster_mage_attack_spike_smart_trace_max));
190 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
191 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
194 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
195 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
200 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
201 this.nextthink = time;// + 0.05; // csqc projectiles
202 UpdateCSQCProjectile(this);
205 void M_Mage_Attack_Spike(entity this, vector dir)
207 makevectors(this.angles);
209 entity missile = new(M_Mage_Attack_Spike);
210 missile.owner = missile.realowner = this;
211 setthink(missile, M_Mage_Attack_Spike_Think);
212 missile.ltime = time + 7;
213 missile.nextthink = time;
214 missile.solid = SOLID_BBOX;
215 set_movetype(missile, MOVETYPE_FLYMISSILE);
216 missile.flags = FL_PROJECTILE;
217 IL_PUSH(g_projectiles, missile);
218 IL_PUSH(g_bot_dodge, missile);
219 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
220 setsize(missile, '0 0 0', '0 0 0');
221 missile.velocity = dir * 400;
222 missile.avelocity = '300 300 300';
223 missile.enemy = this.enemy;
224 settouch(missile, M_Mage_Attack_Spike_Touch);
226 this.mage_spike = missile;
228 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
231 void M_Mage_Defend_Heal(entity this)
233 bool washealed = false;
235 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
238 entity fx = EFFECT_Null;
245 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
251 if(GetResource(it, RES_CELLS)) GiveResourceWithLimit(it, RES_CELLS, 1, g_pickup_cells_max);
252 if(GetResource(it, RES_PLASMA)) GiveResourceWithLimit(it, RES_PLASMA, 1, g_pickup_plasma_max);
253 if(GetResource(it, RES_ROCKETS)) GiveResourceWithLimit(it, RES_ROCKETS, 1, g_pickup_rockets_max);
254 if(GetResource(it, RES_SHELLS)) GiveResourceWithLimit(it, RES_SHELLS, 2, g_pickup_shells_max);
255 if(GetResource(it, RES_BULLETS)) GiveResourceWithLimit(it, RES_BULLETS, 5, g_pickup_nails_max);
257 fx = EFFECT_AMMO_REGEN;
261 if(GetResource(it, RES_ARMOR) < autocvar_g_balance_armor_regenstable)
263 GiveResourceWithLimit(it, RES_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
264 fx = EFFECT_ARMOR_REPAIR;
268 float hp = ((it == this) ? autocvar_g_monster_mage_heal_self : autocvar_g_monster_mage_heal_allies);
269 TakeResource(it, RES_HEALTH, hp); // TODO: use regular damage functions? needs a way to bypass friendly fire checks
274 Send_Effect(fx, it.origin, '0 0 0', 1);
278 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
279 Heal(it, this, autocvar_g_monster_mage_heal_allies, RES_LIMIT_NONE);
280 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
281 WaypointSprite_UpdateHealth(it.sprite, GetResource(it, RES_HEALTH));
287 setanim(this, this.anim_melee, true, true, true);
288 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
289 this.state = MONSTER_ATTACK_MELEE;
290 this.anim_finished = time + 1.5;
294 void M_Mage_Attack_Push(entity this)
296 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
297 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
298 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
299 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
301 setanim(this, this.anim_duckjump, true, true, true);
302 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
303 this.anim_finished = time + 1;
304 this.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
307 void M_Mage_Attack_Teleport(entity this, entity targ)
310 if(vdist(targ.origin - this.origin, >, 1500)) return;
312 if(autocvar_g_monster_mage_attack_teleport_random && random() <= autocvar_g_monster_mage_attack_teleport_random)
314 vector oldpos = this.origin;
315 vector extrasize = '1 1 1' * autocvar_g_monster_mage_attack_teleport_random_range;
316 if(MoveToRandomLocationWithinBounds(this, this.absmin - extrasize, this.absmax + extrasize,
317 DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER,
318 Q3SURFACEFLAG_SKY, 10, 64, 256, true))
320 vector a = vectoangles(targ.origin - this.origin);
321 this.angles = '0 1 0' * a.y;
322 this.fixangle = true;
323 Send_Effect(EFFECT_SPAWN_NEUTRAL, oldpos, '0 0 0', 1);
324 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
325 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
330 if(!IS_ONGROUND(targ)) return;
332 makevectors(targ.angles);
333 tracebox(CENTER_OR_VIEWOFS(targ), this.mins, this.maxs, CENTER_OR_VIEWOFS(targ) + ((v_forward * -1) * 200), MOVE_NOMONSTERS, this);
335 if(trace_fraction < 1)
338 vector newpos = trace_endpos;
340 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
341 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
343 setorigin(this, newpos);
345 vector a = vectoangles(targ.origin - this.origin);
349 this.fixangle = true;
350 this.velocity *= 0.5;
352 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
355 void M_Mage_Defend_Shield(entity this)
357 StatusEffects_apply(STATUSEFFECT_Shield, this, time + autocvar_g_monster_mage_shield_time, 0);
358 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
359 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
360 setanim(this, this.anim_shoot, true, true, true);
361 this.attack_finished_single[0] = time + 1; // give just a short cooldown on attacking
362 this.anim_finished = time + 1;
365 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
369 case MONSTER_ATTACK_MELEE:
371 if(random() <= autocvar_g_monster_mage_attack_push_chance)
373 Weapon wep = WEP_MAGE_SPIKE;
375 wep.wr_think(wep, actor, weaponentity, 2);
381 case MONSTER_ATTACK_RANGED:
383 if(random() <= autocvar_g_monster_mage_attack_teleport_chance)
385 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
386 actor.OffhandMageTeleport_key_pressed = 0;
387 off.offhand_think(off, actor, 1);
390 else if(!actor.mage_spike && random() <= autocvar_g_monster_mage_attack_spike_chance)
392 setanim(actor, actor.anim_shoot, true, true, true);
393 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
394 actor.anim_finished = time + 1;
395 actor.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
396 Weapon wep = WEP_MAGE_SPIKE;
397 wep.wr_think(wep, actor, weaponentity, 1);
408 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
413 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
416 bool need_help = false;
418 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
420 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
421 if(M_Mage_Defend_Heal_Check(actor, it))
430 IL_EACH(g_monsters, it != actor,
432 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
433 if(M_Mage_Defend_Heal_Check(actor, it))
441 if(GetResource(actor, RES_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
442 if(time >= actor.attack_finished_single[0])
444 M_Mage_Defend_Heal(actor);
446 if(actor.enemy && time >= actor.mage_shield_delay && random() < 0.5)
447 if(GetResource(actor, RES_HEALTH) < actor.max_health && !StatusEffects_active(STATUSEFFECT_Shield, actor))
448 M_Mage_Defend_Shield(actor);
453 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
459 METHOD(Mage, mr_death, bool(Mage this, entity actor))
462 setanim(actor, ((random() > 0.5) ? actor.anim_die2 : actor.anim_die1), false, true, true);
468 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
471 vector none = '0 0 0';
472 actor.anim_idle = animfixfps(actor, '0 1 1', none);
473 actor.anim_walk = animfixfps(actor, '1 1 1', none);
474 actor.anim_run = animfixfps(actor, '1 1 1', none);
475 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
476 actor.anim_duckjump = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
477 actor.anim_melee = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
478 //actor.anim_fire1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
479 //actor.anim_fire2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
480 //actor.anim_fire3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
481 actor.anim_pain1 = animfixfps(actor, '6 1 2', none); // 0.5 seconds
482 actor.anim_pain2 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
483 //actor.anim_pain3 = animfixfps(actor, '8 1 2', none); // 0.5 seconds
484 actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds
485 actor.anim_die2 = animfixfps(actor, '10 1 0.5', none); // 2 seconds
486 //actor.anim_dead1 = animfixfps(actor, '11 1 0.5', none); // 2 seconds
487 //actor.anim_dead2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds
493 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
496 if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_mage_health);
497 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
498 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
499 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
500 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
502 actor.monster_loot = ITEM_HealthBig;
503 actor.monster_attackfunc = M_Mage_Attack;