From 3a7bb698fc376fddd5e397050bd5e8e75b6f87d7 Mon Sep 17 00:00:00 2001 From: Maxicarlos08 Date: Sat, 13 Jan 2024 19:53:02 +0100 Subject: [PATCH] handle overlap and queueing correctly --- common/src/comp/buff.rs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index ec58a4c0af..8b98f38284 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -772,18 +772,26 @@ impl Buffs { pub fn insert(&mut self, buff: Buff, current_time: Time) -> BuffKey { let kind = buff.kind; - // Try to find another buff with same data, cat_ids and source - let other_key = self.kinds[kind].as_ref().and_then(|(keys, _)| { - keys.iter() - .find(|key| { - self.buffs.get(**key).map_or(false, |other_buff| { - other_buff.data == buff.data - && other_buff.cat_ids == buff.cat_ids - && other_buff.source == buff.source + // Try to find another overlaping non-queueable buff with same data, cat_ids and + // source. + let other_key = if kind.queues() { + None + } else { + self.kinds[kind].as_ref().and_then(|(keys, _)| { + keys.iter() + .find(|key| { + self.buffs.get(**key).map_or(false, |other_buff| { + other_buff.data == buff.data + && other_buff.cat_ids == buff.cat_ids + && other_buff.source == buff.source + && other_buff + .end_time + .map_or(true, |end_time| end_time.0 >= buff.start_time.0) + }) }) - }) - .copied() - }); + .copied() + }) + }; // If another buff with the same fields is found, update end_time and effects let key = if let Some((other_buff, key)) =