forked from Simple-Station/Einstein-Engines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Simple-Station#92 from SS14-Classic/Update-10/27/2024
Update 10/27/2024
- Loading branch information
Showing
55 changed files
with
3,050 additions
and
1,908 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
Content.Server/Abilities/Psionics/PsionicFamiliarSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using Content.Server.NPC; | ||
using Content.Server.NPC.Components; | ||
using Content.Server.NPC.HTN; | ||
using Content.Server.NPC.Systems; | ||
using Content.Server.Popups; | ||
using Content.Shared.Abilities.Psionics; | ||
using Content.Shared.Actions.Events; | ||
using Content.Shared.Interaction.Events; | ||
using Content.Shared.Mobs; | ||
using Robust.Shared.Map; | ||
using System.Numerics; | ||
|
||
namespace Content.Server.Abilities.Psionics; | ||
|
||
public sealed partial class PsionicFamiliarSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedPsionicAbilitiesSystem _psionics = default!; | ||
[Dependency] private readonly NpcFactionSystem _factions = default!; | ||
[Dependency] private readonly NPCSystem _npc = default!; | ||
[Dependency] private readonly HTNSystem _htn = default!; | ||
[Dependency] private readonly PopupSystem _popup = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<PsionicComponent, SummonPsionicFamiliarActionEvent>(OnSummon); | ||
SubscribeLocalEvent<PsionicFamiliarComponent, ComponentShutdown>(OnFamiliarShutdown); | ||
SubscribeLocalEvent<PsionicFamiliarComponent, AttackAttemptEvent>(OnFamiliarAttack); | ||
SubscribeLocalEvent<PsionicFamiliarComponent, MobStateChangedEvent>(OnFamiliarDeath); | ||
} | ||
|
||
private void OnSummon(EntityUid uid, PsionicComponent psionicComponent, SummonPsionicFamiliarActionEvent args) | ||
{ | ||
if (psionicComponent.Familiars.Count >= psionicComponent.FamiliarLimit | ||
|| !_psionics.OnAttemptPowerUse(args.Performer, args.PowerName, args.ManaCost, args.CheckInsulation) | ||
|| args.Handled || args.FamiliarProto is null) | ||
return; | ||
|
||
args.Handled = true; | ||
var familiar = Spawn(args.FamiliarProto, Transform(uid).Coordinates); | ||
EnsureComp<PsionicFamiliarComponent>(familiar, out var familiarComponent); | ||
familiarComponent.Master = uid; | ||
psionicComponent.Familiars.Add(familiar); | ||
Dirty(familiar, familiarComponent); | ||
Dirty(uid, psionicComponent); | ||
|
||
InheritFactions(uid, familiar, familiarComponent); | ||
HandleBlackboards(uid, familiar, args); | ||
DoGlimmerEffects(uid, psionicComponent, args); | ||
} | ||
|
||
private void InheritFactions(EntityUid uid, EntityUid familiar, PsionicFamiliarComponent familiarComponent) | ||
{ | ||
if (!familiarComponent.InheritMasterFactions | ||
|| !TryComp<NpcFactionMemberComponent>(uid, out var masterFactions) | ||
|| masterFactions.Factions.Count <= 0) | ||
return; | ||
|
||
EnsureComp<NpcFactionMemberComponent>(familiar, out var familiarFactions); | ||
foreach (var faction in masterFactions.Factions) | ||
{ | ||
if (familiarFactions.Factions.Contains(faction)) | ||
continue; | ||
|
||
_factions.AddFaction(familiar, faction, true); | ||
} | ||
} | ||
|
||
private void HandleBlackboards(EntityUid master, EntityUid familiar, SummonPsionicFamiliarActionEvent args) | ||
{ | ||
if (!args.FollowMaster | ||
|| !TryComp<HTNComponent>(familiar, out var htnComponent)) | ||
return; | ||
|
||
_npc.SetBlackboard(familiar, NPCBlackboard.FollowTarget, new EntityCoordinates(master, Vector2.Zero), htnComponent); | ||
_htn.Replan(htnComponent); | ||
} | ||
|
||
private void DoGlimmerEffects(EntityUid uid, PsionicComponent component, SummonPsionicFamiliarActionEvent args) | ||
{ | ||
if (!args.DoGlimmerEffects | ||
|| args.MinGlimmer == 0 && args.MaxGlimmer == 0) | ||
return; | ||
|
||
var minGlimmer = (int) Math.Round(MathF.MinMagnitude(args.MinGlimmer, args.MaxGlimmer) | ||
* component.CurrentAmplification - component.CurrentDampening); | ||
var maxGlimmer = (int) Math.Round(MathF.MaxMagnitude(args.MinGlimmer, args.MaxGlimmer) | ||
* component.CurrentAmplification - component.CurrentDampening); | ||
|
||
_psionics.LogPowerUsed(uid, args.PowerName, minGlimmer, maxGlimmer); | ||
} | ||
|
||
private void OnFamiliarShutdown(EntityUid uid, PsionicFamiliarComponent component, ComponentShutdown args) | ||
{ | ||
if (!Exists(component.Master) | ||
|| !TryComp<PsionicComponent>(component.Master, out var psionicComponent) | ||
|| !psionicComponent.Familiars.Contains(uid)) | ||
return; | ||
|
||
psionicComponent.Familiars.Remove(uid); | ||
} | ||
|
||
private void OnFamiliarAttack(EntityUid uid, PsionicFamiliarComponent component, AttackAttemptEvent args) | ||
{ | ||
if (component.CanAttackMaster || args.Target is null | ||
|| args.Target != component.Master) | ||
return; | ||
|
||
args.Cancel(); | ||
if (!Loc.TryGetString(component.AttackMasterText, out var attackFailMessage)) | ||
return; | ||
|
||
_popup.PopupEntity(attackFailMessage, uid, uid, component.AttackPopupType); | ||
} | ||
|
||
private void OnFamiliarDeath(EntityUid uid, PsionicFamiliarComponent component, MobStateChangedEvent args) | ||
{ | ||
if (!component.DespawnOnFamiliarDeath | ||
|| args.NewMobState != MobState.Dead) | ||
return; | ||
|
||
DespawnFamiliar(uid, component); | ||
} | ||
|
||
public void DespawnFamiliar(EntityUid uid) | ||
{ | ||
if (!TryComp<PsionicFamiliarComponent>(uid, out var familiarComponent)) | ||
return; | ||
|
||
DespawnFamiliar(uid, familiarComponent); | ||
} | ||
|
||
public void DespawnFamiliar(EntityUid uid, PsionicFamiliarComponent component) | ||
{ | ||
var popupText = Loc.GetString(component.DespawnText, ("entity", MetaData(uid).EntityName)); | ||
_popup.PopupEntity(popupText, uid, component.DespawnPopopType); | ||
QueueDel(uid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Content.Server.Chat.Managers; | ||
using Content.Shared.Alert; | ||
using Content.Shared.Chat; | ||
using Content.Shared.Damage; | ||
using Content.Shared.HealthExaminable; | ||
using JetBrains.Annotations; | ||
using Robust.Server.Player; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Server.Alert.Click; | ||
|
||
[UsedImplicitly] | ||
[DataDefinition] | ||
public sealed partial class CheckHealth : IAlertClick | ||
{ | ||
public void AlertClicked(EntityUid player) | ||
{ | ||
var chatManager = IoCManager.Resolve<IChatManager>(); | ||
var entityManager = IoCManager.Resolve<IEntityManager>(); | ||
var playerManager = IoCManager.Resolve<IPlayerManager>(); | ||
|
||
var healthExaminableSystem = entityManager.System<HealthExaminableSystem>(); | ||
|
||
if (!entityManager.TryGetComponent(player, out HealthExaminableComponent? healthExaminable) || | ||
!entityManager.TryGetComponent(player, out DamageableComponent? damageable) || | ||
!playerManager.TryGetSessionByEntity(player, out var session)) | ||
return; | ||
|
||
var baseMsg = Loc.GetString("health-alert-start"); | ||
SendMessage(chatManager, baseMsg, session); | ||
var markup = healthExaminableSystem.GetMarkup(player, (player, healthExaminable), damageable).ToMarkup(); | ||
SendMessage(chatManager, markup, session); | ||
} | ||
|
||
private static void SendMessage(IChatManager chatManager, string msg, ICommonSession session) | ||
{ | ||
chatManager.ChatMessageToOne(ChatChannel.Emotes, | ||
msg, | ||
msg, | ||
EntityUid.Invalid, | ||
false, | ||
session.Channel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.