mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Improve UX of /battlemode
This commit is contained in:
parent
1baa9e9879
commit
844e93e67b
@ -3105,7 +3105,11 @@ fn handle_battlemode(
|
|||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
_action: &ChatCommand,
|
_action: &ChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
|
// TODO: discuss time
|
||||||
|
const COOLDOWN: f64 = 60.0 * 5.0;
|
||||||
|
|
||||||
let ecs = server.state.ecs();
|
let ecs = server.state.ecs();
|
||||||
|
let time = ecs.read_resource::<Time>();
|
||||||
let settings = ecs.read_resource::<Settings>();
|
let settings = ecs.read_resource::<Settings>();
|
||||||
if let Some(mode) = parse_args!(args, String) {
|
if let Some(mode) = parse_args!(args, String) {
|
||||||
if !settings.battle_mode.allow_choosing() {
|
if !settings.battle_mode.allow_choosing() {
|
||||||
@ -3152,10 +3156,7 @@ fn handle_battlemode(
|
|||||||
let mut player_info = players
|
let mut player_info = players
|
||||||
.get_mut(target)
|
.get_mut(target)
|
||||||
.ok_or("Cannot get player component for target")?;
|
.ok_or("Cannot get player component for target")?;
|
||||||
let time = ecs.read_resource::<Time>();
|
|
||||||
if let Some(Time(last_change)) = player_info.last_battlemode_change {
|
if let Some(Time(last_change)) = player_info.last_battlemode_change {
|
||||||
const COOLDOWN: f64 = 60.0 * 5.0;
|
|
||||||
|
|
||||||
let Time(time) = *time;
|
let Time(time) = *time;
|
||||||
let elapsed = time - last_change;
|
let elapsed = time - last_change;
|
||||||
if elapsed < COOLDOWN {
|
if elapsed < COOLDOWN {
|
||||||
@ -3173,6 +3174,9 @@ fn handle_battlemode(
|
|||||||
"pve" => BattleMode::PvE,
|
"pve" => BattleMode::PvE,
|
||||||
_ => return Err("Available modes: pvp, pve".to_owned()),
|
_ => return Err("Available modes: pvp, pve".to_owned()),
|
||||||
};
|
};
|
||||||
|
if player_info.battle_mode == mode {
|
||||||
|
return Err("Attempted to set the same battlemode".to_owned());
|
||||||
|
}
|
||||||
player_info.battle_mode = mode;
|
player_info.battle_mode = mode;
|
||||||
player_info.last_battlemode_change = Some(*time);
|
player_info.last_battlemode_change = Some(*time);
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
@ -3188,12 +3192,23 @@ fn handle_battlemode(
|
|||||||
let player = players
|
let player = players
|
||||||
.get(target)
|
.get(target)
|
||||||
.ok_or("Cannot get player component for target")?;
|
.ok_or("Cannot get player component for target")?;
|
||||||
|
let mut msg = format!("Current battle mode: {:?}.", player.battle_mode);
|
||||||
|
if settings.battle_mode.allow_choosing() {
|
||||||
|
msg.push_str(" Possible to change.");
|
||||||
|
} else {
|
||||||
|
msg.push_str(" Global.");
|
||||||
|
}
|
||||||
|
if let Some(change) = player.last_battlemode_change {
|
||||||
|
let Time(time) = *time;
|
||||||
|
let Time(change) = change;
|
||||||
|
let elapsed = time - change;
|
||||||
|
let next = COOLDOWN - elapsed;
|
||||||
|
let notice = format!(" Next change will be available in: {:.0} seconds", next);
|
||||||
|
msg.push_str(¬ice);
|
||||||
|
}
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(ChatType::CommandInfo, msg),
|
||||||
ChatType::CommandInfo,
|
|
||||||
format!("Current battle mode: {:?}", player.battle_mode),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user