Skip to content

Commit

Permalink
Move faction exception and everything it needs to shared (#25154)
Browse files Browse the repository at this point in the history
* move faction prototype to shared

* move faction exception and member stuff to shared

* fix breaking changes for random stuff

* move pettable friend stuff to shared

* mostly fix

* final fixy

* dragonops

* final fixy II

* use querys and fix warpspeed fish (probably)

* fixer

* Rrrr!

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: metalgearsloth <[email protected]>
  • Loading branch information
deltanedas and metalgearsloth authored Mar 18, 2024
1 parent 0493130 commit 7561bef
Show file tree
Hide file tree
Showing 29 changed files with 449 additions and 408 deletions.
2 changes: 0 additions & 2 deletions Content.Client/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ public override void Init()
_prototypeManager.RegisterIgnore("seed"); // Seeds prototypes are server-only.
_prototypeManager.RegisterIgnore("objective");
_prototypeManager.RegisterIgnore("holiday");
_prototypeManager.RegisterIgnore("aiFaction");
_prototypeManager.RegisterIgnore("htnCompound");
_prototypeManager.RegisterIgnore("htnPrimitive");
_prototypeManager.RegisterIgnore("gameMap");
_prototypeManager.RegisterIgnore("gameMapPool");
_prototypeManager.RegisterIgnore("npcFaction");
_prototypeManager.RegisterIgnore("lobbyBackground");
_prototypeManager.RegisterIgnore("advertisementsPack");
_prototypeManager.RegisterIgnore("gamePreset");
Expand Down
8 changes: 8 additions & 0 deletions Content.Server/Dragon/Components/DragonComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.NPC.Prototypes;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
Expand Down Expand Up @@ -57,5 +58,12 @@ public sealed partial class DragonComponent : Component
{
Params = AudioParams.Default.WithVolume(3f),
};

/// <summary>
/// NPC faction to re-add after being zombified.
/// Prevents zombie dragon from being attacked by its own carp.
/// </summary>
[DataField]
public ProtoId<NpcFactionPrototype> Faction = "Dragon";
}
}
10 changes: 10 additions & 0 deletions Content.Server/Dragon/DragonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Content.Shared.Mind.Components;
using Content.Shared.Mobs;
using Content.Shared.Movement.Systems;
using Content.Shared.NPC.Systems;
using Content.Shared.Zombies;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.GameStates;
Expand All @@ -24,6 +26,7 @@ public sealed partial class DragonSystem : EntitySystem
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDef = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly NpcFactionSystem _faction = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly RoleSystem _role = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
Expand Down Expand Up @@ -55,6 +58,7 @@ public override void Initialize()
SubscribeLocalEvent<DragonComponent, RefreshMovementSpeedModifiersEvent>(OnDragonMove);
SubscribeLocalEvent<DragonComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<DragonComponent, GenericAntagCreatedEvent>(OnCreated);
SubscribeLocalEvent<DragonComponent, EntityZombifiedEvent>(OnZombified);
}

public override void Update(float frameTime)
Expand Down Expand Up @@ -202,6 +206,12 @@ private void OnCreated(EntityUid uid, DragonComponent comp, ref GenericAntagCrea
}, mind);
}

private void OnZombified(Entity<DragonComponent> ent, ref EntityZombifiedEvent args)
{
// prevent carp attacking zombie dragon
_faction.AddFaction(ent.Owner, ent.Comp.Faction);
}

