Add ability to add additional friendly and hostile factions in prototypes (#29636)
* Make friendly and hostile factions in NpcFactionMemberComponent datafiels * :trollface: * :trollface:
This commit is contained in:
parent
54e11ab949
commit
73f02aaa0b
|
|
@ -30,7 +30,7 @@ namespace Content.Server.Psionics
|
|||
[Dependency] private readonly MindSwapPowerSystem _mindSwapPowerSystem = default!;
|
||||
[Dependency] private readonly GlimmerSystem _glimmerSystem = default!;
|
||||
[Dependency] private readonly ChatSystem _chat = default!;
|
||||
[Dependency] private readonly NpcFactionSystem _npcFactonSystem = default!;
|
||||
[Dependency] private readonly NpcFactionSystem _faction = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
|
||||
|
|
@ -98,10 +98,10 @@ namespace Content.Server.Psionics
|
|||
if (!TryComp<NpcFactionMemberComponent>(uid, out var factions))
|
||||
return;
|
||||
|
||||
if (_npcFactonSystem.ContainsFaction(uid, "GlimmerMonster", factions))
|
||||
if (_faction.IsMember((uid, factions), "GlimmerMonster"))
|
||||
return;
|
||||
|
||||
_npcFactonSystem.AddFaction(uid, "PsionicInterloper");
|
||||
_faction.AddFaction((uid, factions) "PsionicInterloper");
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, PsionicComponent component, ComponentRemove args)
|
||||
|
|
@ -109,7 +109,7 @@ namespace Content.Server.Psionics
|
|||
if (!TryComp<NpcFactionMemberComponent>(uid, out var factions))
|
||||
return;
|
||||
|
||||
_npcFactonSystem.RemoveFaction(uid, "PsionicInterloper");
|
||||
_faction.RemoveFaction((uid, factions), "PsionicInterloper");
|
||||
}
|
||||
|
||||
private void OnStamHit(EntityUid uid, AntiPsionicWeaponComponent component, StaminaMeleeHitEvent args)
|
||||
|
|
|
|||
|
|
@ -26,11 +26,15 @@ public sealed partial class NpcFactionMemberComponent : Component
|
|||
[ViewVariables]
|
||||
public readonly HashSet<ProtoId<NpcFactionPrototype>> HostileFactions = new();
|
||||
|
||||
// Nyano - Summary - Begin modified code block: support for specific entities to be friendly.
|
||||
/// <summary>
|
||||
/// Permanently friendly specific entities. Our summoner, etc.
|
||||
/// Would like to separate. Could I do that by extending this method, maybe?
|
||||
/// Used to add friendly factions in prototypes.
|
||||
/// </summary>
|
||||
public HashSet<EntityUid> ExceptionalFriendlies = new();
|
||||
// Nyano - End modified code block.
|
||||
[DataField, ViewVariables]
|
||||
public HashSet<ProtoId<NpcFactionPrototype>>? AddFriendlyFactions;
|
||||
|
||||
/// <summary>
|
||||
/// Used to add hostile factions in prototypes.
|
||||
/// </summary>
|
||||
[DataField, ViewVariables]
|
||||
public HashSet<ProtoId<NpcFactionPrototype>>? AddHostileFactions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,15 @@ public sealed partial class NpcFactionSystem : EntitySystem
|
|||
ent.Comp.FriendlyFactions.UnionWith(factionData.Friendly);
|
||||
ent.Comp.HostileFactions.UnionWith(factionData.Hostile);
|
||||
}
|
||||
// Add additional factions if it is written in prototype
|
||||
if (ent.Comp.AddFriendlyFactions != null)
|
||||
{
|
||||
ent.Comp.FriendlyFactions.UnionWith(ent.Comp.AddFriendlyFactions);
|
||||
}
|
||||
if (ent.Comp.AddHostileFactions != null)
|
||||
{
|
||||
ent.Comp.HostileFactions.UnionWith(ent.Comp.AddHostileFactions);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
using Content.Shared.NPC.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.NPC.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows clothing to add a faction to you when you wear it.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class ClothingAddFactionComponent : Component
|
||||
{
|
||||
public bool IsActive = false;
|
||||
|
||||
/// <summary>
|
||||
/// Faction added
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite),
|
||||
DataField("faction", required: true, customTypeSerializer:typeof(PrototypeIdSerializer<NpcFactionPrototype>))]
|
||||
public string Faction = "";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
using Content.Shared.NPC.Components;
|
||||
|
||||
namespace Content.Shared.NPC.Systems;
|
||||
|
||||
public partial class NpcFactionSystem : EntitySystem
|
||||
{
|
||||
public void InitializeCore()
|
||||
{
|
||||
SubscribeLocalEvent<NpcFactionMemberComponent, GetNearbyHostilesEvent>(OnGetNearbyHostiles);
|
||||
}
|
||||
|
||||
public bool ContainsFaction(EntityUid uid, string faction, NpcFactionMemberComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return false;
|
||||
|
||||
return component.Factions.Contains(faction);
|
||||
}
|
||||
|
||||
public void AddFriendlyEntity(EntityUid uid, EntityUid fEntity, NpcFactionMemberComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return;
|
||||
|
||||
component.ExceptionalFriendlies.Add(fEntity);
|
||||
}
|
||||
|
||||
private void OnGetNearbyHostiles(EntityUid uid, NpcFactionMemberComponent component, ref GetNearbyHostilesEvent args)
|
||||
{
|
||||
args.ExceptionalFriendlies.UnionWith(component.ExceptionalFriendlies);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on an entity when it's trying to determine which nearby entities are hostile.
|
||||
/// </summary>
|
||||
/// <param name="ExceptionalHostiles">Entities that will be counted as hostile regardless of faction. Overriden by friendlies.</param>
|
||||
/// <param name="ExceptionalFriendlies">Entities that will be counted as friendly regardless of faction. Overrides hostiles. </param>
|
||||
[ByRefEvent]
|
||||
public readonly record struct GetNearbyHostilesEvent(HashSet<EntityUid> ExceptionalHostiles, HashSet<EntityUid> ExceptionalFriendlies);
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.NPC.Components;
|
||||
|
||||
namespace Content.Shared.NPC.Systems;
|
||||
|
||||
public partial class NpcFactionSystem : EntitySystem
|
||||
{
|
||||
public void InitializeItems()
|
||||
{
|
||||
// SubscribeLocalEvent<NpcFactionMemberComponent, ItemPurchasedEvent>(OnItemPurchased);
|
||||
|
||||
SubscribeLocalEvent<ClothingAddFactionComponent, GotEquippedEvent>(OnClothingEquipped);
|
||||
SubscribeLocalEvent<ClothingAddFactionComponent, GotUnequippedEvent>(OnClothingUnequipped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If we bought something we probably don't want it to start biting us after it's automatically placed in our hands.
|
||||
/// If you do, consider finding a better solution to grenade penguin CBT.
|
||||
/// </summary>
|
||||
// private void OnItemPurchased(EntityUid uid, NpcFactionMemberComponent component, ref ItemPurchasedEvent args)
|
||||
// {
|
||||
// component.ExceptionalFriendlies.Add(args.Purchaser);
|
||||
// }
|
||||
|
||||
private void OnClothingEquipped(EntityUid uid, ClothingAddFactionComponent component, GotEquippedEvent args)
|
||||
{
|
||||
if (!TryComp<ClothingComponent>(uid, out var clothing))
|
||||
return;
|
||||
|
||||
if (!clothing.Slots.HasFlag(args.SlotFlags))
|
||||
return;
|
||||
|
||||
if (!TryComp<NpcFactionMemberComponent>(args.Equipee, out var factionComponent))
|
||||
return;
|
||||
|
||||
if (factionComponent.Factions.Contains(component.Faction))
|
||||
return;
|
||||
|
||||
component.IsActive = true;
|
||||
AddFaction(args.Equipee, component.Faction);
|
||||
}
|
||||
|
||||
private void OnClothingUnequipped(EntityUid uid, ClothingAddFactionComponent component, GotUnequippedEvent args)
|
||||
{
|
||||
if (!component.IsActive)
|
||||
return;
|
||||
|
||||
component.IsActive = false;
|
||||
RemoveFaction(args.Equipee, component.Faction);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
sprite: Nyanotrasen/Clothing/Uniforms/Jumpsuit/mailman.rsi
|
||||
- type: Clothing
|
||||
sprite: Nyanotrasen/Clothing/Uniforms/Jumpsuit/mailman.rsi
|
||||
# - type: ClothingAddFaction
|
||||
# - type: FactionClothing
|
||||
# faction: Mailman
|
||||
|
||||
- type: entity
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
sprite: Nyanotrasen/Clothing/Uniforms/Jumpskirt/mailman.rsi
|
||||
- type: Clothing
|
||||
sprite: Nyanotrasen/Clothing/Uniforms/Jumpskirt/mailman.rsi
|
||||
# - type: ClothingAddFaction
|
||||
# - type: FactionClothing
|
||||
# faction: Mailman
|
||||
|
||||
- type: entity
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit a9aea7027f1840c83bcaf1c973caf099745f9eed
|
||||
Subproject commit 860c9af2bfbf1477b96519067ef5e62b2525d987
|
||||
Loading…
Reference in New Issue