if (source != null)
{
// Close any AI request windows
- if (_stationAiSystem.TryGetStationAiCore(args.Actor, out var stationAiCore) && stationAiCore != null)
+ if (_stationAiSystem.TryGetCore(args.Actor, out var stationAiCore))
_userInterfaceSystem.CloseUi(receiver.Owner, HolopadUiKey.AiRequestWindow, args.Actor);
// 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.Owner, stationAiTelephone), (source.Value.Owner, sourceTelephone)))
{
_popupSystem.PopupEntity(Loc.GetString("holopad-ai-is-unable-to-reach-holopad"), receiver, args.Actor);
return;
// If the user is an AI, end all calls originating from its
// associated core to ensure that any broadcasts will end
if (!TryComp<StationAiHeldComponent>(args.Actor, out var stationAiHeld) ||
- !_stationAiSystem.TryGetStationAiCore((args.Actor, stationAiHeld), out var stationAiCore))
+ !_stationAiSystem.TryGetCore(args.Actor, out var stationAiCore))
return;
if (TryComp<TelephoneComponent>(stationAiCore, out var telephone))
- _telephoneSystem.EndTelephoneCalls((stationAiCore.Value, telephone));
+ _telephoneSystem.EndTelephoneCalls((stationAiCore, telephone));
}
private void OnHolopadActivateProjector(Entity<HolopadComponent> entity, ref HolopadActivateProjectorMessage args)
// Link the AI to the holopad they are broadcasting from
LinkHolopadToUser(source, args.Actor);
- if (!_stationAiSystem.TryGetStationAiCore((args.Actor, stationAiHeld), out var stationAiCore) ||
- stationAiCore.Value.Comp.RemoteEntity == null ||
+ if (!_stationAiSystem.TryGetCore(args.Actor, out var stationAiCore) ||
+ stationAiCore.Comp?.RemoteEntity == null ||
!TryComp<HolopadComponent>(stationAiCore, out var stationAiCoreHolopad))
return;
// Execute the broadcast, but have it originate from the AI core
- ExecuteBroadcast((stationAiCore.Value, stationAiCoreHolopad), args.Actor);
+ ExecuteBroadcast((stationAiCore, stationAiCoreHolopad), args.Actor);
// Switch the AI's perspective from free roaming to the target holopad
- _xformSystem.SetCoordinates(stationAiCore.Value.Comp.RemoteEntity.Value, Transform(source).Coordinates);
- _stationAiSystem.SwitchRemoteEntityMode(stationAiCore.Value, false);
+ _xformSystem.SetCoordinates(stationAiCore.Comp.RemoteEntity.Value, Transform(source).Coordinates);
+ _stationAiSystem.SwitchRemoteEntityMode(stationAiCore, false);
return;
}
reachableAiCores.Add((receiverUid, receiverTelephone));
- if (!_stationAiSystem.TryGetInsertedAI((receiver, receiverStationAiCore), out var insertedAi))
+ if (!_stationAiSystem.TryGetHeld((receiver, receiverStationAiCore), out var insertedAi))
continue;
- if (_userInterfaceSystem.TryOpenUi(receiverUid, HolopadUiKey.AiRequestWindow, insertedAi.Value.Owner))
+ if (_userInterfaceSystem.TryOpenUi(receiverUid, HolopadUiKey.AiRequestWindow, insertedAi))
LinkHolopadToUser(entity, args.Actor);
}
return;
// Auto-close the AI request window
- if (_stationAiSystem.TryGetInsertedAI((entity, stationAiCore), out var insertedAi))
- _userInterfaceSystem.CloseUi(entity.Owner, HolopadUiKey.AiRequestWindow, insertedAi.Value.Owner);
+ if (_stationAiSystem.TryGetHeld((entity, stationAiCore), out var insertedAi))
+ _userInterfaceSystem.CloseUi(entity.Owner, HolopadUiKey.AiRequestWindow, insertedAi);
}
private void OnTelephoneMessageSent(Entity<HolopadComponent> holopad, ref TelephoneMessageSentEvent args)
if (!TryComp<StationAiHeldComponent>(entity, out var entityStationAiHeld))
return;
- if (!_stationAiSystem.TryGetStationAiCore((entity, entityStationAiHeld), out var stationAiCore))
+ if (!_stationAiSystem.TryGetCore(entity, out var stationAiCore))
return;
if (!TryComp<TelephoneComponent>(stationAiCore, out var stationAiCoreTelephone))
return;
- _telephoneSystem.EndTelephoneCalls((stationAiCore.Value, stationAiCoreTelephone));
+ _telephoneSystem.EndTelephoneCalls((stationAiCore, stationAiCoreTelephone));
}
private void AddToggleProjectorVerb(Entity<HolopadComponent> entity, ref GetVerbsEvent<AlternativeVerb> args)
if (!TryComp<StationAiHeldComponent>(user, out var userAiHeld))
return;
- if (!_stationAiSystem.TryGetStationAiCore((user, userAiHeld), out var stationAiCore) ||
- stationAiCore.Value.Comp.RemoteEntity == null)
+ if (!_stationAiSystem.TryGetCore(user, out var stationAiCore) ||
+ stationAiCore.Comp?.RemoteEntity == null)
return;
AlternativeVerb verb = new()
{
// Check if the associated holopad user is an AI
if (TryComp<StationAiHeldComponent>(entity.Comp.User, out var stationAiHeld) &&
- _stationAiSystem.TryGetStationAiCore((entity.Comp.User.Value, stationAiHeld), out var stationAiCore))
+ _stationAiSystem.TryGetCore(entity.Comp.User.Value, out var stationAiCore))
{
// Return the AI eye to free roaming
- _stationAiSystem.SwitchRemoteEntityMode(stationAiCore.Value, true);
+ _stationAiSystem.SwitchRemoteEntityMode(stationAiCore, true);
// If the AI core is still broadcasting, end its calls
- if (entity.Owner != stationAiCore.Value.Owner &&
+ if (entity.Owner != stationAiCore.Owner &&
TryComp<TelephoneComponent>(stationAiCore, out var stationAiCoreTelephone) &&
- _telephoneSystem.IsTelephoneEngaged((stationAiCore.Value.Owner, stationAiCoreTelephone)))
+ _telephoneSystem.IsTelephoneEngaged((stationAiCore.Owner, stationAiCoreTelephone)))
{
- _telephoneSystem.EndTelephoneCalls((stationAiCore.Value.Owner, stationAiCoreTelephone));
+ _telephoneSystem.EndTelephoneCalls((stationAiCore.Owner, stationAiCoreTelephone));
}
}
if (!TryComp<StationAiHeldComponent>(user, out var userAiHeld))
return;
- if (!_stationAiSystem.TryGetStationAiCore((user, userAiHeld), out var stationAiCore) ||
- stationAiCore.Value.Comp.RemoteEntity == null)
+ if (!_stationAiSystem.TryGetCore(user, out var stationAiCore) ||
+ stationAiCore.Comp?.RemoteEntity == null)
return;
if (!TryComp<TelephoneComponent>(stationAiCore, out var stationAiTelephone))
if (!TryComp<HolopadComponent>(stationAiCore, out var stationAiHolopad))
return;
- var source = new Entity<TelephoneComponent>(stationAiCore.Value, stationAiTelephone);
+ var source = new Entity<TelephoneComponent>(stationAiCore, 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))
if (!_telephoneSystem.IsSourceConnectedToReceiver(source, receiver))
return;
- LinkHolopadToUser((stationAiCore.Value, stationAiHolopad), user);
+ LinkHolopadToUser((stationAiCore, stationAiHolopad), user);
// Switch the AI's perspective from free roaming to the target holopad
- _xformSystem.SetCoordinates(stationAiCore.Value.Comp.RemoteEntity.Value, Transform(entity).Coordinates);
- _stationAiSystem.SwitchRemoteEntityMode(stationAiCore.Value, false);
+ _xformSystem.SetCoordinates(stationAiCore.Comp.RemoteEntity.Value, Transform(entity).Coordinates);
+ _stationAiSystem.SwitchRemoteEntityMode(stationAiCore, false);
// Open the holopad UI if it hasn't been opened yet
if (TryComp<UserInterfaceComponent>(entity, out var entityUserInterfaceComponent))
/// <summary>
/// Tries to get the entity held in the AI core using StationAiCore.
/// </summary>
- private bool TryGetHeld(Entity<StationAiCoreComponent?> entity, out EntityUid held)
+ public bool TryGetHeld(Entity<StationAiCoreComponent?> entity, out EntityUid held)
{
held = EntityUid.Invalid;
/// <summary>
/// Tries to get the entity held in the AI using StationAiHolder.
/// </summary>
- private bool TryGetHeldFromHolder(Entity<StationAiHolderComponent?> entity, out EntityUid held)
+ public bool TryGetHeld(Entity<StationAiHolderComponent?> entity, out EntityUid held)
{
- held = EntityUid.Invalid;
-
- if (!Resolve(entity.Owner, ref entity.Comp))
- return false;
-
- if (!_containers.TryGetContainer(entity.Owner, StationAiHolderComponent.Container, out var container) ||
- container.ContainedEntities.Count == 0)
- return false;
+ TryComp<StationAiCoreComponent>(entity.Owner, out var stationAiCore);
- held = container.ContainedEntities[0];
- return true;
+ return TryGetHeld((entity.Owner, stationAiCore), out held);
}
- private bool TryGetCore(EntityUid ent, out Entity<StationAiCoreComponent?> core)
+ public bool TryGetCore(EntityUid entity, out Entity<StationAiCoreComponent?> core)
{
+ var xform = Transform(entity);
+ var meta = MetaData(entity);
+ var ent = new Entity<TransformComponent?, MetaDataComponent?>(entity, xform, meta);
+
if (!_containers.TryGetContainingContainer(ent, out var container) ||
container.ID != StationAiCoreComponent.Container ||
!TryComp(container.Owner, out StationAiCoreComponent? coreComp) ||
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
-using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
return;
}
- if (TryGetHeldFromHolder((args.Target.Value, targetHolder), out var held) && _timing.CurTime > intelliComp.NextWarningAllowed)
+ if (TryGetHeld((args.Target.Value, targetHolder), out var held) && _timing.CurTime > intelliComp.NextWarningAllowed)
{
intelliComp.NextWarningAllowed = _timing.CurTime + intelliComp.WarningDelay;
AnnounceIntellicardUsage(held, intelliComp.WarningSound);
AttachEye(ent);
}
- public void SwitchRemoteEntityMode(Entity<StationAiCoreComponent> ent, bool isRemote)
+ public void SwitchRemoteEntityMode(Entity<StationAiCoreComponent?> entity, bool isRemote)
{
- if (isRemote == ent.Comp.Remote)
+ if (entity.Comp?.Remote == null || entity.Comp.Remote == isRemote)
return;
+ var ent = new Entity<StationAiCoreComponent>(entity.Owner, entity.Comp);
+
ent.Comp.Remote = isRemote;
EntityCoordinates? coords = ent.Comp.RemoteEntity != null ? Transform(ent.Comp.RemoteEntity.Value).Coordinates : null;
return _blocker.CanComplexInteract(entity.Owner);
}
-
- public bool TryGetStationAiCore(Entity<StationAiHeldComponent?> ent, [NotNullWhen(true)] out Entity<StationAiCoreComponent>? parentEnt)
- {
- parentEnt = null;
- var parent = Transform(ent).ParentUid;
-
- if (!parent.IsValid())
- return false;
-
- if (!TryComp<StationAiCoreComponent>(parent, out var stationAiCore))
- return false;
-
- parentEnt = new Entity<StationAiCoreComponent>(parent, stationAiCore);
-
- return true;
- }
-
- public bool TryGetInsertedAI(Entity<StationAiCoreComponent> ent, [NotNullWhen(true)] out Entity<StationAiHeldComponent>? insertedAi)
- {
- insertedAi = null;
- var insertedEnt = GetInsertedAI(ent);
-
- if (TryComp<StationAiHeldComponent>(insertedEnt, out var stationAiHeld))
- {
- insertedAi = (insertedEnt.Value, stationAiHeld);
- return true;
- }
-
- return false;
- }
}
public sealed partial class JumpToCoreEvent : InstantActionEvent