Use faction keys for shell identity

This commit is contained in:
Meta Vens 2026-06-16 11:43:37 +01:00
commit 8ea97a08f8
11 changed files with 77 additions and 10 deletions

View file

@ -56,13 +56,20 @@ public class Faction : INamedEntry
set => Name = value;
}
public bool HasSameKey(Faction other)
{
return other != null &&
!string.IsNullOrWhiteSpace(FactionKey) &&
string.Equals(FactionKey, other.FactionKey, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode()
{
return ID.GetHashCode();
return StringComparer.OrdinalIgnoreCase.GetHashCode(FactionKey ?? "");
}
public override bool Equals(object obj)
{
return obj is Faction faction && faction.ID == ID;
return obj is Faction faction && HasSameKey(faction);
}
}

View file

@ -289,7 +289,7 @@ public abstract class Entity
// TODO: Inter-faction hostility
// When the entity faction owns the zone, they are hostile to trespassers or those hostile to them
if (Faction.ID == Zone.GalaxyZone.Owner?.ID)
if (Faction.HasSameKey(Zone.GalaxyZone.Owner))
return recursive ? !(other.PresencePermitted?.Value ?? true) : !(other.PresencePermitted?.Value ?? true)|| other.IsHostileTo(this, true);
return !recursive && other.IsHostileTo(this, true);
@ -302,7 +302,7 @@ public abstract class Entity
return FactionRelationship.Neutral;
if (this is Ship {IsPlayerShip: true})
return Zone.Galaxy.FactionRelationships[faction];
return faction.ID == Faction.ID ? FactionRelationship.Beloved : FactionRelationship.Neutral;
return faction.HasSameKey(Faction) ? FactionRelationship.Beloved : FactionRelationship.Neutral;
}
public static bool IsPresencePermitted(FactionRelationship relationship, SecurityLevel securityLevel) =>

View file

@ -254,6 +254,11 @@ public class Galaxy
private static Faction ProjectFaction(AetheriaRuntimeCorporation corporation)
{
if (string.IsNullOrWhiteSpace(corporation.CorporationKey))
{
throw new InvalidOperationException($"Typed catalog corporation {corporation.Name} has no corporation key.");
}
return new Faction
{
ID = ParseLegacyId(corporation.LegacyId, nameof(corporation.LegacyId), corporation.Name),

View file

@ -34,7 +34,7 @@ public class FactionPresenceConstraint : ZoneConstraint
protected override bool TestZone(GalaxyZone zone)
{
return zone.Factions.Any(f=>f.ID == TargetFaction?.ID);
return zone.Factions.Any(f => f.HasSameKey(TargetFaction));
}
}
@ -49,7 +49,7 @@ public class FactionOwnerConstraint : ZoneConstraint
protected override bool TestZone(GalaxyZone zone)
{
return zone.Owner.ID == TargetFaction?.ID;
return zone.Owner?.HasSameKey(TargetFaction) ?? false;
}
}
@ -86,4 +86,4 @@ public class DistanceConstraint : ZoneConstraint
{
return _targetZone != null && _test(zone.Distance[_targetZone]);
}
}
}

View file

@ -269,7 +269,7 @@ public class Zone
var security = SecurityLevel.Open;
foreach (var entity in Entities)
{
if (entity is OrbitalEntity orbitalEntity && orbitalEntity.SecurityRadius > 1 && entity.Faction.ID == GalaxyZone.Owner.ID)
if (entity is OrbitalEntity orbitalEntity && orbitalEntity.SecurityRadius > 1 && entity.Faction.HasSameKey(GalaxyZone.Owner))
{
if (orbitalEntity.SecurityLevel > security && length(orbitalEntity.Position.xz - pos) < orbitalEntity.SecurityRadius * Settings.SecureAreaRadiusMultiplier)
security = orbitalEntity.SecurityLevel;