Added command: '/safezone'

This commit is contained in:
Sam 2021-02-28 18:14:59 -05:00
parent 6ab4e2264e
commit d09baadab2
3 changed files with 61 additions and 26 deletions

View File

@ -70,6 +70,7 @@ pub enum ChatCommand {
Players, Players,
Region, Region,
RemoveLights, RemoveLights,
Safezone,
Say, Say,
SetMotd, SetMotd,
SkillPoint, SkillPoint,
@ -122,6 +123,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
ChatCommand::Players, ChatCommand::Players,
ChatCommand::Region, ChatCommand::Region,
ChatCommand::RemoveLights, ChatCommand::RemoveLights,
ChatCommand::Safezone,
ChatCommand::Say, ChatCommand::Say,
ChatCommand::SetMotd, ChatCommand::SetMotd,
ChatCommand::SkillPoint, ChatCommand::SkillPoint,
@ -370,6 +372,11 @@ impl ChatCommand {
"Send messages to everyone in your region of the world", "Send messages to everyone in your region of the world",
NoAdmin, NoAdmin,
), ),
ChatCommand::Safezone => cmd(
vec![Float("range", 100.0, Optional)],
"Creates a safezone",
Admin,
),
ChatCommand::Say => cmd( ChatCommand::Say => cmd(
vec![Message(Optional)], vec![Message(Optional)],
"Send messages to everyone within shouting distance", "Send messages to everyone within shouting distance",
@ -476,6 +483,7 @@ impl ChatCommand {
ChatCommand::Players => "players", ChatCommand::Players => "players",
ChatCommand::Region => "region", ChatCommand::Region => "region",
ChatCommand::RemoveLights => "remove_lights", ChatCommand::RemoveLights => "remove_lights",
ChatCommand::Safezone => "safezone",
ChatCommand::Say => "say", ChatCommand::Say => "say",
ChatCommand::SetMotd => "set_motd", ChatCommand::SetMotd => "set_motd",
ChatCommand::SkillPoint => "skill_point", ChatCommand::SkillPoint => "skill_point",

View File

@ -431,7 +431,7 @@ pub struct Damage {
impl Damage { impl Damage {
/// Returns the total damage reduction provided by all equipped items /// Returns the total damage reduction provided by all equipped items
pub fn compute_damage_reduction(inventory: Option<&Inventory>, stats: Option<&Stats>) -> f32 { pub fn compute_damage_reduction(inventory: Option<&Inventory>, stats: Option<&Stats>) -> f32 {
let invetory_dr = if let Some(inventory) = inventory { let inventory_dr = if let Some(inventory) = inventory {
let protection = inventory let protection = inventory
.equipped_items() .equipped_items()
.filter_map(|item| { .filter_map(|item| {
@ -461,7 +461,7 @@ impl Damage {
} else { } else {
0.0 0.0
}; };
1.0 - (1.0 - invetory_dr) * (1.0 - stats_dr) 1.0 - (1.0 - inventory_dr) * (1.0 - stats_dr)
} }
pub fn calculate_health_change( pub fn calculate_health_change(

View File

@ -111,6 +111,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
ChatCommand::Players => handle_players, ChatCommand::Players => handle_players,
ChatCommand::Region => handle_region, ChatCommand::Region => handle_region,
ChatCommand::RemoveLights => handle_remove_lights, ChatCommand::RemoveLights => handle_remove_lights,
ChatCommand::Safezone => handle_safezone,
ChatCommand::Say => handle_say, ChatCommand::Say => handle_say,
ChatCommand::SetMotd => handle_set_motd, ChatCommand::SetMotd => handle_set_motd,
ChatCommand::SkillPoint => handle_skill_point, ChatCommand::SkillPoint => handle_skill_point,
@ -975,30 +976,17 @@ fn handle_spawn_campfire(
animated: true, animated: true,
}) })
.with(WaypointArea::default()) .with(WaypointArea::default())
.with(comp::Auras::new(vec![ .with(comp::Auras::new(vec![Aura::new(
Aura::new( AuraKind::Buff {
AuraKind::Buff { kind: BuffKind::CampfireHeal,
kind: BuffKind::CampfireHeal, data: BuffData::new(0.02, Some(Duration::from_secs(1))),
data: BuffData::new(0.02, Some(Duration::from_secs(1))), category: BuffCategory::Natural,
category: BuffCategory::Natural, source: BuffSource::World,
source: BuffSource::World, },
}, 5.0,
5.0, None,
None, AuraTarget::All,
AuraTarget::All, )]))
),
Aura::new(
AuraKind::Buff {
kind: BuffKind::Invulnerability,
data: BuffData::new(1.0, Some(Duration::from_secs(1))),
category: BuffCategory::Natural,
source: BuffSource::World,
},
100.0,
None,
AuraTarget::All,
),
]))
.build(); .build();
server.notify_client( server.notify_client(
@ -1013,6 +1001,45 @@ fn handle_spawn_campfire(
} }
} }
fn handle_safezone(
server: &mut Server,
client: EcsEntity,
target: EcsEntity,
args: String,
action: &ChatCommand,
) {
let range = scan_fmt_some!(&args, &action.arg_fmt(), f32);
match server.state.read_component_copied::<comp::Pos>(target) {
Some(pos) => {
server
.state
.create_object(pos, comp::object::Body::BoltNature)
.with(comp::Auras::new(vec![Aura::new(
AuraKind::Buff {
kind: BuffKind::Invulnerability,
data: BuffData::new(1.0, Some(Duration::from_secs(1))),
category: BuffCategory::Natural,
source: BuffSource::World,
},
range.unwrap_or(100.0),
None,
AuraTarget::All,
)]))
.build();
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned a safe zone"),
);
},
None => server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandError, "You have no position!"),
),
}
}
fn handle_players( fn handle_players(
server: &mut Server, server: &mut Server,
client: EcsEntity, client: EcsEntity,