veloren/server/src/events/entity_creation.rs
Monty Marz ce929d2924 Address comments, clippy and minor adjustments
first bunch of comments addressed

change order or scatter, paths and caves being applied in worldgen to avoid floating scatter objects

campfire adjustments, reduced grass density due to FPS issues

readded item descriptions to the crafting window, item desc for craftable armour

address comments
happy clippy, happy life
clippy

clippy

more clippy
fmt

revert cargo.toml formatting
remove "allow unreachable pattern"
fmt
2020-08-21 22:37:08 +02:00

135 lines
3.3 KiB
Rust

use crate::{sys, Server, StateExt};
use common::{
comp::{
self, Agent, Alignment, Body, Gravity, Item, ItemDrop, LightAnimation, LightEmitter,
Loadout, Pos, Projectile, Scale, Stats, Vel, WaypointArea,
},
outcome::Outcome,
util::Dir,
};
use comp::group;
use specs::{Builder, Entity as EcsEntity, WorldExt};
use vek::{Rgb, Vec3};
pub fn handle_initialize_character(server: &mut Server, entity: EcsEntity, character_id: i32) {
server.state.initialize_character_data(entity, character_id);
}
pub fn handle_loaded_character_data(
server: &mut Server,
entity: EcsEntity,
loaded_components: (comp::Body, comp::Stats, comp::Inventory, comp::Loadout),
) {
server
.state
.update_character_data(entity, loaded_components);
sys::subscription::initialize_region_subscription(server.state.ecs(), entity);
}
#[allow(clippy::too_many_arguments)] // TODO: Pending review in #587
pub fn handle_create_npc(
server: &mut Server,
pos: Pos,
stats: Stats,
loadout: Loadout,
body: Body,
agent: impl Into<Option<Agent>>,
alignment: Alignment,
scale: Scale,
drop_item: Option<Item>,
) {
let group = match alignment {
Alignment::Wild => None,
Alignment::Passive => None,
Alignment::Enemy => Some(group::ENEMY),
Alignment::Npc | Alignment::Tame => Some(group::NPC),
// TODO: handle
Alignment::Owned(_) => None,
};
let entity = server
.state
.create_npc(pos, stats, loadout, body)
.with(scale)
.with(alignment);
let entity = if let Some(group) = group {
entity.with(group)
} else {
entity
};
let entity = if let Some(agent) = agent.into() {
entity.with(agent)
} else {
entity
};
let entity = if let Some(drop_item) = drop_item {
entity.with(ItemDrop(drop_item))
} else {
entity
};
entity.build();
}
pub fn handle_shoot(
server: &mut Server,
entity: EcsEntity,
dir: Dir,
body: Body,
light: Option<LightEmitter>,
projectile: Projectile,
gravity: Option<Gravity>,
) {
let state = server.state_mut();
let mut pos = state
.ecs()
.read_storage::<Pos>()
.get(entity)
.expect("Failed to fetch entity")
.0;
let vel = *dir * 100.0;
// Add an outcome
state
.ecs()
.write_resource::<Vec<Outcome>>()
.push(Outcome::ProjectileShot { pos, body, vel });
// TODO: Player height
pos.z += 1.2;
let mut builder = state.create_projectile(Pos(pos), Vel(vel), body, projectile);
if let Some(light) = light {
builder = builder.with(light)
}
if let Some(gravity) = gravity {
builder = builder.with(gravity)
}
builder.build();
}
pub fn handle_create_waypoint(server: &mut Server, pos: Vec3<f32>) {
server
.state
.create_object(Pos(pos), comp::object::Body::CampfireLit)
.with(LightEmitter {
col: Rgb::new(1.0, 0.8, 0.0),
strength: 8.0,
flicker: 1.0,
animated: true,
})
.with(LightAnimation {
offset: Vec3::new(0.0, 0.0, 2.0),
col: Rgb::new(1.0, 0.8, 0.0),
strength: 8.0,
})
.with(WaypointArea::default())
.build();
}