diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 4fb54e7434..2ff84a99ce 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -293,6 +293,7 @@ pub enum ServerChatCommand { Region, ReloadChunks, RemoveLights, + RepairEquipment, Respawn, RevokeBuild, RevokeBuildAll, @@ -772,6 +773,9 @@ impl ServerChatCommand { "Scale your character", Some(Admin), ), + ServerChatCommand::RepairEquipment => { + cmd(vec![], "Repairs all equipped items", Some(Admin)) + }, } } @@ -859,6 +863,7 @@ impl ServerChatCommand { ServerChatCommand::WeatherZone => "weather_zone", ServerChatCommand::Lightning => "lightning", ServerChatCommand::Scale => "scale", + ServerChatCommand::RepairEquipment => "repair_equipment", } } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 91c4807dd8..44244a619d 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -28,7 +28,10 @@ use common::{ self, aura::{Aura, AuraKind, AuraTarget}, buff::{Buff, BuffCategory, BuffData, BuffKind, BuffSource}, - inventory::item::{tool::AbilityMap, MaterialStatManifest, Quality}, + inventory::{ + item::{tool::AbilityMap, MaterialStatManifest, Quality}, + slot::Slot, + }, invite::InviteKind, AdminRole, ChatType, Inventory, Item, LightEmitter, Presence, PresenceKind, WaypointArea, }, @@ -202,6 +205,7 @@ fn do_command( ServerChatCommand::WeatherZone => handle_weather_zone, ServerChatCommand::Lightning => handle_lightning, ServerChatCommand::Scale => handle_scale, + ServerChatCommand::RepairEquipment => handle_repair_equipment, }; handler(server, client, target, args, cmd) @@ -4123,3 +4127,32 @@ fn handle_scale( Err(action.help_string()) } } + +fn handle_repair_equipment( + server: &mut Server, + client: EcsEntity, + target: EcsEntity, + _args: Vec, + action: &ServerChatCommand, +) -> CmdResult<()> { + let ecs = server.state.ecs(); + if let Some(mut inventory) = ecs.write_storage::().get_mut(target) { + let ability_map = ecs.read_resource::(); + let msm = ecs.read_resource::(); + let slots = inventory + .equipped_items_with_slot() + .filter(|(_, item)| item.has_durability()) + .map(|(slot, _)| slot) + .collect::>(); + for slot in slots { + inventory.repair_item_at_slot(Slot::Equip(slot), &ability_map, &msm); + } + server.notify_client( + client, + ServerGeneral::server_msg(ChatType::CommandInfo, "Repaired all equipped items"), + ); + Ok(()) + } else { + Err(action.help_string()) + } +}