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;
78 void M_Mage_Defend_Heal(entity this);
79 void M_Mage_Defend_Shield(entity this);
82 .float mage_shield_delay;
84 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
88 if(GetResource(targ, RES_HEALTH) <= 0)
90 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
92 if(STAT(FROZEN, targ))
95 return (IS_MONSTER(targ) && GetResource(targ, RES_HEALTH) < targ.max_health);
96 if(StatusEffects_active(STATUSEFFECT_Shield, targ))
101 case 0: return (GetResource(targ, RES_HEALTH) < autocvar_g_balance_health_regenstable);
104 return ((GetResource(targ, RES_CELLS) && GetResource(targ, RES_CELLS) < g_pickup_cells_max)
105 || (GetResource(targ, RES_PLASMA) && GetResource(targ, RES_PLASMA) < g_pickup_plasma_max)
106 || (GetResource(targ, RES_ROCKETS) && GetResource(targ, RES_ROCKETS) < g_pickup_rockets_max)
107 || (GetResource(targ, RES_BULLETS) && GetResource(targ, RES_BULLETS) < g_pickup_nails_max)
108 || (GetResource(targ, RES_SHELLS) && GetResource(targ, RES_SHELLS) < g_pickup_shells_max)
111 case 2: return (GetResource(targ, RES_ARMOR) < autocvar_g_balance_armor_regenstable);
112 case 3: return (GetResource(targ, RES_HEALTH) > 0);
118 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
120 this.event_damage = func_null;
122 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
124 this.realowner.mage_spike = NULL;
126 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
127 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),
128 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
133 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
135 PROJECTILE_TOUCH(this, toucher);
137 M_Mage_Attack_Spike_Explode(this, toucher);
142 // copied from W_Seeker_Think
143 void M_Mage_Attack_Spike_Think(entity this)
145 if (time > this.ltime || (this.enemy && GetResource(this.enemy, RES_HEALTH) <= 0) || !this.owner || GetResource(this.owner, RES_HEALTH) <= 0) {
146 this.projectiledeathtype |= HITTYPE_SPLASH;
147 M_Mage_Attack_Spike_Explode(this, NULL);
150 float spd = vlen(this.velocity);
152 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
153 (autocvar_g_monster_mage_attack_spike_speed_max),
154 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
157 if (this.enemy != NULL)
158 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
161 if (this.enemy != NULL)
163 entity e = this.enemy;
164 vector eorg = 0.5 * (e.absmin + e.absmax);
165 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
166 vector desireddir = normalize(eorg - this.origin);
167 vector olddir = normalize(this.velocity); // get my current direction
169 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
170 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
172 // Is it a better idea (shorter distance) to trace to the target itself?
173 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
174 traceline(this.origin, this.origin + olddir * this.wait, false, this);
176 traceline(this.origin, eorg, false, this);
178 // Setup adaptive tracelength
179 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));
181 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
182 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
185 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
186 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
191 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
192 this.nextthink = time;// + 0.05; // csqc projectiles
193 UpdateCSQCProjectile(this);
196 void M_Mage_Attack_Spike(entity this, vector dir)
198 makevectors(this.angles);
200 entity missile = new(M_Mage_Attack_Spike);
201 missile.owner = missile.realowner = this;
202 setthink(missile, M_Mage_Attack_Spike_Think);
203 missile.ltime = time + 7;
204 missile.nextthink = time;
205 missile.solid = SOLID_BBOX;
206 set_movetype(missile, MOVETYPE_FLYMISSILE);
207 missile.flags = FL_PROJECTILE;
208 IL_PUSH(g_projectiles, missile);
209 IL_PUSH(g_bot_dodge, missile);
210 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
211 setsize(missile, '0 0 0', '0 0 0');
212 missile.velocity = dir * 400;
213 missile.avelocity = '300 300 300';
214 missile.enemy = this.enemy;
215 settouch(missile, M_Mage_Attack_Spike_Touch);
217 this.mage_spike = missile;
219 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
222 void M_Mage_Defend_Heal(entity this)
224 bool washealed = false;
226 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
229 entity fx = EFFECT_Null;
236 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
242 if(GetResource(it, RES_CELLS)) GiveResourceWithLimit(it, RES_CELLS, 1, g_pickup_cells_max);
243 if(GetResource(it, RES_PLASMA)) GiveResourceWithLimit(it, RES_PLASMA, 1, g_pickup_plasma_max);
244 if(GetResource(it, RES_ROCKETS)) GiveResourceWithLimit(it, RES_ROCKETS, 1, g_pickup_rockets_max);
245 if(GetResource(it, RES_SHELLS)) GiveResourceWithLimit(it, RES_SHELLS, 2, g_pickup_shells_max);
246 if(GetResource(it, RES_BULLETS)) GiveResourceWithLimit(it, RES_BULLETS, 5, g_pickup_nails_max);
248 fx = EFFECT_AMMO_REGEN;
252 if(GetResource(it, RES_ARMOR) < autocvar_g_balance_armor_regenstable)
254 GiveResourceWithLimit(it, RES_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
255 fx = EFFECT_ARMOR_REPAIR;
259 float hp = ((it == this) ? autocvar_g_monster_mage_heal_self : autocvar_g_monster_mage_heal_allies);
260 TakeResource(it, RES_HEALTH, hp); // TODO: use regular damage functions? needs a way to bypass friendly fire checks
265 Send_Effect(fx, it.origin, '0 0 0', 1);
269 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
270 Heal(it, this, autocvar_g_monster_mage_heal_allies, RES_LIMIT_NONE);
271 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
272 WaypointSprite_UpdateHealth(it.sprite, GetResource(it, RES_HEALTH));
278 setanim(this, this.anim_melee, true, true, true);
279 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
280 this.state = MONSTER_ATTACK_MELEE;
281 this.anim_finished = time + 1.5;
285 void M_Mage_Attack_Push(entity this)
287 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
288 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
289 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
290 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
292 setanim(this, this.anim_duckjump, true, true, true);
293 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
294 this.anim_finished = time + 1;
295 this.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
298 void M_Mage_Attack_Teleport(entity this, entity targ)
301 if(vdist(targ.origin - this.origin, >, autocvar_g_monster_mage_attack_teleport_random_range)) return;
303 if(autocvar_g_monster_mage_attack_teleport_random && random() <= autocvar_g_monster_mage_attack_teleport_random)
305 vector oldpos = this.origin;
306 vector extrasize = '1 1 1' * autocvar_g_monster_mage_attack_teleport_random_range;
307 if(MoveToRandomLocationWithinBounds(this, this.absmin - extrasize, this.absmax + extrasize,
308 DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER,
309 Q3SURFACEFLAG_SKY, 10, 64, 256, true))
311 vector a = vectoangles(targ.origin - this.origin);
312 this.angles = '0 1 0' * a.y;
313 this.fixangle = true;
314 Send_Effect(EFFECT_SPAWN_NEUTRAL, oldpos, '0 0 0', 1);
315 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
316 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
321 if(!IS_ONGROUND(targ)) return;
323 makevectors(targ.angles);
324 tracebox(CENTER_OR_VIEWOFS(targ), this.mins, this.maxs, CENTER_OR_VIEWOFS(targ) + ((v_forward * -1) * 200), MOVE_NOMONSTERS, this);
326 if(trace_fraction < 1)
329 vector newpos = trace_endpos;
331 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
332 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
334 setorigin(this, newpos);
336 vector a = vectoangles(targ.origin - this.origin);
340 this.fixangle = true;
341 this.velocity *= 0.5;
343 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
346 void M_Mage_Defend_Shield(entity this)
348 StatusEffects_apply(STATUSEFFECT_Shield, this, time + autocvar_g_monster_mage_shield_time, 0);
349 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
350 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
351 setanim(this, this.anim_shoot, true, true, true);
352 this.attack_finished_single[0] = time + 1; // give just a short cooldown on attacking
353 this.anim_finished = time + 1;
356 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
360 case MONSTER_ATTACK_MELEE:
362 if(random() <= autocvar_g_monster_mage_attack_push_chance)
364 Weapon wep = WEP_MAGE_SPIKE;
366 wep.wr_think(wep, actor, weaponentity, 2);
372 case MONSTER_ATTACK_RANGED:
374 if(random() <= autocvar_g_monster_mage_attack_teleport_chance)
376 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
377 actor.OffhandMageTeleport_key_pressed = 0;
378 off.offhand_think(off, actor, 1);
381 else if(!actor.mage_spike && random() <= autocvar_g_monster_mage_attack_spike_chance)
383 setanim(actor, actor.anim_shoot, true, true, true);
384 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
385 actor.anim_finished = time + 1;
386 actor.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
387 Weapon wep = WEP_MAGE_SPIKE;
388 wep.wr_think(wep, actor, weaponentity, 1);
399 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
404 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
407 bool need_help = false;
409 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
411 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
412 if(M_Mage_Defend_Heal_Check(actor, it))
421 IL_EACH(g_monsters, it != actor,
423 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
424 if(M_Mage_Defend_Heal_Check(actor, it))
432 if(GetResource(actor, RES_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
433 if(time >= actor.attack_finished_single[0])
435 M_Mage_Defend_Heal(actor);
437 if(actor.enemy && time >= actor.mage_shield_delay && random() < 0.5)
438 if(GetResource(actor, RES_HEALTH) < actor.max_health && !StatusEffects_active(STATUSEFFECT_Shield, actor))
439 M_Mage_Defend_Shield(actor);
444 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
450 METHOD(Mage, mr_death, bool(Mage this, entity actor))
453 setanim(actor, ((random() > 0.5) ? actor.anim_die2 : actor.anim_die1), false, true, true);
459 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
462 vector none = '0 0 0';
463 actor.anim_idle = animfixfps(actor, '0 1 1', none);
464 actor.anim_walk = animfixfps(actor, '1 1 1', none);
465 actor.anim_run = animfixfps(actor, '1 1 1', none);
466 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
467 actor.anim_duckjump = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
468 actor.anim_melee = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
469 //actor.anim_fire1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
470 //actor.anim_fire2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
471 //actor.anim_fire3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
472 actor.anim_pain1 = animfixfps(actor, '6 1 2', none); // 0.5 seconds
473 actor.anim_pain2 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
474 //actor.anim_pain3 = animfixfps(actor, '8 1 2', none); // 0.5 seconds
475 actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds
476 actor.anim_die2 = animfixfps(actor, '10 1 0.5', none); // 2 seconds
477 //actor.anim_dead1 = animfixfps(actor, '11 1 0.5', none); // 2 seconds
478 //actor.anim_dead2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds
484 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
487 if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_mage_health);
488 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
489 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
490 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
491 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
493 actor.monster_loot = ITEM_HealthBig;
494 actor.monster_attackfunc = M_Mage_Attack;