]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Don't apply status effects ending the moment they are applied. It fixes spawnshield...
authorterencehill <piuntn@gmail.com>
Sun, 1 Sep 2024 12:07:16 +0000 (14:07 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 1 Sep 2024 12:07:16 +0000 (14:07 +0200)
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

qcsrc/common/mutators/mutator/status_effects/status_effects.qc
qcsrc/server/items/items.qc

index eb1ced075d17c3643e5b260044c05d21f7191c33..5775032440a83c7144b73dccdb80d9ba9daa9966 100644 (file)
@@ -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);
 }
 
index f43fa3b3dc0cbc2d708f0a28bb541eaa26f8bc9e..6fc66efbdf4264bcfc446a4d6cf33028e48bc707 100644 (file)
@@ -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)
        {