mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Made NPCs talk and trade
This commit is contained in:
parent
ff7478eb01
commit
ee048ad5a2
@ -3,13 +3,14 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::sys::terrain::NpcData;
|
use crate::sys::terrain::NpcData;
|
||||||
use common::{
|
use common::{
|
||||||
comp::{self, inventory::loadout::Loadout},
|
comp::{self, inventory::loadout::Loadout, skillset::skills},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
generation::{BodyBuilder, EntityConfig, EntityInfo},
|
generation::{BodyBuilder, EntityConfig, EntityInfo},
|
||||||
resources::{DeltaTime, Time},
|
resources::{DeltaTime, Time},
|
||||||
rtsim::{RtSimController, RtSimEntity},
|
rtsim::{RtSimController, RtSimEntity},
|
||||||
slowjob::SlowJobPool,
|
slowjob::SlowJobPool,
|
||||||
LoadoutBuilder,
|
LoadoutBuilder,
|
||||||
|
SkillSetBuilder,
|
||||||
};
|
};
|
||||||
use common_ecs::{Job, Origin, Phase, System};
|
use common_ecs::{Job, Origin, Phase, System};
|
||||||
use rtsim2::data::npc::{NpcMode, Profession};
|
use rtsim2::data::npc::{NpcMode, Profession};
|
||||||
@ -104,16 +105,37 @@ impl<'a> System<'a> for Sys {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let can_speak = npc.profession.is_some(); // TODO: not this
|
||||||
|
|
||||||
|
let trade_for_site = if let Some(Profession::Merchant) = npc.profession {
|
||||||
|
npc.home.and_then(|home| Some(data.sites.get(home)?.world_site?.id()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let skill_set = SkillSetBuilder::default().build();
|
||||||
|
let health_level = skill_set
|
||||||
|
.skill_level(skills::Skill::General(skills::GeneralSkill::HealthIncrease))
|
||||||
|
.unwrap_or(0);
|
||||||
emitter.emit(ServerEvent::CreateNpc {
|
emitter.emit(ServerEvent::CreateNpc {
|
||||||
pos: comp::Pos(npc.wpos),
|
pos: comp::Pos(npc.wpos),
|
||||||
stats: comp::Stats::new("Rtsim NPC".to_string()),
|
stats: comp::Stats::new("Rtsim NPC".to_string()),
|
||||||
skill_set: comp::SkillSet::default(),
|
skill_set: skill_set,
|
||||||
health: None,
|
health: Some(comp::Health::new(body, health_level)),
|
||||||
poise: comp::Poise::new(body),
|
poise: comp::Poise::new(body),
|
||||||
inventory: comp::Inventory::with_loadout(loadout_builder.build(), body),
|
inventory: comp::Inventory::with_loadout(loadout_builder.build(), body),
|
||||||
body,
|
body,
|
||||||
agent: Some(comp::Agent::from_body(&body)),
|
agent: Some(comp::Agent::from_body(&body)
|
||||||
alignment: comp::Alignment::Wild,
|
.with_behavior(
|
||||||
|
comp::Behavior::default()
|
||||||
|
.maybe_with_capabilities(can_speak.then_some(comp::BehaviorCapability::SPEAK))
|
||||||
|
.with_trade_site(trade_for_site),
|
||||||
|
)),
|
||||||
|
alignment: if can_speak {
|
||||||
|
comp::Alignment::Npc
|
||||||
|
} else {
|
||||||
|
comp::Alignment::Wild
|
||||||
|
},
|
||||||
scale: comp::Scale(1.0),
|
scale: comp::Scale(1.0),
|
||||||
anchor: None,
|
anchor: None,
|
||||||
loot: Default::default(),
|
loot: Default::default(),
|
||||||
|
Loading…
Reference in New Issue
Block a user