3 #include <common/mapobjects/target/music.qh>
4 #include <common/mutators/mutator/powerups/_mod.qh>
5 #include <common/gamemodes/_mod.qh>
6 #include <server/items/items.qh>
8 bool buffs_BuffModel_Customize(entity this, entity client)
10 entity player = WaypointSprite_getviewentity(client);
11 entity myowner = this.owner;
12 entity heldbuff = buff_FirstFromFlags(myowner);
17 if(myowner.alpha <= 0.5 && DIFF_TEAM(player, myowner) && myowner.alpha != 0)
20 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
25 // somewhat hide the model, but keep the glow
31 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
32 this.alpha = myowner.alpha;
37 void buffs_BuffModel_Think(entity this)
39 this.nextthink = time;
40 entity player = this.owner;
41 if(player.alpha < 0 || player.buff_model != this)
43 if(player) // remnant from ChatBubbleThink, same question... WHY?!
44 player.buff_model = NULL;
49 entity heldbuff = buff_FirstFromFlags(player);
53 this.effects = EF_NODRAW;
57 this.color = heldbuff.m_color;
58 this.glowmod = heldbuff.m_color;
59 this.skin = heldbuff.m_skin;
61 this.effects = player.effects;
62 this.effects |= EF_LOWPRECISION;
63 this.effects = this.effects & EFMASK_CHEAP; // eat performance
65 this.alpha = player.alpha;
68 void buffs_BuffModel_Remove(entity player)
71 delete(player.buff_model);
72 player.buff_model = NULL;
75 void buffs_BuffModel_Spawn(entity player)
77 player.buff_model = new(buff_model);
78 setmodel(player.buff_model, MDL_BUFF);
79 setsize(player.buff_model, '0 0 -40', '0 0 40');
80 setattachment(player.buff_model, player, "");
81 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
82 player.buff_model.owner = player;
83 player.buff_model.exteriormodeltoclient = player;
84 player.buff_model.scale = 0.7;
85 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
86 player.buff_model.light_lev = 200;
87 setthink(player.buff_model, buffs_BuffModel_Think);
88 player.buff_model.nextthink = time;
89 setcefc(player.buff_model, buffs_BuffModel_Customize);
92 void buffs_BuffModel_Update(entity this)
96 // spawn a buff model entity if needed
98 buffs_BuffModel_Spawn(this);
101 void buff_Effect(entity player, string eff)
103 if(!autocvar_g_buffs_effects) { return; }
105 if(time >= player.buff_effect_delay)
107 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
108 player.buff_effect_delay = time + 0.05; // prevent spam
113 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
115 if(!this.owner.buff_active && !this.owner.buff_activetime || !this.owner.buffdef)
118 entity heldbuff = buff_FirstFromFlags(view); // TODO: cache this information so it isn't performing a loop every frame
121 return CS_CVAR(view).cvar_cl_buffs_autoreplace == false || heldbuff != this.owner.buffdef;
124 return WaypointSprite_visible_for_player(this, player, view);
127 void buff_Waypoint_Spawn(entity e)
129 if(autocvar_g_buffs_waypoint_distance <= 0) return;
131 entity buff = e.buffdef;
132 entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, NULL, e.team_forced, e, buff_waypoint, true, RADARICON_Buff);
133 wp.wp_extra = buff.m_id;
134 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
135 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
138 void buff_SetCooldown(entity this, float cd)
142 if(!this.buff_waypoint)
143 buff_Waypoint_Spawn(this);
145 if(this.buff_waypoint)
146 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
148 this.buff_activetime = cd;
149 this.buff_active = !cd;
152 void buff_Respawn(entity this)
154 if(game_stopped) return;
156 vector oldbufforigin = this.origin;
157 this.velocity = '0 0 200';
159 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
160 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
162 entity spot = SelectSpawnPoint(this, true);
163 setorigin(this, spot.origin);
164 this.velocity = ((randomvec() * 100) + '0 0 200');
165 this.angles = spot.angles;
168 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
170 setorigin(this, trace_endpos); // attempt to unstick
172 set_movetype(this, MOVETYPE_TOSS);
174 makevectors(this.angles);
175 this.angles = '0 0 0';
176 if(autocvar_g_buffs_random_lifetime > 0)
177 this.lifetime = time + autocvar_g_buffs_random_lifetime;
179 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
180 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
182 WaypointSprite_Ping(this.buff_waypoint);
184 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
187 void buff_Touch(entity this, entity toucher)
189 if(game_stopped) return;
191 if(ITEM_TOUCH_NEEDKILL())
197 if(!this.buff_active)
200 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
202 toucher = M_ARGV(1, entity);
204 if(!IS_PLAYER(toucher))
205 return; // incase mutator changed toucher
207 if((this.team_forced && toucher.team != this.team_forced)
208 || (STAT(FROZEN, toucher))
210 || (!this.buffdef) // TODO: error out or maybe reset type if this occurs?
211 || (time < toucher.buff_shield)
218 entity heldbuff = buff_FirstFromFlags(toucher);
219 entity thebuff = this.buffdef;
223 if (CS_CVAR(toucher).cvar_cl_buffs_autoreplace && heldbuff != thebuff)
225 // TODO: lost-gained notification for this case
226 int buffid = heldbuff.m_id;
227 Send_Notification(NOTIF_ONE, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
228 if(!IS_INDEPENDENT_PLAYER(toucher))
229 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
231 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
233 else { return; } // do nothing
236 this.owner = toucher;
237 this.buff_active = false;
239 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, thebuff.m_id);
240 if(!IS_INDEPENDENT_PLAYER(toucher))
241 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, thebuff.m_id);
243 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
244 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
245 float oldtime = StatusEffects_gettime(thebuff, toucher);
246 float bufftime = ((this.buffs_finished) ? this.buffs_finished : thebuff.m_time(thebuff));
248 buff_RemoveAll(toucher, STATUSEFFECT_REMOVE_NORMAL); // remove previous buffs so that a new one may be added
250 StatusEffects_apply(thebuff, toucher, min(time + bufftime, max(oldtime, time) + bufftime), 0);
252 StatusEffects_apply(thebuff, toucher, time + 999, 0); // HACK: zero timer means "infinite"!
254 STAT(LAST_PICKUP, toucher) = time;
257 float buff_Available(entity buff)
261 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_AMMO) || cvar("g_melee_only")))
263 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
265 return cvar(strcat("g_buffs_", buff.netname));
270 void buff_NewType(entity ent)
272 RandomSelection_Init();
273 FOREACH(StatusEffect, it.instanceOfBuff && buff_Available(it),
275 // if it's already been chosen, give it a lower priority
276 float myseencount = (it.buff_seencount > 0) ? it.buff_seencount : 1; // no division by zero please!
277 RandomSelection_AddEnt(it, max(0.2, 1 / myseencount), 1);
279 entity newbuff = RandomSelection_chosen_ent;
282 newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
283 ent.buffdef = newbuff;
286 void buff_RemoveAll(entity actor, int removal_type)
288 if(!actor.statuseffects)
290 FOREACH(StatusEffect, it.instanceOfBuff,
292 it.m_remove(it, actor, removal_type);
296 entity buff_FirstFromFlags(entity actor)
298 if(!actor.statuseffects)
300 FOREACH(StatusEffect, it.instanceOfBuff && it.m_active(it, actor), { return it; });
304 void buff_Think(entity this)
306 if(this.buff_waypoint && autocvar_g_buffs_waypoint_distance <= 0)
307 WaypointSprite_Kill(this.buff_waypoint);
309 if(this.buffdef != this.oldbuffs)
311 entity buff = this.buffdef;
312 this.color = buff.m_color;
313 this.glowmod = buff.m_color;
314 this.skin = buff.m_skin;
316 setmodel(this, MDL_BUFF);
317 setsize(this, BUFF_MIN, BUFF_MAX);
319 if(this.buff_waypoint)
321 //WaypointSprite_Disown(this.buff_waypoint, 1);
322 WaypointSprite_Kill(this.buff_waypoint);
323 buff_Waypoint_Spawn(this);
324 if(this.buff_activetime)
325 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
328 this.oldbuffs = this.buffdef;
332 if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
333 if(!this.buff_activetime_updated)
335 buff_SetCooldown(this, this.buff_activetime);
336 this.buff_activetime_updated = true;
339 if(!this.buff_active && !this.buff_activetime)
340 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle
341 || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway) || this.buffdef != buff_FirstFromFlags(this.owner))
343 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
345 if(autocvar_g_buffs_randomize && (!teamplay || autocvar_g_buffs_randomize_teamplay))
348 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
352 if(this.buff_activetime)
354 if((round_handler_IsActive() && round_handler_IsRoundStarted()) || time >= game_starttime)
356 this.buff_activetime = max(0, this.buff_activetime - frametime);
358 if(!this.buff_activetime)
360 this.buff_active = true;
361 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
362 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
368 if(this.team_forced && !this.buff_waypoint)
369 buff_Waypoint_Spawn(this);
371 if(this.lifetime && time >= this.lifetime)
375 this.nextthink = time;
376 //this.angles_y = time * 110.1;
379 void buff_Waypoint_Reset(entity this)
381 WaypointSprite_Kill(this.buff_waypoint);
383 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
386 void buff_Reset(entity this)
388 if(autocvar_g_buffs_randomize && (!teamplay || autocvar_g_buffs_randomize_teamplay))
391 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
392 buff_Waypoint_Reset(this);
393 this.buff_activetime_updated = false;
395 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
399 bool buff_Customize(entity this, entity client)
401 entity player = WaypointSprite_getviewentity(client);
402 if((!this.buff_active || !this.buffdef) || (this.team_forced && player.team != this.team_forced))
405 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
411 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
412 this.light_lev = 220 + 36 * sin(time);
413 this.pflags = PFLAGS_FULLDYNAMIC;
418 void buff_Delete(entity this)
420 WaypointSprite_Kill(this.buff_waypoint);
424 void buff_Init(entity this)
426 if(!cvar("g_buffs")) { delete(this); return; }
428 entity buff = this.buffdef;
430 if(!buff || !buff_Available(buff))
433 this.classname = "item_buff";
434 this.solid = SOLID_TRIGGER;
435 this.flags = FL_ITEM;
436 this.bot_pickup = true;
437 this.bot_pickupevalfunc = generic_pickupevalfunc;
438 this.bot_pickupbasevalue = 1000;
439 IL_PUSH(g_items, this);
440 setthink(this, buff_Think);
441 settouch(this, buff_Touch);
442 setmodel(this, MDL_BUFF);
443 setsize(this, BUFF_MIN, BUFF_MAX);
444 this.reset = buff_Reset;
445 this.nextthink = time + 0.1;
447 set_movetype(this, MOVETYPE_TOSS);
449 this.skin = buff.m_skin;
450 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
451 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
452 setcefc(this, buff_Customize);
453 //this.gravity = 100;
454 this.color = buff.m_color;
455 this.glowmod = buff.m_color;
456 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
457 this.buff_active = !this.buff_activetime;
458 this.pflags = PFLAGS_FULLDYNAMIC;
459 this.dtor = buff_Delete;
461 if(!this.buffs_finished)
462 this.buffs_finished = this.count; // legacy support
464 if(this.spawnflags & 1)
468 set_movetype(this, MOVETYPE_NONE); // reset by random location
470 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
474 void buff_Init_Compat(entity ent, entity replacement)
478 if (ent.spawnflags & 2)
479 ent.team_forced = NUM_TEAM_1;
480 else if (ent.spawnflags & 4)
481 ent.team_forced = NUM_TEAM_2;
484 ent.buffdef = replacement;
489 void buff_SpawnReplacement(entity ent, entity old)
491 setorigin(ent, old.origin);
492 ent.angles = old.angles;
493 ent.noalign = ITEM_SHOULD_KEEP_POSITION(old);
498 void buff_Vengeance_DelayedDamage(entity this)
501 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, DMG_NOWEP, this.enemy.origin, '0 0 0');
507 float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
509 return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
512 METHOD(Buff, m_apply, void(StatusEffects this, entity actor, float eff_time, float eff_flags))
515 actor.effects |= EF_NOSHADOW; // does not play well with buff icon
516 SUPER(Buff).m_apply(this, actor, eff_time, eff_flags);
518 METHOD(Buff, m_remove, void(StatusEffects this, entity actor, int removal_type))
520 bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
523 int buffid = this.m_id;
524 if(removal_type == STATUSEFFECT_REMOVE_TIMEOUT)
526 Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
527 sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
529 else if(removal_type == STATUSEFFECT_REMOVE_NORMAL && !IS_INDEPENDENT_PLAYER(actor))
530 Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
531 actor.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
534 actor.effects &= ~EF_NOSHADOW;
535 SUPER(Buff).m_remove(this, actor, removal_type);
538 METHOD(AmmoBuff, m_apply, void(StatusEffects this, entity actor, float eff_time, float eff_flags))
540 bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
543 actor.buff_ammo_prev_infitems = (actor.items & IT_UNLIMITED_AMMO);
544 actor.items |= IT_UNLIMITED_AMMO;
545 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
547 .entity weaponentity = weaponentities[slot];
548 if(!actor.(weaponentity))
550 if(actor.(weaponentity).clip_load)
551 actor.(weaponentity).buff_ammo_prev_clipload = actor.(weaponentity).clip_load;
552 if(actor.(weaponentity).clip_size)
553 actor.(weaponentity).clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_switchweapon.m_id]) = actor.(weaponentity).clip_size;
556 SUPER(AmmoBuff).m_apply(this, actor, eff_time, eff_flags);
558 METHOD(AmmoBuff, m_remove, void(StatusEffects this, entity actor, int removal_type))
560 bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
563 actor.items = BITSET(actor.items, IT_UNLIMITED_AMMO, actor.buff_ammo_prev_infitems);
564 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
566 .entity weaponentity = weaponentities[slot];
567 if(!actor.(weaponentity))
569 if(actor.(weaponentity).buff_ammo_prev_clipload)
571 actor.(weaponentity).clip_load = actor.(weaponentity).buff_ammo_prev_clipload;
572 actor.(weaponentity).buff_ammo_prev_clipload = 0;
576 actor.buff_ammo_prev_infitems = 0;
577 SUPER(AmmoBuff).m_remove(this, actor, removal_type);
579 METHOD(AmmoBuff, m_tick, void(StatusEffects this, entity actor))
583 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
585 .entity weaponentity = weaponentities[slot];
586 if(actor.(weaponentity).clip_size)
587 actor.(weaponentity).clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_switchweapon.m_id]) = actor.(weaponentity).clip_size;
591 SUPER(AmmoBuff).m_tick(this, actor);
595 METHOD(FlightBuff, m_apply, void(StatusEffects this, entity actor, float eff_time, float eff_flags))
597 bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
600 actor.buff_flight_oldgravity = actor.gravity;
604 SUPER(FlightBuff).m_apply(this, actor, eff_time, eff_flags);
606 METHOD(FlightBuff, m_remove, void(StatusEffects this, entity actor, int removal_type))
608 bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
611 actor.gravity = ((actor.trigger_gravity_check) ? actor.trigger_gravity_check.enemy.gravity : actor.buff_flight_oldgravity);
613 actor.buff_flight_oldgravity = 0;
614 SUPER(FlightBuff).m_remove(this, actor, removal_type);
617 METHOD(MagnetBuff, m_tick, void(StatusEffects this, entity actor))
622 IL_EACH(g_items, it.itemdef,
625 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
627 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
629 if(boxesoverlap(actor.absmin - pickup_size, actor.absmax + pickup_size, it.absmin, it.absmax))
632 gettouch(it)(it, actor);
637 SUPER(MagnetBuff).m_tick(this, actor);
641 MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
643 entity frag_attacker = M_ARGV(1, entity);
644 entity frag_target = M_ARGV(2, entity);
645 float frag_deathtype = M_ARGV(3, float);
646 float frag_damage = M_ARGV(4, float);
647 vector frag_force = M_ARGV(6, vector);
649 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
651 if(StatusEffects_active(BUFF_RESISTANCE, frag_target))
653 float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent;
654 frag_damage = bound(0, frag_damage - reduced, frag_damage);
657 if(StatusEffects_active(BUFF_MEDIC, frag_target))
658 if((GetResource(frag_target, RES_HEALTH) - frag_damage) <= 0)
659 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
661 if(random() <= autocvar_g_buffs_medic_survive_chance)
662 frag_damage = max(5, GetResource(frag_target, RES_HEALTH) - autocvar_g_buffs_medic_survive_health);
664 if(StatusEffects_active(BUFF_JUMP, frag_target))
665 if(frag_deathtype == DEATH_FALL.m_id)
668 if(StatusEffects_active(BUFF_VENGEANCE, frag_target))
670 if(frag_attacker != frag_target)
671 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
673 entity dmgent = new_pure(dmgent);
675 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
676 dmgent.enemy = frag_attacker;
677 dmgent.owner = frag_target;
678 setthink(dmgent, buff_Vengeance_DelayedDamage);
679 dmgent.nextthink = time + 0.1;
682 if(StatusEffects_active(BUFF_BASH, frag_target))
683 if(frag_attacker != frag_target)
684 frag_force = '0 0 0';
686 if(StatusEffects_active(BUFF_BASH, frag_attacker))
689 if(frag_attacker == frag_target)
690 frag_force *= autocvar_g_buffs_bash_force_self;
692 frag_force *= autocvar_g_buffs_bash_force;
695 if(StatusEffects_active(BUFF_DISABILITY, frag_attacker))
696 if(frag_target != frag_attacker)
697 StatusEffects_apply(STATUSEFFECT_Stunned, frag_target, time + autocvar_g_buffs_disability_slowtime, 0);
699 if(StatusEffects_active(BUFF_INFERNO, frag_target))
701 if(frag_deathtype == DEATH_FIRE.m_id)
703 if(frag_deathtype == DEATH_LAVA.m_id)
704 frag_damage *= 0.5; // TODO: cvarize?
707 if(StatusEffects_active(BUFF_LUCK, frag_attacker))
708 if(frag_attacker != frag_target)
709 if(autocvar_g_buffs_luck_damagemultiplier > 0)
710 if(random() <= autocvar_g_buffs_luck_chance)
711 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
713 if(StatusEffects_active(BUFF_INFERNO, frag_attacker))
714 if(frag_target != frag_attacker) {
715 float btime = buff_Inferno_CalculateTime(
718 autocvar_g_buffs_inferno_burntime_min_time,
719 autocvar_g_buffs_inferno_burntime_target_damage,
720 autocvar_g_buffs_inferno_burntime_target_time,
721 autocvar_g_buffs_inferno_burntime_factor
723 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
726 M_ARGV(4, float) = frag_damage;
727 M_ARGV(6, vector) = frag_force;
730 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
732 // NOTE: vampire PlayerDamage_SplitHealthArmor code is similar
733 entity frag_attacker = M_ARGV(1, entity);
734 entity frag_target = M_ARGV(2, entity);
735 if(!StatusEffects_active(BUFF_VAMPIRE, frag_attacker))
737 float health_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
739 if (!StatusEffects_active(STATUSEFFECT_SpawnShield, frag_target) && frag_target != frag_attacker
740 && IS_PLAYER(frag_attacker) && !IS_DEAD(frag_target) && !STAT(FROZEN, frag_target))
742 GiveResource(frag_attacker, RES_HEALTH, autocvar_g_buffs_vampire_damage_steal * health_take);
746 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
748 entity player = M_ARGV(0, entity);
749 // these automatically reset, no need to worry
751 if(StatusEffects_active(STATUSEFFECT_Stunned, player))
752 STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
755 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
757 entity player = M_ARGV(0, entity);
758 // these automatically reset, no need to worry
760 if(StatusEffects_active(BUFF_JUMP, player))
761 STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
764 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
766 entity mon = M_ARGV(0, entity);
768 if(StatusEffects_active(STATUSEFFECT_Stunned, mon))
770 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
771 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
775 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
777 if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
779 entity player = M_ARGV(0, entity);
781 entity heldbuff = buff_FirstFromFlags(player);
784 int buffid = heldbuff.m_id;
785 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
786 if(!IS_INDEPENDENT_PLAYER(player))
787 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
789 buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
790 player.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
791 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
796 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
798 if(MUTATOR_RETURNVALUE || game_stopped) return;
799 entity player = M_ARGV(0, entity);
801 if(StatusEffects_active(BUFF_SWAPPER, player))
803 float best_distance = autocvar_g_buffs_swapper_range;
804 entity closest = NULL;
805 FOREACH_CLIENT(IS_PLAYER(it), {
806 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
807 if(DIFF_TEAM(it, player))
809 float test = vlen2(player.origin - it.origin);
810 if(test <= best_distance * best_distance)
812 best_distance = sqrt(test);
820 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
822 my_org = player.origin;
823 my_vel = player.velocity;
824 my_ang = player.angles;
825 their_org = closest.origin;
826 their_vel = closest.velocity;
827 their_ang = closest.angles;
829 Drop_Special_Items(closest);
831 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
833 setorigin(player, their_org);
834 setorigin(closest, my_org);
836 closest.velocity = my_vel;
837 closest.angles = my_ang;
838 if (IS_BOT_CLIENT(closest))
840 closest.v_angle = closest.angles;
841 bot_aim_reset(closest);
843 closest.fixangle = true;
844 closest.oldorigin = my_org;
845 closest.oldvelocity = my_vel;
846 player.velocity = their_vel;
847 player.angles = their_ang;
848 if (IS_BOT_CLIENT(player))
850 player.v_angle = player.angles;
851 bot_aim_reset(player);
853 player.fixangle = true;
854 player.oldorigin = their_org;
855 player.oldvelocity = their_vel;
857 // set pusher so player gets the kill if they fall into void
858 closest.pusher = player;
859 closest.pushltime = time + autocvar_g_maxpushtime;
860 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
862 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
863 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
865 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
866 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
868 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
869 buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
875 bool buffs_RemovePlayer(entity player)
877 buffs_BuffModel_Remove(player);
881 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
882 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
884 MUTATOR_HOOKFUNCTION(buffs, FilterItem)
886 if(autocvar_g_buffs < 0)
887 return false; // no auto replacing of entities in this mode
889 entity item = M_ARGV(0, entity);
891 if(autocvar_g_buffs_replace_powerups && item.itemdef.instanceOfPowerup)
894 buff_SpawnReplacement(e, item);
901 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
903 entity player = M_ARGV(1, entity);
905 if(StatusEffects_active(STATUSEFFECT_Stunned, player))
906 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
909 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
911 entity player = M_ARGV(1, entity);
913 if(StatusEffects_active(STATUSEFFECT_Stunned, player))
914 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
917 MUTATOR_HOOKFUNCTION(buffs, Freeze)
919 entity targ = M_ARGV(0, entity);
920 buff_RemoveAll(targ, STATUSEFFECT_REMOVE_NORMAL);
923 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
925 entity player = M_ARGV(0, entity);
927 if(game_stopped || IS_DEAD(player) || !IS_PLAYER(player)) return;
929 // NOTE: this is kept here to ensure crouches are picked up each player movement frame
930 if(StatusEffects_active(BUFF_FLIGHT, player))
932 if(!PHYS_INPUT_BUTTON_CROUCH(player))
933 player.buff_flight_crouchheld = false;
934 else if(!player.buff_flight_crouchheld)
936 player.buff_flight_crouchheld = true;
937 player.gravity *= -1;
941 if(IS_PLAYER(player))
942 buffs_BuffModel_Update(player);
945 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
947 entity player = M_ARGV(0, entity);
949 if(StatusEffects_active(BUFF_MEDIC, player))
951 M_ARGV(3, float) = autocvar_g_buffs_medic_rot; // rot_mod
952 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
953 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
957 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
959 if(autocvar_g_buffs > 0) // only report as a mutator if they're enabled
960 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
963 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
965 if(autocvar_g_buffs > 0)
966 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
969 void buffs_DelayedInit(entity this)
971 if(autocvar_g_buffs_spawn_count > 0)
972 if(find(NULL, classname, "item_buff") == NULL)
975 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
978 e.spawnflags |= 64; // always randomize
979 e.velocity = randomvec() * 250; // this gets reset anyway if random location works
985 void buffs_Initialize()
987 // if buffs are above 0, allow random spawning
988 if(autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0)
989 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);