private void Roar(EntityUid uid, DragonComponent comp)
{
if (comp.SoundRoar != null)
Expand Down
23 changes: 0 additions & 23 deletions Content.Server/Friends/Components/PettableFriendComponent.cs

This file was deleted.

50 changes: 0 additions & 50 deletions Content.Server/Friends/Systems/PettableFriendSystem.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Content.Server.Maps;
using Content.Server.NPC.Components;
using Content.Server.RoundEnd;
using Content.Server.StationEvents.Events;
using Content.Shared.Dataset;
using Content.Shared.NPC.Prototypes;
using Content.Shared.Roles;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Content.Server.NPC.Components;
using Content.Shared.Dataset;
using Content.Shared.NPC.Prototypes;
using Content.Shared.Random;
using Content.Shared.Roles;
using Robust.Shared.Audio;
Expand Down
6 changes: 3 additions & 3 deletions Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using Content.Server.Ghost.Roles.Events;
using Content.Server.Humanoid;
using Content.Server.Mind;
using Content.Server.NPC.Components;
using Content.Server.NPC.Systems;
using Content.Server.Nuke;
using Content.Server.NukeOps;
using Content.Server.Popups;
Expand All @@ -30,6 +28,8 @@
using Content.Shared.Mind.Components;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Systems;
using Content.Shared.Nuke;
using Content.Shared.NukeOps;
using Content.Shared.Preferences;
Expand Down Expand Up @@ -474,7 +474,7 @@ private void OnRoundStart(EntityUid uid, NukeopsRuleComponent? component = null)
var eligibleQuery = EntityQueryEnumerator<StationEventEligibleComponent, NpcFactionMemberComponent>();
while (eligibleQuery.MoveNext(out var eligibleUid, out var eligibleComp, out var member))
{
if (!_npcFaction.IsFactionHostile(component.Faction, eligibleUid, member))
if (!_npcFaction.IsFactionHostile(component.Faction, (eligibleUid, member)))
continue;

eligible.Add((eligibleUid, eligibleComp, member));
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/GameTicking/Rules/PiratesRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Content.Server.Cargo.Systems;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.NPC.Components;
using Content.Server.NPC.Systems;
using Content.Server.Preferences.Managers;
using Content.Server.Spawners.Components;
using Content.Server.Station.Components;
Expand All @@ -14,6 +12,8 @@
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Mind;
using Content.Shared.NPC.Prototypes;
using Content.Shared.NPC.Systems;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Robust.Server.GameObjects;
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Content.Server.Flash;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Mind;
using Content.Server.NPC.Components;
using Content.Server.NPC.Systems;
using Content.Server.Popups;
using Content.Server.Revolutionary;
using Content.Server.Revolutionary.Components;
Expand All @@ -23,6 +21,8 @@
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.NPC.Prototypes;
using Content.Shared.NPC.Systems;
using Content.Shared.Revolutionary.Components;
using Content.Shared.Roles;
using Content.Shared.Stunnable;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Content.Server.Antag;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Mind;
using Content.Server.NPC.Systems;
using Content.Server.Objectives;
using Content.Server.PDA.Ringer;
using Content.Server.Roles;
Expand All @@ -10,6 +9,7 @@
using Content.Shared.Dataset;
using Content.Shared.Mind;
using Content.Shared.Mobs.Systems;
using Content.Shared.NPC.Systems;
using Content.Shared.Objectives.Components;
using Content.Shared.PDA;
using Content.Shared.Roles;
Expand Down
16 changes: 0 additions & 16 deletions Content.Server/NPC/Components/FactionExceptionTrackerComponent.cs

This file was deleted.

29 changes: 0 additions & 29 deletions Content.Server/NPC/Components/NpcFactionMemberComponent.cs

This file was deleted.

22 changes: 0 additions & 22 deletions Content.Server/NPC/Components/NpcFactionPrototype.cs

This file was deleted.

13 changes: 0 additions & 13 deletions Content.Server/NPC/FactionData.cs

This file was deleted.

32 changes: 17 additions & 15 deletions Content.Server/NPC/Systems/NPCRetaliationSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Content.Server.NPC.Components;
using Content.Server.NPC.Components;
using Content.Shared.CombatMode;
using Content.Shared.Damage;
using Content.Shared.Mobs.Components;
using Content.Shared.NPC.Components;
using Content.Shared.NPC.Systems;
using Robust.Shared.Collections;
using Robust.Shared.Timing;

Expand All @@ -22,37 +24,35 @@ public override void Initialize()
SubscribeLocalEvent<NPCRetaliationComponent, DisarmedEvent>(OnDisarmed);
}

private void OnDamageChanged(EntityUid uid, NPCRetaliationComponent component, DamageChangedEvent args)
private void OnDamageChanged(Entity<NPCRetaliationComponent> ent, ref DamageChangedEvent args)
{
if (!args.DamageIncreased)
return;

if (args.Origin is not { } origin)
if (args.Origin is not {} origin)
return;

TryRetaliate(uid, origin, component);
TryRetaliate(ent, origin);
}

private void OnDisarmed(EntityUid uid, NPCRetaliationComponent component, DisarmedEvent args)
private void OnDisarmed(Entity<NPCRetaliationComponent> ent, ref DisarmedEvent args)
{
TryRetaliate(uid, args.Source, component);
TryRetaliate(ent, args.Source);
}

public bool TryRetaliate(EntityUid uid, EntityUid target, NPCRetaliationComponent? component = null)
public bool TryRetaliate(Entity<NPCRetaliationComponent> ent, EntityUid target)
{
if (!Resolve(uid, ref component))
return false;

// don't retaliate against inanimate objects.
if (!HasComp<MobStateComponent>(target))
return false;

if (_npcFaction.IsEntityFriendly(uid, target))
// don't retaliate against the same faction
if (_npcFaction.IsEntityFriendly(ent.Owner, target))
return false;

_npcFaction.AggroEntity(uid, target);
if (component.AttackMemoryLength is { } memoryLength)
component.AttackMemories[target] = _timing.CurTime + memoryLength;
_npcFaction.AggroEntity(ent.Owner, target);
if (ent.Comp.AttackMemoryLength is {} memoryLength)
ent.Comp.AttackMemories[target] = _timing.CurTime + memoryLength;

return true;
}
Expand All @@ -64,12 +64,14 @@ public override void Update(float frameTime)
var query = EntityQueryEnumerator<NPCRetaliationComponent, FactionExceptionComponent>();
while (query.MoveNext(out var uid, out var retaliationComponent, out var factionException))
{
// TODO: can probably reuse this allocation and clear it
foreach (var entity in new ValueList<EntityUid>(retaliationComponent.AttackMemories.Keys))
{
if (!TerminatingOrDeleted(entity) && _timing.CurTime < retaliationComponent.AttackMemories[entity])
continue;

_npcFaction.DeAggroEntity(uid, entity, factionException);
_npcFaction.DeAggroEntity((uid, factionException), entity);
// TODO: should probably remove the AttackMemory, thats the whole point of the ValueList right??
}
}
}
Expand Down
Loading

0 comments on commit 7561bef

Please sign in to comment.