From: Mario Date: Tue, 5 May 2020 20:34:03 +0000 (+1000) Subject: Improve reliability of giving buffs via triggers, fixes some odd cases involving... X-Git-Tag: xonotic-v0.8.5~1090 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b0cf4c6dd97724dabf844d02e0e3252e9bf86655;p=xonotic%2Fxonotic-data.pk3dir.git Improve reliability of giving buffs via triggers, fixes some odd cases involving the wrong buffs being given --- diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 6f385cdb4..7dccf97a2 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -1619,28 +1619,36 @@ float GiveWeapon(entity e, float wpn, float op, float val) bool GiveBuff(entity e, Buff thebuff, int op, int val) { bool had_buff = (STAT(BUFFS, e) & thebuff.m_itemid); + float new_buff_time = ((had_buff) ? STAT(BUFF_TIME, e) : 0); switch (op) { case OP_SET: - STAT(BUFF_TIME, e) = val; + new_buff_time = val; break; case OP_MIN: - STAT(BUFF_TIME, e) = max(STAT(BUFF_TIME, e), val); + new_buff_time = max(new_buff_time, val); break; case OP_MAX: - STAT(BUFF_TIME, e) = min(STAT(BUFF_TIME, e), val); + new_buff_time = min(new_buff_time, val); break; case OP_PLUS: - STAT(BUFF_TIME, e) += val; + new_buff_time += val; break; case OP_MINUS: - STAT(BUFF_TIME, e) -= val; + new_buff_time -= val; break; } - if(STAT(BUFF_TIME, e) <= 0) + if(new_buff_time <= 0) + { + if(had_buff) + STAT(BUFF_TIME, e) = new_buff_time; STAT(BUFFS, e) &= ~thebuff.m_itemid; + } else + { + STAT(BUFF_TIME, e) = new_buff_time; STAT(BUFFS, e) = thebuff.m_itemid; // NOTE: replaces any existing buffs on the player! + } bool have_buff = (STAT(BUFFS, e) & thebuff.m_itemid); return (had_buff != have_buff); }