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:
@ -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.
|
- Allow spawning individual pet species, not just generic body kinds.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Brighter / higher contrast main-map
|
- Brighter / higher contrast main-map
|
||||||
- Removed highlighting of non-collectible sprites
|
- Removed highlighting of non-collectible sprites
|
||||||
|
- Fixed /give_exp ignoring player argument
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -234,11 +234,18 @@ lazy_static! {
|
|||||||
),
|
),
|
||||||
ChatCommand::new(
|
ChatCommand::new(
|
||||||
"give_exp",
|
"give_exp",
|
||||||
"{} {}",
|
"{d} {}",
|
||||||
"/give_exp <playername> <amount> : Give experience to specified player",
|
"/give_exp <amount> <playername?> : Give experience to yourself or specify a target player",
|
||||||
true,
|
true,
|
||||||
handle_exp,
|
handle_exp,
|
||||||
),
|
),
|
||||||
|
ChatCommand::new(
|
||||||
|
"set_level",
|
||||||
|
"{d} {}",
|
||||||
|
"/set_level <level> <playername?> : Set own Level or specify a target player",
|
||||||
|
true,
|
||||||
|
handle_level
|
||||||
|
),
|
||||||
ChatCommand::new(
|
ChatCommand::new(
|
||||||
"removelights",
|
"removelights",
|
||||||
"{}",
|
"{}",
|
||||||
@ -1015,27 +1022,69 @@ spawn_rate {:?} "#,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_exp(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
|
fn find_target(
|
||||||
let (a_alias, a_exp) = scan_fmt_some!(&args, action.arg_fmt, String, i64);
|
ecs: &specs::World,
|
||||||
if let (Some(alias), Some(exp)) = (a_alias, a_exp) {
|
opt_alias: Option<String>,
|
||||||
let ecs = server.state.ecs_mut();
|
fallback: EcsEntity,
|
||||||
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
) -> Result<EcsEntity, ServerMsg> {
|
||||||
|
if let Some(alias) = opt_alias {
|
||||||
|
(&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
||||||
.join()
|
.join()
|
||||||
.find(|(_, player)| player.alias == alias)
|
.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;
|
let mut error_msg = None;
|
||||||
|
|
||||||
match opt_player {
|
match target {
|
||||||
Some(_alias) => {
|
Ok(player) => {
|
||||||
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(entity) {
|
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(player) {
|
||||||
stats.exp.change_by(exp);
|
stats.exp.change_by(exp);
|
||||||
} else {
|
} else {
|
||||||
error_msg = Some(ServerMsg::private(String::from("Player has no stats!")));
|
error_msg = Some(ServerMsg::private(String::from("Player has no stats!")));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
Err(e) => {
|
||||||
error_msg = Some(ServerMsg::private(format!("Player '{}' not found!", alias)));
|
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);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user