Skip to content

Commit 77b34f4

Browse files
committed
Core: PathSettings: Id can be specified by the user.
Core: RequirementFactory: Be able to use 'PathDist' Requirement for local context.
1 parent fcf2445 commit 77b34f4

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Core/ClassConfig/ClassConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public void Initialise(IServiceProvider sp, Dictionary<int, string> overridePath
150150
settings.Init(globalTime, playerReader, i);
151151
}
152152

153+
if (Paths.Select(x => x.Id).Distinct().Count() != Paths.Length)
154+
{
155+
throw new ArgumentException("One ore more PathSettings share the same Id. Must be unique!");
156+
}
157+
153158
RequirementFactory factory = new(sp, this);
154159

155160
var baseActionKeys = GetByType<KeyAction>();

Core/ClassConfig/PathSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void Init(RecordInt globalTime, PlayerReader playerReader, int id)
4444
{
4545
this.globalTime = globalTime;
4646
this.playerReader = playerReader;
47-
Id = id;
47+
Id = Id == default ? id : Id;
4848
}
4949

5050
public bool CanRun()

Core/Requirement/RequirementFactory.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,22 +520,26 @@ private void BindPathSettingsIntVariables(PathSettings[] paths)
520520
{
521521
PathSettings settings = paths[i];
522522

523-
string nameDistanceToPath = $"PathDist_{settings.Id}";
524-
intVariables.TryAdd(nameDistanceToPath, settings.GetDistanceXYFromPath);
523+
string prefixKey = "PathDist";
524+
string suffix = $"{settings.Id}";
525+
string key = $"{prefixKey}_{suffix}";
526+
intVariables.TryAdd(key, settings.GetDistanceXYFromPath);
527+
528+
InitPerKeyAction(prefixKey, suffix);
525529

526530
Init(settings);
527531
}
528532
}
529533

530534
private void InitPerKeyAction(KeyAction item)
531535
{
532-
InitPerKeyAction(item, "CD");
533-
InitPerKeyAction(item, "Cost");
536+
InitPerKeyAction("CD", item.Name);
537+
InitPerKeyAction("Cost", item.Name);
534538
}
535539

536-
private void InitPerKeyAction(KeyAction item, string prefixKey)
540+
private void InitPerKeyAction(string prefixKey, string suffix)
537541
{
538-
string key = $"{prefixKey}_{item.Name}";
542+
string key = $"{prefixKey}_{suffix}";
539543
intVariables.Remove(prefixKey);
540544

541545
if (intVariables.TryGetValue(key, out Func<int>? func))

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ The path that the player follows during [Follow Route Goal](#follow-route-goal),
620620
| Property Name | Description | Optional | Default value |
621621
| --- | --- | --- | --- |
622622
| `"PathFilename"` | [Path](#path) to use while alive | **false** | `""` |
623+
| `"Id"` | <b>Must be a Unique Integer value</b> to identify PathSettings. | true | `"Auto incremented from zero"` or `"Unless specified by user."` |
623624
| `"PathThereAndBack"` | While using the path, [should go start to and reverse](#there-and-back) | true | `true` |
624625
| `"PathReduceSteps"` | Reduce the number of path points | true | `false` |
625626
| `"SideActivityRequirements"` | List of [Requirements](#requirement) to limit when the player should search for target<br/>Great for enforcing how closely should follow the path. | true | `true` |
@@ -629,6 +630,7 @@ The path that the player follows during [Follow Route Goal](#follow-route-goal),
629630
When the bellow properties are defined in the [Class Configuration](#12-class-configuration), a new [PathSettings](#pathsettings) instance is created under in `Paths` array as the first element.
630631

631632
```json
633+
"Id": 42, // Optional - Helps identify the path
632634
"PathFilename": "_pack\\1-20\\Dwarf.Gnome\\1-4_Dun Morogh.json.json", // the path to walk when alive
633635
"PathThereAndBack": true, // if true walks the path and the walks it backwards.
634636
"PathReduceSteps": true, // uses every other coordinate, halve the coordinate count
@@ -1393,6 +1395,7 @@ Formula: `[Keyword] [Operator] [Numeric integer value]`
13931395
| `SessionHours` | Returns with the elapsed time in Hours since the Session started.<br>The Session starts when the `Start Bot` button is pressed! |
13941396
| `ExpPerc` | Returns with the player experience as percentage to hit next level. |
13951397
| `UIMapId` | Returns with the player current [UIMapId](https://github.com/Xian55/WowClassicGrindBot/blob/9bea201760babc0f6670df2bd5c071c9c3f1220d/Json/dbc/som/WorldMapArea.json#L3C6-L3C11) |
1398+
| `PathDist` | Returns the context [PathSettings](#pathsettings) of closest distance (in yards) from the player location to the Path. |
13961399
| `PathDist_{PathSettings.Id}` | Returns the closest distance (in yards) from the player location to the Path. |
13971400

13981401
For the `MinRange` and `MaxRange` gives an approximation range distance between the player and target.

0 commit comments

Comments
 (0)