From: terencehill Date: Sun, 1 Sep 2024 12:07:16 +0000 (+0200) Subject: Don't apply status effects ending the moment they are applied. It fixes spawnshield... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c8beae0cb6c02aebf419d1779d9539d3a0616172;p=xonotic%2Fxonotic-data.pk3dir.git Don't apply status effects ending the moment they are applied. It fixes spawnshield applied for a moment even if g_spawnshieldtime is 0 This change required a refactoring of the give command code, which now no longer needs changing internal fields of the status effects to update them --- diff --git a/qcsrc/common/mutators/mutator/status_effects/status_effects.qc b/qcsrc/common/mutators/mutator/status_effects/status_effects.qc index eb1ced075..577503244 100644 --- a/qcsrc/common/mutators/mutator/status_effects/status_effects.qc +++ b/qcsrc/common/mutators/mutator/status_effects/status_effects.qc @@ -27,6 +27,9 @@ float StatusEffects_gettime(StatusEffects this, entity actor) #ifdef SVQC void StatusEffects_apply(StatusEffects this, entity actor, float eff_time, int eff_flags) { + if (!actor || eff_time <= time) + return; + this.m_apply(this, actor, eff_time, eff_flags); } diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index f43fa3b3d..6fc66efbd 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -1466,17 +1466,17 @@ float GiveWeapon(entity e, float wpn, float op, float val) bool GiveBuff(entity e, Buff thebuff, int op, int val) { bool had_buff = StatusEffects_active(thebuff, e); - float new_buff_time = ((had_buff) ? StatusEffects_gettime(thebuff, e) : 0); + float new_buff_time = ((had_buff) ? StatusEffects_gettime(thebuff, e) : time); switch (op) { case OP_SET: - new_buff_time = val; + new_buff_time = time + val; break; case OP_MIN: - new_buff_time = max(new_buff_time, val); + new_buff_time = max(new_buff_time, time + val); break; case OP_MAX: - new_buff_time = min(new_buff_time, val); + new_buff_time = min(new_buff_time, time + val); break; case OP_PLUS: new_buff_time += val; @@ -1485,7 +1485,7 @@ bool GiveBuff(entity e, Buff thebuff, int op, int val) new_buff_time -= val; break; } - if(new_buff_time <= 0) + if(new_buff_time <= time) { if(had_buff) // only trigger removal mechanics if there is an effect to remove! StatusEffects_remove(thebuff, e, STATUSEFFECT_REMOVE_NORMAL); @@ -1542,17 +1542,17 @@ bool GiveResourceValue(entity e, Resource res_type, int op, int val) bool GiveStatusEffect(entity e, StatusEffects this, int op, float val) { bool had_eff = StatusEffects_active(this, e); - float new_eff_time = ((had_eff) ? StatusEffects_gettime(this, e) : 0); + float new_eff_time = ((had_eff) ? StatusEffects_gettime(this, e) : time); switch (op) { case OP_SET: - new_eff_time = val; + new_eff_time = time + val; break; case OP_MIN: - new_eff_time = max(new_eff_time, val); + new_eff_time = max(new_eff_time, time + val); break; case OP_MAX: - new_eff_time = min(new_eff_time, val); + new_eff_time = min(new_eff_time, time + val); break; case OP_PLUS: new_eff_time += val; @@ -1561,7 +1561,7 @@ bool GiveStatusEffect(entity e, StatusEffects this, int op, float val) new_eff_time -= val; break; } - if(new_eff_time <= 0) + if(new_eff_time <= time) { if(had_eff) // only trigger removal mechanics if there is an effect to remove! StatusEffects_remove(this, e, STATUSEFFECT_REMOVE_NORMAL); @@ -1595,14 +1595,6 @@ float GiveItems(entity e, float beginarg, float endarg) } } - if(e.statuseffects) - { - FOREACH(StatusEffect, true, - { - e.statuseffects.statuseffect_time[it.m_id] = max(0, e.statuseffects.statuseffect_time[it.m_id] - time); - }); - } - PREGIVE(e, items); PREGIVE_WEAPONS(e); PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength); @@ -1730,8 +1722,8 @@ float GiveItems(entity e, float beginarg, float endarg) break; }); FOREACH(Weapons, it != WEP_Null && (cmd == it.netname || cmd == it.m_deprecated_netname), { - got += GiveWeapon(e, it.m_id, op, val); - break; + got += GiveWeapon(e, it.m_id, op, val); + break; }); break; } @@ -1765,21 +1757,11 @@ float GiveItems(entity e, float beginarg, float endarg) if(!StatusEffects_active(STATUSEFFECT_Superweapons, e)) { if(!g_weaponarena && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS)) - StatusEffects_apply(STATUSEFFECT_Superweapons, e, autocvar_g_balance_superweapons_time, 0); + StatusEffects_apply(STATUSEFFECT_Superweapons, e, time + autocvar_g_balance_superweapons_time, 0); } if(e.statuseffects) - { - FOREACH(StatusEffect, true, - { - if(e.statuseffects.statuseffect_time[it.m_id] <= 0) - e.statuseffects.statuseffect_time[it.m_id] = 0; - else - e.statuseffects.statuseffect_time[it.m_id] += time; - }); - StatusEffects_update(e); - } for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) {