# Conditional Switching & Automation
**Referenced Files in This Document**
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
- [SkillManager.cs](file://ClassicAssist.Shared/Data/Skills/SkillManager.cs)
- [Region.cs](file://ClassicAssist.Shared/Data/Regions/Region.cs)
- [PlayerStatus.cs](file://ClassicAssist.Shared/UO/Data/PlayerStatus.cs)
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.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)
## Introduction
This document explains advanced conditional switching and automation features in the Dress Manager. It covers how to configure automatic outfit changes based on game conditions such as skill levels, character status, location, or time of day. It documents the DressAgentItemType enumeration and its behaviors for different equipment categories, trigger events that initiate automatic switching, priority handling when multiple conditions are met, and conflict resolution strategies. Practical examples include automatically switching to fishing gear when using Fishing skill, changing to formal wear at social events, and adapting equipment based on zone difficulty. Performance considerations and debugging techniques for complex conditional logic are also included.
## Project Structure
The Dress Manager is implemented across shared data models, UI view models, and platform-specific views. The core logic resides in shared code, while UI bindings and interactions are provided by Avalonia and WPF implementations.
```mermaid
graph TB
subgraph "Shared Data"
A["DressAgentItemType.cs"]
B["DressManager.cs"]
C["DressAgentEntry.cs"]
D["DressAgentItem.cs"]
E["SkillManager.cs"]
F["Region.cs"]
G["PlayerStatus.cs"]
end
subgraph "UI - Avalonia"
H["DressTabViewModel.cs"]
I["DressTabControl.xaml.cs (Avalonia)"]
end
subgraph "UI - WPF"
J["DressTabControl.xaml.cs (WPF)"]
end
subgraph "Network Handlers"
K["IncomingPacketHandlers.cs"]
L["OutgoingPacketHandlers.cs"]
end
H --> B
I --> H
J --> H
B --> A
B --> C
B --> D
B --> E
B --> F
B --> G
K --> B
L --> B
```
**Diagram sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
- [SkillManager.cs](file://ClassicAssist.Shared/Data/Skills/SkillManager.cs)
- [Region.cs](file://ClassicAssist.Shared/Data/Regions/Region.cs)
- [PlayerStatus.cs](file://ClassicAssist.Shared/UO/Data/PlayerStatus.cs)
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
**Section sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
- [SkillManager.cs](file://ClassicAssist.Shared/Data/Skills/SkillManager.cs)
- [Region.cs](file://ClassicAssist.Shared/Data/Regions/Region.cs)
- [PlayerStatus.cs](file://ClassicAssist.Shared/UO/Data/PlayerStatus.cs)
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
## Core Components
- DressAgentItemType: Enumeration defining equipment categories used by the Dress Manager to target specific slots (e.g., head, torso, legs, shoes, gloves, ring, necklace, etc.). Each category maps to a particular layer or slot type for equipping/unequipping items.
- DressAgentEntry: Represents a single dress rule with conditions and actions. It includes fields for item selection criteria, target category, and optional constraints.
- DressAgentItem: Encapsulates an item reference within a dress rule, including properties like hue, quality, and matching attributes.
- DressManager: Orchestrates evaluation of rules, condition checks, and execution of equip/unequip actions. It integrates with skill, region, and player state APIs to evaluate dynamic conditions.
- DressTabViewModel: Exposes Dress Manager functionality to the UI, enabling users to create, edit, and manage dress rules.
- Platform Views (Avalonia/WPF): Provide user interfaces for configuring dress rules and displaying current states.
Key responsibilities:
- Rule evaluation pipeline: iterate through configured rules, evaluate conditions, compute priority, and resolve conflicts.
- Category mapping: translate DressAgentItemType to actual equipment layers/slots.
- Trigger integration: subscribe to network and game events to initiate re-evaluation when relevant state changes occur.
**Section sources**
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
## Architecture Overview
The Dress Manager follows a rule-based architecture where each rule defines conditions and actions. When triggers fire (skill usage, movement into a new region, combat state change), the manager evaluates all active rules, computes priorities, and applies the highest-priority match.
```mermaid
sequenceDiagram
participant Game as "Game Engine"
participant Net as "Network Handlers"
participant DM as "DressManager"
participant VM as "DressTabViewModel"
participant UI as "DressTabControl (Avalonia/WPF)"
Game->>Net : "Event : Skill Use / Region Change / Status Update"
Net->>DM : "Notify : Trigger event"
DM->>DM : "Evaluate Rules
Compute Priority"
DM-->>VM : "Update State (Active Outfit)"
VM-->>UI : "Refresh UI Bindings"
DM->>Game : "Equip/Unequip Items per Rule"
```
**Diagram sources**
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
## Detailed Component Analysis
### DressAgentItemType Enumeration
Purpose:
- Defines equipment categories targeted by dress rules.
- Maps to specific layers/slots for equipping/unequipping items.
Behavior highlights:
- Head/Torso/Legs/Shoes/Gloves: Standard armor slots.
- Ring/Necklace: Accessory slots.
- Weapon/Shield: Combat-oriented slots.
- Other categories may exist depending on implementation details.
Practical implications:
- Rules can target specific categories to ensure precise control over which slots are changed.
- Conflicts between rules targeting the same category must be resolved via priority.
**Section sources**
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
### Dress Agent Entry and Item Models
- DressAgentEntry:
- Contains rule metadata, conditions, and actions.
- Includes fields for category selection and item matching parameters.
- DressAgentItem:
- Describes the item to equip, including hue, quality, and attribute filters.
Usage patterns:
- Create entries for distinct scenarios (e.g., fishing, formal wear).
- Use DressAgentItem to constrain matches by hue or other properties.
**Section sources**
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
### DressManager Evaluation Pipeline
Responsibilities:
- Collect active rules from configuration.
- Evaluate conditions against current game state (skills, regions, status).
- Compute priority for each matching rule.
- Resolve conflicts when multiple rules match the same category.
- Execute equip/unequip actions for the winning rule.
Evaluation flow:
```mermaid
flowchart TD
Start(["Start Evaluation"]) --> GatherRules["Gather Active Rules"]
GatherRules --> ForEachRule{"For Each Rule"}
ForEachRule --> |Yes| CheckConditions["Check Conditions
Skills/Region/Status"]
CheckConditions --> ConditionMet{"Condition Met?"}
ConditionMet --> |No| NextRule["Next Rule"]
ConditionMet --> |Yes| ComputePriority["Compute Priority"]
ComputePriority --> StoreCandidate["Store Candidate (Category -> Priority)"]
StoreCandidate --> NextRule
NextRule --> |All Done| ResolveConflicts["Resolve Conflicts by Priority"]
ResolveConflicts --> ApplyActions["Apply Equip/Unequip Actions"]
ApplyActions --> End(["End Evaluation"])
```
**Diagram sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
**Section sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
### Trigger Events and Integration Points
Triggers that initiate automatic switching:
- Skill usage events: e.g., using Fishing skill.
- Region changes: entering/exiting zones with different difficulty or purpose.
- Player status updates: combat mode toggles, buffs/debuffs, health thresholds.
- Time-of-day indicators: if available via game state or server messages.
Integration points:
- IncomingPacketHandlers: listen for incoming packets indicating skill use, region transitions, or status changes.
- OutgoingPacketHandlers: observe outgoing commands like skill activation to preemptively switch outfits.
- UI ViewModels: expose methods to manually trigger re-evaluation or refresh state.
**Section sources**
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
### Priority Handling and Conflict Resolution
When multiple rules match:
- Priority computation considers factors such as explicit rule priority, specificity of conditions, and category overlap.
- Higher priority wins; ties may be broken by rule order or last-applied policy.
- Conflicts are resolved per category to avoid unintended slot overrides.
Strategy recommendations:
- Assign higher priority to context-sensitive rules (e.g., combat vs. social).
- Use narrower conditions to reduce ambiguity.
- Avoid overlapping rules for the same category unless necessary.
**Section sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
### Practical Examples
- Automatically switch to fishing gear when using Fishing skill:
- Create a rule targeting fishing-related categories (e.g., gloves, weapon).
- Condition: Fishing skill usage detected via outgoing packet handler.
- Priority: High during active skill use.
- Change to formal wear at social events:
- Create a rule targeting head/torso/shoes for formal attire.
- Condition: Region name or chat context indicates social gathering.
- Priority: Medium-high to override casual wear but not combat gear.
- Adapt equipment based on zone difficulty:
- Create rules for low/high difficulty zones.
- Condition: Region change event with difficulty classification.
- Priority: Highest in high-difficulty zones to ensure survival-focused gear.
[No sources needed since this section provides conceptual examples]
## Dependency Analysis
The Dress Manager depends on several subsystems to evaluate conditions and execute actions.
```mermaid
graph TB
DM["DressManager.cs"]
ItemType["DressAgentItemType.cs"]
Entry["DressAgentEntry.cs"]
Item["DressAgentItem.cs"]
Skills["SkillManager.cs"]
Region["Region.cs"]
Status["PlayerStatus.cs"]
InPkt["IncomingPacketHandlers.cs"]
OutPkt["OutgoingPacketHandlers.cs"]
VM["DressTabViewModel.cs"]
UIA["DressTabControl.xaml.cs (Avalonia)"]
UIW["DressTabControl.xaml.cs (WPF)"]
DM --> ItemType
DM --> Entry
DM --> Item
DM --> Skills
DM --> Region
DM --> Status
InPkt --> DM
OutPkt --> DM
VM --> DM
UIA --> VM
UIW --> VM
```
**Diagram sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
- [SkillManager.cs](file://ClassicAssist.Shared/Data/Skills/SkillManager.cs)
- [Region.cs](file://ClassicAssist.Shared/Data/Regions/Region.cs)
- [PlayerStatus.cs](file://ClassicAssist.Shared/UO/Data/PlayerStatus.cs)
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
**Section sources**
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressAgentItemType.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItemType.cs)
- [DressAgentEntry.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentEntry.cs)
- [DressAgentItem.cs](file://ClassicAssist.Shared/Data/Dress/DressAgentItem.cs)
- [SkillManager.cs](file://ClassicAssist.Shared/Data/Skills/SkillManager.cs)
- [Region.cs](file://ClassicAssist.Shared/Data/Regions/Region.cs)
- [PlayerStatus.cs](file://ClassicAssist.Shared/UO/Data/PlayerStatus.cs)
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist.Avalonia/Views/Agents/DressTabControl.xaml.cs)
- [DressTabControl.xaml.cs](file://ClassicAssist/Views/Agents/DressTabControl.xaml.cs)
## Performance Considerations
- Minimize rule count: Keep only necessary rules active to reduce evaluation overhead.
- Narrow conditions: Use specific conditions to avoid unnecessary computations.
- Debounce rapid triggers: Coalesce frequent events (e.g., rapid region changes) to prevent excessive evaluations.
- Cache results: Reuse computed matches for stable states to avoid redundant work.
- Prefer lightweight checks: Favor fast API calls (e.g., current region name) over heavy queries.
[No sources needed since this section provides general guidance]
## Troubleshooting Guide
Common issues and diagnostics:
- No outfit change occurs:
- Verify trigger events are firing (check network handlers).
- Confirm conditions match current state (skills, region, status).
- Inspect priority settings and potential conflicts.
- Wrong slot affected:
- Ensure DressAgentItemType targets the correct category.
- Validate item matching parameters (hue, quality).
- Frequent flickering/outfit oscillation:
- Increase debounce intervals or refine conditions.
- Adjust priorities to stabilize outcomes.
Debugging techniques:
- Log rule evaluations and priorities.
- Add UI indicators showing active rule and reason for selection.
- Temporarily disable non-essential rules to isolate problems.
**Section sources**
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
- [OutgoingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/OutgoingPacketHandlers.cs)
- [DressManager.cs](file://ClassicAssist.Shared/Data/Dress/DressManager.cs)
- [DressTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/DressTabViewModel.cs)
## Conclusion
The Dress Manager’s conditional switching system enables powerful automation based on skills, regions, status, and more. By understanding DressAgentItemType categories, crafting precise rules, managing priorities, and integrating with trigger events, you can implement robust outfit automation. Follow performance best practices and use the troubleshooting guide to maintain reliable behavior under complex conditions.