forked from blasthavers/blastmud
Fix bug that leads to some players never having urges like hunger
This commit is contained in:
parent
50f23e1c56
commit
472bdb4f0e
@ -10,7 +10,7 @@ use crate::{
|
||||
task::{Task, TaskDetails, TaskMeta, TaskRecurrence},
|
||||
},
|
||||
regular_tasks::{TaskHandler, TaskRunContext},
|
||||
static_content::{species::SpeciesType, StaticTask},
|
||||
static_content::{npc::npc_by_code, species::SpeciesType, StaticTask},
|
||||
DResult,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
@ -274,9 +274,27 @@ pub fn urge_tasks() -> Box<dyn Iterator<Item = StaticTask>> {
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn set_has_urges_if_needed(trans: &DBTrans, player_item: &mut Item) -> DResult<()> {
|
||||
let mut has_urges = player_item.death_data.is_none()
|
||||
&& match player_item.urges {
|
||||
pub fn ever_has_urges(item: &mut Item) -> bool {
|
||||
match item.item_type.as_str() {
|
||||
"player" => true,
|
||||
"npc"
|
||||
if npc_by_code()
|
||||
.get(item.item_code.as_str())
|
||||
.map(|npc| npc.has_urges)
|
||||
.unwrap_or(false) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn set_has_urges_if_needed(trans: &DBTrans, item: &mut Item) -> DResult<()> {
|
||||
if !ever_has_urges(item) {
|
||||
return Ok(());
|
||||
}
|
||||
let mut has_urges = item.death_data.is_none()
|
||||
&& match item.urges {
|
||||
None => false,
|
||||
Some(Urges {
|
||||
hunger: Urge { growth: hunger, .. },
|
||||
@ -286,7 +304,7 @@ pub async fn set_has_urges_if_needed(trans: &DBTrans, player_item: &mut Item) ->
|
||||
}) => hunger != 0 || stress != 0 || thirst != 0,
|
||||
};
|
||||
if has_urges {
|
||||
match player_item.location.split_once("/") {
|
||||
match item.location.split_once("/") {
|
||||
None => {}
|
||||
Some((loc_type, loc_code)) => {
|
||||
has_urges |= trans
|
||||
@ -298,9 +316,9 @@ pub async fn set_has_urges_if_needed(trans: &DBTrans, player_item: &mut Item) ->
|
||||
}
|
||||
}
|
||||
if has_urges {
|
||||
player_item.flags.push(ItemFlag::HasUrges);
|
||||
item.flags.push(ItemFlag::HasUrges);
|
||||
} else {
|
||||
player_item.flags = player_item
|
||||
item.flags = item
|
||||
.flags
|
||||
.clone()
|
||||
.into_iter()
|
||||
@ -334,7 +352,7 @@ pub async fn change_stress_considering_cool(
|
||||
stress_changed(trans, who).await
|
||||
}
|
||||
|
||||
pub async fn recalculate_urge_growth(_trans: &DBTrans, item: &mut Item) -> DResult<()> {
|
||||
pub async fn recalculate_urge_growth(trans: &DBTrans, item: &mut Item) -> DResult<()> {
|
||||
let cool = item.total_stats.get(&StatType::Cool).unwrap_or(&8.0);
|
||||
let relax_action_factor = match item.action_type {
|
||||
LocationActionType::Sitting(_) => 100.0,
|
||||
@ -358,5 +376,6 @@ pub async fn recalculate_urge_growth(_trans: &DBTrans, item: &mut Item) -> DResu
|
||||
..old_urges.stress
|
||||
},
|
||||
});
|
||||
set_has_urges_if_needed(trans, item).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ pub struct NPC {
|
||||
pub player_consents: Vec<ConsentType>,
|
||||
pub hire_data: Option<HireData>,
|
||||
pub extra_flags: Vec<ItemFlag>,
|
||||
pub has_urges: bool,
|
||||
}
|
||||
|
||||
impl Default for NPC {
|
||||
@ -150,6 +151,7 @@ impl Default for NPC {
|
||||
player_consents: vec![],
|
||||
hire_data: None,
|
||||
extra_flags: vec![],
|
||||
has_urges: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user