mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Chat commands for group manipulation
This commit is contained in:
parent
f8d48ad4a0
commit
c975f811e7
@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- Added chat commands for inviting, kicking, leaving, and promoting in groups
|
||||
|
||||
### Changed
|
||||
- Doubled range of ScaleMode slider when set to Custom
|
||||
|
||||
|
@ -49,6 +49,10 @@ pub enum ChatCommand {
|
||||
GiveItem,
|
||||
Goto,
|
||||
Group,
|
||||
GroupInvite,
|
||||
GroupKick,
|
||||
GroupLeave,
|
||||
GroupPromote,
|
||||
Health,
|
||||
Help,
|
||||
Home,
|
||||
@ -97,6 +101,10 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
||||
ChatCommand::GiveItem,
|
||||
ChatCommand::Goto,
|
||||
ChatCommand::Group,
|
||||
ChatCommand::GroupInvite,
|
||||
ChatCommand::GroupKick,
|
||||
ChatCommand::GroupLeave,
|
||||
ChatCommand::GroupPromote,
|
||||
ChatCommand::Health,
|
||||
ChatCommand::Help,
|
||||
ChatCommand::Home,
|
||||
@ -259,6 +267,22 @@ impl ChatCommand {
|
||||
"Send messages to your group",
|
||||
NoAdmin,
|
||||
),
|
||||
ChatCommand::GroupInvite => cmd(
|
||||
vec![PlayerName(Required)],
|
||||
"Invite a player to join a group",
|
||||
NoAdmin,
|
||||
),
|
||||
ChatCommand::GroupKick => cmd(
|
||||
vec![PlayerName(Required)],
|
||||
"Remove a player from a group",
|
||||
NoAdmin,
|
||||
),
|
||||
ChatCommand::GroupLeave => cmd(vec![], "Leave the current group", NoAdmin),
|
||||
ChatCommand::GroupPromote => cmd(
|
||||
vec![PlayerName(Required)],
|
||||
"Promote a player to group leader",
|
||||
NoAdmin,
|
||||
),
|
||||
ChatCommand::Health => cmd(
|
||||
vec![Integer("hp", 100, Required)],
|
||||
"Set your current health",
|
||||
@ -427,6 +451,10 @@ impl ChatCommand {
|
||||
ChatCommand::GiveItem => "give_item",
|
||||
ChatCommand::Goto => "goto",
|
||||
ChatCommand::Group => "group",
|
||||
ChatCommand::GroupInvite => "group_invite",
|
||||
ChatCommand::GroupKick => "group_kick",
|
||||
ChatCommand::GroupPromote => "group_promote",
|
||||
ChatCommand::GroupLeave => "group_leave",
|
||||
ChatCommand::Health => "health",
|
||||
ChatCommand::JoinFaction => "join_faction",
|
||||
ChatCommand::Help => "help",
|
||||
|
@ -81,6 +81,10 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
||||
ChatCommand::GiveItem => handle_give_item,
|
||||
ChatCommand::Goto => handle_goto,
|
||||
ChatCommand::Group => handle_group,
|
||||
ChatCommand::GroupInvite => handle_group_invite,
|
||||
ChatCommand::GroupKick => handle_group_kick,
|
||||
ChatCommand::GroupLeave => handle_group_leave,
|
||||
ChatCommand::GroupPromote => handle_group_promote,
|
||||
ChatCommand::Health => handle_health,
|
||||
ChatCommand::Help => handle_help,
|
||||
ChatCommand::Home => handle_home,
|
||||
@ -1451,6 +1455,144 @@ fn handle_group(
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_group_invite(
|
||||
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 {
|
||||
let uid = *ecs
|
||||
.read_storage::<Uid>()
|
||||
.get(target_player)
|
||||
.expect("Failed to get uid for player");
|
||||
|
||||
ecs.read_resource::<EventBus<ServerEvent>>()
|
||||
.emit_now(ServerEvent::GroupManip(
|
||||
client,
|
||||
comp::GroupManip::Invite(uid),
|
||||
));
|
||||
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandInfo.server_msg(format!("Invited {} to the group.", target_alias)),
|
||||
);
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError
|
||||
.server_msg(format!("Player with alias {} not found", target_alias)),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(action.help_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_group_kick(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
// Checking if leader is already done in group_manip
|
||||
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 {
|
||||
let uid = *ecs
|
||||
.read_storage::<Uid>()
|
||||
.get(target_player)
|
||||
.expect("Failed to get uid for player");
|
||||
|
||||
ecs.read_resource::<EventBus<ServerEvent>>()
|
||||
.emit_now(ServerEvent::GroupManip(client, comp::GroupManip::Kick(uid)));
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError
|
||||
.server_msg(format!("Player with alias {} not found", target_alias)),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(action.help_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_group_leave(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
_args: String,
|
||||
_action: &ChatCommand,
|
||||
) {
|
||||
server
|
||||
.state
|
||||
.ecs()
|
||||
.read_resource::<EventBus<ServerEvent>>()
|
||||
.emit_now(ServerEvent::GroupManip(client, comp::GroupManip::Leave));
|
||||
}
|
||||
|
||||
fn handle_group_promote(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
_target: EcsEntity,
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
// Checking if leader is already done in group_manip
|
||||
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 {
|
||||
let uid = *ecs
|
||||
.read_storage::<Uid>()
|
||||
.get(target_player)
|
||||
.expect("Failed to get uid for player");
|
||||
|
||||
ecs.read_resource::<EventBus<ServerEvent>>()
|
||||
.emit_now(ServerEvent::GroupManip(
|
||||
client,
|
||||
comp::GroupManip::AssignLeader(uid),
|
||||
));
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError
|
||||
.server_msg(format!("Player with alias {} not found", target_alias)),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg(action.help_string()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_region(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
|
Loading…
Reference in New Issue
Block a user