using System; using System.Collections.Generic; using Server.Items; using Server.Targeting; namespace Server.Commands.Generic { public class ContainedCommandImplementor : BaseCommandImplementor { public ContainedCommandImplementor() { Accessors = new[] { "Contained" }; SupportRequirement = CommandSupport.Contained; AccessLevel = AccessLevel.GameMaster; Usage = "Contained [condition]"; Description = "Invokes the command on all child items in a targeted container. Optional condition arguments can further restrict the set of objects."; } public override void Process(Mobile from, BaseCommand command, string[] args) { if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args))) from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, (m, targeted) => OnTarget(m, targeted, command, args)); } public void OnTarget(Mobile from, object targeted, BaseCommand command, string[] args) { if (!BaseCommand.IsAccessible(from, targeted)) { from.SendLocalizedMessage(500447); // That is not accessible. return; } if (command.ObjectTypes == ObjectTypes.Mobiles) return; // sanity check if (!(targeted is Container cont)) { from.SendMessage("That is not a container."); return; } try { Extensions ext = Extensions.Parse(from, ref args); if (!CheckObjectTypes(from, command, ext, out bool items, out bool _)) return; if (!items) { from.SendMessage("This command only works on items."); return; } List list = new List(); foreach (Item item in cont.FindItemsByType()) if (ext.IsValid(item)) list.Add(item); ext.Filter(list); RunCommand(from, list, command, args); } catch (Exception e) { from.SendMessage(e.Message); } } } }