Add `Map.GetCharacters()`
parent
4c780da552
commit
a67dedf3f9
|
@ -104,19 +104,17 @@ public partial class NPC : Character
|
|||
{
|
||||
float bestScore = float.MaxValue;
|
||||
Character bestChar = null;
|
||||
// NOTE: this relies on all Characters being under the Entities node
|
||||
foreach (Node node in GetParent().GetChildren())
|
||||
|
||||
foreach (var character in World.Instance.CurrentMap.GetCharacters())
|
||||
{
|
||||
if (node is Character character)
|
||||
{
|
||||
bool isFriendly = character.Faction == Faction;
|
||||
if (isFriendly || character.Health <= 0)
|
||||
bool isFriendly = ((IFaction)character).AlignsWith(this);
|
||||
if (isFriendly || !character.IsAlive)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
float score = 0;
|
||||
score -= Position.DistanceTo(character.Position);
|
||||
score += GlobalPosition.DistanceSquaredTo(character.GlobalPosition);
|
||||
|
||||
if (score < bestScore)
|
||||
{
|
||||
|
@ -124,7 +122,7 @@ public partial class NPC : Character
|
|||
bestChar = character;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestChar;
|
||||
}
|
||||
|
||||
|
@ -147,7 +145,7 @@ public partial class NPC : Character
|
|||
}
|
||||
|
||||
float score = 0;
|
||||
score -= Position.DistanceTo(character.Position);
|
||||
score -= Position.DistanceSquaredTo(character.Position);
|
||||
|
||||
if (score < bestScore)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using SupaLidlGame.Extensions;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SupaLidlGame.Scenes;
|
||||
|
||||
|
@ -71,6 +72,17 @@ public partial class Map : TileMap
|
|||
GetNode<Audio.AudioManager>("/root/AudioManager").PlayBackground(Music);
|
||||
}
|
||||
|
||||
public IEnumerable<Characters.Character> GetCharacters()
|
||||
{
|
||||
foreach (var child in Entities.GetChildren())
|
||||
{
|
||||
if (child is Characters.Character c)
|
||||
{
|
||||
yield return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Node SpawnEntity(PackedScene scene)
|
||||
{
|
||||
var instance = scene.Instantiate();
|
||||
|
|
Loading…
Reference in New Issue