Skip to content

Commit 41b8e4a

Browse files
authored
Add Faction friends to Destroyable component (#246)
* Add Faction friends to Destroyable component * Match code style
1 parent df9e510 commit 41b8e4a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Uchu.World/Objects/Components/DestroyableComponent.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class DestroyableComponent : Component, ISavableComponent
2727

2828
public int[] Factions { get; set; } = new int[0];
2929

30+
public int[] Friends { get; set; } = new int[0];
31+
3032
public int[] Enemies { get; set; } = new int[0];
3133

3234
public uint DamageAbsorptionPoints { get; set; }
@@ -252,6 +254,16 @@ protected DestroyableComponent()
252254
.Split(',')
253255
.Select(int.Parse)
254256
.ToArray();
257+
258+
if (faction?.FriendList == default) return;
259+
260+
if (string.IsNullOrWhiteSpace(faction.FriendList)) return;
261+
262+
Friends = faction.FriendList
263+
.Replace(" ", "")
264+
.Split(',')
265+
.Select(int.Parse)
266+
.ToArray();
255267
});
256268

257269
Listen(OnDestroyed, () =>
@@ -454,4 +466,4 @@ public async Task SaveAsync(UchuContext context)
454466
Logger.Debug($"Saved character stats for {GameObject}");
455467
}
456468
}
457-
}
469+
}

Uchu.World/Objects/Components/ReplicaComponents/BaseCombatAIComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public GameObject[] SeekValidTargets()
150150
if (entry.GameObject.TryGetComponent<TriggerComponent>(out _))
151151
continue;
152152

153-
if (Stats.Enemies.Contains(entry.Factions.First()))
153+
if (Stats.Enemies.Contains(entry.Factions.First()) && !Stats.Friends.Contains(entry.Factions.First()))
154154
{
155155
targets.Add(entry.GameObject);
156156
}

0 commit comments

Comments
 (0)