From 752af74337c5175fdba98ff5f3fa5fab50d8b0db Mon Sep 17 00:00:00 2001 From: Condorra Date: Sat, 16 Sep 2023 22:41:38 +1000 Subject: [PATCH] Implement a 'poverty discount' to help players stuck with no money. --- .../src/message_handler/user_commands/buy.rs | 38 ++++++++++++++++--- .../src/message_handler/user_commands/list.rs | 14 ++++++- blastmud_game/src/services/urges.rs | 2 +- blastmud_game/src/static_content/room.rs | 2 + .../src/static_content/room/melbs.rs | 1 + 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/blastmud_game/src/message_handler/user_commands/buy.rs b/blastmud_game/src/message_handler/user_commands/buy.rs index b7f76e8..89aeae4 100644 --- a/blastmud_game/src/message_handler/user_commands/buy.rs +++ b/blastmud_game/src/message_handler/user_commands/buy.rs @@ -4,7 +4,10 @@ use super::{ }; use crate::{ models::item::Item, - services::capacity::{check_item_capacity, check_item_ref_capacity, CapacityLevel}, + services::{ + capacity::{check_item_capacity, check_item_ref_capacity, CapacityLevel}, + urges::change_stress_considering_cool, + }, static_content::possession_type::possession_data, static_content::room, }; @@ -68,12 +71,35 @@ impl UserVerb for Verb { { if offset_remaining <= 1 { if let Some(user) = ctx.user_dat.as_mut() { + let mut paid_price = stock.list_price; if user.credits < stock.list_price { - user_error( - "You don't have enough credits to buy that!".to_owned(), - )?; + if stock.poverty_discount { + if let Some(urges) = player_item.urges.as_ref() { + if urges.stress.value > 500 { + user_error(ansi!("You don't have the money to pay full price, \ + and are too tired to try begging for a \ + discount. [Hint: Try to recline \ + for a bit and try again]").to_owned())?; + } + let mut player_item_mut = (*player_item).clone(); + change_stress_considering_cool( + &ctx.trans, + &mut player_item_mut, + 2000, + ) + .await?; + ctx.trans.save_item_model(&player_item_mut).await?; + } + paid_price = user.credits; + user.credits = 0; + } else { + user_error( + "You don't have enough credits to buy that!".to_owned(), + )?; + } + } else { + user.credits -= stock.list_price; } - user.credits -= stock.list_price; let player_item_str = player_item.refstr(); let item_code = ctx.trans.alloc_item_code().await?; let loc = match check_item_capacity( @@ -133,7 +159,7 @@ impl UserVerb for Verb { &ctx.session, Some(&format!( "Your wristpad beeps for a deduction of {} credits.\n", - stock.list_price + paid_price )), ) .await?; diff --git a/blastmud_game/src/message_handler/user_commands/list.rs b/blastmud_game/src/message_handler/user_commands/list.rs index 05a58f2..1f80efb 100644 --- a/blastmud_game/src/message_handler/user_commands/list.rs +++ b/blastmud_game/src/message_handler/user_commands/list.rs @@ -1,4 +1,7 @@ -use super::{get_player_item_or_fail, user_error, UResult, UserVerb, UserVerbRef, VerbContext}; +use super::{ + get_player_item_or_fail, get_user_or_fail, user_error, UResult, UserVerb, UserVerbRef, + VerbContext, +}; use crate::{language, static_content::possession_type::possession_data, static_content::room}; use ansi::ansi; use async_trait::async_trait; @@ -13,6 +16,7 @@ impl UserVerb for Verb { _remaining: &str, ) -> UResult<()> { let player_item = get_player_item_or_fail(ctx).await?; + let user = get_user_or_fail(ctx)?; if player_item.death_data.is_some() { user_error( @@ -51,10 +55,16 @@ impl UserVerb for Verb { } else { &possession_type.display }; + + let mut price = stock.list_price; + if stock.poverty_discount && price > user.credits { + price = user.credits; + } + msg.push_str(&format!( "| {:40} | {:15.2} |\n", &language::caps_first(&display), - &stock.list_price + &price )) } } diff --git a/blastmud_game/src/services/urges.rs b/blastmud_game/src/services/urges.rs index 05bb230..2f6a210 100644 --- a/blastmud_game/src/services/urges.rs +++ b/blastmud_game/src/services/urges.rs @@ -392,7 +392,7 @@ pub async fn recalculate_urge_growth(_trans: &DBTrans, item: &mut Item) -> DResu ..old_urges.bladder }, stress: Urge { - growth: (-(cool.max(7.0) - 7.0) * 4.0 * relax_action_factor) as i16, + growth: (-(cool.max(7.0) - 7.0) * 10.0 * relax_action_factor) as i16, ..old_urges.stress }, }); diff --git a/blastmud_game/src/static_content/room.rs b/blastmud_game/src/static_content/room.rs index 6fd99f2..a623c09 100644 --- a/blastmud_game/src/static_content/room.rs +++ b/blastmud_game/src/static_content/room.rs @@ -276,6 +276,7 @@ pub struct SecondaryZoneRecord { pub struct RoomStock { pub possession_type: PossessionType, pub list_price: u64, + pub poverty_discount: bool, } impl Default for RoomStock { @@ -283,6 +284,7 @@ impl Default for RoomStock { Self { possession_type: PossessionType::AntennaWhip, list_price: 1000000000, + poverty_discount: false, } } } diff --git a/blastmud_game/src/static_content/room/melbs.rs b/blastmud_game/src/static_content/room/melbs.rs index ad7235a..fc1ffea 100644 --- a/blastmud_game/src/static_content/room/melbs.rs +++ b/blastmud_game/src/static_content/room/melbs.rs @@ -117,6 +117,7 @@ pub fn room_list() -> Vec { RoomStock { possession_type: PossessionType::GreasyBurger, list_price: 5, + poverty_discount: true, ..Default::default() } ],