Compare commits

...

3 Commits

Author SHA1 Message Date
wrk f88e947391 Added ,stop cmd 2023-06-09 02:17:46 +02:00
wrk 48957df3cd Using new ircie version 2023-06-09 02:00:32 +02:00
wrk 14800c2ddc fixed cargo dep 2023-06-09 01:04:14 +02:00
2 changed files with 28 additions and 7 deletions

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ircie = { path = "../drugwars_v2/ircie" }
ircie = { path = "../ircie" }
tokio = { version = "1.28.2", features = ["full"] }
env_logger = "0.10.0"
rand = "0.8.5"

View File

@ -9,7 +9,7 @@ use std::{
use ircie::{
format::{Color, Msg},
system::IntoResponse,
system_params::{AnyArguments, Res, ResMut},
system_params::{AnyArguments, Channel, Context, Res, ResMut},
Irc,
};
use itertools::Itertools;
@ -208,6 +208,7 @@ enum FightStatus {
#[derive(Default)]
struct Fight {
status: FightStatus,
channel: String,
kind: FightKind,
fighters: Vec<Fighter>,
}
@ -233,20 +234,24 @@ async fn main() -> std::io::Result<()> {
.add_system("h", show_help)
.await
.add_system("s", show_status)
.await;
.await
.add_system("stop", stop)
.await
;
irc.run().await?;
Ok(())
}
fn fight(
mut ctx: Context,
mut fight: ResMut<Fight>,
mut rng: ResMut<StdRng>,
mut hall_of_fame: ResMut<HallOfFame>,
) -> impl IntoResponse {
) {
if fight.status == FightStatus::Idle {
std::thread::sleep(Duration::from_millis(50));
return None;
return;
}
let teams_remaining: Vec<_> = fight
@ -304,7 +309,11 @@ fn fight(
fight.fighters = vec![];
hall_of_fame.save(SAVE_LOC).unwrap();
return Some((false, lines));
for line in lines {
ctx.privmsg(&fight.channel, &line.to_string())
}
fight.channel = "".to_owned();
return;
}
let mut lines = vec![];
@ -383,11 +392,14 @@ fn fight(
fight.fighters.remove(victim_idx);
}
Some((false, lines))
for line in lines {
ctx.privmsg(&fight.channel, &line.to_string())
}
}
fn new_fight(
arguments: AnyArguments,
channel: Channel,
mut fight: ResMut<Fight>,
mut rng: ResMut<StdRng>,
) -> impl IntoResponse {
@ -442,6 +454,8 @@ fn new_fight(
fight.status = FightStatus::Happening;
fight.channel = channel.to_owned();
let mut init_msg = vec![Msg::new()
.color(Color::Yellow)
.text("THE FIGHT IS ABOUT TO BEGIN! TAKE YOUR BETS!")];
@ -521,6 +535,7 @@ fn show_help() -> impl IntoResponse {
",f <nick> ... vs <nick> ... | team battle",
",f <nick> <nick> <nick> ... | free for all",
",s | show the current fight status",
",stop | stop the current fight",
",hof | hall of fame",
],
)
@ -533,3 +548,9 @@ fn show_status(fight: Res<Fight>) -> impl IntoResponse {
format!("{} fighters remaining", fight.fighters.len())
}
fn stop(mut fight: ResMut<Fight>) {
fight.fighters = vec![];
fight.channel = "".to_owned();
fight.status = FightStatus::Idle;
}