From d25a907ae6961c5e0fbf1c58165c9c25e96bfe56 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 9 Jul 2023 10:08:51 -0600 Subject: [PATCH] Balanced lil fren and added command to give medicine + clippy + fmt --- src/discord/little_fren.rs | 41 ++++++++++++++++++++++++++++++++++++-- src/models/lil_fren.rs | 15 +++++++------- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/discord/little_fren.rs b/src/discord/little_fren.rs index be870a6..bcaaec2 100644 --- a/src/discord/little_fren.rs +++ b/src/discord/little_fren.rs @@ -11,7 +11,7 @@ use serenity::model::misc::EmojiIdentifier; use serenity::utils::MessageBuilder; #[group] -#[commands(adopt, checkup, feed, give_water, play)] +#[commands(adopt, checkup, feed, give_water, play, give_medicine)] pub struct Buddy; #[command] @@ -186,7 +186,7 @@ async fn play(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { if let Some(mut lil_fren) = lil_fren { if lil_fren.is_alive() == AliveState::Alive { lil_fren.entertainment = - (lil_fren.entertainment + thread_rng().gen_range(-0.10..1.0)).clamp(-1.0, 1.0); + (lil_fren.entertainment + thread_rng().gen_range(0.10..1.0)).clamp(-1.0, 1.0); let guild = msg.guild_id.unwrap(); let lil_fren_emoji = guild.emoji(&ctx.http, lil_fren.emoji).await?; @@ -206,3 +206,40 @@ async fn play(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { Ok(()) } + +#[command] +#[description("Help heal buddy")] +async fn give_medicine(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { + let mut data = ctx.data.write().await; + let global_data = data.get_mut::().unwrap(); + + let lil_fren = LilFren::get_lil_fren(&global_data.db)?; + + if let Some(mut lil_fren) = lil_fren { + if lil_fren.is_alive() == AliveState::Alive { + let guild = msg.guild_id.unwrap(); + + let reply = if lil_fren.state == LilFrenState::Sick { + lil_fren.state = LilFrenState::Standing; + "Little buddy feels better now!" + } else { + "Little buddy is now addicted to cough drops, I hope you are happy" + }; + + let lil_fren_emoji = guild.emoji(&ctx.http, lil_fren.emoji).await?; + + global_data.db.insert(lil_fren)?; + + msg.reply(&ctx.http, reply).await?; + msg.reply(&ctx.http, lil_fren::draw_feed(&lil_fren_emoji, ":pill:")) + .await?; + } else { + msg.reply(&ctx.http, "You may want to check on your buddy...") + .await?; + } + } else { + msg.reply(&ctx.http, "Sorry no little buddy found!").await?; + } + + Ok(()) +} diff --git a/src/models/lil_fren.rs b/src/models/lil_fren.rs index 697a178..3b329f8 100644 --- a/src/models/lil_fren.rs +++ b/src/models/lil_fren.rs @@ -175,7 +175,7 @@ impl LilFren { entertainment: 1.0, state: LilFrenState::Standing, smarts: thread_rng().gen_range(0.0..0.5), - metabolism: thread_rng().gen_range(0.0..0.5), + metabolism: thread_rng().gen_range(0.2..0.75), } } @@ -202,16 +202,17 @@ impl LilFren { } let (hunger_diff, thirst_diff, entertainment_diff) = match lil_fren.state { - LilFrenState::Standing => (-0.01, -0.02, -0.01), - LilFrenState::TaxFraud => (-0.01, -0.02, 0.01), - LilFrenState::Sick => (-0.1, -0.15, -0.01), - LilFrenState::Dancing => (-0.05, -0.8, 0.05), - LilFrenState::Sleep => (-0.005, -0.01, 0.00), + LilFrenState::Standing => (-0.002, -0.002, -0.001), + LilFrenState::TaxFraud => (-0.002, -0.002, 0.001), + LilFrenState::Sick => (-0.005, -0.005, -0.001), + LilFrenState::Dancing => (-0.005, -0.008, 0.01), + LilFrenState::Sleep => (-0.001, -0.002, 0.00), }; lil_fren.hunger = (lil_fren.hunger + hunger_diff * self.metabolism).clamp(-1.0, 1.0); lil_fren.thirst = (lil_fren.thirst + thirst_diff * self.metabolism).clamp(-1.0, 1.0); - lil_fren.thirst = (lil_fren.entertainment + entertainment_diff * self.smarts).clamp(-1.0, 1.0); + lil_fren.thirst = + (lil_fren.entertainment + entertainment_diff * self.smarts).clamp(-1.0, 1.0); if thread_rng().gen_bool(0.75) { println!("fren is now {:?}", self.state);