mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
make merchants use tell, and general cleanup
This commit is contained in:
parent
b022076a5c
commit
d53b344c23
@ -64,7 +64,7 @@ impl NpcBuilder {
|
||||
stats,
|
||||
skill_set: comp::SkillSet::default(),
|
||||
health: None,
|
||||
poise: comp::Poise::new(body.clone()),
|
||||
poise: comp::Poise::new(body),
|
||||
inventory: comp::Inventory::with_empty(),
|
||||
body,
|
||||
agent: None,
|
||||
|
@ -389,7 +389,7 @@ impl SitePrices {
|
||||
.as_ref()
|
||||
.map(|ri| {
|
||||
let item = ri.inventory.get(slot)?;
|
||||
if let Some(vec) = TradePricing::get_materials(&item.name.as_ref()) {
|
||||
let vec = TradePricing::get_materials(&item.name.as_ref())?;
|
||||
Some(
|
||||
vec.iter()
|
||||
.map(|(amount2, material)| {
|
||||
@ -400,9 +400,6 @@ impl SitePrices {
|
||||
.sum::<f32>()
|
||||
* (*amount as f32),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or(Some(0.0))
|
||||
})
|
||||
|
@ -469,7 +469,7 @@ impl<F: FnMut(&mut NpcCtx) -> Node<R> + Send + Sync + 'static, R: 'static> Actio
|
||||
};
|
||||
|
||||
match prev.0.tick(ctx) {
|
||||
ControlFlow::Continue(()) => return ControlFlow::Continue(()),
|
||||
ControlFlow::Continue(()) => ControlFlow::Continue(()),
|
||||
ControlFlow::Break(r) => {
|
||||
self.prev = None;
|
||||
ControlFlow::Break(r)
|
||||
|
@ -150,9 +150,7 @@ impl Data {
|
||||
.with_personality(Personality::random_evil(&mut rng))
|
||||
.with_faction(site.faction)
|
||||
.with_home(site_id)
|
||||
.with_profession(match rng.gen_range(0..20) {
|
||||
_ => Profession::Cultist,
|
||||
}),
|
||||
.with_profession(Profession::Cultist),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -136,9 +136,9 @@ impl RtState {
|
||||
}
|
||||
|
||||
pub fn emit<E: Event>(&mut self, e: E, world: &World, index: IndexRef) {
|
||||
self.event_handlers
|
||||
.get::<EventHandlersOf<E>>()
|
||||
.map(|handlers| handlers.iter().for_each(|f| f(self, world, index, &e)));
|
||||
if let Some(handlers) = self.event_handlers.get::<EventHandlersOf<E>>() {
|
||||
handlers.iter().for_each(|f| f(self, world, index, &e));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(
|
||||
|
@ -45,7 +45,7 @@ fn path_in_site(start: Vec2<i32>, end: Vec2<i32>, site: &site2::Site) -> PathRes
|
||||
let mut astar = Astar::new(
|
||||
1000,
|
||||
start,
|
||||
&heuristic,
|
||||
heuristic,
|
||||
BuildHasherDefault::<FxHasher64>::default(),
|
||||
);
|
||||
|
||||
@ -76,12 +76,12 @@ fn path_in_site(start: Vec2<i32>, end: Vec2<i32>, site: &site2::Site) -> PathRes
|
||||
let building = if a_tile.is_building() && b_tile.is_road() {
|
||||
a_tile
|
||||
.plot
|
||||
.and_then(|plot| is_door_tile(plot, *a).then(|| 1.0))
|
||||
.and_then(|plot| is_door_tile(plot, *a).then_some(1.0))
|
||||
.unwrap_or(10000.0)
|
||||
} else if b_tile.is_building() && a_tile.is_road() {
|
||||
b_tile
|
||||
.plot
|
||||
.and_then(|plot| is_door_tile(plot, *b).then(|| 1.0))
|
||||
.and_then(|plot| is_door_tile(plot, *b).then_some(1.0))
|
||||
.unwrap_or(10000.0)
|
||||
} else if (a_tile.is_building() || b_tile.is_building()) && a_tile.plot != b_tile.plot {
|
||||
10000.0
|
||||
@ -493,7 +493,7 @@ fn adventure() -> impl Action {
|
||||
casual(finish().boxed())
|
||||
}
|
||||
})
|
||||
.debug(move || format!("adventure"))
|
||||
.debug(move || "adventure")
|
||||
}
|
||||
|
||||
fn villager(visiting_site: SiteId) -> impl Action {
|
||||
@ -513,9 +513,9 @@ fn villager(visiting_site: SiteId) -> impl Action {
|
||||
// Travel to the site we're supposed to be in
|
||||
urgent(travel_to_site(visiting_site).debug(move || {
|
||||
if npc_home == Some(visiting_site) {
|
||||
format!("travel home")
|
||||
"travel home".to_string()
|
||||
} else {
|
||||
format!("travel to visiting site")
|
||||
"travel to visiting site".to_string()
|
||||
}
|
||||
}))
|
||||
} else if DayPeriod::from(ctx.time_of_day.0).is_dark()
|
||||
|
@ -27,13 +27,11 @@ impl Rule for SimulateNpcs {
|
||||
if let Some(vehicle) = data.npcs.vehicles.get_mut(ride.vehicle) {
|
||||
let actor = crate::data::Actor::Npc(npc_id);
|
||||
vehicle.riders.push(actor);
|
||||
if ride.steering {
|
||||
if vehicle.driver.replace(actor).is_some() {
|
||||
if ride.steering && vehicle.driver.replace(actor).is_some() {
|
||||
panic!("Replaced driver");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(home) = npc.home.and_then(|home| data.sites.get_mut(home)) {
|
||||
home.population.insert(npc_id);
|
||||
|
@ -1290,7 +1290,7 @@ fn handle_rtsim_purge(
|
||||
);
|
||||
Ok(())
|
||||
} else {
|
||||
return Err(action.help_string());
|
||||
Err(action.help_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ impl RtSim {
|
||||
);
|
||||
}
|
||||
|
||||
let data = Data::generate(settings, &world, index);
|
||||
let data = Data::generate(settings, world, index);
|
||||
info!("Rtsim data generated.");
|
||||
data
|
||||
};
|
||||
|
@ -165,25 +165,7 @@ pub fn handle_inbox_talk(bdata: &mut BehaviorData) -> bool {
|
||||
standard_response_msg()
|
||||
};
|
||||
agent_data.chat_npc(msg, event_emitter);
|
||||
}
|
||||
/*else if agent.behavior.can_trade(agent_data.alignment.copied(), by) {
|
||||
if !agent.behavior.is(BehaviorState::TRADING) {
|
||||
controller.push_initiate_invite(by, InviteKind::Trade);
|
||||
agent_data.chat_npc(
|
||||
"npc-speech-merchant_advertisement",
|
||||
event_emitter,
|
||||
);
|
||||
} else {
|
||||
let default_msg = "npc-speech-merchant_busy";
|
||||
let msg = if agent.rtsim_controller.personality.is(PersonalityTrait::Disagreeable) {
|
||||
"npc-speech-merchant_busy_rude"
|
||||
} else {
|
||||
default_msg
|
||||
};
|
||||
agent_data.chat_npc(msg, event_emitter);
|
||||
}
|
||||
}*/
|
||||
else {
|
||||
let mut rng = thread_rng();
|
||||
if let Some(extreme_trait) =
|
||||
agent.rtsim_controller.personality.chat_trait(&mut rng)
|
||||
@ -522,22 +504,36 @@ pub fn handle_inbox_update_pending_trade(bdata: &mut BehaviorData) -> bool {
|
||||
let (tradeid, pending, prices, inventories) = *boxval;
|
||||
if agent.behavior.is(BehaviorState::TRADING) {
|
||||
let who = usize::from(!agent.behavior.is(BehaviorState::TRADING_ISSUER));
|
||||
let mut message = |msg| {
|
||||
if let Some(with) = agent
|
||||
.target
|
||||
.as_ref()
|
||||
.and_then(|tgt_data| read_data.uids.get(tgt_data.target))
|
||||
{
|
||||
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc_tell(
|
||||
*agent_data.uid,
|
||||
*with,
|
||||
msg,
|
||||
)));
|
||||
} else {
|
||||
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc_say(
|
||||
*agent_data.uid,
|
||||
msg,
|
||||
)));
|
||||
}
|
||||
};
|
||||
match agent.behavior.trading_behavior {
|
||||
TradingBehavior::RequireBalanced { .. } => {
|
||||
let balance0 = prices.balance(&pending.offers, &inventories, 1 - who, true);
|
||||
let balance1 = prices.balance(&pending.offers, &inventories, who, false);
|
||||
match (balance0, balance1) {
|
||||
(_, None) => {
|
||||
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc_say(
|
||||
*agent_data.uid,
|
||||
format!("I'm not willing to sell that item"),
|
||||
)))
|
||||
let msg = "I'm not willing to sell that item".to_string();
|
||||
message(msg);
|
||||
},
|
||||
(None, _) => {
|
||||
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc_say(
|
||||
*agent_data.uid,
|
||||
format!("I'm not willing to buy that item"),
|
||||
)))
|
||||
let msg = "I'm not willing to buy that item".to_string();
|
||||
message(msg);
|
||||
},
|
||||
(Some(balance0), Some(balance1)) => {
|
||||
if balance0 >= balance1 {
|
||||
@ -567,27 +563,7 @@ pub fn handle_inbox_update_pending_trade(bdata: &mut BehaviorData) -> bool {
|
||||
"That only covers {:.0}% of my costs!",
|
||||
(balance0 / balance1 * 100.0).floor()
|
||||
);
|
||||
if let Some(tgt_data) = &agent.target {
|
||||
// If talking with someone in particular, "tell" it only to
|
||||
// them
|
||||
if let Some(with) = read_data.uids.get(tgt_data.target) {
|
||||
event_emitter.emit(ServerEvent::Chat(
|
||||
UnresolvedChatMsg::npc_tell(
|
||||
*agent_data.uid,
|
||||
*with,
|
||||
msg,
|
||||
),
|
||||
));
|
||||
} else {
|
||||
event_emitter.emit(ServerEvent::Chat(
|
||||
UnresolvedChatMsg::npc_say(*agent_data.uid, msg),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
event_emitter.emit(ServerEvent::Chat(
|
||||
UnresolvedChatMsg::npc_say(*agent_data.uid, msg),
|
||||
));
|
||||
}
|
||||
message(msg);
|
||||
}
|
||||
if pending.phase != TradePhase::Mutate {
|
||||
// we got into the review phase but without balanced goods,
|
||||
|
@ -4035,16 +4035,19 @@ impl Hud {
|
||||
remove,
|
||||
quantity: &mut u32| {
|
||||
if let Some(prices) = prices {
|
||||
let balance0 = prices
|
||||
if let Some((balance0, balance1)) = prices
|
||||
.balance(&trade.offers, &r_inventories, who, true)
|
||||
.unwrap_or(0.0); // TODO: Don't default to 0 here?
|
||||
let balance1 = prices
|
||||
.balance(&trade.offers, &r_inventories, 1 - who, false)
|
||||
.unwrap_or(0.0); // TODO: Don't default to 0 here?
|
||||
if let Some(item) = inventory.get(slot) {
|
||||
if let Some(materials) =
|
||||
TradePricing::get_materials(&item.item_definition_id())
|
||||
.zip(prices.balance(
|
||||
&trade.offers,
|
||||
&r_inventories,
|
||||
1 - who,
|
||||
false,
|
||||
))
|
||||
{
|
||||
if let Some(item) = inventory.get(slot) {
|
||||
if let Some(materials) = TradePricing::get_materials(
|
||||
&item.item_definition_id(),
|
||||
) {
|
||||
let unit_price: f32 = materials
|
||||
.iter()
|
||||
.map(|e| {
|
||||
@ -4076,6 +4079,7 @@ impl Hud {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
match slot {
|
||||
Inventory(i) => {
|
||||
|
Loading…
Reference in New Issue
Block a user