From aa7734947cf0f57182c5885e07d1683262c23915 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 14 May 2024 01:24:57 +0200 Subject: [PATCH] implement achievements --- src/actor.rs | 17 ++++++++-- src/chat.rs | 9 ++++++ src/chats/serenity.yaml | 4 +++ src/cmd.rs | 7 ++++ src/game.rs | 72 ++++++++++++++++++++++++++++++++++++++++- src/var.rs | 17 +++++++++- 6 files changed, 121 insertions(+), 5 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index a704b91..c217c99 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -64,6 +64,7 @@ pub enum DamageType { pub struct VehicleEnterExitEvent { vehicle: Entity, driver: Entity, + name: Option, is_entering: bool, is_player: bool } @@ -293,7 +294,7 @@ pub fn handle_input( player: Query>, q_camera: Query<&Transform, With>, mut q_flashlight: Query<&mut Visibility, With>, - q_vehicles: Query<(Entity, &Transform), (With, Without, Without)>, + q_vehicles: Query<(Entity, &Actor, &Transform), (With, Without, Without)>, mut ew_conv: EventWriter, mut ew_vehicle: EventWriter, mut ew_sfx: EventWriter, @@ -319,16 +320,20 @@ pub fn handle_input( } // Entering Vehicles if q_player_drives.is_empty() { - let objects: Vec<(Entity, &Transform)> = q_vehicles + let objects: Vec<((Entity, &Actor), &Transform)> = q_vehicles .iter() + .map(|(entity, actor, transform)| ((entity, actor), transform)) .collect(); - if let (Some(entity), dist) = camera::find_closest_target::(objects, camtrans) { + if let (Some((entity, actor)), dist) = + camera::find_closest_target::<(Entity, &Actor)>(objects, camtrans) + { if dist <= MAX_INTERACT_DISTANCE { commands.entity(entity).insert(ActorVehicleBeingEntered); commands.entity(player_entity).insert(ActorEnteringVehicle); ew_vehicle.send(VehicleEnterExitEvent{ vehicle: entity, driver: player_entity, + name: actor.name.clone(), is_entering: q_player_drives.is_empty(), is_player: true, }); @@ -344,6 +349,7 @@ pub fn handle_input( ew_vehicle.send(VehicleEnterExitEvent{ vehicle: vehicle_entity, driver: player_entity, + name: None, is_entering: false, is_player: true, }); @@ -368,6 +374,7 @@ pub fn handle_vehicle_enter_exit( mut commands: Commands, mut settings: ResMut, mut er_vehicle: EventReader, + mut ew_achievement: EventWriter, mut q_playerflashlight: Query<&mut Visibility, (With, Without, Without)>, mut q_drivers: Query<(Entity, &mut Visibility, Option<&Collider>), (Without, With)>, mut q_vehicles: Query<(Entity, &mut Vehicle, &mut Visibility), (With, Without)>, @@ -398,6 +405,10 @@ pub fn handle_vehicle_enter_exit( *flashlight_vis = Visibility::Hidden; settings.flashlight_active = false; } + if let Some(vehicle_name) = &event.name { + ew_achievement.send(game::AchievementEvent + ::RideVehicle(vehicle_name.clone())); + } } else { // Exiting Vehicle diff --git a/src/chat.rs b/src/chat.rs index c114223..becd4ea 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -618,6 +618,7 @@ pub fn handle_new_conversations( mut er_conv: EventReader, mut ew_sfx: EventWriter, mut ew_chatevent: EventWriter, + mut ew_achievement: EventWriter, chatdb: Res, q_chats: Query<&Chat>, time: Res