Skip to content

Commit

Permalink
done: добавить siliconChargers
Browse files Browse the repository at this point in the history
  • Loading branch information
modern-nm committed Dec 11, 2023
1 parent a001864 commit 6cd12df
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
using Content.Shared.Interaction.Components;
using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Power;
using Content.Shared.PowerCell.Components;
using Content.Shared.SimpleStation14.Silicon;
using Content.Shared.SimpleStation14.Silicon.Charge;
using Content.Shared.StepTrigger.Components;
using Content.Shared.Storage.Components;
using Robust.Shared.Physics.Events;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
Expand All @@ -27,14 +28,15 @@ namespace Content.Server.SimpleStation14.Silicon.Charge;

public sealed class SiliconChargerSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly HandsSystem _hands = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ExplosionSystem _explosion = default!;
[Dependency] private readonly SharedSiliconChargerSystem _sharedCharger = default!;
//[Dependency] private readonly SharedSiliconChargerSystem _sharedCharger = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IGameTiming _timing = default!;
Expand All @@ -51,10 +53,24 @@ public override void Initialize()
SubscribeLocalEvent<SiliconChargerComponent, EndCollideEvent>(OnEndCollide);

SubscribeLocalEvent<SiliconChargerComponent, ComponentShutdown>(OnChargerShutdown);

SubscribeLocalEvent<SiliconChargerComponent, StorageAfterOpenEvent>(HandleStateOpen);
SubscribeLocalEvent<SiliconChargerComponent, StorageAfterCloseEvent>(HandleStateClose);
}

// TODO: Potentially refactor this so it chaches all found entities upon the storage being closed, or stepped on, etc.
// Perhaps a variable for it? Open chargers like the pad wouldn't update to things picked up, but it seems silly to redo it each frame for closed ones.
private void HandleStateOpen(EntityUid uid, SiliconChargerComponent component, ref StorageAfterOpenEvent _)
{
UpdateState(uid, component);
}

/// <inheritdoc cref="HandleStateOpen"/>
private void HandleStateClose(EntityUid uid, SiliconChargerComponent component, ref StorageAfterCloseEvent _)
{
UpdateState(uid, component);
}

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand All @@ -70,7 +86,7 @@ public override void Update(float frameTime)
if (TryComp<ApcPowerReceiverComponent>(uid, out var powerComp) && !powerComp.Powered)
{
if (chargerComp.Active != wasActive)
_sharedCharger.UpdateState(uid, chargerComp);
UpdateState(uid, chargerComp);

continue;
}
Expand All @@ -93,7 +109,7 @@ public override void Update(float frameTime)
}

if (chargerComp.Active != wasActive)
_sharedCharger.UpdateState(uid, chargerComp);
UpdateState(uid, chargerComp);
}
#endregion Entity Storage Chargers

Expand All @@ -108,15 +124,15 @@ public override void Update(float frameTime)
if (chargerComp.Active)
{
chargerComp.Active = false;
_sharedCharger.UpdateState(uid, chargerComp);
UpdateState(uid, chargerComp);
}
continue;
}

if (!chargerComp.Active)
{
chargerComp.Active = true;
_sharedCharger.UpdateState(uid, chargerComp);
UpdateState(uid, chargerComp);
}

var chargeRate = frameTime * chargerComp.ChargeMulti / chargerComp.PresentEntities.Count;
Expand Down Expand Up @@ -325,4 +341,41 @@ private void OnEndCollide(EntityUid uid, SiliconChargerComponent component, ref
}
#endregion Step Trigger Chargers
#endregion Charger specific

