@@ 131,7 131,7 @@ public class Bot : IStatefulEntity
(
entity.Id,
_walkManager,
- new UseSkillPolicy(true, null)
+ new SkillSelector(Piis.Contains(entity.VNum))
),
ct
);
@@ 145,7 145,7 @@ public class Bot : IStatefulEntity
}
}
- private ILivingEntity? ChooseNextEntity(Map map, Character character, Position characterPosition)
+ private Monster? ChooseNextEntity(Map map, Character character, Position characterPosition)
{
var piisCount = map.Entities
.GetEntities()
@@ 159,6 159,18 @@ public class Bot : IStatefulEntity
choosingList = Piis;
}
+ var piiOrPod = GetEntity(choosingList, map, characterPosition);
+
+ if (piiOrPod is null && piisCount != 0)
+ {
+ piiOrPod = GetEntity(Piis, map, characterPosition);
+ }
+
+ return piiOrPod;
+ }
+
+ private Monster? GetEntity(long[] choosingList, Map map, Position characterPosition)
+ {
return map.Entities.GetEntities()
.OfType<Monster>()
.Where(x => x.Hp?.Percentage > 0)
@@ 0,0 1,50 @@
+//
+// SkillSelector.cs
+//
+// Copyright (c) František Boháček. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using NosSmooth.Data.Abstractions.Enums;
+using NosSmooth.Extensions.Combat.Errors;
+using NosSmooth.Extensions.Combat.Selectors;
+using NosSmooth.Game.Data.Characters;
+using Remora.Results;
+
+namespace SimplePiiBot;
+
+/// <summary>
+/// Selects skill for the pii bot.
+/// </summary>
+public class SkillSelector : ISkillSelector
+{
+ private bool _isPii;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="SkillSelector"/> class.
+ /// </summary>
+ /// <param name="isPii">Whether the target entity is a pii (false for pii pod).</param>
+ public SkillSelector(bool isPii)
+ {
+ _isPii = isPii;
+ }
+
+ /// <inheritdoc />
+ public Result<Skill> GetSelectedSkill(IEnumerable<Skill> usableSkills)
+ {
+ var skills = usableSkills.ToList();
+
+ var skill = skills.MaxBy(x => x.Info!.Range);
+ if (_isPii)
+ {
+ // try to find skill that does area damage
+ skill = skills.MinBy(x => x.Info!.HitType == HitType.EnemiesInZone ? 0 : 1);
+ }
+
+ if (skill is null)
+ {
+ return new SkillNotFoundError();
+ }
+
+ return skill;
+ }
+}<
\ No newline at end of file