fix duplicate heads collecting

turns out we did not consider the ActiveHeads just duplicates in the backpack
This commit is contained in:
2025-12-10 19:32:32 -05:00
parent abf037baa3
commit e044558a93
2 changed files with 11 additions and 4 deletions

View File

@@ -4,7 +4,10 @@ use crate::{
protocol::PlaySound,
};
use crate::{
cash::CashCollectEvent, global_observer, head_drop::HeadCollected, heads::HeadState,
cash::CashCollectEvent,
global_observer,
head_drop::HeadCollected,
heads::{ActiveHeads, HeadState},
heads_database::HeadsDatabase,
};
use bevy::prelude::*;
@@ -155,14 +158,14 @@ fn sync_backpack_ui(backpack: &Backpack, state: &mut BackpackUiState, time: f32)
fn on_head_collect(
trigger: On<HeadCollected>,
mut cmds: Commands,
mut backpack: Query<&mut Backpack>,
mut query: Query<(&mut Backpack, &ActiveHeads)>,
heads_db: Res<HeadsDatabase>,
) -> Result {
let HeadCollected { head, entity } = *trigger.event();
let mut backpack = backpack.get_mut(entity)?;
let (mut backpack, active_heads) = query.get_mut(entity)?;
if backpack.contains(head) {
if backpack.contains(head) || active_heads.contains(head) {
cmds.trigger(CashCollectEvent);
} else {
backpack.insert(head, heads_db.as_ref());

View File

@@ -171,6 +171,10 @@ impl ActiveHeads {
None
}
pub fn contains(&self, head: usize) -> bool {
self.heads.iter().any(|h| h.is_some_and(|h| h.head == head))
}
}
#[derive(Event)]