2020-02-16 20:04:06 +00:00
|
|
|
use crate::{sys, Server, StateExt};
|
2020-03-28 01:31:22 +00:00
|
|
|
use common::{
|
|
|
|
comp::{
|
|
|
|
self, Agent, Alignment, Body, Gravity, LightEmitter, Loadout, Pos, Projectile, Scale,
|
|
|
|
Stats, Vel, WaypointArea,
|
|
|
|
},
|
|
|
|
util::Dir,
|
2020-02-16 20:04:06 +00:00
|
|
|
};
|
|
|
|
use specs::{Builder, Entity as EcsEntity, WorldExt};
|
|
|
|
use vek::{Rgb, Vec3};
|
|
|
|
|
|
|
|
pub fn handle_create_character(
|
|
|
|
server: &mut Server,
|
|
|
|
entity: EcsEntity,
|
|
|
|
name: String,
|
|
|
|
body: Body,
|
|
|
|
main: Option<String>,
|
|
|
|
) {
|
|
|
|
let state = &mut server.state;
|
|
|
|
let server_settings = &server.server_settings;
|
|
|
|
|
2020-03-10 02:27:32 +00:00
|
|
|
state.create_player_character(entity, name, body, main, server_settings);
|
2020-02-16 20:04:06 +00:00
|
|
|
sys::subscription::initialize_region_subscription(state.ecs(), entity);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn handle_create_npc(
|
|
|
|
server: &mut Server,
|
|
|
|
pos: Pos,
|
|
|
|
stats: Stats,
|
2020-02-26 17:04:43 +00:00
|
|
|
loadout: Loadout,
|
2020-02-16 20:04:06 +00:00
|
|
|
body: Body,
|
|
|
|
agent: Agent,
|
|
|
|
alignment: Alignment,
|
|
|
|
scale: Scale,
|
|
|
|
) {
|
|
|
|
server
|
|
|
|
.state
|
2020-02-26 17:04:43 +00:00
|
|
|
.create_npc(pos, stats, loadout, body)
|
2020-02-16 20:04:06 +00:00
|
|
|
.with(agent)
|
|
|
|
.with(scale)
|
|
|
|
.with(alignment)
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn handle_shoot(
|
|
|
|
server: &mut Server,
|
|
|
|
entity: EcsEntity,
|
2020-03-28 01:31:22 +00:00
|
|
|
dir: Dir,
|
2020-02-16 20:04:06 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
// TODO: Player height
|
|
|
|
pos.z += 1.2;
|
|
|
|
|
2020-03-28 01:31:22 +00:00
|
|
|
let mut builder = state.create_projectile(Pos(pos), Vel(*dir * 100.0), body, projectile);
|
2020-02-16 20:04:06 +00:00
|
|
|
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
|
2020-03-10 02:27:32 +00:00
|
|
|
.state
|
2020-02-16 20:04:06 +00:00
|
|
|
.create_object(Pos(pos), comp::object::Body::CampfireLit)
|
|
|
|
.with(LightEmitter {
|
|
|
|
col: Rgb::new(1.0, 0.65, 0.2),
|
|
|
|
strength: 2.0,
|
2020-05-04 15:15:31 +00:00
|
|
|
flicker: 1.0,
|
|
|
|
animated: true,
|
2020-02-16 20:04:06 +00:00
|
|
|
})
|
|
|
|
.with(WaypointArea::default())
|
|
|
|
.build();
|
|
|
|
}
|