mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Player to player DM #191
This commit is contained in:
parent
2bf2e7f958
commit
5dee589107
@ -118,6 +118,12 @@ lazy_static! {
|
||||
"/build : Toggles build mode on and off",
|
||||
handle_build,
|
||||
),
|
||||
ChatCommand::new(
|
||||
"msg",
|
||||
"{}",
|
||||
"/msg <alias> : Send a message to another player",
|
||||
handle_msg,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@ -407,3 +413,58 @@ fn kind_to_body(kind: NpcKind) -> comp::Body {
|
||||
NpcKind::Wolf => comp::Body::QuadrupedMedium(comp::quadruped_medium::Body::random()),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_msg(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
||||
let opt_alias = scan_fmt!(&args, action.arg_fmt, String);
|
||||
match opt_alias {
|
||||
Some(alias) => {
|
||||
let ecs = server.state.ecs();
|
||||
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
.join()
|
||||
.find(|(_, player)| player.alias == alias)
|
||||
.map(|(entity, _)| entity);
|
||||
let msg = &args[alias.len()..args.len()];
|
||||
match opt_player {
|
||||
Some(player) => {
|
||||
if msg.len() > 1 {
|
||||
let opt_name = ecs
|
||||
.read_storage::<comp::Player>()
|
||||
.get(entity)
|
||||
.map(|s| s.alias.clone());
|
||||
match opt_name {
|
||||
Some(name) => {
|
||||
server.clients.notify(
|
||||
player,
|
||||
ServerMsg::Chat(format!("{} tells you:{}", name, msg)),
|
||||
);
|
||||
}
|
||||
None => {
|
||||
server.clients.notify(
|
||||
entity,
|
||||
ServerMsg::Chat(String::from("You do not exist!")),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server.clients.notify(
|
||||
entity,
|
||||
ServerMsg::Chat(format!(
|
||||
"You really should say something to {}!",
|
||||
alias
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
server.clients.notify(
|
||||
entity,
|
||||
ServerMsg::Chat(format!("Player '{}' not found!", alias)),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => server
|
||||
.clients
|
||||
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user