# Autoloot System **Referenced Files in This Document** - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [AutolootHelpers.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootHelpers.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) - [ClilocSelectionViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/ClilocSelectionViewModel.cs) - [PropertySelectionViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/PropertySelectionViewModel.cs) - [CustomPropertiesViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/CustomPropertiesViewModel.cs) - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [ClilocSelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/ClilocSelectionWindow.xaml.cs) - [PropertySelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/PropertySelectionWindow.xaml.cs) - [CustomPropertiesWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/CustomPropertiesWindow.xaml.cs) - [Item.cs](file://ClassicAssist.Shared/UO/Objects/Item.cs) - [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs) - [AutolootTests.cs](file://ClassicAssist.Tests/Agents/AutolootTests.cs) ## Table of Contents 1. [Introduction](#introduction) 2. [Project Structure](#project-structure) 3. [Core Components](#core-components) 4. [Architecture Overview](#architecture-overview) 5. [Detailed Component Analysis](#detailed-component-analysis) 6. [Dependency Analysis](#dependency-analysis) 7. [Performance Considerations](#performance-considerations) 8. [Troubleshooting Guide](#troubleshooting-guide) 9. [Conclusion](#conclusion) 10. [Appendices](#appendices) ## Introduction The Autoloot system is a rule-based item collection engine that automatically picks up items based on configurable criteria. It allows players to define rules that match items by properties such as name, hue, weight, and more. Each rule consists of one or more constraints evaluated with logical operators (AND/OR). The UI provides intuitive windows for selecting cliloc names and properties, enabling users to build complex filters without writing code. This document explains the data model, constraint matching engine, operator types, property filtering, UI components, practical scenarios, performance optimization techniques, and debugging strategies for autoloot rules. ## Project Structure The Autoloot system spans shared data models, managers, UI view models, and Avalonia/WPF views: - Shared data layer: - Rule entry and constraint definitions - Operator enumeration and helper utilities - Property metadata and type mapping - Manager and helpers: - Rule evaluation and integration with game objects - UI layer: - ViewModels for managing rules and selection dialogs - Avalonia and WPF views for user interaction ```mermaid graph TB subgraph "Shared Data" A["AutolootEntry"] B["AutolootConstraintEntry"] C["AutolootOperator"] D["PropertyEntry"] E["PropertyType"] F["AutolootManager"] G["AutolootHelpers"] end subgraph "UI Layer" H["AutolootViewModel"] I["ClilocSelectionViewModel"] J["PropertySelectionViewModel"] K["CustomPropertiesViewModel"] L["AutolootTabControl (Avalonia)"] M["ClilocSelectionWindow (WPF)"] N["PropertySelectionWindow (WPF)"] O["CustomPropertiesWindow (WPF)"] end subgraph "Game Objects" P["Item"] Q["EntityCollection"] end A --> B B --> C A --> D D --> E F --> A F --> B F --> C F --> G F --> P F --> Q H --> A H --> F I --> M J --> N K --> O L --> H ``` **Diagram sources** - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [AutolootHelpers.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootHelpers.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) - [ClilocSelectionViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/ClilocSelectionViewModel.cs) - [PropertySelectionViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/PropertySelectionViewModel.cs) - [CustomPropertiesViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/CustomPropertiesViewModel.cs) - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [ClilocSelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/ClilocSelectionWindow.xaml.cs) - [PropertySelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/PropertySelectionWindow.xaml.cs) - [CustomPropertiesWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/CustomPropertiesWindow.xaml.cs) - [Item.cs](file://ClassicAssist.Shared/UO/Objects/Item.cs) - [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs) **Section sources** - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [AutolootHelpers.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootHelpers.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) - [ClilocSelectionViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/ClilocSelectionViewModel.cs) - [PropertySelectionViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/PropertySelectionViewModel.cs) - [CustomPropertiesViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Autoloot/CustomPropertiesViewModel.cs) - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [ClilocSelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/ClilocSelectionWindow.xaml.cs) - [PropertySelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/PropertySelectionWindow.xaml.cs) - [CustomPropertiesWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/CustomPropertiesWindow.xaml.cs) - [Item.cs](file://ClassicAssist.Shared/UO/Objects/Item.cs) - [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs) ## Core Components - AutolootEntry: Represents a single autoloot rule with a list of constraints and an overall logical combination strategy. - AutolootConstraintEntry: Defines a single condition consisting of a target property, an operator, and a value. - AutolootOperator: Enumerates supported comparison operators (e.g., Equals, Contains, GreaterThan, LessThan, NotEquals, StartsWith, EndsWith). - PropertyEntry and PropertyType: Provide metadata about available item properties and their types for safe comparisons. - AutolootManager: Orchestrates rule evaluation against the current item pool and triggers pick-up actions when rules match. - AutolootHelpers: Utility functions for parsing, normalization, and common operations used during constraint evaluation. Key responsibilities: - Constraint matching: Evaluate each constraint against an Item’s properties using the specified operator and value. - Logical composition: Combine multiple constraints within a rule using AND/OR logic. - Integration: Connect with the game object model (Item) and collections (EntityCollection) to scan and act on items. **Section sources** - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [AutolootHelpers.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootHelpers.cs) ## Architecture Overview The Autoloot system follows a layered architecture: - Data layer: Models and enumerations define the structure of rules and constraints. - Engine layer: Manager evaluates rules against live game objects and performs actions. - UI layer: ViewModels and Views provide configuration interfaces for creating and editing rules. ```mermaid sequenceDiagram participant User as "User" participant Tab as "AutolootTabControl" participant VM as "AutolootViewModel" participant Manager as "AutolootManager" participant Pool as "EntityCollection" participant Item as "Item" User->>Tab : Open Autoloot tab Tab->>VM : Initialize ViewModel VM->>Manager : Load rules and settings loop For each new item Pool->>Manager : Notify item added Manager->>Pool : Iterate visible items Manager->>Item : Read properties Manager->>Manager : Evaluate constraints per rule alt Rule matches Manager-->>User : Pick up item else No match Manager-->>Pool : Continue scanning end end ``` **Diagram sources** - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs) - [Item.cs](file://ClassicAssist.Shared/UO/Objects/Item.cs) ## Detailed Component Analysis ### AutolootEntry and Constraint Matching AutolootEntry encapsulates a rule composed of multiple AutolootConstraintEntry instances. Each constraint specifies: - Target property (from PropertyEntry) - Operator (from AutolootOperator) - Value to compare against Logical combination: - Rules can combine constraints using AND/OR semantics. - When all constraints are satisfied under the chosen combination, the rule matches. Evaluation flow: - For each Item, read relevant properties. - Apply operator-specific comparison logic. - Aggregate results according to the rule’s logical combination. ```mermaid flowchart TD Start(["Start Evaluation"]) --> GetRule["Get AutolootEntry"] GetRule --> InitResult["Initialize result based on combination (AND/OR)"] InitResult --> LoopConstraints{"For each constraint"} LoopConstraints --> |Next| ReadProp["Read Item property"] ReadProp --> Compare["Apply operator vs value"] Compare --> UpdateResult["Update aggregate result"] UpdateResult --> LoopConstraints LoopConstraints --> |Done| FinalCheck{"Final result true?"} FinalCheck --> |Yes| Match["Rule matches"] FinalCheck --> |No| NoMatch["Rule does not match"] Match --> End(["End"]) NoMatch --> End ``` **Diagram sources** - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) **Section sources** - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) ### Operators and Property Filtering Supported operators include: - Equals: Exact match - NotEquals: Inverse exact match - Contains: Substring presence - StartsWith: Prefix match - EndsWith: Suffix match - GreaterThan: Numeric greater than - LessThan: Numeric less than - GreaterThanOrEqual: Numeric greater than or equal - LessThanOrEqual: Numeric less than or equal Property filtering capabilities: - PropertyEntry defines available properties and their types (PropertyType). - Type-aware comparisons ensure correct handling of strings, numbers, booleans, and enums. - Helpers normalize values (e.g., trimming, case-insensitive comparisons where appropriate). Practical examples: - Gold collection: Match items by name containing “Gold” and weight equals zero. - Material gathering: Match items by category or name patterns and exclude low-value variants. - Equipment filtering: Match by slot, quality thresholds, and specific hues. **Section sources** - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [AutolootHelpers.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootHelpers.cs) ### UI Components: ClilocSelectionWindow and PropertySelectionWindow The UI enables users to create and manage autoloot rules through dedicated windows and tabs: - ClilocSelectionWindow: Allows selecting localized text entries (clilocs) to match item names or descriptions. - PropertySelectionWindow: Provides a structured interface to choose properties and set constraints. - CustomPropertiesWindow: Enables advanced property configuration and custom filters. - AutolootTabControl (Avalonia): Hosts the main autoloot management interface and integrates with ViewModels. Workflow: - Users open the Autoloot tab and add/edit rules. - They use ClilocSelectionWindow to pick cliloc-based name filters. - They use PropertySelectionWindow to select properties and operators. - Changes propagate via ViewModels to the manager for evaluation. ```mermaid classDiagram class AutolootTabControl { +Initialize() +LoadRules() +SaveRules() } class AutolootViewModel { +Rules +AddRule() +RemoveRule() +EvaluateAll() } class ClilocSelectionWindow { +ShowDialog() +SelectedClilocs } class PropertySelectionWindow { +ShowDialog() +SelectedProperties } class CustomPropertiesWindow { +ShowDialog() +CustomFilters } AutolootTabControl --> AutolootViewModel : "uses" AutolootViewModel --> ClilocSelectionWindow : "opens" AutolootViewModel --> PropertySelectionWindow : "opens" AutolootViewModel --> CustomPropertiesWindow : "opens" ``` **Diagram sources** - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) - [ClilocSelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/ClilocSelectionWindow.xaml.cs) - [PropertySelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/PropertySelectionWindow.xaml.cs) - [CustomPropertiesWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/CustomPropertiesWindow.xaml.cs) **Section sources** - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) - [ClilocSelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/ClilocSelectionWindow.xaml.cs) - [PropertySelectionWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/PropertySelectionWindow.xaml.cs) - [CustomPropertiesWindow.xaml.cs](file://ClassicAssist/Views/Autoloot/CustomPropertiesWindow.xaml.cs) ### Practical Scenarios - Gold Collection: - Create a rule with a constraint on item name containing “Gold”. - Add a weight equals zero constraint to avoid heavy stacks. - Use OR to allow multiple gold variants if needed. - Material Gathering: - Define constraints for material categories using property filters. - Exclude unwanted hues or qualities using NotEquals and LessThan operators. - Equipment Filtering: - Match by slot and quality thresholds. - Use StartsWith/EndsWith for naming conventions. - Combine constraints with AND to narrow down precise matches. [No sources needed since this section provides general guidance] ## Dependency Analysis The Autoloot system has clear separation between data models, evaluation logic, and UI components. Key dependencies: - AutolootManager depends on: - AutolootEntry and AutolootConstraintEntry for rule structures - AutolootOperator for comparison logic - PropertyEntry and PropertyType for property metadata - Item and EntityCollection for scanning and acting on game objects - UI components depend on: - AutolootViewModel for state and actions - Selection windows for user input ```mermaid graph LR Manager["AutolootManager"] --> Entry["AutolootEntry"] Manager --> Constraint["AutolootConstraintEntry"] Manager --> Operator["AutolootOperator"] Manager --> PropEntry["PropertyEntry"] Manager --> PropType["PropertyType"] Manager --> ItemObj["Item"] Manager --> Pool["EntityCollection"] Tab["AutolootTabControl"] --> VM["AutolootViewModel"] VM --> Manager ``` **Diagram sources** - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [Item.cs](file://ClassicAssist.Shared/UO/Objects/Item.cs) - [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs) - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) **Section sources** - [AutolootManager.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootManager.cs) - [AutolootEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootEntry.cs) - [AutolootConstraintEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootConstraintEntry.cs) - [AutolootOperator.cs](file://ClassicAssist.Shared/Data/Autoloot/AutolootOperator.cs) - [PropertyEntry.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyEntry.cs) - [PropertyType.cs](file://ClassicAssist.Shared/Data/Autoloot/PropertyType.cs) - [Item.cs](file://ClassicAssist.Shared/UO/Objects/Item.cs) - [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs) - [AutolootTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/AutolootTabControl.axaml.cs) - [AutolootViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/AutolootViewModel.cs) ## Performance Considerations Optimization techniques for large item pools: - Early exit: Short-circuit constraint evaluation when a rule fails early (especially with AND combinations). - Property caching: Cache frequently accessed properties to reduce repeated reads. - Batch scanning: Process items in batches to minimize overhead and improve throughput. - Indexing: Maintain lightweight indexes for commonly filtered properties (e.g., hue, weight). - Avoid expensive operations: Prefer substring checks only when necessary; use prefix/suffix operators for faster matching. - Throttling: Limit evaluation frequency to avoid excessive CPU usage during high packet rates. [No sources needed since this section provides general guidance] ## Troubleshooting Guide Common issues and debugging strategies: - Rule conflicts: - Multiple rules may match the same item; review logical combinations and precedence. - Use logging to trace which rules matched and why. - Incorrect property values: - Verify PropertyType alignment with operator usage (e.g., numeric operators on string properties). - Normalize inputs (trimming, case-insensitivity) to prevent false negatives. - Performance bottlenecks: - Monitor evaluation time per rule; simplify constraints or reduce rule count. - Profile item pool size and adjust scanning intervals. - UI misconfiguration: - Ensure selected clilocs and properties exist and are valid. - Reopen selection windows to refresh available options. Use tests to validate behavior: - AutolootTests cover typical scenarios and edge cases. **Section sources** - [AutolootTests.cs](file://ClassicAssist.Tests/Agents/AutolootTests.cs) ## Conclusion The Autoloot system provides a flexible, rule-based approach to automatic item collection. By combining property filtering, operator support, and logical composition, it accommodates diverse gameplay needs—from simple gold pickup to sophisticated equipment filtering. The UI components streamline rule creation, while the manager ensures efficient evaluation against the active item pool. With careful design and performance optimizations, the system scales well even with large item counts. [No sources needed since this section summarizes without analyzing specific files] ## Appendices - Additional references: - AutolootViewModel for rule lifecycle management - AutolootHelpers for utility functions used across evaluation - PropertyEntry and PropertyType for comprehensive property metadata [No sources needed since this section provides general guidance]