|
|
|
@ -1,7 +1,8 @@
|
|
|
|
|
use rand::prelude::*;
|
|
|
|
|
use redis::Commands as RedisCommands;
|
|
|
|
|
use valence::prelude::*;
|
|
|
|
|
|
|
|
|
|
use crate::{player::Alive, GameState, CONFIG};
|
|
|
|
|
use crate::{db::Connection, player::Alive, GameState, CONFIG};
|
|
|
|
|
|
|
|
|
|
pub fn start_game(
|
|
|
|
|
mut clients: Query<(&mut Client, &mut Position, &mut GameMode, &mut Alive)>,
|
|
|
|
@ -43,15 +44,17 @@ pub fn stop_game(
|
|
|
|
|
&mut GameMode,
|
|
|
|
|
&mut Alive,
|
|
|
|
|
&Username,
|
|
|
|
|
&UniqueId,
|
|
|
|
|
)>,
|
|
|
|
|
mut connection: ResMut<Connection>,
|
|
|
|
|
) {
|
|
|
|
|
tracing::debug!("Stopping game!");
|
|
|
|
|
|
|
|
|
|
let mut alive_players = vec![];
|
|
|
|
|
|
|
|
|
|
for (mut client, mut pos, mut gamemode, mut alive, username) in &mut clients {
|
|
|
|
|
for (mut client, mut pos, mut gamemode, mut alive, username, uuid) in &mut clients {
|
|
|
|
|
if alive.0 {
|
|
|
|
|
alive_players.push(username);
|
|
|
|
|
alive_players.push((username, uuid));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*gamemode = GameMode::Spectator;
|
|
|
|
@ -66,13 +69,20 @@ pub fn stop_game(
|
|
|
|
|
// if statement to not panic if somehow no one was alive when the game ended
|
|
|
|
|
if alive_players.len() >= 1 {
|
|
|
|
|
// let's assume there's only one alive player
|
|
|
|
|
alive_players[0].0.clone()
|
|
|
|
|
alive_players[0].0 .0.clone()
|
|
|
|
|
} else {
|
|
|
|
|
"Somehow, no one".to_string()
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
None,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if alive_players.len() == 1 {
|
|
|
|
|
let _: i32 = connection
|
|
|
|
|
.0
|
|
|
|
|
.hincr("wins".to_string(), alive_players[0].1 .0.to_string(), 1)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|