Add `Map.GetCharacters()`
parent
4c780da552
commit
a67dedf3f9
|
@ -104,27 +104,25 @@ public partial class NPC : Character
|
||||||
{
|
{
|
||||||
float bestScore = float.MaxValue;
|
float bestScore = float.MaxValue;
|
||||||
Character bestChar = null;
|
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 = ((IFaction)character).AlignsWith(this);
|
||||||
|
if (isFriendly || !character.IsAlive)
|
||||||
{
|
{
|
||||||
bool isFriendly = character.Faction == Faction;
|
continue;
|
||||||
if (isFriendly || character.Health <= 0)
|
}
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
float score = 0;
|
float score = 0;
|
||||||
score -= Position.DistanceTo(character.Position);
|
score += GlobalPosition.DistanceSquaredTo(character.GlobalPosition);
|
||||||
|
|
||||||
if (score < bestScore)
|
if (score < bestScore)
|
||||||
{
|
{
|
||||||
bestScore = score;
|
bestScore = score;
|
||||||
bestChar = character;
|
bestChar = character;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestChar;
|
return bestChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +145,7 @@ public partial class NPC : Character
|
||||||
}
|
}
|
||||||
|
|
||||||
float score = 0;
|
float score = 0;
|
||||||
score -= Position.DistanceTo(character.Position);
|
score -= Position.DistanceSquaredTo(character.Position);
|
||||||
|
|
||||||
if (score < bestScore)
|
if (score < bestScore)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
using SupaLidlGame.Extensions;
|
using SupaLidlGame.Extensions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SupaLidlGame.Scenes;
|
namespace SupaLidlGame.Scenes;
|
||||||
|
|
||||||
|
@ -71,6 +72,17 @@ public partial class Map : TileMap
|
||||||
GetNode<Audio.AudioManager>("/root/AudioManager").PlayBackground(Music);
|
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)
|
public Node SpawnEntity(PackedScene scene)
|
||||||
{
|
{
|
||||||
var instance = scene.Instantiate();
|
var instance = scene.Instantiate();
|
||||||
|
|
Loading…
Reference in New Issue