mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'imarv/fix-give-exp' into 'master'
Fix /give_exp command an introduce /set_level Closes #481 and #460 See merge request veloren/veloren!793
This commit is contained in:
commit
3c1121261a
@ -16,8 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Allow spawning individual pet species, not just generic body kinds.
|
||||
|
||||
### Changed
|
||||
|
||||
- Brighter / higher contrast main-map
|
||||
- Removed highlighting of non-collectible sprites
|
||||
- Fixed /give_exp ignoring player argument
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -234,11 +234,18 @@ lazy_static! {
|
||||
),
|
||||
ChatCommand::new(
|
||||
"give_exp",
|
||||
"{} {}",
|
||||
"/give_exp <playername> <amount> : Give experience to specified player",
|
||||
"{d} {}",
|
||||
"/give_exp <amount> <playername?> : Give experience to yourself or specify a target player",
|
||||
true,
|
||||
handle_exp,
|
||||
),
|
||||
ChatCommand::new(
|
||||
"set_level",
|
||||
"{d} {}",
|
||||
"/set_level <level> <playername?> : Set own Level or specify a target player",
|
||||
true,
|
||||
handle_level
|
||||
),
|
||||
ChatCommand::new(
|
||||
"removelights",
|
||||
"{}",
|
||||
@ -1015,27 +1022,69 @@ spawn_rate {:?} "#,
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_exp(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
||||
let (a_alias, a_exp) = scan_fmt_some!(&args, action.arg_fmt, String, i64);
|
||||
if let (Some(alias), Some(exp)) = (a_alias, a_exp) {
|
||||
let ecs = server.state.ecs_mut();
|
||||
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
fn find_target(
|
||||
ecs: &specs::World,
|
||||
opt_alias: Option<String>,
|
||||
fallback: EcsEntity,
|
||||
) -> Result<EcsEntity, ServerMsg> {
|
||||
if let Some(alias) = opt_alias {
|
||||
(&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||
.join()
|
||||
.find(|(_, player)| player.alias == alias)
|
||||
.map(|(entity, _)| entity);
|
||||
.map(|(entity, _)| entity)
|
||||
.ok_or(ServerMsg::private(format!("Player '{}' not found!", alias)))
|
||||
} else {
|
||||
Ok(fallback)
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_exp(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
||||
let (a_exp, a_alias) = scan_fmt_some!(&args, action.arg_fmt, i64, String);
|
||||
|
||||
if let Some(exp) = a_exp {
|
||||
let ecs = server.state.ecs_mut();
|
||||
let target = find_target(&ecs, a_alias, entity);
|
||||
|
||||
let mut error_msg = None;
|
||||
|
||||
match opt_player {
|
||||
Some(_alias) => {
|
||||
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(entity) {
|
||||
match target {
|
||||
Ok(player) => {
|
||||
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(player) {
|
||||
stats.exp.change_by(exp);
|
||||
} else {
|
||||
error_msg = Some(ServerMsg::private(String::from("Player has no stats!")));
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
error_msg = Some(ServerMsg::private(format!("Player '{}' not found!", alias)));
|
||||
Err(e) => {
|
||||
error_msg = Some(e);
|
||||
},
|
||||
}
|
||||
|
||||
if let Some(msg) = error_msg {
|
||||
server.notify_client(entity, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_level(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
||||
let (a_lvl, a_alias) = scan_fmt_some!(&args, action.arg_fmt, u32, String);
|
||||
|
||||
if let Some(lvl) = a_lvl {
|
||||
let ecs = server.state.ecs_mut();
|
||||
let target = find_target(&ecs, a_alias, entity);
|
||||
|
||||
let mut error_msg = None;
|
||||
|
||||
match target {
|
||||
Ok(player) => {
|
||||
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(player) {
|
||||
stats.level.set_level(lvl);
|
||||
} else {
|
||||
error_msg = Some(ServerMsg::private(String::from("Player has no stats!")));
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
error_msg = Some(e);
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user