Merge pull request #820 from nolt/feature-bots
(cherry picked from commit b10de0645a869485fbb5771a739abd06b5708c2d)
This commit is contained in:
@@ -18,6 +18,9 @@ using MUnique.OpenMU.Interfaces;
|
||||
/// </summary>
|
||||
public sealed class HealingHandler
|
||||
{
|
||||
/// <summary>Drink a mana potion once mana falls below this share, so casters can keep casting.</summary>
|
||||
private const int ManaThresholdPercent = 30;
|
||||
|
||||
private static readonly ItemConsumeAction ConsumeAction = new();
|
||||
|
||||
private static readonly ItemIdentifier[] HealthPotionPriority =
|
||||
@@ -28,6 +31,13 @@ public sealed class HealingHandler
|
||||
ItemConstants.Apple,
|
||||
];
|
||||
|
||||
private static readonly ItemIdentifier[] ManaPotionPriority =
|
||||
[
|
||||
ItemConstants.LargeManaPotion,
|
||||
ItemConstants.MediumManaPotion,
|
||||
ItemConstants.SmallManaPotion,
|
||||
];
|
||||
|
||||
private readonly OfflinePlayer _player;
|
||||
private readonly IMuHelperSettings? _config;
|
||||
|
||||
@@ -75,7 +85,25 @@ public sealed class HealingHandler
|
||||
if (this._config!.UseHealPotion && this.IsHealthBelowThreshold(this._player, this._config.PotionThresholdPercent))
|
||||
{
|
||||
await this.UseHealthPotionAsync().ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._config.UseManaPotion && this.IsManaBelowThreshold())
|
||||
{
|
||||
await this.UsePotionAsync(ManaPotionPriority).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsManaBelowThreshold()
|
||||
{
|
||||
if (this._player.Attributes is not { } attributes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
double mana = attributes[Stats.CurrentMana];
|
||||
double maxMana = attributes[Stats.MaximumMana];
|
||||
return maxMana > 0 && (mana * 100.0 / maxMana) <= ManaThresholdPercent;
|
||||
}
|
||||
|
||||
private async ValueTask PerformPartyHealingAsync()
|
||||
@@ -126,14 +154,16 @@ public sealed class HealingHandler
|
||||
return maxHp > 0 && (hp * 100.0 / maxHp) <= thresholdPercent;
|
||||
}
|
||||
|
||||
private async ValueTask UseHealthPotionAsync()
|
||||
private ValueTask UseHealthPotionAsync() => this.UsePotionAsync(HealthPotionPriority);
|
||||
|
||||
private async ValueTask UsePotionAsync(ItemIdentifier[] priority)
|
||||
{
|
||||
if (this._player.Inventory is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var identifier in HealthPotionPriority)
|
||||
foreach (var identifier in priority)
|
||||
{
|
||||
var potion = this._player.Inventory.Items
|
||||
.FirstOrDefault(i => i.Definition?.Group == identifier.Group
|
||||
|
||||
Reference in New Issue
Block a user