4 float autocvar_g_monster_mage_health;
5 float autocvar_g_monster_mage_damageforcescale = 0.5;
6 float autocvar_g_monster_mage_attack_spike_damage;
7 float autocvar_g_monster_mage_attack_spike_radius;
8 float autocvar_g_monster_mage_attack_spike_delay;
9 float autocvar_g_monster_mage_attack_spike_accel;
10 float autocvar_g_monster_mage_attack_spike_decel;
11 float autocvar_g_monster_mage_attack_spike_chance = 0.45;
12 float autocvar_g_monster_mage_attack_spike_turnrate;
13 float autocvar_g_monster_mage_attack_spike_speed_max;
14 float autocvar_g_monster_mage_attack_spike_smart;
15 float autocvar_g_monster_mage_attack_spike_smart_trace_min;
16 float autocvar_g_monster_mage_attack_spike_smart_trace_max;
17 float autocvar_g_monster_mage_attack_spike_smart_mindist;
18 float autocvar_g_monster_mage_attack_push_chance = 0.7;
19 float autocvar_g_monster_mage_attack_push_damage;
20 float autocvar_g_monster_mage_attack_push_radius;
21 float autocvar_g_monster_mage_attack_push_delay;
22 float autocvar_g_monster_mage_attack_push_force;
23 float autocvar_g_monster_mage_attack_teleport_chance = 0.2;
24 float autocvar_g_monster_mage_attack_teleport_delay = 2;
25 float autocvar_g_monster_mage_attack_teleport_random = 0.4;
26 float autocvar_g_monster_mage_attack_teleport_random_range = 1200;
27 float autocvar_g_monster_mage_heal_allies;
28 float autocvar_g_monster_mage_heal_minhealth;
29 float autocvar_g_monster_mage_heal_range;
30 float autocvar_g_monster_mage_heal_delay;
31 float autocvar_g_monster_mage_shield_time;
32 float autocvar_g_monster_mage_shield_delay;
33 float autocvar_g_monster_mage_shield_blockpercent;
34 float autocvar_g_monster_mage_speed_stop;
35 float autocvar_g_monster_mage_speed_run;
36 float autocvar_g_monster_mage_speed_walk;
38 SOUND(MageSpike_FIRE, W_Sound("electro_fire"));
39 void M_Mage_Attack_Spike(entity this, vector dir);
40 void M_Mage_Attack_Push(entity this);
41 METHOD(MageSpike, wr_think, void(MageSpike thiswep, entity actor, .entity weaponentity, int fire))
43 TC(MageSpike, thiswep);
45 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, false, 0.2)) {
46 if (!actor.target_range) actor.target_range = autocvar_g_monsters_target_range;
47 actor.enemy = Monster_FindTarget(actor);
48 monster_makevectors(actor, actor.enemy);
49 W_SetupShot_Dir(actor, weaponentity, v_forward, false, 0, SND_MageSpike_FIRE, CH_WEAPON_B, 0, DEATH_MONSTER_MAGE.m_id);
50 if (!IS_PLAYER(actor)) w_shotdir = normalize((actor.enemy.origin + '0 0 10') - actor.origin);
51 M_Mage_Attack_Spike(actor, w_shotdir);
52 weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, 0, w_ready);
55 if (!IS_PLAYER(actor) || weapon_prepareattack(thiswep, actor, weaponentity, true, 0.5)) {
56 M_Mage_Attack_Push(actor);
57 weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, 0, w_ready);
61 void M_Mage_Attack_Teleport(entity this, entity targ);
63 CLASS(OffhandMageTeleport, OffhandWeapon)
64 .bool OffhandMageTeleport_key_pressed;
65 METHOD(OffhandMageTeleport, offhand_think, void(OffhandMageTeleport this, entity player, bool key_pressed))
67 TC(OffhandMageTeleport, this);
68 if (key_pressed && !player.OffhandMageTeleport_key_pressed)
69 M_Mage_Attack_Teleport(player, player.enemy);
70 player.OffhandMageTeleport_key_pressed = key_pressed;
72 ENDCLASS(OffhandMageTeleport)
73 OffhandMageTeleport OFFHAND_MAGE_TELEPORT;
74 STATIC_INIT(OFFHAND_MAGE_TELEPORT) { OFFHAND_MAGE_TELEPORT = NEW(OffhandMageTeleport); }
76 void M_Mage_Defend_Heal(entity this);
77 void M_Mage_Defend_Shield(entity this);
80 .float mage_shield_delay;
82 bool M_Mage_Defend_Heal_Check(entity this, entity targ)
86 if(GetResource(targ, RES_HEALTH) <= 0)
88 if(DIFF_TEAM(targ, this) && targ != this.monster_follow)
90 if(STAT(FROZEN, targ))
93 return (IS_MONSTER(targ) && GetResource(targ, RES_HEALTH) < targ.max_health);
94 if(StatusEffects_active(STATUSEFFECT_Shield, targ))
99 case 0: return (GetResource(targ, RES_HEALTH) < autocvar_g_balance_health_regenstable);
102 return ((GetResource(targ, RES_CELLS) && GetResource(targ, RES_CELLS) < g_pickup_cells_max)
103 || (GetResource(targ, RES_PLASMA) && GetResource(targ, RES_PLASMA) < g_pickup_plasma_max)
104 || (GetResource(targ, RES_ROCKETS) && GetResource(targ, RES_ROCKETS) < g_pickup_rockets_max)
105 || (GetResource(targ, RES_BULLETS) && GetResource(targ, RES_BULLETS) < g_pickup_nails_max)
106 || (GetResource(targ, RES_SHELLS) && GetResource(targ, RES_SHELLS) < g_pickup_shells_max)
109 case 2: return (GetResource(targ, RES_ARMOR) < autocvar_g_balance_armor_regenstable);
115 void M_Mage_Attack_Spike_Explode(entity this, entity directhitentity)
117 this.event_damage = func_null;
119 sound(this, CH_SHOTS, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
121 this.realowner.mage_spike = NULL;
123 Send_Effect(EFFECT_EXPLOSION_SMALL, this.origin, '0 0 0', 1);
124 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),
125 NULL, NULL, 0, DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, directhitentity);
130 void M_Mage_Attack_Spike_Touch(entity this, entity toucher)
132 PROJECTILE_TOUCH(this, toucher);
134 M_Mage_Attack_Spike_Explode(this, toucher);
139 // copied from W_Seeker_Think
140 void M_Mage_Attack_Spike_Think(entity this)
142 if (time > this.ltime || (this.enemy && GetResource(this.enemy, RES_HEALTH) <= 0) || !this.owner || GetResource(this.owner, RES_HEALTH) <= 0) {
143 this.projectiledeathtype |= HITTYPE_SPLASH;
144 M_Mage_Attack_Spike_Explode(this, NULL);
147 float spd = vlen(this.velocity);
149 spd - (autocvar_g_monster_mage_attack_spike_decel) * frametime,
150 (autocvar_g_monster_mage_attack_spike_speed_max),
151 spd + (autocvar_g_monster_mage_attack_spike_accel) * frametime
154 if (this.enemy != NULL)
155 if (this.enemy.takedamage != DAMAGE_AIM || IS_DEAD(this.enemy))
158 if (this.enemy != NULL)
160 entity e = this.enemy;
161 vector eorg = 0.5 * (e.absmin + e.absmax);
162 float turnrate = (autocvar_g_monster_mage_attack_spike_turnrate); // how fast to turn
163 vector desireddir = normalize(eorg - this.origin);
164 vector olddir = normalize(this.velocity); // get my current direction
166 // Do evasive maneuvers for world objects? ( this should be a cpu hog. :P )
167 if ((autocvar_g_monster_mage_attack_spike_smart) && vdist(eorg - this.origin, >, autocvar_g_monster_mage_attack_spike_smart_mindist))
169 // Is it a better idea (shorter distance) to trace to the target itself?
170 if ( vlen2(this.origin + olddir * this.wait) < vlen2(eorg - this.origin))
171 traceline(this.origin, this.origin + olddir * this.wait, false, this);
173 traceline(this.origin, eorg, false, this);
175 // Setup adaptive tracelength
176 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));
178 // Calc how important it is that we turn and add this to the desierd (enemy) dir.
179 desireddir = normalize(((trace_plane_normal * (1 - trace_fraction)) + (desireddir * trace_fraction)) * 0.5);
182 vector newdir = normalize(olddir + desireddir * turnrate); // take the average of the 2 directions; not the best method but simple & easy
183 this.velocity = newdir * spd; // make me fly in the new direction at my flight speed
188 //this.angles = vectoangles(this.velocity); // turn model in the new flight direction
189 this.nextthink = time;// + 0.05; // csqc projectiles
190 UpdateCSQCProjectile(this);
193 void M_Mage_Attack_Spike(entity this, vector dir)
195 makevectors(this.angles);
197 entity missile = new(M_Mage_Attack_Spike);
198 missile.owner = missile.realowner = this;
199 setthink(missile, M_Mage_Attack_Spike_Think);
200 missile.ltime = time + 7;
201 missile.nextthink = time;
202 missile.solid = SOLID_BBOX;
203 set_movetype(missile, MOVETYPE_FLYMISSILE);
204 missile.flags = FL_PROJECTILE;
205 IL_PUSH(g_projectiles, missile);
206 IL_PUSH(g_bot_dodge, missile);
207 setorigin(missile, this.origin + v_forward * 14 + '0 0 30' + v_right * -14);
208 setsize(missile, '0 0 0', '0 0 0');
209 missile.velocity = dir * 400;
210 missile.avelocity = '300 300 300';
211 missile.enemy = this.enemy;
212 settouch(missile, M_Mage_Attack_Spike_Touch);
214 this.mage_spike = missile;
216 CSQCProjectile(missile, true, PROJECTILE_MAGE_SPIKE, true);
219 void M_Mage_Defend_Heal(entity this)
221 bool washealed = false;
223 FOREACH_ENTITY_RADIUS(this.origin, autocvar_g_monster_mage_heal_range, M_Mage_Defend_Heal_Check(this, it),
226 entity fx = EFFECT_Null;
233 Heal(it, this, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_health_regenstable);
239 if(GetResource(it, RES_CELLS)) GiveResourceWithLimit(it, RES_CELLS, 1, g_pickup_cells_max);
240 if(GetResource(it, RES_PLASMA)) GiveResourceWithLimit(it, RES_PLASMA, 1, g_pickup_plasma_max);
241 if(GetResource(it, RES_ROCKETS)) GiveResourceWithLimit(it, RES_ROCKETS, 1, g_pickup_rockets_max);
242 if(GetResource(it, RES_SHELLS)) GiveResourceWithLimit(it, RES_SHELLS, 2, g_pickup_shells_max);
243 if(GetResource(it, RES_BULLETS)) GiveResourceWithLimit(it, RES_BULLETS, 5, g_pickup_nails_max);
245 fx = EFFECT_AMMO_REGEN;
249 if(GetResource(it, RES_ARMOR) < autocvar_g_balance_armor_regenstable)
251 GiveResourceWithLimit(it, RES_ARMOR, autocvar_g_monster_mage_heal_allies, autocvar_g_balance_armor_regenstable);
252 fx = EFFECT_ARMOR_REPAIR;
257 Send_Effect(fx, it.origin, '0 0 0', 1);
261 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
262 Heal(it, this, autocvar_g_monster_mage_heal_allies, RES_LIMIT_NONE);
263 if(!(it.spawnflags & MONSTERFLAG_INVINCIBLE) && it.sprite)
264 WaypointSprite_UpdateHealth(it.sprite, GetResource(it, RES_HEALTH));
270 setanim(this, this.anim_melee, true, true, true);
271 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_heal_delay);
272 this.state = MONSTER_ATTACK_MELEE;
273 this.anim_finished = time + 1.5;
277 void M_Mage_Attack_Push(entity this)
279 sound(this, CH_SHOTS, SND_TAGEXP1, 1, ATTEN_NORM);
280 RadiusDamage (this, this, (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_damage), (autocvar_g_monster_mage_attack_push_radius),
281 NULL, NULL, (autocvar_g_monster_mage_attack_push_force), DEATH_MONSTER_MAGE.m_id, DMG_NOWEP, this.enemy);
282 Send_Effect(EFFECT_TE_EXPLOSION, this.origin, '0 0 0', 1);
284 setanim(this, this.anim_duckjump, true, true, true);
285 this.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_push_delay);
286 this.anim_finished = time + 1;
287 this.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
290 void M_Mage_Attack_Teleport(entity this, entity targ)
293 if(vdist(targ.origin - this.origin, >, autocvar_g_monster_mage_attack_teleport_random_range)) return;
295 if(autocvar_g_monster_mage_attack_teleport_random && random() <= autocvar_g_monster_mage_attack_teleport_random)
297 vector oldpos = this.origin;
298 vector extrasize = '1 1 1' * autocvar_g_monster_mage_attack_teleport_random_range;
299 if(MoveToRandomLocationWithinBounds(this, this.absmin - extrasize, this.absmax + extrasize,
300 DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER,
301 Q3SURFACEFLAG_SKY, 10, 64, 256, true))
303 vector a = vectoangles(targ.origin - this.origin);
304 this.angles = '0 1 0' * a.y;
305 this.fixangle = true;
306 Send_Effect(EFFECT_SPAWN_NEUTRAL, oldpos, '0 0 0', 1);
307 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
308 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
313 if(!IS_ONGROUND(targ)) return;
315 makevectors(targ.angles);
316 tracebox(CENTER_OR_VIEWOFS(targ), this.mins, this.maxs, CENTER_OR_VIEWOFS(targ) + ((v_forward * -1) * 200), MOVE_NOMONSTERS, this);
318 if(trace_fraction < 1)
321 vector newpos = trace_endpos;
323 Send_Effect(EFFECT_SPAWN_NEUTRAL, this.origin, '0 0 0', 1);
324 Send_Effect(EFFECT_SPAWN_NEUTRAL, newpos, '0 0 0', 1);
326 setorigin(this, newpos);
328 vector a = vectoangles(targ.origin - this.origin);
332 this.fixangle = true;
333 this.velocity *= 0.5;
335 this.attack_finished_single[0] = time + autocvar_g_monster_mage_attack_teleport_delay;
338 void M_Mage_Defend_Shield(entity this)
340 StatusEffects_apply(STATUSEFFECT_Shield, this, time + autocvar_g_monster_mage_shield_time, 0);
341 this.mage_shield_delay = time + (autocvar_g_monster_mage_shield_delay);
342 SetResourceExplicit(this, RES_ARMOR, autocvar_g_monster_mage_shield_blockpercent);
343 setanim(this, this.anim_shoot, true, true, true);
344 this.attack_finished_single[0] = time + 1; // give just a short cooldown on attacking
345 this.anim_finished = time + 1;
348 bool M_Mage_Attack(int attack_type, entity actor, entity targ, .entity weaponentity)
352 case MONSTER_ATTACK_MELEE:
354 if(random() <= autocvar_g_monster_mage_attack_push_chance)
356 Weapon wep = WEP_MAGE_SPIKE;
358 wep.wr_think(wep, actor, weaponentity, 2);
364 case MONSTER_ATTACK_RANGED:
366 if(random() <= autocvar_g_monster_mage_attack_teleport_chance)
368 OffhandWeapon off = OFFHAND_MAGE_TELEPORT;
369 actor.OffhandMageTeleport_key_pressed = 0;
370 off.offhand_think(off, actor, 1);
373 else if(!actor.mage_spike && random() <= autocvar_g_monster_mage_attack_spike_chance)
375 setanim(actor, actor.anim_shoot, true, true, true);
376 actor.attack_finished_single[0] = time + (autocvar_g_monster_mage_attack_spike_delay);
377 actor.anim_finished = time + 1;
378 actor.state = MONSTER_ATTACK_MELEE; // prevent moving while firing spike
379 Weapon wep = WEP_MAGE_SPIKE;
380 wep.wr_think(wep, actor, weaponentity, 1);
391 spawnfunc(monster_mage) { Monster_Spawn(this, true, MON_MAGE); }
396 METHOD(Mage, mr_think, bool(Mage thismon, entity actor))
399 bool need_help = false;
401 FOREACH_CLIENT(IS_PLAYER(it) && it != actor,
403 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
404 if(M_Mage_Defend_Heal_Check(actor, it))
413 IL_EACH(g_monsters, it != actor,
415 if(vdist(it.origin - actor.origin, <=, autocvar_g_monster_mage_heal_range))
416 if(M_Mage_Defend_Heal_Check(actor, it))
424 if(GetResource(actor, RES_HEALTH) < (autocvar_g_monster_mage_heal_minhealth) || need_help)
425 if(time >= actor.attack_finished_single[0])
427 M_Mage_Defend_Heal(actor);
429 if(actor.enemy && time >= actor.mage_shield_delay && random() < 0.5)
430 if(GetResource(actor, RES_HEALTH) < actor.max_health && !StatusEffects_active(STATUSEFFECT_Shield, actor))
431 M_Mage_Defend_Shield(actor);
436 METHOD(Mage, mr_pain, float(Mage this, entity actor, float damage_take, entity attacker, float deathtype))
442 METHOD(Mage, mr_death, bool(Mage this, entity actor))
445 setanim(actor, ((random() > 0.5) ? actor.anim_die2 : actor.anim_die1), false, true, true);
451 METHOD(Mage, mr_anim, bool(Mage this, entity actor))
454 vector none = '0 0 0';
455 actor.anim_idle = animfixfps(actor, '0 1 1', none);
456 actor.anim_walk = animfixfps(actor, '1 1 1', none);
457 actor.anim_run = animfixfps(actor, '1 1 1', none);
458 actor.anim_shoot = animfixfps(actor, '2 1 5', none); // analyze models and set framerate
459 actor.anim_duckjump = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
460 actor.anim_melee = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
461 //actor.anim_fire1 = animfixfps(actor, '3 1 5', none); // analyze models and set framerate
462 //actor.anim_fire2 = animfixfps(actor, '4 1 5', none); // analyze models and set framerate
463 //actor.anim_fire3 = animfixfps(actor, '5 1 5', none); // analyze models and set framerate
464 actor.anim_pain1 = animfixfps(actor, '6 1 2', none); // 0.5 seconds
465 actor.anim_pain2 = animfixfps(actor, '7 1 2', none); // 0.5 seconds
466 //actor.anim_pain3 = animfixfps(actor, '8 1 2', none); // 0.5 seconds
467 actor.anim_die1 = animfixfps(actor, '9 1 0.5', none); // 2 seconds
468 actor.anim_die2 = animfixfps(actor, '10 1 0.5', none); // 2 seconds
469 //actor.anim_dead1 = animfixfps(actor, '11 1 0.5', none); // 2 seconds
470 //actor.anim_dead2 = animfixfps(actor, '12 1 0.5', none); // 2 seconds
476 METHOD(Mage, mr_setup, bool(Mage this, entity actor))
479 if(!GetResource(this, RES_HEALTH)) SetResourceExplicit(actor, RES_HEALTH, autocvar_g_monster_mage_health);
480 if(!actor.speed) { actor.speed = (autocvar_g_monster_mage_speed_walk); }
481 if(!actor.speed2) { actor.speed2 = (autocvar_g_monster_mage_speed_run); }
482 if(!actor.stopspeed) { actor.stopspeed = (autocvar_g_monster_mage_speed_stop); }
483 if(!actor.damageforcescale) { actor.damageforcescale = (autocvar_g_monster_mage_damageforcescale); }
485 actor.monster_loot = ITEM_HealthBig;
486 actor.monster_attackfunc = M_Mage_Attack;