From f5bc4d60f43a957e8b6d4fe6a119b32492a183d8 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 1 Jan 2023 18:45:08 +0100 Subject: [PATCH] feat(samples): make custom SimplePiiBot skill selector Selects areal skills for Piis, any skill for PiiPod --- src/Samples/HighLevel/SimplePiiBot/Bot.cs | 16 +++++- .../HighLevel/SimplePiiBot/SkillSelector.cs | 50 +++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 src/Samples/HighLevel/SimplePiiBot/SkillSelector.cs diff --git a/src/Samples/HighLevel/SimplePiiBot/Bot.cs b/src/Samples/HighLevel/SimplePiiBot/Bot.cs index 1a624d9..9453466 100644 --- a/src/Samples/HighLevel/SimplePiiBot/Bot.cs +++ b/src/Samples/HighLevel/SimplePiiBot/Bot.cs @@ -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() .Where(x => x.Hp?.Percentage > 0) diff --git a/src/Samples/HighLevel/SimplePiiBot/SkillSelector.cs b/src/Samples/HighLevel/SimplePiiBot/SkillSelector.cs new file mode 100644 index 0000000..8e7aa87 --- /dev/null +++ b/src/Samples/HighLevel/SimplePiiBot/SkillSelector.cs @@ -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; + +/// +/// Selects skill for the pii bot. +/// +public class SkillSelector : ISkillSelector +{ + private bool _isPii; + + /// + /// Initializes a new instance of the class. + /// + /// Whether the target entity is a pii (false for pii pod). + public SkillSelector(bool isPii) + { + _isPii = isPii; + } + + /// + public Result GetSelectedSkill(IEnumerable 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 -- 2.49.0