public void UpdateState(EntityUid uid, SiliconChargerComponent? component = null)
{
if (!Resolve(uid, ref component))
return;

if (component.Active)
{
_appearance.SetData(uid, PowerDeviceVisuals.VisualState, SiliconChargerVisualState.Charging);

// If we're in prediction, return since Client doesn't have the information needed to handle this.
// Didn't seem to matter in practice, but probably for the best.
if (_timing.InPrediction)
return;

//if (component.SoundLoop != null && component.SoundStream == null)
// component.SoundStream =
// _audio.PlayPvs(component.SoundLoop, uid, AudioParams.Default.WithLoop(true).WithMaxDistance(5));
}
else
{
var state = SiliconChargerVisualState.Normal;

if (EntityManager.TryGetComponent<EntityStorageComponent>(uid, out var storageComp) && storageComp.Open)
state = SiliconChargerVisualState.NormalOpen;

_appearance.SetData(uid, PowerDeviceVisuals.VisualState, state);

// If we're in prediction, return since Client doesn't have the information needed to handle this.
// Didn't seem to matter in practice, but probably for the best.
if (_timing.InPrediction)
return;

//component.SoundStream?.Stop();
//component.SoundStream = null;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
- SubstationMachineCircuitboard
- CellRechargerCircuitboard
- BorgChargerCircuitboard
- IndustrialChargerCircuitboard
- WeaponCapacitorRechargerCircuitboard
- type: EmagLatheRecipes
emagStaticRecipes:
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Structures/Power/chargers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
whitelist:
components:
- BorgChassis
#- type: SiliconCharger
# chargeMulti: 50
# targetTemp: 390
- type: Construction
containers:
- machine_parts
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
- type: entity
id: IndustrialChargerCircuitboard
parent: BaseMachineCircuitboard
name: industrial charger machine board
description: A machine printed circuit board for an industrial charger
components:
- type: Sprite
state: engineering
- type: MachineBoard
prototype: SiliconChargerIndustrial
requirements:
Capacitor: 8
Manipulator: 2
materialRequirements:
Plastic: 6
CableHV: 4
CableMV: 8

# - type: entity # странная вещь, ну её нахер. Серьёзно.
# id: ChargingPadCircuitboard
# parent: BaseMachineCircuitboard
# name: charging pad machine board
# description: A machine printed circuit board for a charging pad
# components:
# - type: Sprite
# state: engineering
# - type: MachineBoard
# prototype: SiliconChargerChargePad
# requirements:
# Capacitor: 3
# Manipulator: 5
# materialRequirements:
# CableHV: 2
# CableMV: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
- type: entity
id: SiliconChargerIndustrial
parent: BaseMachinePowered
name: industrial charger
description: A heavy duty machine for inductively charging robotic beings. Gets extremely hot!
components:
- type: Sprite
sprite: SimpleStation14/Structures/Machines/borgcharger.rsi
noRot: true
layers:
- state: base
- state: closed
map: ["enum.StorageVisualLayers.Door"]
- state: borgcharger_closed_unlit
shader: unshaded
map: ["enum.SiliconChargerVisuals.Lights"]
- type: EntityStorageVisuals
stateDoorOpen: open
stateDoorClosed: closed
- type: GenericVisualizer
visuals:
enum.PowerDeviceVisuals.VisualState:
enum.SiliconChargerVisuals.Lights:
Normal: { state: "borgcharger_closed_unlit" }
NormalOpen: { state: "borgcharger_open_unlit" }
Charging: { state: "borgcharger_active_unlit" }
enum.PowerDeviceVisuals.Powered:
enum.SiliconChargerVisuals.Lights:
True: { visible: true }
False: { visible: false }
- type: Icon
sprite: SimpleStation14/Structures/Machines/borgcharger.rsi
state: icon
- type: Physics
bodyType: Static
- type: Fixtures
fixtures:
fix1:
shape: !type:PhysShapeAabb
bounds: "-0.45,-0.5,0.45,0.5"
density: 190
mask:
- MachineMask
layer:
- MachineLayer
- type: ApcPowerReceiver
powerLoad: 500
- type: StaticPrice #было DynamicPrice
price: 600
- type: EntityStorage
maxItemSize: Tiny
- type: Appearance
- type: ContainerContainer
containers:
machine_board: !type:Container
machine_parts: !type:Container
entity_storage: !type:Container
- type: SiliconCharger
chargeMulti: 1000
targetTemp: 390
- type: Construction
graph: Machine
node: machine
containers:
- machine_board
- machine_parts
- type: Machine
board: IndustrialChargerCircuitboard
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 350
behaviors:
- !type:ChangeConstructionNodeBehavior
node: machineFrame
- !type:DoActsBehavior
acts: ["Destruction"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- type: latheRecipe
id: IndustrialChargerCircuitboard
result: IndustrialChargerCircuitboard
completetime: 2
materials:
Steel: 50
Plastic: 50
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6cd12df

Please sign in to comment.