Add campfire command

This commit is contained in:
scott-c 2020-07-31 17:34:26 +08:00
parent 82a0ecad6b
commit 1a263834e7
2 changed files with 46 additions and 0 deletions

View File

@ -38,6 +38,7 @@ pub enum ChatCommand {
Adminify,
Alias,
Build,
Campfire,
Debug,
DebugColumn,
Dummy,
@ -79,6 +80,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
ChatCommand::Adminify,
ChatCommand::Alias,
ChatCommand::Build,
ChatCommand::Campfire,
ChatCommand::Debug,
ChatCommand::DebugColumn,
ChatCommand::Dummy,
@ -185,6 +187,7 @@ impl ChatCommand {
),
ChatCommand::Alias => cmd(vec![Any("name", Required)], "Change your alias", NoAdmin),
ChatCommand::Build => cmd(vec![], "Toggles build mode on and off", Admin),
ChatCommand::Campfire => cmd(vec![], "Spawns a campfire", Admin),
ChatCommand::Debug => cmd(vec![], "Place all debug items into your pack.", Admin),
ChatCommand::DebugColumn => cmd(
vec![Integer("x", 15000, Required), Integer("y", 15000, Required)],
@ -365,6 +368,7 @@ impl ChatCommand {
ChatCommand::Adminify => "adminify",
ChatCommand::Alias => "alias",
ChatCommand::Build => "build",
ChatCommand::Campfire => "campfire",
ChatCommand::Debug => "debug",
ChatCommand::DebugColumn => "debug_column",
ChatCommand::Dummy => "dummy",

View File

@ -65,6 +65,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
ChatCommand::Adminify => handle_adminify,
ChatCommand::Alias => handle_alias,
ChatCommand::Build => handle_build,
ChatCommand::Campfire => handle_spawn_campfire,
ChatCommand::Debug => handle_debug,
ChatCommand::DebugColumn => handle_debug_column,
ChatCommand::Dummy => handle_spawn_training_dummy,
@ -664,6 +665,47 @@ fn handle_spawn_training_dummy(
}
}
fn handle_spawn_campfire(
server: &mut Server,
client: EcsEntity,
target: EcsEntity,
_args: String,
_action: &ChatCommand,
) {
match server.state.read_component_cloned::<comp::Pos>(target) {
Some(pos) => {
let vel = Vec3::new(
rand::thread_rng().gen_range(-2.0, 3.0),
rand::thread_rng().gen_range(-2.0, 3.0),
10.0,
);
let body = comp::Body::Object(comp::object::Body::CampfireLit);
let mut stats = comp::Stats::new("Campfire".to_string(), body);
// Level 0 will prevent exp gain from kill
stats.level.set_level(0);
server
.state
.create_npc(pos, stats, comp::Loadout::default(), body)
.with(comp::Vel(vel))
.with(comp::MountState::Unmounted)
.build();
server.notify_client(
client,
ChatType::CommandInfo.server_msg("Spawned a campfire"),
);
},
None => server.notify_client(
client,
ChatType::CommandError.server_msg("You have no position!"),
),
}
}
fn handle_players(
server: &mut Server,
client: EcsEntity,