71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using Cielonos.MainGame.Characters;
|
|
|
|
namespace Cielonos.MainGame.Inventory.Collections
|
|
{
|
|
public partial class FutureWand
|
|
{
|
|
private const float DefaultTargetingRadius = 25f;
|
|
private readonly List<Enemy> _currentTargets = new List<Enemy>(3);
|
|
|
|
private IReadOnlyList<Enemy> CurrentTargets => _currentTargets;
|
|
private Enemy PrimaryTarget => _currentTargets.Count > 0 ? _currentTargets[0] : null;
|
|
|
|
private Enemy RefreshPrimaryTarget(float radius = DefaultTargetingRadius)
|
|
{
|
|
return RefreshPrimaryTarget(TargetingScorePreset.RangedAttack, radius);
|
|
}
|
|
|
|
private Enemy RefreshPrimaryTargetByMelee(float radius = DefaultTargetingRadius)
|
|
{
|
|
return RefreshPrimaryTarget(TargetingScorePreset.MeleeAttack, radius);
|
|
}
|
|
|
|
private Enemy RefreshPrimaryTarget(TargetingScorePreset preset, float radius = DefaultTargetingRadius)
|
|
{
|
|
RefreshCurrentTargets(1, radius, preset);
|
|
return PrimaryTarget;
|
|
}
|
|
|
|
private IReadOnlyList<Enemy> RefreshCurrentTargets(int maxTargetCount, float radius = DefaultTargetingRadius,
|
|
TargetingScorePreset preset = TargetingScorePreset.RangedAttack)
|
|
{
|
|
_currentTargets.Clear();
|
|
if (maxTargetCount <= 0) return CurrentTargets;
|
|
|
|
Enemy firstTarget = CombatManager.EnemySm.Query(radius, preset).LockonFirst();
|
|
if (firstTarget != null)
|
|
{
|
|
_currentTargets.Add(firstTarget);
|
|
}
|
|
|
|
int remainingCount = maxTargetCount - _currentTargets.Count;
|
|
if (remainingCount > 0)
|
|
{
|
|
List<Enemy> targets = CombatManager.EnemySm.Query(radius, preset).Exclude(_currentTargets).Best(remainingCount);
|
|
_currentTargets.AddRange(targets);
|
|
}
|
|
|
|
return CurrentTargets;
|
|
}
|
|
|
|
private List<Enemy> GetCurrentTargets(int targetCount, float radius = DefaultTargetingRadius)
|
|
{
|
|
if (targetCount <= 0) return new List<Enemy>();
|
|
if (_currentTargets.Count < targetCount)
|
|
{
|
|
RefreshCurrentTargets(targetCount, radius);
|
|
}
|
|
|
|
int resultCount = targetCount < _currentTargets.Count ? targetCount : _currentTargets.Count;
|
|
List<Enemy> result = new List<Enemy>(resultCount);
|
|
for (int i = 0; i < resultCount; i++)
|
|
{
|
|
result.Add(_currentTargets[i]);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|