16 KiB
Action Commands
**Referenced Files in This Document** - [ActionCommands.cs](file://ClassicAssist.Shared/Data/Macros/Commands/ActionCommands.cs) - [MacroInvoker.cs](file://ClassicAssist.Shared/Data/Macros/MacroInvoker.cs) - [HotkeyCommand.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/HotkeyCommand.cs) - [UseInHand.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/UseInHand.cs) - [DropHoldingObject.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/DropHoldingObject.cs) - [EquipLastWeapon.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/EquipLastWeapon.cs) - [ConsumeCommands.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/ConsumeCommands.cs) - [Targeting.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/Targeting.cs) - [MovementCommands.cs](file://ClassicAssist.Shared/Data/Hotkeys/Commands/MovementCommands.cs)Table of Contents
- Introduction
- Project Structure
- Core Components
- Architecture Overview
- Detailed Component Analysis
- Dependency Analysis
- Performance Considerations
- Troubleshooting Guide
- Conclusion
- Appendices
Introduction
Action Commands are a fundamental component of the ClassicAssist macro system, providing automated control over core game operations including item usage, equipment management, and game state manipulation. These commands enable players to create sophisticated automation patterns for inventory management, equipment switching, resource consumption, and other repetitive tasks that enhance gameplay efficiency.
The Action Commands system is designed to be both powerful and accessible, supporting complex automation scenarios while maintaining simplicity for common use cases. Commands execute within the context of the macro system, ensuring proper timing, error handling, and integration with other macro components.
Project Structure
The Action Commands system is organized within the ClassicAssist.Shared module, following a modular architecture that separates concerns between different types of actions:
graph TB
subgraph "Macro System"
MC[Macros Manager]
MI[Macro Invoker]
AC[Action Commands]
end
subgraph "Hotkey Integration"
HKC[Hotkey Commands]
UH[Use In Hand]
DHO[Drop Holding Object]
ELW[Equip Last Weapon]
CC[Consume Commands]
TG[Targeting]
MCMD[Movement Commands]
end
subgraph "Game Engine"
GE[Game Engine]
IM[Item Management]
EM[Equipment Management]
GS[Game State]
end
MC --> MI
MI --> AC
MI --> HKC
HKC --> UH
HKC --> DHO
HKC --> ELW
HKC --> CC
HKC --> TG
HKC --> MCMD
AC --> GE
HKC --> GE
GE --> IM
GE --> EM
GE --> GS
Diagram sources
Section sources
Core Components
The Action Commands system consists of several key components that work together to provide comprehensive automation capabilities:
Command Execution Framework
The foundation of the Action Commands system provides a unified interface for executing various game actions through a consistent command pattern.
Item Management Operations
Commands for interacting with items in containers, inventory, and equipment slots, including selection, movement, and usage operations.
Equipment Management
Specialized commands for managing character equipment, including equipping, dequipping, and switching between different gear sets.
Game State Manipulation
Commands that modify or query the current game state, including targeting, movement, and interaction with game objects.
Section sources
Architecture Overview
The Action Commands system follows a layered architecture that ensures proper separation of concerns and maintainable code structure:
sequenceDiagram
participant Macro as "Macro Script"
participant Invoker as "Macro Invoker"
participant Command as "Action Command"
participant Hotkey as "Hotkey Handler"
participant Engine as "Game Engine"
participant State as "Game State"
Macro->>Invoker : Execute Command
Invoker->>Command : Parse Parameters
Command->>Hotkey : Route to Handler
Hotkey->>Engine : Send Action Packet
Engine->>State : Update Game State
State-->>Engine : Confirmation
Engine-->>Hotkey : Action Result
Hotkey-->>Command : Execution Status
Command-->>Invoker : Return Value
Invoker-->>Macro : Command Result
Note over Macro,State : Command execution lifecycle
Diagram sources
Detailed Component Analysis
Item Usage Commands
Item usage commands provide automated control over consuming, using, and manipulating items throughout the game world. These commands support various item types and usage contexts.
Use Item Command
Executes usage actions on specified items with intelligent target resolution and validation.
Method Signature:
public bool UseItem(int serial, int amount = 1, int x = -1, int y = -1, int z = -1)
Parameters:
serial: The unique identifier of the item to useamount: Number of items to consume (default: 1)x: Target X coordinate (-1 for no specific location)y: Target Y coordinate (-1 for no specific location)z: Target Z coordinate (-1 for no specific location)
Return Values:
true: Item successfully usedfalse: Item usage failed (invalid target, insufficient quantity, etc.)
Error Handling:
- Validates item existence and accessibility
- Checks player range and line of sight
- Handles item-specific usage restrictions
- Manages cooldown periods and skill requirements
Drop Item Command
Removes items from inventory or equipment by dropping them at specified locations.
Method Signature:
public bool DropItem(int serial, int x = -1, int y = -1, int z = -1)
Parameters:
serial: The unique identifier of the item to dropx: Target X coordinate for drop locationy: Target Y coordinate for drop locationz: Target Z coordinate for drop location
Return Values:
true: Item successfully droppedfalse: Drop operation failed (item not droppable, invalid location, etc.)
Section sources
Equipment Management Commands
Equipment management commands enable automated control over character gear, allowing for dynamic equipment switching and optimization based on game conditions.
Equip Item Command
Equips items to appropriate character slots with validation and conflict resolution.
Method Signature:
public bool EquipItem(int serial, int layer = -1)
Parameters:
serial: The unique identifier of the item to equiplayer: Specific equipment layer (-1 for automatic detection)
Return Values:
true: Item successfully equippedfalse: Equipping failed (slot occupied, item incompatible, etc.)
Conflict Resolution:
- Automatically handles slot conflicts by dequipping existing items
- Validates item-layer compatibility
- Manages equipment bonuses and stat modifications
Dequip Item Command
Removes items from character equipment slots.
Method Signature:
public bool DequipItem(int layer)
Parameters:
layer: The equipment layer to dequip
Return Values:
true: Item successfully dequippedfalse: Dequipping failed (no item in slot, invalid layer, etc.)
Section sources
Game State Manipulation Commands
Game state manipulation commands provide control over character positioning, targeting, and interaction with the game environment.
Movement Commands
Enable automated character movement with pathfinding and collision avoidance.
Method Signature:
public bool MoveTo(int x, int y, int z = -1, bool run = false)
Parameters:
x: Target X coordinatey: Target Y coordinatez: Target Z coordinate (-1 for ground level)run: Whether to run instead of walk
Return Values:
true: Movement initiated successfullyfalse: Movement failed (obstacles, out of bounds, etc.)
Targeting Commands
Manage character targeting with intelligent object selection and validation.
Method Signature:
public bool TargetSerial(int serial)
Parameters:
serial: The unique identifier of the target object
Return Values:
true: Target set successfullyfalse: Targeting failed (invalid target, out of range, etc.)
Section sources
Resource Consumption Commands
Resource consumption commands automate the use of consumable items such as potions, scrolls, and food with intelligent selection and validation.
Consume Item Command
Automatically consumes appropriate items from inventory based on current needs.
Method Signature:
public bool ConsumeItem(string itemType, int minAmount = 1)
Parameters:
itemType: Type or name of item to consumeminAmount: Minimum quantity required (default: 1)
Return Values:
true: Item consumed successfullyfalse: Consumption failed (no suitable items, insufficient quantity, etc.)
Intelligent Selection:
- Prioritizes items based on quality and availability
- Considers item properties and effects
- Validates consumability and expiration dates
Section sources
Dependency Analysis
The Action Commands system maintains clear dependency relationships that ensure modularity and testability:
graph TD
subgraph "Core Dependencies"
A[ActionCommands]
B[HotkeyCommand Base]
C[Game Engine Interface]
D[Item Management]
E[Equipment Management]
F[Targeting System]
end
subgraph "External Dependencies"
G[UO Network Packets]
H[Game State Manager]
I[Pathfinding Engine]
J[Inventory Manager]
end
A --> B
A --> C
A --> D
A --> E
A --> F
B --> G
C --> H
D --> J
F --> I
D --> G
E --> G
F --> G
Diagram sources
Coupling Analysis
- Low Coupling: Commands depend on abstract interfaces rather than concrete implementations
- High Cohesion: Related functionality grouped within logical command categories
- Dependency Injection: External dependencies injected through constructor parameters
Circular Dependency Prevention
- Clear separation between command logic and game engine interactions
- Event-driven communication between components
- Interface-based abstraction preventing tight coupling
Section sources
Performance Considerations
The Action Commands system is optimized for performance-critical gaming scenarios:
Execution Timing
- Commands execute asynchronously to prevent blocking the main game loop
- Batch processing for multiple related operations
- Intelligent queuing to prevent action spam and server rejection
Memory Management
- Efficient object pooling for frequently created command instances
- Lazy loading of command definitions and metadata
- Proper disposal of temporary resources and network connections
Network Optimization
- Packet coalescing for related actions
- Rate limiting to comply with server constraints
- Connection state awareness to prevent failed operations
Error Recovery
- Automatic retry mechanisms for transient failures
- Graceful degradation when optional features are unavailable
- Comprehensive logging for debugging performance issues
Troubleshooting Guide
Common issues and their solutions when working with Action Commands:
Command Execution Failures
- Symptom: Commands return false without detailed error messages
- Solution: Enable debug logging and check command parameter validation
- Prevention: Validate prerequisites before command execution
Timing Issues
- Symptom: Commands fail due to game state changes during execution
- Solution: Add appropriate delays between dependent commands
- Prevention: Use conditional checks and state verification
Network Problems
- Symptom: Commands succeed locally but fail on server
- Solution: Implement retry logic and connection monitoring
- Prevention: Check network status before critical operations
Resource Conflicts
- Symptom: Equipment or inventory operations fail unexpectedly
- Solution: Verify item availability and slot conflicts
- Prevention: Use atomic operations and transaction-like behavior
Section sources
Conclusion
The Action Commands system provides a robust and flexible foundation for automating game operations in ClassicAssist. Through its modular architecture, comprehensive command set, and careful attention to performance and reliability, it enables players to create sophisticated automation patterns that enhance gameplay efficiency while maintaining the integrity of the gaming experience.
The system's design emphasizes maintainability, extensibility, and ease of use, making it accessible to both novice users creating simple macros and advanced developers building complex automation systems. With proper error handling, performance optimization, and integration with the broader macro ecosystem, Action Commands serve as a cornerstone of the ClassicAssist automation framework.
Appendices
Practical Automation Patterns
Inventory Management Pattern
flowchart TD
Start([Start Inventory Management]) --> CheckSpace["Check Available Space"]
CheckSpace --> HasSpace{"Sufficient Space?"}
HasSpace --> |No| Organize["Organize Inventory"]
HasSpace --> |Yes| ScanItems["Scan for Items"]
ScanItems --> FoundItems{"Items Found?"}
FoundItems --> |No| End([End])
FoundItems --> |Yes| SortItems["Sort by Priority"]
SortItems --> ProcessItems["Process Each Item"]
ProcessItems --> MoveItem["Move to Container"]
MoveItem --> NextItem{"More Items?"}
NextItem --> |Yes| ProcessItems
NextItem --> |No| End
Organize --> CheckSpace
Diagram sources
Equipment Switching Pattern
stateDiagram-v2
[*] --> Idle
Idle --> Checking : "Monitor Conditions"
Checking --> NeedsSwitch{"Conditions Met?"}
NeedsSwitch --> |No| Idle
NeedsSwitch --> |Yes| Preparing["Prepare New Equipment"]
Preparing --> Equipping["Equip New Items"]
Equipping --> Verifying["Verify Equipment"]
Verifying --> Success{"Equipment Valid?"}
Success --> |Yes| Active["Active State"]
Success --> |No| Reverting["Revert Changes"]
Reverting --> Idle
Active --> Monitoring["Monitor Status"]
Monitoring --> Checking
Diagram sources