first commit
This commit is contained in:
+457
@@ -0,0 +1,457 @@
|
||||
# Optimization Strategies
|
||||
|
||||
<cite>
|
||||
**Referenced Files in This Document**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerEntry.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerEntry.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [ScavengerTests.cs](file://ClassicAssist.Tests/Agents/ScavengerTests.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [Utility.cs](file://ClassicAssist.Shared/Misc/Utility.cs)
|
||||
</cite>
|
||||
|
||||
## 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
|
||||
This document explains optimization strategies for the Scavenger Agent in ClassicAssist.Avalonia, focusing on efficient scanning across large map areas, distance-based prioritization, pathfinding considerations, and performance tuning for long automation sessions. It also covers power consumption considerations for mobile devices, advanced route planning, batch processing, multi-agent coordination, troubleshooting common issues (memory leaks, CPU spikes, network latency), and best practices for different environments and server conditions.
|
||||
|
||||
## Project Structure
|
||||
The Scavenger feature spans shared data models, UI view models, Avalonia views, tests, and core UO networking/data layers:
|
||||
- Data layer: Scavenger configuration entries and manager orchestration
|
||||
- UI layer: View model and tab control for configuring and monitoring scavengers
|
||||
- Core UO layer: Entity/item collections, map utilities, pathfinding packets, and packet queues
|
||||
- Tests: Validation of scavenger behavior and edge cases
|
||||
|
||||
```mermaid
|
||||
graph TB
|
||||
subgraph "Shared"
|
||||
SM["ScavengerManager.cs"]
|
||||
SE["ScavengerEntry.cs"]
|
||||
EC["EntityCollection.cs"]
|
||||
IC["ItemCollection.cs"]
|
||||
MP["Map.cs"]
|
||||
PF["Pathfind.cs"]
|
||||
TPQ["ThreadPriorityQueue.cs"]
|
||||
APQ["ActionPacketQueue.cs"]
|
||||
IPH["IncomingPacketHandlers.cs"]
|
||||
UT["Utility.cs"]
|
||||
end
|
||||
subgraph "Avalonia UI"
|
||||
VM["ScavengerTabViewModel.cs"]
|
||||
TAB["ScavengerTabControl.axaml.cs"]
|
||||
end
|
||||
subgraph "Tests"
|
||||
TST["ScavengerTests.cs"]
|
||||
end
|
||||
VM --> SM
|
||||
TAB --> VM
|
||||
SM --> EC
|
||||
SM --> IC
|
||||
SM --> MP
|
||||
SM --> PF
|
||||
SM --> TPQ
|
||||
SM --> APQ
|
||||
SM --> IPH
|
||||
SM --> UT
|
||||
TST --> SM
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerEntry.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerEntry.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [Utility.cs](file://ClassicAssist.Shared/Misc/Utility.cs)
|
||||
- [ScavengerTests.cs](file://ClassicAssist.Tests/Agents/ScavengerTests.cs)
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerEntry.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerEntry.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [Utility.cs](file://ClassicAssist.Shared/Misc/Utility.cs)
|
||||
- [ScavengerTests.cs](file://ClassicAssist.Tests/Agents/ScavengerTests.cs)
|
||||
|
||||
## Core Components
|
||||
- ScavengerManager: Orchestrates scanning, prioritization, batching, and execution of scavenger tasks. Integrates with entity/item collections, map utilities, and pathfinding.
|
||||
- ScavengerEntry: Represents a single scavenger rule or target definition used by the manager to filter and prioritize items.
|
||||
- ScavengerTabViewModel: Exposes configuration and runtime state to the UI; coordinates user actions with the manager.
|
||||
- ScavengerTabControl.axaml.cs: Hosts the UI tab and binds to the view model.
|
||||
- EntityCollection/ItemCollection: Provide access to world entities and items, enabling selective loading and filtering.
|
||||
- Map: Supplies spatial utilities for distance calculations and region queries.
|
||||
- Pathfind: Encapsulates pathfinding packet interactions for movement planning.
|
||||
- ThreadPriorityQueue/ActionPacketQueue: Manage task scheduling and outgoing action pacing.
|
||||
- IncomingPacketHandlers: Update world state from server packets, affecting item/entity availability.
|
||||
- Utility: Common helpers for math, timing, and general operations.
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerEntry.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerEntry.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [Utility.cs](file://ClassicAssist.Shared/Misc/Utility.cs)
|
||||
|
||||
## Architecture Overview
|
||||
The Scavenger Agent follows a pipeline:
|
||||
- Configuration and rules are defined via ScavengerEntry and managed by ScavengerManager.
|
||||
- The UI (ScavengerTabViewModel + ScavengerTabControl) allows users to configure and monitor agents.
|
||||
- Scanning uses ItemCollection and EntityCollection filtered by ScavengerEntry criteria.
|
||||
- Distance-based prioritization leverages Map utilities to rank candidates.
|
||||
- Pathfinding uses Pathfind packets to plan routes around obstacles.
|
||||
- Execution is scheduled via ThreadPriorityQueue and ActionPacketQueue to pace actions and avoid flooding the server.
|
||||
- World updates come through IncomingPacketHandlers, keeping collections current.
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant UI as "ScavengerTabViewModel"
|
||||
participant Tab as "ScavengerTabControl"
|
||||
participant Manager as "ScavengerManager"
|
||||
participant Items as "ItemCollection"
|
||||
participant Entities as "EntityCollection"
|
||||
participant Map as "Map"
|
||||
participant PF as "Pathfind"
|
||||
participant Queue as "ActionPacketQueue"
|
||||
participant Net as "IncomingPacketHandlers"
|
||||
UI->>Manager : Configure rules (ScavengerEntry[])
|
||||
Tab->>UI : User actions (start/stop/pause)
|
||||
Manager->>Items : Query items by filters
|
||||
Manager->>Entities : Query nearby entities if needed
|
||||
Manager->>Map : Compute distances and sort
|
||||
Manager->>PF : Request path to target
|
||||
PF-->>Manager : Path result
|
||||
Manager->>Queue : Enqueue pick/use/drop actions
|
||||
Net-->>Manager : Updates (items/entities change)
|
||||
Manager-->>UI : Progress and status updates
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
|
||||
## Detailed Component Analysis
|
||||
|
||||
### ScavengerManager
|
||||
Responsibilities:
|
||||
- Rule evaluation against item/entity collections
|
||||
- Distance-based prioritization using map utilities
|
||||
- Batch grouping of similar targets to reduce overhead
|
||||
- Scheduling via priority queue and action queue
|
||||
- Coordination with pathfinding and incoming updates
|
||||
|
||||
Optimization patterns:
|
||||
- Selective loading: Filter by type, hue, location before scoring
|
||||
- Spatial pruning: Use bounding boxes or radius checks to limit candidate sets
|
||||
- Priority scoring: Combine distance, rarity, and urgency into a single score
|
||||
- Batching: Group identical or similar items to minimize repeated pathfinding and packet bursts
|
||||
- Backoff and throttling: Pace actions to avoid server-side rate limits and reduce CPU/network spikes
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class ScavengerManager {
|
||||
+configure(entries)
|
||||
+scan()
|
||||
+prioritize(candidates)
|
||||
+batch(targets)
|
||||
+schedule(actions)
|
||||
+updateFromPackets()
|
||||
}
|
||||
class ScavengerEntry {
|
||||
+type
|
||||
+hue
|
||||
+filters
|
||||
+priorityWeight
|
||||
}
|
||||
class ItemCollection
|
||||
class EntityCollection
|
||||
class Map
|
||||
class Pathfind
|
||||
class ActionPacketQueue
|
||||
class ThreadPriorityQueue
|
||||
ScavengerManager --> ScavengerEntry : "uses"
|
||||
ScavengerManager --> ItemCollection : "queries"
|
||||
ScavengerManager --> EntityCollection : "queries"
|
||||
ScavengerManager --> Map : "distance/radius"
|
||||
ScavengerManager --> Pathfind : "route planning"
|
||||
ScavengerManager --> ActionPacketQueue : "enqueues actions"
|
||||
ScavengerManager --> ThreadPriorityQueue : "task scheduling"
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerEntry.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerEntry.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerEntry.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerEntry.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
|
||||
### Scanning Algorithm and Prioritization
|
||||
Key steps:
|
||||
- Candidate selection: Apply ScavengerEntry filters to ItemCollection and optionally EntityCollection
|
||||
- Spatial pruning: Limit to a configurable radius around the player or waypoint
|
||||
- Scoring: Combine distance, rarity, and urgency weights
|
||||
- Sorting: Produce an ordered list of targets
|
||||
- Batching: Merge adjacent or identical targets to reduce redundant work
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
Start(["Start Scan"]) --> LoadCandidates["Load candidates from ItemCollection<br/>and EntityCollection"]
|
||||
LoadCandidates --> ApplyFilters["Apply ScavengerEntry filters"]
|
||||
ApplyFilters --> SpatialPrune["Spatial prune by radius/bounds"]
|
||||
SpatialPrune --> ScoreTargets["Score targets (distance + weights)"]
|
||||
ScoreTargets --> SortTargets["Sort by score"]
|
||||
SortTargets --> BatchTargets["Batch similar/adjacent targets"]
|
||||
BatchTargets --> ScheduleActions["Schedule actions via queues"]
|
||||
ScheduleActions --> End(["End Scan"])
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
|
||||
### Pathfinding Integration
|
||||
- Uses Pathfind packets to compute routes to target locations
|
||||
- Considers obstacles and terrain flags via Map data
|
||||
- Replans when dynamic changes occur (e.g., new objects blocking paths)
|
||||
- Integrates with ActionPacketQueue to pace movement commands
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant M as "ScavengerManager"
|
||||
participant P as "Pathfind"
|
||||
participant Q as "ActionPacketQueue"
|
||||
M->>P : Request path to target
|
||||
P-->>M : Path nodes or failure
|
||||
alt Path found
|
||||
M->>Q : Enqueue move-to-node actions
|
||||
else No path
|
||||
M->>M : Fallback (wait/retry or skip)
|
||||
end
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
|
||||
**Section sources**
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
|
||||
### UI and Configuration Flow
|
||||
- ScavengerTabViewModel exposes configuration properties and runtime state
|
||||
- ScavengerTabControl hosts the UI and forwards user actions to the view model
|
||||
- Changes propagate to ScavengerManager for immediate effect
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant User as "User"
|
||||
participant Tab as "ScavengerTabControl"
|
||||
participant VM as "ScavengerTabViewModel"
|
||||
participant M as "ScavengerManager"
|
||||
User->>Tab : Adjust settings
|
||||
Tab->>VM : Update bound properties
|
||||
VM->>M : Apply configuration
|
||||
M-->>VM : Emit progress/status
|
||||
VM-->>Tab : Refresh UI
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
|
||||
### Testing and Validation
|
||||
- ScavengerTests validates key behaviors such as filtering, prioritization, and batching under various scenarios
|
||||
- Helps ensure stability and regression-free updates
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerTests.cs](file://ClassicAssist.Tests/Agents/ScavengerTests.cs)
|
||||
|
||||
## Dependency Analysis
|
||||
High-level dependencies:
|
||||
- ScavengerManager depends on ItemCollection, EntityCollection, Map, Pathfind, ActionPacketQueue, ThreadPriorityQueue, and IncomingPacketHandlers
|
||||
- UI components depend on ScavengerManager via ScavengerTabViewModel
|
||||
- Tests depend on ScavengerManager for behavioral validation
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
VM["ScavengerTabViewModel.cs"] --> M["ScavengerManager.cs"]
|
||||
TAB["ScavengerTabControl.axaml.cs"] --> VM
|
||||
M --> IC["ItemCollection.cs"]
|
||||
M --> EC["EntityCollection.cs"]
|
||||
M --> MAP["Map.cs"]
|
||||
M --> PF["Pathfind.cs"]
|
||||
M --> APQ["ActionPacketQueue.cs"]
|
||||
M --> TPQ["ThreadPriorityQueue.cs"]
|
||||
M --> IPH["IncomingPacketHandlers.cs"]
|
||||
TST["ScavengerTests.cs"] --> M
|
||||
```
|
||||
|
||||
**Diagram sources**
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [ScavengerTests.cs](file://ClassicAssist.Tests/Agents/ScavengerTests.cs)
|
||||
|
||||
**Section sources**
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
- [ScavengerTabViewModel.cs](file://ClassicAssist.Shared/UI/ViewModels/Agents/ScavengerTabViewModel.cs)
|
||||
- [ScavengerTabControl.axaml.cs](file://ClassicAssist.Avalonia/Views/Agents/ScavengerTabControl.axaml.cs)
|
||||
- [ItemCollection.cs](file://ClassicAssist.Shared/UO/Objects/ItemCollection.cs)
|
||||
- [EntityCollection.cs](file://ClassicAssist.Shared/UO/Objects/EntityCollection.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [Pathfind.cs](file://ClassicAssist.Shared/UO/Data/Gumps/Packets/Pathfind.cs)
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [ThreadPriorityQueue.cs](file://ClassicAssist.Shared/Misc/ThreadPriorityQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [ScavengerTests.cs](file://ClassicAssist.Tests/Agents/ScavengerTests.cs)
|
||||
|
||||
## Performance Considerations
|
||||
- Selective entity loading
|
||||
- Prefer targeted queries over full scans; use filters early to reduce candidate sets
|
||||
- Limit scan radius based on environment density and server load
|
||||
- Memory usage reduction
|
||||
- Avoid retaining references to transient items after processing
|
||||
- Reuse buffers and temporary lists where possible
|
||||
- Periodically compact or clear caches if applicable
|
||||
- CPU cycle management
|
||||
- Throttle scan frequency; adapt to FPS or tick rates
|
||||
- Use priority queues to process high-value targets first
|
||||
- Batch pathfinding requests and reuse computed paths when stable
|
||||
- Network efficiency
|
||||
- Coalesce actions into batches to reduce packet volume
|
||||
- Respect server rate limits; implement backoff on failures
|
||||
- Battery life optimization (mobile)
|
||||
- Reduce scan frequency and background activity when idle
|
||||
- Lower screen refresh and disable non-essential UI updates during automation
|
||||
- Prefer offline computations (scoring, sorting) over frequent network calls
|
||||
- Advanced strategies
|
||||
- Intelligent route planning: Plan multi-stop routes that minimize total travel distance
|
||||
- Batch processing: Group similar items (same type/hue) to amortize pathfinding and interaction costs
|
||||
- Multi-agent coordination: Share target assignments to avoid duplicate pickups and conflicts
|
||||
|
||||
[No sources needed since this section provides general guidance]
|
||||
|
||||
## Troubleshooting Guide
|
||||
Common issues and resolutions:
|
||||
- High CPU usage
|
||||
- Reduce scan frequency and tighten filters
|
||||
- Increase batch sizes to lower per-item overhead
|
||||
- Profile hotspots in prioritization and pathfinding
|
||||
- Memory growth or leaks
|
||||
- Ensure temporary collections are cleared after each scan
|
||||
- Avoid holding long-lived references to items/mobs
|
||||
- Monitor collection sizes and reset when appropriate
|
||||
- Network latency spikes
|
||||
- Implement exponential backoff on failed actions
|
||||
- Stagger outgoing packets via ActionPacketQueue
|
||||
- Avoid excessive property queries; cache results when safe
|
||||
- Pathfinding failures
|
||||
- Retry with larger radii or alternate waypoints
|
||||
- Validate destination accessibility using Map data
|
||||
- Fall back to nearest valid tile if blocked
|
||||
- UI freezes
|
||||
- Offload heavy work off the UI thread
|
||||
- Debounce UI updates and coalesce state changes
|
||||
|
||||
**Section sources**
|
||||
- [ActionPacketQueue.cs](file://ClassicAssist.Shared/UO/Network/ActionPacketQueue.cs)
|
||||
- [IncomingPacketHandlers.cs](file://ClassicAssist.Shared/UO/Network/IncomingPacketHandlers.cs)
|
||||
- [Map.cs](file://ClassicAssist.Shared/UO/Data/Map.cs)
|
||||
- [ScavengerManager.cs](file://ClassicAssist.Shared/Data/Scavenger/ScavengerManager.cs)
|
||||
|
||||
## Conclusion
|
||||
Effective Scavenger Agent optimization hinges on precise filtering, spatial pruning, intelligent prioritization, and careful batching. By integrating robust pathfinding, pacing actions through queues, and adapting to server and device constraints, you can achieve reliable, efficient automation across diverse environments. Continuous testing and monitoring help maintain performance and stability over extended sessions.
|
||||
|
||||
[No sources needed since this section summarizes without analyzing specific files]
|
||||
|
||||
## Appendices
|
||||
- Best practices for configuration
|
||||
- Start with conservative scan radii and gradually expand
|
||||
- Tune priority weights to match your goals (speed vs. completeness)
|
||||
- Enable batching for dense areas; disable for sparse maps to reduce latency
|
||||
- Use multiple agents with partitioned regions to avoid contention
|
||||
- Server-specific tips
|
||||
- On high-population servers, increase throttling and batch sizes
|
||||
- On low-latency servers, reduce delays for snappier responses
|
||||
- For laggy connections, rely more on local caching and fewer round-trips
|
||||
|
||||
[No sources needed since this section provides general guidance]
|
||||
Reference in New Issue
Block a user