2019-05-17 09:22:32 +00:00
|
|
|
//! # Implementing new commands.
|
2019-04-16 16:08:36 +00:00
|
|
|
//! To implement a new command, add an instance of `ChatCommand` to `CHAT_COMMANDS`
|
2019-04-16 16:22:44 +00:00
|
|
|
//! and provide a handler function.
|
2019-04-16 16:08:36 +00:00
|
|
|
|
2019-04-16 15:38:01 +00:00
|
|
|
use crate::Server;
|
2019-06-01 19:49:34 +00:00
|
|
|
use common::{
|
|
|
|
comp,
|
|
|
|
msg::ServerMsg,
|
|
|
|
npc::{get_npc_name, NpcKind},
|
2019-07-01 13:38:45 +00:00
|
|
|
state::{TerrainChange, TimeOfDay},
|
2019-07-01 13:36:45 +00:00
|
|
|
terrain::Block,
|
|
|
|
vol::Vox,
|
2019-06-01 19:49:34 +00:00
|
|
|
};
|
2019-05-12 19:57:39 +00:00
|
|
|
use specs::{Builder, Entity as EcsEntity, Join};
|
2019-04-16 15:38:01 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2019-04-16 16:34:41 +00:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use scan_fmt::scan_fmt;
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Struct representing a command that a user can run from server chat.
|
2019-04-16 15:38:01 +00:00
|
|
|
pub struct ChatCommand {
|
2019-05-17 09:22:32 +00:00
|
|
|
/// The keyword used to invoke the command, omitting the leading '/'.
|
2019-04-16 15:38:01 +00:00
|
|
|
pub keyword: &'static str,
|
2019-05-17 09:22:32 +00:00
|
|
|
/// A format string for parsing arguments.
|
2019-04-16 15:38:01 +00:00
|
|
|
arg_fmt: &'static str,
|
2019-05-17 09:22:32 +00:00
|
|
|
/// A message that explains how the command is used.
|
2019-04-16 15:38:01 +00:00
|
|
|
help_string: &'static str,
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Handler function called when the command is executed.
|
2019-04-16 16:22:44 +00:00
|
|
|
/// # Arguments
|
2019-05-17 09:22:32 +00:00
|
|
|
/// * `&mut Server` - the `Server` instance executing the command.
|
|
|
|
/// * `EcsEntity` - an `Entity` corresponding to the player that invoked the command.
|
|
|
|
/// * `String` - a `String` containing the part of the command after the keyword.
|
|
|
|
/// * `&ChatCommand` - the command to execute with the above arguments.
|
|
|
|
/// Handler functions must parse arguments from the the given `String` (`scan_fmt!` is included for this purpose).
|
2019-04-16 15:38:01 +00:00
|
|
|
handler: fn(&mut Server, EcsEntity, String, &ChatCommand),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ChatCommand {
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Creates a new chat command.
|
2019-04-16 15:38:01 +00:00
|
|
|
pub fn new(
|
|
|
|
keyword: &'static str,
|
|
|
|
arg_fmt: &'static str,
|
|
|
|
help_string: &'static str,
|
|
|
|
handler: fn(&mut Server, EcsEntity, String, &ChatCommand),
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
keyword,
|
|
|
|
arg_fmt,
|
|
|
|
help_string,
|
|
|
|
handler,
|
|
|
|
}
|
|
|
|
}
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Calls the contained handler function, passing `&self` as the last argument.
|
2019-04-16 15:38:01 +00:00
|
|
|
pub fn execute(&self, server: &mut Server, entity: EcsEntity, args: String) {
|
|
|
|
(self.handler)(server, entity, args, self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lazy_static! {
|
2019-05-17 09:22:32 +00:00
|
|
|
/// Static list of chat commands available to the server.
|
2019-04-16 15:38:01 +00:00
|
|
|
pub static ref CHAT_COMMANDS: Vec<ChatCommand> = vec![
|
|
|
|
ChatCommand::new(
|
|
|
|
"jump",
|
|
|
|
"{d} {d} {d}",
|
2019-04-17 13:00:24 +00:00
|
|
|
"/jump <dx> <dy> <dz> : Offset your current position",
|
2019-06-21 08:42:16 +00:00
|
|
|
handle_jump,
|
2019-04-16 15:38:01 +00:00
|
|
|
),
|
|
|
|
ChatCommand::new(
|
|
|
|
"goto",
|
|
|
|
"{d} {d} {d}",
|
2019-04-17 13:00:24 +00:00
|
|
|
"/goto <x> <y> <z> : Teleport to a position",
|
2019-06-21 08:42:16 +00:00
|
|
|
handle_goto,
|
2019-04-16 15:38:01 +00:00
|
|
|
),
|
|
|
|
ChatCommand::new(
|
|
|
|
"alias",
|
|
|
|
"{}",
|
2019-04-17 13:00:24 +00:00
|
|
|
"/alias <name> : Change your alias",
|
2019-06-21 08:42:16 +00:00
|
|
|
handle_alias,
|
2019-04-16 15:38:01 +00:00
|
|
|
),
|
|
|
|
ChatCommand::new(
|
|
|
|
"tp",
|
|
|
|
"{}",
|
2019-05-11 12:43:19 +00:00
|
|
|
"/tp <alias> : Teleport to another player",
|
2019-06-21 08:42:16 +00:00
|
|
|
handle_tp,
|
2019-04-16 15:38:01 +00:00
|
|
|
),
|
2019-05-19 21:54:09 +00:00
|
|
|
ChatCommand::new(
|
|
|
|
"kill",
|
|
|
|
"{}",
|
|
|
|
"/kill : Kill yourself",
|
2019-06-21 08:42:16 +00:00
|
|
|
handle_kill,
|
|
|
|
),
|
|
|
|
ChatCommand::new(
|
|
|
|
"time",
|
|
|
|
"{} {s}",
|
|
|
|
"/time : Set the time of day",
|
|
|
|
handle_time,
|
2019-05-19 21:54:09 +00:00
|
|
|
),
|
2019-05-11 12:43:19 +00:00
|
|
|
ChatCommand::new(
|
2019-06-15 07:54:47 +00:00
|
|
|
"spawn",
|
|
|
|
"{} {} {d}",
|
2019-06-15 08:15:04 +00:00
|
|
|
"/spawn <alignment> <entity> [amount] : Spawn a test entity",
|
2019-06-21 08:42:16 +00:00
|
|
|
handle_spawn,
|
2019-05-27 11:18:14 +00:00
|
|
|
),
|
2019-06-11 04:24:35 +00:00
|
|
|
ChatCommand::new(
|
2019-06-29 12:05:30 +00:00
|
|
|
"players",
|
2019-06-11 04:24:35 +00:00
|
|
|
"{}",
|
2019-06-29 12:05:30 +00:00
|
|
|
"/players : Show the online players list",
|
|
|
|
handle_players,
|
2019-06-11 04:24:35 +00:00
|
|
|
),
|
2019-07-01 13:36:45 +00:00
|
|
|
ChatCommand::new(
|
|
|
|
"solid",
|
|
|
|
"{}",
|
|
|
|
"/solid : Make the blocks around you solid",
|
|
|
|
handle_solid,
|
|
|
|
),
|
|
|
|
ChatCommand::new(
|
|
|
|
"empty",
|
|
|
|
"{}",
|
|
|
|
"/empty : Make the blocks around you empty",
|
|
|
|
handle_empty,
|
|
|
|
),
|
2019-05-17 09:22:32 +00:00
|
|
|
ChatCommand::new(
|
|
|
|
"help", "", "/help: Display this message", handle_help)
|
2019-04-16 15:38:01 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_jump(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
|
|
|
let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32);
|
|
|
|
match (opt_x, opt_y, opt_z) {
|
|
|
|
(Some(x), Some(y), Some(z)) => {
|
2019-06-14 15:27:05 +00:00
|
|
|
match server.state.read_component_cloned::<comp::Pos>(entity) {
|
2019-04-17 13:00:24 +00:00
|
|
|
Some(current_pos) => {
|
2019-04-29 20:37:19 +00:00
|
|
|
server
|
|
|
|
.state
|
2019-06-14 15:27:05 +00:00
|
|
|
.write_component(entity, comp::Pos(current_pos.0 + Vec3::new(x, y, z)));
|
|
|
|
server.state.write_component(entity, comp::ForceUpdate);
|
2019-04-29 20:37:19 +00:00
|
|
|
}
|
2019-04-16 16:34:41 +00:00
|
|
|
None => server.clients.notify(
|
2019-04-16 15:38:01 +00:00
|
|
|
entity,
|
2019-07-01 13:36:45 +00:00
|
|
|
ServerMsg::Chat(String::from("You have no position!")),
|
2019-04-16 16:34:41 +00:00
|
|
|
),
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_goto(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
|
|
|
let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32);
|
2019-06-28 14:22:25 +00:00
|
|
|
match server.state.read_component_cloned::<comp::Pos>(entity) {
|
2019-07-01 16:38:19 +00:00
|
|
|
Some(_pos) => match (opt_x, opt_y, opt_z) {
|
2019-06-28 14:22:25 +00:00
|
|
|
(Some(x), Some(y), Some(z)) => {
|
|
|
|
server
|
|
|
|
.state
|
|
|
|
.write_component(entity, comp::Pos(Vec3::new(x, y, z)));
|
|
|
|
server.state.write_component(entity, comp::ForceUpdate);
|
|
|
|
}
|
|
|
|
_ => server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat(String::from("You don't have any position!")),
|
|
|
|
);
|
2019-04-29 20:37:19 +00:00
|
|
|
}
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 14:48:41 +00:00
|
|
|
fn handle_kill(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
2019-05-19 21:54:09 +00:00
|
|
|
server
|
|
|
|
.state
|
2019-05-25 21:13:38 +00:00
|
|
|
.ecs_mut()
|
|
|
|
.write_storage::<comp::Stats>()
|
|
|
|
.get_mut(entity)
|
2019-06-30 11:48:28 +00:00
|
|
|
.map(|s| s.health.set_to(0, comp::HealthSource::Suicide));
|
2019-05-19 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 08:42:16 +00:00
|
|
|
fn handle_time(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
|
|
|
let time = scan_fmt!(&args, action.arg_fmt, String);
|
2019-06-23 19:43:02 +00:00
|
|
|
server.state.ecs_mut().write_resource::<TimeOfDay>().0 = match time.as_ref().map(|s| s.as_str())
|
|
|
|
{
|
|
|
|
Some("day") => 12.0 * 3600.0,
|
|
|
|
Some("night") => 24.0 * 3600.0,
|
|
|
|
Some("dawn") => 5.0 * 3600.0,
|
|
|
|
Some("dusk") => 17.0 * 3600.0,
|
|
|
|
Some(n) => match n.parse() {
|
|
|
|
Ok(n) => n,
|
|
|
|
Err(_) => {
|
|
|
|
server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(format!("'{}' is not a time!", n)));
|
2019-06-21 08:42:16 +00:00
|
|
|
return;
|
2019-06-23 19:43:02 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat("You must specify a time!".to_string()),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2019-06-21 08:42:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 15:38:01 +00:00
|
|
|
fn handle_alias(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
|
|
|
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
|
|
|
|
match opt_alias {
|
2019-05-19 00:45:02 +00:00
|
|
|
Some(alias) => {
|
|
|
|
server
|
|
|
|
.state
|
|
|
|
.ecs_mut()
|
|
|
|
.write_storage::<comp::Player>()
|
|
|
|
.get_mut(entity)
|
|
|
|
.map(|player| player.alias = alias);
|
|
|
|
}
|
2019-04-16 15:38:01 +00:00
|
|
|
None => server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
|
|
|
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
|
|
|
|
match opt_alias {
|
|
|
|
Some(alias) => {
|
2019-04-22 08:20:25 +00:00
|
|
|
let ecs = server.state.ecs();
|
2019-06-14 15:27:05 +00:00
|
|
|
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
2019-04-16 15:38:01 +00:00
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == alias)
|
|
|
|
.map(|(entity, _)| entity);
|
2019-06-28 14:22:25 +00:00
|
|
|
match server.state.read_component_cloned::<comp::Pos>(entity) {
|
2019-07-01 16:38:19 +00:00
|
|
|
Some(_pos) => match opt_player {
|
2019-06-28 14:22:25 +00:00
|
|
|
Some(player) => match server.state.read_component_cloned::<comp::Pos>(player) {
|
|
|
|
Some(pos) => {
|
|
|
|
server.state.write_component(entity, pos);
|
|
|
|
server.state.write_component(entity, comp::ForceUpdate);
|
|
|
|
}
|
|
|
|
None => server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat(format!("Unable to teleport to player '{}'!", alias)),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat(format!("Player '{}' not found!", alias)),
|
|
|
|
);
|
|
|
|
server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(String::from(action.help_string)));
|
2019-04-29 20:37:19 +00:00
|
|
|
}
|
2019-04-16 15:38:01 +00:00
|
|
|
},
|
|
|
|
None => {
|
2019-07-01 13:38:45 +00:00
|
|
|
server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(format!("You have no position!")));
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 07:54:47 +00:00
|
|
|
fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
2019-06-15 08:15:04 +00:00
|
|
|
let (opt_align, opt_id, opt_amount) = scan_fmt!(&args, action.arg_fmt, String, NpcKind, String);
|
2019-06-15 15:23:53 +00:00
|
|
|
// This should be just an enum handled with scan_fmt!
|
2019-06-15 07:54:47 +00:00
|
|
|
let opt_agent = alignment_to_agent(&opt_align.unwrap_or(String::new()), entity);
|
2019-06-15 08:15:04 +00:00
|
|
|
|
|
|
|
// Make sure the amount is either not provided or a valid value
|
2019-06-15 13:42:39 +00:00
|
|
|
let opt_amount = opt_amount
|
2019-06-15 15:23:53 +00:00
|
|
|
.map_or(Some(1), |a| a.parse().ok())
|
2019-06-15 13:42:39 +00:00
|
|
|
.and_then(|a| if a > 0 { Some(a) } else { None });
|
2019-06-15 08:15:04 +00:00
|
|
|
|
2019-06-15 07:54:47 +00:00
|
|
|
match (opt_agent, opt_id, opt_amount) {
|
|
|
|
(Some(agent), Some(id), Some(amount)) => {
|
2019-06-14 15:27:05 +00:00
|
|
|
match server.state.read_component_cloned::<comp::Pos>(entity) {
|
2019-06-15 07:54:47 +00:00
|
|
|
Some(mut pos) => {
|
|
|
|
pos.0.x += 1.0; // Temp fix TODO: Solve NaN issue with positions of pets
|
|
|
|
for _ in 0..amount {
|
2019-06-28 16:58:47 +00:00
|
|
|
let body = kind_to_body(id);
|
2019-06-15 07:54:47 +00:00
|
|
|
server
|
2019-06-15 11:48:14 +00:00
|
|
|
.create_npc(pos, get_npc_name(id), body)
|
2019-06-15 07:54:47 +00:00
|
|
|
.with(agent)
|
|
|
|
.build();
|
|
|
|
}
|
2019-06-15 11:48:14 +00:00
|
|
|
server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat(format!("Spawned {} entities", amount).to_owned()),
|
|
|
|
);
|
2019-06-15 07:54:47 +00:00
|
|
|
}
|
|
|
|
None => server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat("You have no position!".to_owned())),
|
|
|
|
}
|
2019-06-15 11:48:14 +00:00
|
|
|
}
|
2019-06-15 07:54:47 +00:00
|
|
|
_ => server
|
2019-05-12 21:34:20 +00:00
|
|
|
.clients
|
2019-06-15 07:54:47 +00:00
|
|
|
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
|
2019-05-11 12:43:19 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 03:01:52 +00:00
|
|
|
|
2019-06-29 12:05:30 +00:00
|
|
|
fn handle_players(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
2019-06-11 04:24:35 +00:00
|
|
|
let ecs = server.state.ecs();
|
|
|
|
let players = ecs.read_storage::<comp::Player>();
|
|
|
|
let count = players.join().count();
|
2019-07-01 16:38:19 +00:00
|
|
|
let header_message: String = format!("{} online players: \n", count);
|
2019-06-11 04:24:35 +00:00
|
|
|
if count > 0 {
|
2019-06-29 22:16:16 +00:00
|
|
|
let mut player_iter = players.join();
|
|
|
|
let first = player_iter.next().unwrap().alias.to_owned();
|
2019-06-29 23:05:34 +00:00
|
|
|
let player_list = player_iter.fold(first, |mut s, p| {
|
2019-06-29 22:56:10 +00:00
|
|
|
s += ",\n";
|
|
|
|
s += &p.alias;
|
|
|
|
s
|
|
|
|
});
|
2019-06-29 22:16:16 +00:00
|
|
|
|
2019-06-11 04:24:35 +00:00
|
|
|
server
|
2019-06-29 12:05:30 +00:00
|
|
|
.clients
|
2019-06-29 22:16:16 +00:00
|
|
|
.notify(entity, ServerMsg::Chat(header_message + &player_list));
|
2019-06-11 04:24:35 +00:00
|
|
|
} else {
|
2019-06-29 22:56:10 +00:00
|
|
|
server
|
|
|
|
.clients
|
|
|
|
.notify(entity, ServerMsg::Chat(header_message));
|
2019-06-11 04:24:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 18:49:42 +00:00
|
|
|
fn handle_solid(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
2019-07-01 13:36:45 +00:00
|
|
|
match server.state.read_component_cloned::<comp::Pos>(entity) {
|
|
|
|
Some(current_pos) => {
|
2019-07-01 14:38:40 +00:00
|
|
|
server.state.ecs().write_resource::<TerrainChange>().set(
|
|
|
|
current_pos.0.map(|e| e.floor() as i32),
|
|
|
|
Block::new(1, Rgb::broadcast(255)),
|
|
|
|
);
|
2019-07-01 13:36:45 +00:00
|
|
|
}
|
|
|
|
None => server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat(String::from("You have no position!")),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-01 18:49:42 +00:00
|
|
|
fn handle_empty(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
2019-07-01 13:36:45 +00:00
|
|
|
match server.state.read_component_cloned::<comp::Pos>(entity) {
|
|
|
|
Some(current_pos) => {
|
2019-07-01 13:38:45 +00:00
|
|
|
let mut terrain_change = server.state.ecs().write_resource::<TerrainChange>();
|
2019-07-01 13:36:45 +00:00
|
|
|
|
|
|
|
for i in -1..2 {
|
|
|
|
for j in -1..2 {
|
|
|
|
for k in -2..1 {
|
|
|
|
terrain_change.set(
|
|
|
|
current_pos.0.map(|e| e.floor() as i32) + Vec3::new(i, j, k),
|
|
|
|
Block::empty(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => server.clients.notify(
|
|
|
|
entity,
|
|
|
|
ServerMsg::Chat(String::from("You have no position!")),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-15 07:54:47 +00:00
|
|
|
fn handle_help(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
|
|
|
for cmd in CHAT_COMMANDS.iter() {
|
|
|
|
server
|
2019-05-26 03:31:41 +00:00
|
|
|
.clients
|
2019-06-15 07:54:47 +00:00
|
|
|
.notify(entity, ServerMsg::Chat(String::from(cmd.help_string)));
|
2019-05-26 03:31:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 03:01:52 +00:00
|
|
|
|
2019-06-15 07:54:47 +00:00
|
|
|
fn alignment_to_agent(alignment: &str, target: EcsEntity) -> Option<comp::Agent> {
|
|
|
|
match alignment {
|
|
|
|
"hostile" => Some(comp::Agent::Enemy { target: None }),
|
2019-06-15 11:48:14 +00:00
|
|
|
"friendly" => Some(comp::Agent::Pet {
|
|
|
|
target,
|
|
|
|
offset: Vec2::zero(),
|
|
|
|
}),
|
2019-06-15 09:32:07 +00:00
|
|
|
// passive?
|
2019-06-15 11:48:14 +00:00
|
|
|
_ => None,
|
2019-05-27 11:18:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 03:01:52 +00:00
|
|
|
|
2019-06-15 07:54:47 +00:00
|
|
|
fn kind_to_body(kind: NpcKind) -> comp::Body {
|
|
|
|
match kind {
|
2019-06-28 23:42:51 +00:00
|
|
|
NpcKind::Humanoid => comp::Body::Humanoid(comp::humanoid::Body::random()),
|
|
|
|
NpcKind::Pig => comp::Body::Quadruped(comp::quadruped::Body::random()),
|
|
|
|
NpcKind::Wolf => comp::Body::QuadrupedMedium(comp::quadruped_medium::Body::random()),
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
2019-04-17 13:00:24 +00:00
|
|
|
}
|