Implement /battlemode_force command

+ add placeholder for /battlemode command (currently can only show your
  battle mode)
This commit is contained in:
juliancoffee 2021-08-27 19:25:05 +03:00
parent f01309dfc2
commit 2e79c61123
2 changed files with 82 additions and 1 deletions

View File

@ -47,6 +47,8 @@ pub enum ChatCommand {
Alias,
ApplyBuff,
Ban,
BattleMode,
BattleModeForce,
Build,
BuildAreaAdd,
BuildAreaList,
@ -321,6 +323,25 @@ impl ChatCommand {
true for overwrite to alter an existing ban..",
Some(Moderator),
),
ChatCommand::BattleMode => cmd(
vec![Enum(
"battle mode",
vec!["pvp".to_owned(), "pve".to_owned()],
Optional,
)],
"Set your battle mode to pvp/pve.\n\
If called without arguments will show current battle mode.",
None,
),
ChatCommand::BattleModeForce => cmd(
vec![Enum(
"battle mode",
vec!["pvp".to_owned(), "pve".to_owned()],
Required,
)],
"Change your battle mode flag without any checks",
Some(Admin),
),
ChatCommand::Build => cmd(vec![], "Toggles build mode on and off", None),
ChatCommand::BuildAreaAdd => cmd(
vec![
@ -623,6 +644,8 @@ impl ChatCommand {
ChatCommand::Alias => "alias",
ChatCommand::ApplyBuff => "buff",
ChatCommand::Ban => "ban",
ChatCommand::BattleMode => "battlemode",
ChatCommand::BattleModeForce => "battlemode_force",
ChatCommand::Build => "build",
ChatCommand::BuildAreaAdd => "build_area_add",
ChatCommand::BuildAreaList => "build_area_list",

View File

@ -31,7 +31,7 @@ use common::{
event::{EventBus, ServerEvent},
generation::EntityInfo,
npc::{self, get_npc_name},
resources::{PlayerPhysicsSettings, TimeOfDay},
resources::{PlayerPhysicsSettings, TimeOfDay, BattleMode},
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
uid::Uid,
vol::RectVolSize,
@ -113,6 +113,8 @@ fn do_command(
ChatCommand::Alias => handle_alias,
ChatCommand::ApplyBuff => handle_apply_buff,
ChatCommand::Ban => handle_ban,
ChatCommand::BattleMode => handle_battlemode,
ChatCommand::BattleModeForce => handle_battlemode_force,
ChatCommand::Build => handle_build,
ChatCommand::BuildAreaAdd => handle_build_area_add,
ChatCommand::BuildAreaList => handle_build_area_list,
@ -3094,6 +3096,62 @@ fn handle_ban(
}
}
fn handle_battlemode(
server: &mut Server,
client: EcsEntity,
target: EcsEntity,
args: Vec<String>,
_action: &ChatCommand,
) -> CmdResult<()> {
let ecs = &server.state.ecs();
if let Some(mode) = parse_args!(args, String) {
Err("Seting mode isn't implemented".to_owned())
} else {
let players = ecs.read_storage::<comp::Player>();
let player = players
.get(target)
.ok_or_else(|| "Cannot get player component for target".to_string())?;
server.notify_client(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Battle mode is {:?}", player.battle_mode),
),
);
Ok(())
}
}
fn handle_battlemode_force(
server: &mut Server,
client: EcsEntity,
target: EcsEntity,
args: Vec<String>,
action: &ChatCommand,
) -> CmdResult<()> {
let ecs = &server.state.ecs();
let mut players = ecs.write_storage::<comp::Player>();
let mode = parse_args!(args, String).ok_or_else(|| action.help_string())?;
let mode = match mode.as_str() {
"pvp" => BattleMode::PvP,
"pve" => BattleMode::PvE,
_ => return Err("Available modes: pvp, pve".to_owned()),
};
if let Some(ref mut player) = players.get_mut(target) {
player.battle_mode = mode;
server.notify_client(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Set battle_mode to {:?}", player.battle_mode),
),
);
Ok(())
} else {
Err("Cannot get player component for target".to_owned())
}
}
fn handle_unban(
server: &mut Server,
client: EcsEntity,