-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathWeaponSelector.cs
36 lines (29 loc) · 1022 Bytes
/
WeaponSelector.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
namespace DaLion.Overhaul.Modules.Combat;
#region using directives
using DaLion.Shared.Extensions.Stardew;
using StardewValley.Monsters;
#endregion using directives
/// <summary>Smart <see cref="Tool"/> selector.</summary>
internal static class WeaponSelector
{
internal static bool TryFor(Farmer who, out int index)
{
index = -1;
var closest = who.GetClosestCharacter<Monster>(out var distance);
if (closest is null)
{
return false;
}
if (CombatModule.State.AutoSelectableMelee is not null &&
distance <= CombatModule.Config.MeleeAutoSelectionRange)
{
index = who.Items.IndexOf(CombatModule.State.AutoSelectableMelee);
}
else if (CombatModule.State.AutoSelectableRanged is not null &&
distance <= CombatModule.Config.RangedAutoSelectionRange)
{
index = who.Items.IndexOf(CombatModule.State.AutoSelectableRanged);
}
return index >= 0;
}
}