Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

holopad fixes #1091

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions Content.Server/Holopad/HolopadSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ private void OnHolopadAnswerCall(Entity<HolopadComponent> receiver, ref HolopadA
var source = GetLinkedHolopads(receiver).FirstOrNull();

if (source != null)

{
// Close any AI request windows
if (_stationAiSystem.TryGetStationAiCore(args.Actor, out var stationAiCore) && stationAiCore != null)
Expand All @@ -128,16 +127,15 @@ private void OnHolopadAnswerCall(Entity<HolopadComponent> receiver, ref HolopadA
// Try to warn the AI if the source of the call is out of its range
if (TryComp<TelephoneComponent>(stationAiCore, out var stationAiTelephone) &&
TryComp<TelephoneComponent>(source, out var sourceTelephone) &&
!_telephoneSystem.IsSourceInRangeOfReceiver((stationAiCore.Value.Owner, stationAiTelephone),
(source.Value.Owner, sourceTelephone)))
!_telephoneSystem.IsSourceInRangeOfReceiver((stationAiCore.Value.Owner, stationAiTelephone), (source.Value.Owner, sourceTelephone)))
{
_popupSystem.PopupEntity(Loc.GetString("holopad-ai-is-unable-to-reach-holopad"),
receiver,
args.Actor);
_popupSystem.PopupEntity(Loc.GetString("holopad-ai-is-unable-to-reach-holopad"), receiver, args.Actor);
return;
}

ActivateProjector(source.Value, args.Actor);
}

return;
}

Expand All @@ -161,8 +159,7 @@ private void OnHolopadEndCall(Entity<HolopadComponent> entity, ref HolopadEndCal
!_stationAiSystem.TryGetStationAiCore((args.Actor, stationAiHeld), out var stationAiCore))
return;

if (TryComp<TelephoneComponent>(stationAiCore, out var telephone) &&
telephone.CurrentState != TelephoneState.EndingCall && telephone.CurrentState != TelephoneState.Idle)
if (TryComp<TelephoneComponent>(stationAiCore, out var telephone))
_telephoneSystem.EndTelephoneCalls((stationAiCore.Value, telephone));
}

Expand Down Expand Up @@ -216,7 +213,8 @@ private void OnHolopadStationAiRequest(Entity<HolopadComponent> entity, ref Holo
{
var receiver = new Entity<TelephoneComponent>(receiverUid, receiverTelephone);

if (!_telephoneSystem.IsSourceAbleToReachReceiver(source, receiver))
// Check if the core can reach the call source, rather than the other way around
if (!_telephoneSystem.IsSourceAbleToReachReceiver(receiver, source))
continue;

if (_telephoneSystem.IsTelephoneEngaged(receiver))
Expand All @@ -231,10 +229,9 @@ private void OnHolopadStationAiRequest(Entity<HolopadComponent> entity, ref Holo
LinkHolopadToUser(entity, args.Actor);
}

if (!reachableAiCores.Any())
return;

_telephoneSystem.BroadcastCallToTelephones(source, reachableAiCores, args.Actor);
// Ignore range so that holopads that ignore other devices on the same grid can request the AI
var options = new TelephoneCallOptions { IgnoreRange = true };
_telephoneSystem.BroadcastCallToTelephones(source, reachableAiCores, args.Actor, options);
}

#endregion
Expand Down Expand Up @@ -355,6 +352,9 @@ private void OnHolopadUserInit(Entity<HolopadUserComponent> entity, ref Componen

private void OnHolopadShutdown(Entity<HolopadComponent> entity, ref ComponentShutdown args)
{
if (TryComp<TelephoneComponent>(entity, out var telphone) && _telephoneSystem.IsTelephoneEngaged((entity.Owner, telphone)))
_telephoneSystem.EndTelephoneCalls((entity, telphone));

ShutDownHolopad(entity);
SetHolopadAmbientState(entity, false);
}
Expand Down Expand Up @@ -611,15 +611,8 @@ private void ShutDownHolopad(Entity<HolopadComponent> entity)
UnlinkHolopadFromUser(entity, entity.Comp.User.Value);

if (TryComp<StationAiCoreComponent>(entity, out var stationAiCore))
{
_stationAiSystem.SwitchRemoteEntityMode((entity.Owner, stationAiCore), true);


if (TryComp<TelephoneComponent>(entity, out var stationAiCoreTelphone) &&
stationAiCoreTelphone.CurrentState != TelephoneState.EndingCall && stationAiCoreTelphone.CurrentState != TelephoneState.Idle)
_telephoneSystem.EndTelephoneCalls((entity, stationAiCoreTelphone));
}

Dirty(entity);
}

Expand Down Expand Up @@ -670,8 +663,12 @@ private void ActivateProjector(Entity<HolopadComponent> entity, EntityUid user)

var source = new Entity<TelephoneComponent>(stationAiCore.Value, stationAiTelephone);

// Check if the AI is unable to activate the projector (unlikely this will ever pass; its just a safeguard)
if (!_telephoneSystem.IsSourceInRangeOfReceiver(source, receiver))
{
_popupSystem.PopupEntity(Loc.GetString("holopad-ai-is-unable-to-activate-projector"), receiver, user);
return;
}

// Terminate any calls that the core is hosting and immediately connect to the receiver
_telephoneSystem.TerminateTelephoneCalls(source);
Expand Down Expand Up @@ -716,7 +713,6 @@ private void ExecuteBroadcast(Entity<HolopadComponent> source, EntityUid user)
var receiverTelephoneEntity = new Entity<TelephoneComponent>(receiver, receiverTelephone);

if (sourceTelephoneEntity == receiverTelephoneEntity ||
receiverTelephone.UnlistedNumber ||
!_telephoneSystem.IsSourceAbleToReachReceiver(sourceTelephoneEntity, receiverTelephoneEntity))
continue;

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Telephone/TelephoneSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void CallTelephone(Entity<TelephoneComponent> source, Entity<TelephoneCom

private bool TryCallTelephone(Entity<TelephoneComponent> source, Entity<TelephoneComponent> receiver, EntityUid user, TelephoneCallOptions? options = null)
{
if (!IsSourceAbleToReachReceiver(source, receiver))
if (!IsSourceAbleToReachReceiver(source, receiver) && options?.IgnoreRange != true)
return false;

if (IsTelephoneEngaged(receiver) &&
Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Telephone/TelephoneComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public record struct TelephoneCallEndedEvent();
[Serializable, NetSerializable]
public struct TelephoneCallOptions
{
public bool IgnoreRange; // The source can always reach its target
public bool ForceConnect; // The source immediately starts a call with the receiver, potentially interrupting a call that is already in progress
public bool ForceJoin; // The source smoothly joins a call in progress, or starts a normal call with the receiver if there is none
public bool MuteSource; // Chatter from the source is not transmitted - could be used for eavesdropping when combined with 'ForceJoin'
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/holopad/holopad.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ holopad-hologram-name = hologram of {THE($name)}
# Holopad actions
holopad-activate-projector-verb = Activate holopad projector
holopad-ai-is-unable-to-reach-holopad = You are unable to interface with the source of the call, it is too far from your core.
holopad-ai-is-unable-to-activate-projector = You are unable to activate the holopad's projector, it is too far from your core.
# Mapping prototypes
# General
holopad-general-tools = General - Tools
Expand Down
Loading