mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 00:06:02 +00:00
普攻添加选取目标的方法
This commit is contained in:
parent
13a6adb41b
commit
46620aefd7
@ -188,6 +188,16 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// </summary>
|
||||
public bool CanSelectTeammate { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 选取所有敌对角色,优先级大于 <see cref="CanSelectTargetCount"/>
|
||||
/// </summary>
|
||||
public bool SelectAllEnemies { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 选取所有友方角色,优先级大于 <see cref="CanSelectTargetCount"/>,默认包含自身
|
||||
/// </summary>
|
||||
public bool SelectAllTeammates { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 可选取的作用目标数量
|
||||
/// </summary>
|
||||
@ -231,17 +241,17 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
/// <summary>
|
||||
/// 获取可选择的目标列表
|
||||
/// </summary>
|
||||
/// <param name="caster"></param>
|
||||
/// <param name="attacker"></param>
|
||||
/// <param name="enemys"></param>
|
||||
/// <param name="teammates"></param>
|
||||
/// <returns></returns>
|
||||
public List<Character> GetSelectableTargets(Character caster, List<Character> enemys, List<Character> teammates)
|
||||
public List<Character> GetSelectableTargets(Character attacker, List<Character> enemys, List<Character> teammates)
|
||||
{
|
||||
List<Character> selectable = [];
|
||||
|
||||
if (CanSelectSelf)
|
||||
{
|
||||
selectable.Add(caster);
|
||||
selectable.Add(attacker);
|
||||
}
|
||||
|
||||
foreach (Character character in enemys)
|
||||
@ -263,6 +273,43 @@ namespace Milimoe.FunGame.Core.Entity
|
||||
return selectable;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 选取普攻目标
|
||||
/// </summary>
|
||||
/// <param name="attacker"></param>
|
||||
/// <param name="enemys"></param>
|
||||
/// <param name="teammates"></param>
|
||||
/// <returns></returns>
|
||||
public List<Character> SelectTargets(Character attacker, List<Character> enemys, List<Character> teammates)
|
||||
{
|
||||
List<Character> tobeSelected = GetSelectableTargets(attacker, enemys, teammates);
|
||||
|
||||
List<Character> targets = [];
|
||||
|
||||
if (SelectAllTeammates || SelectAllEnemies)
|
||||
{
|
||||
if (SelectAllTeammates)
|
||||
{
|
||||
targets.AddRange(tobeSelected.Where(c => c == attacker || teammates.Contains(c)));
|
||||
}
|
||||
if (SelectAllEnemies)
|
||||
{
|
||||
targets.AddRange(tobeSelected.Where(enemys.Contains));
|
||||
}
|
||||
}
|
||||
else if (tobeSelected.Count <= CanSelectTargetCount)
|
||||
{
|
||||
targets.AddRange(tobeSelected);
|
||||
}
|
||||
else
|
||||
{
|
||||
targets.AddRange(tobeSelected.OrderBy(x => Random.Shared.Next()).Take(CanSelectTargetCount));
|
||||
}
|
||||
|
||||
return [.. targets.Distinct()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对目标(或多个目标)发起普通攻击
|
||||
/// </summary>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
|
||||
namespace Milimoe.FunGame.Core.Interface.Entity
|
||||
{
|
||||
@ -52,6 +51,17 @@ namespace Milimoe.FunGame.Core.Interface.Entity
|
||||
/// 可选取友方角色
|
||||
/// </summary>
|
||||
public bool CanSelectTeammate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 选取所有敌对角色,优先级大于 <see cref="CanSelectTargetCount"/>
|
||||
/// </summary>
|
||||
public bool SelectAllEnemies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 选取所有友方角色,优先级大于 <see cref="CanSelectTargetCount"/>,默认包含自身
|
||||
/// </summary>
|
||||
public bool SelectAllTeammates { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 可选取的作用目标数量
|
||||
/// </summary>
|
||||
|
||||
@ -2370,11 +2370,7 @@ namespace Milimoe.FunGame.Core.Model
|
||||
List<Character> targets = await OnSelectNormalAttackTargetsAsync(character, attack, enemys, teammates);
|
||||
if (targets.Count == 0 && CharactersInAI.Contains(character))
|
||||
{
|
||||
targets = character.NormalAttack.GetSelectableTargets(character, enemys, teammates);
|
||||
if (targets.Count > 0)
|
||||
{
|
||||
targets = [targets[Random.Shared.Next(targets.Count)]];
|
||||
}
|
||||
targets = character.NormalAttack.SelectTargets(character, enemys, teammates);
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user