mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add /alignment command
This commit is contained in:
parent
8889407660
commit
70b5c2927d
@ -310,6 +310,7 @@ pub enum ServerChatCommand {
|
||||
Adminify,
|
||||
Airship,
|
||||
Alias,
|
||||
Alignment,
|
||||
AreaAdd,
|
||||
AreaList,
|
||||
AreaRemove,
|
||||
@ -431,6 +432,25 @@ impl ServerChatCommand {
|
||||
"Change your alias",
|
||||
Some(Moderator),
|
||||
),
|
||||
ServerChatCommand::Alignment => cmd(
|
||||
vec![
|
||||
Enum(
|
||||
"alignment",
|
||||
vec![
|
||||
"wild".to_owned(),
|
||||
"enemy".to_owned(),
|
||||
"npc".to_owned(),
|
||||
"tame".to_owned(),
|
||||
"owned".to_owned(),
|
||||
"passive".to_owned(),
|
||||
],
|
||||
Required,
|
||||
),
|
||||
Boolean("+group", "true".to_string(), Optional),
|
||||
],
|
||||
"Change your alignment",
|
||||
Some(Moderator),
|
||||
),
|
||||
ServerChatCommand::Buff => cmd(
|
||||
vec![
|
||||
Enum("buff", BUFFS.clone(), Required),
|
||||
@ -956,6 +976,7 @@ impl ServerChatCommand {
|
||||
ServerChatCommand::Adminify => "adminify",
|
||||
ServerChatCommand::Airship => "airship",
|
||||
ServerChatCommand::Alias => "alias",
|
||||
ServerChatCommand::Alignment => "alignment",
|
||||
ServerChatCommand::Ban => "ban",
|
||||
ServerChatCommand::BattleMode => "battlemode",
|
||||
ServerChatCommand::BattleModeForce => "battlemode_force",
|
||||
|
@ -127,6 +127,7 @@ fn do_command(
|
||||
ServerChatCommand::Adminify => handle_adminify,
|
||||
ServerChatCommand::Airship => handle_spawn_airship,
|
||||
ServerChatCommand::Alias => handle_alias,
|
||||
ServerChatCommand::Alignment => handle_alignment,
|
||||
ServerChatCommand::Ban => handle_ban,
|
||||
ServerChatCommand::BattleMode => handle_battlemode,
|
||||
ServerChatCommand::BattleModeForce => handle_battlemode_force,
|
||||
@ -615,6 +616,59 @@ fn handle_make_block(
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_alignment(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
target: EcsEntity,
|
||||
args: Vec<String>,
|
||||
action: &ServerChatCommand,
|
||||
) -> CmdResult<()> {
|
||||
let (Some(alignment_spec), and_group) = parse_cmd_args!(args, String, bool) else {
|
||||
return Err(Content::Plain(action.help_string()));
|
||||
};
|
||||
let and_group = and_group.is_some_and(|flag| flag);
|
||||
|
||||
let alignment = match alignment_spec.as_str() {
|
||||
"wild" => Alignment::Wild,
|
||||
"enemy" => Alignment::Enemy,
|
||||
"npc" => Alignment::Npc,
|
||||
"tame" => Alignment::Tame,
|
||||
"owned" => {
|
||||
// Switch to Owned by client
|
||||
//
|
||||
// If client = target, you'll be owned by yourself, and treated as
|
||||
// Player.
|
||||
//
|
||||
// If client != target, target will be your pet now.
|
||||
let uid = uid(server, client, "client")?;
|
||||
|
||||
Alignment::Owned(uid)
|
||||
},
|
||||
"passive" => Alignment::Passive,
|
||||
_ => return Err(Content::Plain(action.help_string())),
|
||||
};
|
||||
|
||||
insert_or_replace_component(server, target, alignment, "player")?;
|
||||
|
||||
if and_group {
|
||||
let npc_group = match alignment {
|
||||
Alignment::Enemy => Some(comp::group::ENEMY),
|
||||
Alignment::Npc | Alignment::Tame => Some(comp::group::NPC),
|
||||
Alignment::Wild | Alignment::Passive | Alignment::Owned(_) => None,
|
||||
};
|
||||
|
||||
// Set the group or remove it
|
||||
if let Some(group) = npc_group {
|
||||
insert_or_replace_component(server, target, group, "player")?;
|
||||
} else {
|
||||
let ecs = server.state.ecs();
|
||||
ecs.write_storage::<comp::Group>().remove(target);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_be_npc(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
@ -636,8 +690,8 @@ fn handle_be_npc(
|
||||
else {
|
||||
return Err(Content::Plain(action.help_string()));
|
||||
};
|
||||
let and_alignment = and_alignment.is_some_and(|o| o);
|
||||
let and_group = and_group.is_some_and(|o| o);
|
||||
let and_alignment = and_alignment.is_some_and(|flag| flag);
|
||||
let and_group = and_group.is_some_and(|flag| flag);
|
||||
|
||||
let config = match EntityConfig::load(&entity_config) {
|
||||
Ok(asset) => asset.read(),
|
||||
|
Loading…
Reference in New Issue
Block a user