mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Made merchants advertise wares
This commit is contained in:
parent
b72d8f3192
commit
1fcb46ae0c
@ -222,7 +222,8 @@ pub enum NpcActivity {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum NpcAction {
|
||||
Greet(Actor),
|
||||
// TODO: Use some sort of structured, language-independent value that frontends can translate instead
|
||||
// TODO: Use some sort of structured, language-independent value that frontends can translate
|
||||
// instead
|
||||
Say(Cow<'static, str>),
|
||||
}
|
||||
|
||||
|
@ -124,11 +124,11 @@ pub trait Action<R = ()>: Any + Send + Sync {
|
||||
/// go_on_an_adventure().repeat().stop_if(|ctx| ctx.npc.age > 111.0)
|
||||
/// ```
|
||||
#[must_use]
|
||||
fn stop_if<F: FnMut(&mut NpcCtx) -> bool>(self, f: F) -> StopIf<Self, F>
|
||||
fn stop_if<F: FnMut(&mut NpcCtx) -> bool + Clone>(self, f: F) -> StopIf<Self, F>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
StopIf(self, f)
|
||||
StopIf(self, f.clone(), f)
|
||||
}
|
||||
|
||||
/// Map the completion value of this action to something else.
|
||||
@ -704,10 +704,10 @@ where
|
||||
|
||||
/// See [`Action::stop_if`].
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct StopIf<A, F>(A, F);
|
||||
pub struct StopIf<A, F>(A, F, F);
|
||||
|
||||
impl<A: Action<R>, F: FnMut(&mut NpcCtx) -> bool + Send + Sync + 'static, R> Action<Option<R>>
|
||||
for StopIf<A, F>
|
||||
impl<A: Action<R>, F: FnMut(&mut NpcCtx) -> bool + Clone + Send + Sync + 'static, R>
|
||||
Action<Option<R>> for StopIf<A, F>
|
||||
{
|
||||
fn is_same(&self, other: &Self) -> bool { self.0.is_same(&other.0) }
|
||||
|
||||
@ -715,7 +715,10 @@ impl<A: Action<R>, F: FnMut(&mut NpcCtx) -> bool + Send + Sync + 'static, R> Act
|
||||
|
||||
fn backtrace(&self, bt: &mut Vec<String>) { self.0.backtrace(bt); }
|
||||
|
||||
fn reset(&mut self) { self.0.reset(); }
|
||||
fn reset(&mut self) {
|
||||
self.0.reset();
|
||||
self.1 = self.2.clone();
|
||||
}
|
||||
|
||||
fn tick(&mut self, ctx: &mut NpcCtx) -> ControlFlow<Option<R>> {
|
||||
if (self.1)(ctx) {
|
||||
|
@ -469,6 +469,7 @@ fn socialize() -> impl Action {
|
||||
just(|ctx| ctx.controller.do_dance())
|
||||
.repeat()
|
||||
.stop_if(timeout(6.0))
|
||||
.debug(|| "dancing")
|
||||
.map(|_| ())
|
||||
.boxed()
|
||||
} else {
|
||||
@ -644,6 +645,29 @@ fn villager(visiting_site: SiteId) -> impl Action {
|
||||
.map(|_| ()),
|
||||
);
|
||||
}
|
||||
} else if matches!(ctx.npc.profession, Some(Profession::Merchant))
|
||||
&& thread_rng().gen_bool(0.8)
|
||||
{
|
||||
return casual(
|
||||
just(|ctx| {
|
||||
ctx.controller.say(
|
||||
*[
|
||||
"All my goods are of the highest quality!",
|
||||
"Does anybody want to buy my wares?",
|
||||
"I've got the best offers in town.",
|
||||
"Looking for supplies? I've got you covered.",
|
||||
]
|
||||
.iter()
|
||||
.choose(&mut thread_rng())
|
||||
.unwrap(),
|
||||
) // Can't fail
|
||||
})
|
||||
.then(idle().repeat().stop_if(timeout(8.0)))
|
||||
.repeat()
|
||||
.stop_if(timeout(60.0))
|
||||
.debug(|| "sell wares")
|
||||
.map(|_| ()),
|
||||
);
|
||||
}
|
||||
|
||||
// If nothing else needs doing, walk between plazas and socialize
|
||||
|
@ -506,6 +506,7 @@ fn handle_rtsim_actions(bdata: &mut BehaviorData) -> bool {
|
||||
}
|
||||
},
|
||||
NpcAction::Say(msg) => {
|
||||
bdata.controller.push_utterance(UtteranceKind::Greeting);
|
||||
bdata.agent_data.chat_npc(msg, &mut bdata.event_emitter);
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user