更新地图选取范围格子的逻辑

This commit is contained in:
milimoe 2025-09-07 22:42:11 +08:00
parent 030ef179e8
commit 09eea71cb6
Signed by: milimoe
GPG Key ID: 9554D37E4B8991D0
4 changed files with 25 additions and 9 deletions

View File

@ -813,6 +813,7 @@ namespace Milimoe.FunGame.Core.Entity
{ {
result = damageType == DamageType.Physical ? GamingQueue.CalculatePhysicalDamage(actor, enemy, false, expectedDamage, out damage, ref changeCount) : GamingQueue.CalculateMagicalDamage(actor, enemy, false, MagicType, expectedDamage, out damage, ref changeCount); result = damageType == DamageType.Physical ? GamingQueue.CalculatePhysicalDamage(actor, enemy, false, expectedDamage, out damage, ref changeCount) : GamingQueue.CalculateMagicalDamage(actor, enemy, false, MagicType, expectedDamage, out damage, ref changeCount);
} }
// 注意此方法在后台线程运行
GamingQueue.DamageToEnemyAsync(actor, enemy, damage, false, damageType, magicType, result); GamingQueue.DamageToEnemyAsync(actor, enemy, damage, false, damageType, magicType, result);
return result; return result;
} }

View File

@ -205,12 +205,13 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon
} }
/// <summary> /// <summary>
/// 获取以某个格子为中心,一定范围内的格子(曼哈顿距离),只考虑同一平面的格子,不包含中心格子 /// 获取以某个格子为中心,一定范围内的格子(曼哈顿距离),只考虑同一平面的格子
/// </summary> /// </summary>
/// <param name="grid"></param> /// <param name="grid"></param>
/// <param name="range"></param> /// <param name="range"></param>
/// <param name="includeCharacter"></param>
/// <returns></returns> /// <returns></returns>
public virtual List<Grid> GetGridsByRange(Grid grid, int range) public virtual List<Grid> GetGridsByRange(Grid grid, int range, bool includeCharacter = false)
{ {
List<Grid> grids = []; List<Grid> grids = [];
@ -226,24 +227,27 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon
int y = grid.Y + dy; int y = grid.Y + dy;
int z = grid.Z; int z = grid.Z;
if (GridsByCoordinate.TryGetValue((x, y, z), out Grid? select) && select != null) if (GridsByCoordinate.TryGetValue((x, y, z), out Grid? select) && select != null)
{
if (includeCharacter || select.Characters.Count == 0)
{ {
grids.Add(select); grids.Add(select);
} }
} }
} }
} }
grids.RemoveAll(g => g.Id == grid.Id); }
return grids; return grids;
} }
/// <summary> /// <summary>
/// 获取以某个格子为中心,一定半径内的格子(圆形范围,欧几里得距离),只考虑同一平面的格子,不包含中心格子 /// 获取以某个格子为中心,一定半径内的格子(圆形范围,欧几里得距离),只考虑同一平面的格子
/// </summary> /// </summary>
/// <param name="grid"></param> /// <param name="grid"></param>
/// <param name="range"></param> /// <param name="range"></param>
/// <param name="includeCharacter"></param>
/// <returns></returns> /// <returns></returns>
public virtual List<Grid> GetGridsByCircleRange(Grid grid, int range) public virtual List<Grid> GetGridsByCircleRange(Grid grid, int range, bool includeCharacter = false)
{ {
List<Grid> grids = []; List<Grid> grids = [];
@ -264,13 +268,15 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon
int z = grid.Z; int z = grid.Z;
if (GridsByCoordinate.TryGetValue((x, y, z), out Grid? select) && select != null) if (GridsByCoordinate.TryGetValue((x, y, z), out Grid? select) && select != null)
{
if (includeCharacter || select.Characters.Count == 0)
{ {
grids.Add(select); grids.Add(select);
} }
} }
} }
} }
grids.RemoveAll(g => g.Id == grid.Id); }
return grids; return grids;
} }

View File

@ -44,5 +44,14 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon
/// 此格子呈现的颜色(默认为 <see cref="Color.Gray"/> /// 此格子呈现的颜色(默认为 <see cref="Color.Gray"/>
/// </summary> /// </summary>
public Color Color { get; set; } = Color.Gray; public Color Color { get; set; } = Color.Gray;
/// <summary>
/// 默认的字符串表示形式
/// </summary>
/// <returns></returns>
public override string ToString()
{
return $"Grid: {Id} ({X}, {Y}, {Z})";
}
} }
} }

View File

@ -2342,7 +2342,7 @@ namespace Milimoe.FunGame.Core.Model
{ {
return target; return target;
} }
if (map.Characters.TryGetValue(character, out Grid? current) && current != null) else if (target.Id == -2 && map.Characters.TryGetValue(character, out Grid? current) && current != null)
{ {
List<Grid> grids = map.GetGridsByRange(current, character.MOV); List<Grid> grids = map.GetGridsByRange(current, character.MOV);
if (grids.Count > 0) if (grids.Count > 0)