fix: Grant focus reward berries at the end of the focus phase
This commit is contained in:
@@ -10,6 +10,3 @@ pub struct PhaseTimerPauseMessage;
|
||||
|
||||
#[derive(Message)]
|
||||
pub struct NextPhaseMessage;
|
||||
|
||||
#[derive(Message)]
|
||||
pub struct PhaseMinutePassedMessage;
|
||||
|
||||
@@ -18,7 +18,6 @@ impl Plugin for PhasePlugin {
|
||||
}));
|
||||
|
||||
app.add_message::<PhaseTimerFinishedMessage>();
|
||||
app.add_message::<PhaseMinutePassedMessage>();
|
||||
|
||||
app.add_systems(OnEnter(AppState::GameScreen), load_rules);
|
||||
app.add_systems(
|
||||
@@ -76,7 +75,6 @@ fn tick_timer(
|
||||
time: Res<Time>,
|
||||
mut phase_res: ResMut<CurrentPhase>,
|
||||
mut finish_writer: MessageWriter<PhaseTimerFinishedMessage>,
|
||||
mut minute_writer: MessageWriter<PhaseMinutePassedMessage>,
|
||||
mut savegame_messages: MessageWriter<SavegameDumpMessage>,
|
||||
) {
|
||||
let delta = time.delta_secs();
|
||||
@@ -84,13 +82,7 @@ fn tick_timer(
|
||||
|
||||
match phase {
|
||||
Phase::Focus { duration } | Phase::Break { duration } => {
|
||||
let old_minutes = (*duration / 60.0).floor() as i32;
|
||||
*duration -= delta;
|
||||
let new_minutes = (*duration / 60.0).floor() as i32;
|
||||
|
||||
if new_minutes < old_minutes {
|
||||
minute_writer.write(PhaseMinutePassedMessage);
|
||||
}
|
||||
|
||||
if *duration <= 0.0 {
|
||||
finish_writer.write(PhaseTimerFinishedMessage {
|
||||
@@ -110,8 +102,7 @@ fn tick_timer(
|
||||
}
|
||||
|
||||
fn grant_focus_rewards(
|
||||
mut messages: MessageReader<PhaseMinutePassedMessage>,
|
||||
phase_res: Res<CurrentPhase>,
|
||||
mut messages: MessageReader<PhaseTimerFinishedMessage>,
|
||||
config: Res<GameConfig>,
|
||||
mut inventory: ResMut<Inventory>,
|
||||
mut commands: Commands,
|
||||
@@ -119,31 +110,30 @@ fn grant_focus_rewards(
|
||||
mut session_tracker: ResMut<SessionTracker>,
|
||||
game_config: Res<GameConfig>,
|
||||
mut notifications: ResMut<Notifications>,
|
||||
timer_settings: Res<TimerSettings>,
|
||||
) {
|
||||
for _ in messages.read() {
|
||||
if let Phase::Focus { .. } = &phase_res.0 {
|
||||
println!(
|
||||
"A minute of focus has been completed. Granting {} berries as a reward.",
|
||||
config.berries_per_focus_minute
|
||||
);
|
||||
for message in messages.read() {
|
||||
if matches!(message.phase, Phase::Focus { .. }) {
|
||||
let berries = config.berries_per_focus_minute
|
||||
* (timer_settings.focus_duration as f32 / 60.0).floor() as u32;
|
||||
|
||||
inventory.update_item_stack(
|
||||
&mut commands,
|
||||
&mut items_query,
|
||||
ItemType::Berry,
|
||||
config.berries_per_focus_minute as i32,
|
||||
berries as i32,
|
||||
);
|
||||
session_tracker.total_berries_earned += config.berries_per_focus_minute;
|
||||
session_tracker.total_berries_earned += berries;
|
||||
|
||||
let berries_name = match config.berries_per_focus_minute {
|
||||
let berries_name = match berries {
|
||||
1 => ItemType::Berry.singular(&game_config),
|
||||
_ => ItemType::Berry.plural(&game_config),
|
||||
};
|
||||
notifications.info(
|
||||
Some("Fokus Belohnung"),
|
||||
format!(
|
||||
"Du hast {} {} als Belohnung für das Abschließen einer Minute der Fokus-Phase erhalten!",
|
||||
config.berries_per_focus_minute, berries_name
|
||||
"Du hast {} {} als Belohnung für das Abschließen einer Fokus-Phase erhalten!",
|
||||
berries, berries_name
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user