mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add commands to manage build areas
This commit is contained in:
parent
77d48657c6
commit
f08c4e6585
@ -40,6 +40,8 @@ pub enum ChatCommand {
|
||||
Alias,
|
||||
Ban,
|
||||
Build,
|
||||
BuildAreaAdd,
|
||||
BuildAreaRemove,
|
||||
Campfire,
|
||||
Debug,
|
||||
DebugColumn,
|
||||
@ -72,6 +74,8 @@ pub enum ChatCommand {
|
||||
Players,
|
||||
Region,
|
||||
RemoveLights,
|
||||
RevokeBuild,
|
||||
RevokeBuildAll,
|
||||
Safezone,
|
||||
Say,
|
||||
SetMotd,
|
||||
@ -95,6 +99,8 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
||||
ChatCommand::Alias,
|
||||
ChatCommand::Ban,
|
||||
ChatCommand::Build,
|
||||
ChatCommand::BuildAreaAdd,
|
||||
ChatCommand::BuildAreaRemove,
|
||||
ChatCommand::Campfire,
|
||||
ChatCommand::Debug,
|
||||
ChatCommand::DebugColumn,
|
||||
@ -127,6 +133,8 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
||||
ChatCommand::Players,
|
||||
ChatCommand::Region,
|
||||
ChatCommand::RemoveLights,
|
||||
ChatCommand::RevokeBuild,
|
||||
ChatCommand::RevokeBuildAll,
|
||||
ChatCommand::Safezone,
|
||||
ChatCommand::Say,
|
||||
ChatCommand::SetMotd,
|
||||
@ -238,6 +246,24 @@ impl ChatCommand {
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::Build => cmd(vec![], "Toggles build mode on and off", NoAdmin),
|
||||
ChatCommand::BuildAreaAdd => cmd(
|
||||
vec![
|
||||
Any("name", Required),
|
||||
Integer("xlo", 0, Required),
|
||||
Integer("xhi", 10, Required),
|
||||
Integer("ylo", 0, Required),
|
||||
Integer("yhi", 10, Required),
|
||||
Integer("zlo", 0, Required),
|
||||
Integer("zhi", 10, Required),
|
||||
],
|
||||
"Adds a new build area",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::BuildAreaRemove => cmd(
|
||||
vec![Any("name", Required)],
|
||||
"Removes specified build area",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::Campfire => cmd(vec![], "Spawns a campfire", Admin),
|
||||
ChatCommand::Debug => cmd(vec![], "Place all debug items into your pack.", Admin),
|
||||
ChatCommand::DebugColumn => cmd(
|
||||
@ -371,15 +397,7 @@ impl ChatCommand {
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::PermitBuild => cmd(
|
||||
vec![
|
||||
PlayerName(Required),
|
||||
Integer("xlo", 0, Required),
|
||||
Integer("xhi", 10, Required),
|
||||
Integer("ylo", 0, Required),
|
||||
Integer("yhi", 10, Required),
|
||||
Integer("ylo", 0, Required),
|
||||
Integer("yhi", 10, Required),
|
||||
],
|
||||
vec![PlayerName(Required), Any("area_name", Required)],
|
||||
"Grants player a bounded box they can build in",
|
||||
Admin,
|
||||
),
|
||||
@ -389,6 +407,16 @@ impl ChatCommand {
|
||||
"Removes all lights spawned by players",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::RevokeBuild => cmd(
|
||||
vec![PlayerName(Required), Any("area_name", Required)],
|
||||
"Revokes build area permission for given player",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::RevokeBuildAll => cmd(
|
||||
vec![PlayerName(Required)],
|
||||
"Revokes all build area permissions for given player",
|
||||
Admin,
|
||||
),
|
||||
ChatCommand::Region => cmd(
|
||||
vec![Message(Optional)],
|
||||
"Send messages to everyone in your region of the world",
|
||||
@ -475,6 +503,8 @@ impl ChatCommand {
|
||||
ChatCommand::Alias => "alias",
|
||||
ChatCommand::Ban => "ban",
|
||||
ChatCommand::Build => "build",
|
||||
ChatCommand::BuildAreaAdd => "build_area_add",
|
||||
ChatCommand::BuildAreaRemove => "build_area_remove",
|
||||
ChatCommand::Campfire => "campfire",
|
||||
ChatCommand::Debug => "debug",
|
||||
ChatCommand::DebugColumn => "debug_column",
|
||||
@ -507,6 +537,8 @@ impl ChatCommand {
|
||||
ChatCommand::Players => "players",
|
||||
ChatCommand::Region => "region",
|
||||
ChatCommand::RemoveLights => "remove_lights",
|
||||
ChatCommand::RevokeBuild => "revoke_build",
|
||||
ChatCommand::RevokeBuildAll => "revoke_build_all",
|
||||
ChatCommand::Safezone => "safezone",
|
||||
ChatCommand::Say => "say",
|
||||
ChatCommand::SetMotd => "set_motd",
|
||||
|
@ -10,11 +10,11 @@ use common::{
|
||||
region::RegionMap,
|
||||
resources::{DeltaTime, GameMode, PlayerEntity, Time, TimeOfDay},
|
||||
slowjob::SlowJobPool,
|
||||
store::{Id, Store},
|
||||
terrain::{Block, TerrainChunk, TerrainGrid},
|
||||
time::DayPeriod,
|
||||
trade::Trades,
|
||||
vol::{ReadVol, WriteVol},
|
||||
store::Store,
|
||||
};
|
||||
use common_base::span;
|
||||
use common_ecs::{run_now, PhysicsMetrics, SysMetrics};
|
||||
@ -43,12 +43,14 @@ const MAX_DELTA_TIME: f32 = 1.0;
|
||||
#[derive(Default)]
|
||||
pub struct BuildAreas {
|
||||
pub areas: Store<geom::Aabb<i32>>,
|
||||
pub area_names: HashMap<String, Id<Aabb<i32>>>,
|
||||
}
|
||||
|
||||
impl BuildAreas {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
areas: Store::default()
|
||||
areas: Store::default(),
|
||||
area_names: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,11 @@ use common_net::{
|
||||
use common_sys::state::BuildAreas;
|
||||
use rand::Rng;
|
||||
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
||||
use std::{convert::TryFrom, ops::DerefMut, time::Duration};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
ops::{Deref, DerefMut},
|
||||
time::Duration,
|
||||
};
|
||||
use vek::*;
|
||||
use world::util::Sampler;
|
||||
|
||||
@ -82,6 +86,8 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
||||
ChatCommand::Alias => handle_alias,
|
||||
ChatCommand::Ban => handle_ban,
|
||||
ChatCommand::Build => handle_build,
|
||||
ChatCommand::BuildAreaAdd => handle_build_area_add,
|
||||
ChatCommand::BuildAreaRemove => handle_build_area_remove,
|
||||
ChatCommand::Campfire => handle_spawn_campfire,
|
||||
ChatCommand::Debug => handle_debug,
|
||||
ChatCommand::DebugColumn => handle_debug_column,
|
||||
@ -114,6 +120,8 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
||||
ChatCommand::Players => handle_players,
|
||||
ChatCommand::Region => handle_region,
|
||||
ChatCommand::RemoveLights => handle_remove_lights,
|
||||
ChatCommand::RevokeBuild => handle_revoke_build,
|
||||
ChatCommand::RevokeBuildAll => handle_revoke_build_all,
|
||||
ChatCommand::Safezone => handle_safezone,
|
||||
ChatCommand::Say => handle_say,
|
||||
ChatCommand::SetMotd => handle_set_motd,
|
||||
@ -1125,17 +1133,9 @@ fn handle_permit_build(
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
if let (Some(target_alias), Some(xlo), Some(xhi), Some(ylo), Some(yhi), Some(zlo), Some(zhi)) = scan_fmt_some!(
|
||||
&args,
|
||||
&action.arg_fmt(),
|
||||
String,
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
i32
|
||||
) {
|
||||
if let (Some(target_alias), Some(area_name)) =
|
||||
scan_fmt_some!(&args, &action.arg_fmt(), String, String)
|
||||
{
|
||||
let ecs = server.state.ecs();
|
||||
let target_player_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
.join()
|
||||
@ -1147,59 +1147,130 @@ fn handle_permit_build(
|
||||
.state
|
||||
.read_storage::<comp::CanBuild>()
|
||||
.get(target_player)
|
||||
.is_some()
|
||||
.is_none()
|
||||
{
|
||||
// ecs.write_storage::<comp::CanBuild>().remove(target_player);
|
||||
// server.notify_client(
|
||||
// client,
|
||||
// ServerGeneral::server_msg(
|
||||
// ChatType::CommandInfo,
|
||||
// format!("Removed {}'s permission to build", target_alias),
|
||||
// ),
|
||||
// );
|
||||
let bb_id = ecs
|
||||
.write_resource::<BuildAreas>()
|
||||
.deref_mut()
|
||||
.areas
|
||||
.insert(Aabb {
|
||||
min: Vec3::new(xlo, ylo, zlo),
|
||||
max: Vec3::new(xhi, yhi, zhi),
|
||||
});
|
||||
if let Some(mut comp_can_build) =
|
||||
ecs.write_storage::<comp::CanBuild>().get_mut(target_player)
|
||||
{
|
||||
comp_can_build.build_areas.push(bb_id);
|
||||
}
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!("Gave {} permission to build", target_alias),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
let bb_id = ecs
|
||||
.write_resource::<BuildAreas>()
|
||||
.deref_mut()
|
||||
.areas
|
||||
.insert(Aabb {
|
||||
min: Vec3::new(xlo, ylo, zlo),
|
||||
max: Vec3::new(xhi, yhi, zhi),
|
||||
});
|
||||
let _ =
|
||||
ecs.write_storage::<comp::CanBuild>()
|
||||
.insert(target_player, comp::CanBuild {
|
||||
building_is_on: false,
|
||||
build_areas: vec![bb_id],
|
||||
build_areas: Vec::new(),
|
||||
});
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!("Gave {} permission to build", target_alias),
|
||||
),
|
||||
);
|
||||
}
|
||||
if let Some(bb_id) = ecs
|
||||
.read_resource::<BuildAreas>()
|
||||
.deref()
|
||||
.area_names
|
||||
.get(&area_name)
|
||||
{
|
||||
if let Some(mut comp_can_build) =
|
||||
ecs.write_storage::<comp::CanBuild>().get_mut(target_player)
|
||||
{
|
||||
comp_can_build.build_areas.push(*bb_id);
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!("Gave {} permission to build in {}", target_alias, area_name),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandError,
|
||||
format!("Player '{}' not found!", target_alias),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(ChatType::CommandError, action.help_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_revoke_build(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
if let (Some(target_alias), Some(area_name)) =
|
||||
scan_fmt_some!(&args, &action.arg_fmt(), String, String)
|
||||
{
|
||||
let ecs = server.state.ecs();
|
||||
let target_player_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
.join()
|
||||
.find(|(_, player)| player.alias == target_alias)
|
||||
.map(|(entity, _)| entity);
|
||||
|
||||
if let Some(target_player) = target_player_opt {
|
||||
if let Some(bb_id) = ecs
|
||||
.read_resource::<BuildAreas>()
|
||||
.deref()
|
||||
.area_names
|
||||
.get(&area_name)
|
||||
{
|
||||
if let Some(mut comp_can_build) =
|
||||
ecs.write_storage::<comp::CanBuild>().get_mut(target_player)
|
||||
{
|
||||
comp_can_build.build_areas.retain(|&x| x != *bb_id);
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!(
|
||||
"Revoked {}'s permission to build in {}",
|
||||
target_alias, area_name
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandError,
|
||||
format!("Player '{}' not found!", target_alias),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(ChatType::CommandError, action.help_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_revoke_build_all(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
if let Some(target_alias) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
||||
let ecs = server.state.ecs();
|
||||
let target_player_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
.join()
|
||||
.find(|(_, player)| player.alias == target_alias)
|
||||
.map(|(entity, _)| entity);
|
||||
|
||||
if let Some(target_player) = target_player_opt {
|
||||
ecs.write_storage::<comp::CanBuild>().remove(target_player);
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!("Revoked {}'s permission to build everywhere", target_alias),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
@ -1281,6 +1352,84 @@ fn handle_build(
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_build_area_add(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
if let (Some(area_name), Some(xlo), Some(xhi), Some(ylo), Some(yhi), Some(zlo), Some(zhi)) = scan_fmt_some!(
|
||||
&args,
|
||||
&action.arg_fmt(),
|
||||
String,
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
i32,
|
||||
i32
|
||||
) {
|
||||
let ecs = server.state.ecs();
|
||||
let bb_id = ecs
|
||||
.write_resource::<BuildAreas>()
|
||||
.deref_mut()
|
||||
.areas
|
||||
.insert(Aabb {
|
||||
min: Vec3::new(xlo, ylo, zlo),
|
||||
max: Vec3::new(xhi, yhi, zhi),
|
||||
});
|
||||
ecs.write_resource::<BuildAreas>()
|
||||
.deref_mut()
|
||||
.area_names
|
||||
.insert(area_name.clone(), bb_id);
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!("Created build zone {}", area_name),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_build_area_remove(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
if let Some(area_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
||||
let ecs = server.state.ecs();
|
||||
let mut build_areas = ecs.write_resource::<BuildAreas>();
|
||||
|
||||
let bb_id = match &build_areas.area_names.get(&area_name) {
|
||||
Some(x) => *x.clone(),
|
||||
None => {
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandError,
|
||||
format!("No such build area '{}'", area_name),
|
||||
),
|
||||
);
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
let _ = build_areas.area_names.remove(&area_name);
|
||||
let _ = build_areas.areas.remove(bb_id);
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
ChatType::CommandInfo,
|
||||
format!("Removed build zone {}", area_name),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_help(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
|
@ -106,9 +106,13 @@ impl Sys {
|
||||
if let Some(comp_can_build) = can_build.get(entity) {
|
||||
if comp_can_build.building_is_on {
|
||||
for area in comp_can_build.build_areas.iter() {
|
||||
if build_areas.areas.get(*area).contains_point(pos) {
|
||||
if let Ok(block) = terrain.get(pos) {
|
||||
block_changes.set(pos, block.into_vacant());
|
||||
if build_areas.areas.contains(*area) {
|
||||
println!("build area exists!");
|
||||
if build_areas.areas.get(*area).contains_point(pos) {
|
||||
println!("got build area!");
|
||||
if let Ok(block) = terrain.get(pos) {
|
||||
block_changes.set(pos, block.into_vacant());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,8 +123,10 @@ impl Sys {
|
||||
if let Some(comp_can_build) = can_build.get(entity) {
|
||||
if comp_can_build.building_is_on {
|
||||
for area in comp_can_build.build_areas.iter() {
|
||||
if build_areas.areas.get(*area).contains_point(pos) {
|
||||
block_changes.try_set(pos, block);
|
||||
if build_areas.areas.contains(*area) {
|
||||
if build_areas.areas.get(*area).contains_point(pos) {
|
||||
block_changes.try_set(pos, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user