Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Station AI Improvements
Browse files Browse the repository at this point in the history
- ToggleHealthOverlay Action
- Moved files to better paths
- Shared the disallowed events to prevent desync
  • Loading branch information
DEATHB4DEFEAT committed Feb 19, 2023
1 parent e478961 commit da14a79
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Content.Shared.EntityHealthBar;
using Content.Shared.SimpleStation14.StationAI.Events;

namespace Content.Client.SimpleStation14.StationAI
{
public sealed class StationAISystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeNetworkEvent<NetworkedAIHealthOverlayEvent>(OnHealthOverlayEvent);
}

private void OnHealthOverlayEvent(NetworkedAIHealthOverlayEvent args)
{
var uid = args.Performer;

if (!_entityManager.TryGetComponent<ShowHealthBarsComponent>(uid, out var health))
{
health = _entityManager.AddComponent<ShowHealthBarsComponent>(uid);
}
else {
_entityManager.RemoveComponent<ShowHealthBarsComponent>(uid);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
using Content.Shared.Actions.ActionTypes;
using Content.Shared.StatusEffect;
using Content.Shared.Abilities.Psionics;
using Content.Shared.SimpleStation14.Abilities.Psionics;
using Content.Shared.SimpleStation14.StationAI;
using Content.Server.Mind.Components;
using Robust.Shared.Prototypes;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Content.Server.Abilities.Psionics;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Content.Shared.Throwing;
using Content.Shared.Item;
using Content.Shared.DragDrop;
using Content.Shared.Strip.Components;

namespace Content.Server.SimpleStation14.Abilities.Psionics
namespace Content.Server.SimpleStation14.StationAI
{
public sealed class AITelegnosisPowerSystem : EntitySystem
{
Expand All @@ -37,11 +33,6 @@ public override void Initialize()
SubscribeLocalEvent<AITelegnosisPowerComponent, AITelegnosisPowerActionEvent>(OnPowerUsed);

SubscribeLocalEvent<AITelegnosisPowerComponent, MobStateChangedEvent>(OnMobStateChanged);

SubscribeLocalEvent<AITelegnosisPowerComponent, ThrowAttemptEvent>(OnDisallowedEvent);
SubscribeLocalEvent<AITelegnosisPowerComponent, PickupAttemptEvent>(OnDisallowedEvent);
SubscribeLocalEvent<AITelegnosisPowerComponent, DropAttemptEvent>(OnDisallowedEvent);
SubscribeLocalEvent<AITelegnosisPowerComponent, StrippingSlotButtonPressed>(OnStripEvent);
}

private void OnInit(EntityUid uid, AITelegnosisPowerComponent component, ComponentInit args)
Expand Down Expand Up @@ -92,16 +83,6 @@ private void OnMobStateChanged(EntityUid uid, AITelegnosisPowerComponent compone
// SoundSystem.Play("/Audio/SimpleStation14/Machines/AI/borg_death.ogg", Filter.Pvs(component.Owner), component.Owner); // Eye shouldn't emit the sound
SoundSystem.Play("/Audio/SimpleStation14/Machines/AI/borg_death.ogg", Filter.Pvs(mindSwapped.OriginalEntity), mindSwapped.OriginalEntity);
}

private void OnDisallowedEvent(EntityUid uid, AITelegnosisPowerComponent drone, CancellableEntityEventArgs args)
{
args.Cancel();
}

private void OnStripEvent(EntityUid uid, AITelegnosisPowerComponent component, StrippingSlotButtonPressed args)
{
return;
}
}

public sealed class AITelegnosisPowerActionEvent : InstantActionEvent { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Content.Shared.Actions;
using Content.Shared.EntityHealthBar;
using Content.Shared.Actions.ActionTypes;
using Robust.Shared.Prototypes;
using Content.Shared.SimpleStation14.StationAI.Events;

namespace Content.Shared.SimpleStation14.StationAI
{
public sealed class StationAISystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<StationAIComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<StationAIComponent, ComponentShutdown>(OnShutdown);

SubscribeLocalEvent<AIHealthOverlayEvent>(OnHealthOverlayEvent);
}

private void OnStartup(EntityUid uid, StationAIComponent component, ComponentStartup args)
{
if (!_prototypeManager.TryIndex(component.Action, out InstantActionPrototype? proto)) return;
var action = new InstantAction(proto);
_actions.AddAction(uid, action, null);
}

private void OnShutdown(EntityUid uid, StationAIComponent component, ComponentShutdown args)
{
if (!_prototypeManager.TryIndex(component.Action, out InstantActionPrototype? proto)) return;
var action = new InstantAction(proto);
_actions.RemoveAction(uid, action, null);
}


private void OnHealthOverlayEvent(AIHealthOverlayEvent args)
{
RaiseNetworkEvent(new NetworkedAIHealthOverlayEvent(args.Performer));
args.Handled = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Content.Shared.Actions.ActionTypes;

namespace Content.Shared.SimpleStation14.Abilities.Psionics
namespace Content.Shared.SimpleStation14.StationAI
{
[RegisterComponent]
public sealed class AITelegnosisPowerComponent : Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Content.Shared.SimpleStation14.Abilities.Psionics
namespace Content.Shared.SimpleStation14.StationAI
{
[RegisterComponent]
public sealed class AITelegnosticProjectionComponent : Component
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Shared.SimpleStation14.StationAI
{
[RegisterComponent]
public sealed class StationAIComponent : Component
{
[DataField("action")]
public string Action = "AIHealthOverlay";
}
}
24 changes: 24 additions & 0 deletions Content.Shared/SimpleStation14/StationAI/Events/StationAIEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Content.Shared.Actions;
using Robust.Shared.Serialization;

namespace Content.Shared.SimpleStation14.StationAI.Events
{
public sealed class AIHealthOverlayEvent : InstantActionEvent
{
public AIHealthOverlayEvent()
{

}
}

[Serializable, NetSerializable]
public sealed class NetworkedAIHealthOverlayEvent : EntityEventArgs
{
public EntityUid Performer = EntityUid.Invalid;

public NetworkedAIHealthOverlayEvent(EntityUid performer)
{
Performer = performer;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Content.Shared.Throwing;
using Content.Shared.Item;
using Content.Shared.DragDrop;
using Content.Shared.Strip.Components;

namespace Content.Shared.SimpleStation14.StationAI
{
public sealed class StationAISystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<StationAIComponent, ThrowAttemptEvent>(OnDisallowedEvent);
SubscribeLocalEvent<StationAIComponent, PickupAttemptEvent>(OnDisallowedEvent);
SubscribeLocalEvent<StationAIComponent, DropAttemptEvent>(OnDisallowedEvent);
SubscribeLocalEvent<StationAIComponent, StrippingSlotButtonPressed>(OnStripEvent);
}

private void OnDisallowedEvent(EntityUid uid, Component component, CancellableEntityEventArgs args)
{
args.Cancel();
}

private void OnStripEvent(EntityUid uid, Component component, StrippingSlotButtonPressed args)
{
return;
}
}
}
5 changes: 0 additions & 5 deletions Resources/Prototypes/Entities/Objects/Devices/door_remote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
- type: Access
groups:
- AllAccess
# - type: entity
# parent: DoorRemoteAI
# id: DoorRemoteAIur
# components:
# - type: Unremoveable

- type: entity
parent: DoorRemoteDefault
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
- type: body
id: AI
name: "routerai" # Thanks for the idea, and a base to go off
name: "routerai" # :)
root: hand 1
slots: # Thanks for reminding me to fix this Faye
slots:
hand 1:
part: LeftArmBorg
connections:
- hand 2
hand 2:
part: RightArmBorg # LeftArmBorg
part: RightArmBorg
# connections:
# - hand 3
# hand 3:
Expand All @@ -30,6 +30,7 @@
abstract: true
id: AIbase
components:
- type: StationAI
- type: Visibility
- type: Psionic
- type: UserInterface
Expand All @@ -44,7 +45,7 @@
toggleAction:
name: action-name-show-laws
description: action-description-show-laws
icon: Structures/Wallmounts/posters.rsi/poster11_legit.png #someone wanna make new icons?
icon: Structures/Wallmounts/posters.rsi/poster11_legit.png
iconOn: Structures/Wallmounts/posters.rsi/poster11_legit.png
keywords: ["AI", "console", "interface", "laws", "borg"]
priority: -3
Expand Down Expand Up @@ -141,6 +142,7 @@
id: AIeye
parent: AIbase
name: Invalid AI name
noSpawn: true
components:
- type: Visibility
layer: 2
Expand Down Expand Up @@ -175,13 +177,6 @@
energy: 1
color: "#9dc5c9"
- type: MovementIgnoreGravity
- type: MobState
- type: MobThresholds
thresholds:
0: Alive
100000: Dead
- type: Damageable
damageContainer: Inorganic

- type: entity
parent: AIbase
Expand Down Expand Up @@ -259,3 +254,14 @@
- Structure
- type: StaticPrice
price: 50000

- type: instantAction
id: AIHealthOverlay
name: Health Overlay
description: Toggles the AI's health overlay.
useDelay: 2.5
itemIconStyle: NoItem
icon:
sprite: Interface/Alerts/human_alive.rsi
state: health0
event: !type:AIHealthOverlayEvent
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
- type: Icon
sprite: SimpleStation14/Objects/Devices/pda.rsi
state: pda-ai
# - type: entity
# parent: AIPDA
# id: AIPDAur
# components:
# - type: Unremoveable

- type: entity
parent: BasePDA
Expand Down
2 changes: 1 addition & 1 deletion Scripts/bat/runconfigserver.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ soft_max_players = 48
type = 1
lobbyenabled = true
lobbyduration = 180
role_timers = true
role_timers = false
fallbackpreset = "extended"
map_pool = "ParkMapPool"

Expand Down
2 changes: 1 addition & 1 deletion Scripts/sh/runconfigserver.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ soft_max_players = 48
type = 1
lobbyenabled = true
lobbyduration = 180
role_timers = true
role_timers = false
fallbackpreset = "extended"
map_pool = "ParkMapPool"

Expand Down

0 comments on commit da14a79

Please sign in to comment.