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

View File

@ -431,7 +431,7 @@ pub struct Damage {
impl Damage {
/// Returns the total damage reduction provided by all equipped items
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
.equipped_items()
.filter_map(|item| {
@ -461,7 +461,7 @@ impl Damage {
} else {
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(

View File

@ -111,6 +111,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
ChatCommand::Players => handle_players,
ChatCommand::Region => handle_region,
ChatCommand::RemoveLights => handle_remove_lights,
ChatCommand::Safezone => handle_safezone,
ChatCommand::Say => handle_say,
ChatCommand::SetMotd => handle_set_motd,
ChatCommand::SkillPoint => handle_skill_point,
@ -975,30 +976,17 @@ fn handle_spawn_campfire(
animated: true,
})
.with(WaypointArea::default())
.with(comp::Auras::new(vec![
Aura::new(
AuraKind::Buff {
kind: BuffKind::CampfireHeal,
data: BuffData::new(0.02, Some(Duration::from_secs(1))),
category: BuffCategory::Natural,
source: BuffSource::World,
},
5.0,
None,
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,
),
]))
.with(comp::Auras::new(vec![Aura::new(
AuraKind::Buff {
kind: BuffKind::CampfireHeal,
data: BuffData::new(0.02, Some(Duration::from_secs(1))),
category: BuffCategory::Natural,
source: BuffSource::World,
},
5.0,
None,
AuraTarget::All,
)]))
.build();
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(
server: &mut Server,
client: EcsEntity,