2021-02-02 05:20:24 -06:00
|
|
|
#nullable enable
|
2021-01-03 09:13:01 -06:00
|
|
|
using System;
|
2020-08-18 14:39:08 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-07-25 15:11:16 +02:00
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Server.GameObjects.Components.MachineLinking;
|
2020-10-30 19:46:19 +01:00
|
|
|
using Content.Server.GameObjects.Components.MachineLinking.Signals;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.Components.Mobs;
|
2021-02-26 04:31:06 +03:00
|
|
|
using Content.Server.GameObjects.Components.Observer;
|
|
|
|
|
using Content.Shared.Actions;
|
Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.
* Updated submodule and also lost some progress cause I fucked it up xd
* First unfinished draft of the BodySystem. Doesn't compile.
* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.
* Many cleanup changes.
* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"
This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.
* Commit human.yml
* Updated a lot of things to be more classy, more progress overall, etc. etc.
* Latest update with many changes
* Minor changes
* Fixed Travis build bug
* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)
* Commit rest of stuff
* Latest changes
* Latest changes again
* 14 naked cowboys
* Yay!
* Latest changes (probably doesnt compile)
* Surgery!!!!!!!!!~1116y
* Cleaned some stuff up
* More cleanup
* Refactoring of code. Basic surgery path now done.
* Removed readme, has been added to HackMD
* Fixes typo (and thus test errors)
* WIP changes, committing so I can pull latest master changes
* Still working on that god awful merge
* Latest changes
* Latest changes!!
* Beginning of refactor to BoundUserInterface
* Surgery!
* Latest changes - fixes pr change requests and random fixes
* oops
* Fixes bodypart recursion
* Beginning of work on revamping the damage system.
* More latest changes
* Latest changes
* Finished merge
* Commit before removing old healthcode
* Almost done with removing speciescomponent...
* It compiles!!!
* yahoo more work
* Fixes to make it work
* Merge conflict fixes
* Deleting species visualizer was a mistake
* IDE warnings are VERBOTEN
* makes the server not kill itself on startup, some cleanup (#1)
* Namespaces, comments and exception fixes
* Fix conveyor and conveyor switch serialization
SS14 in reactive when
* Move damage, acts and body to shared
Damage cleanup
Comment cleanup
* Rename SpeciesComponent to RotationComponent and cleanup
Damage cleanup
Comment cleanup
* Fix nullable warnings
* Address old reviews
Fix off welder suicide damage type, deathmatch and suspicion
* Fix new test fail with units being able to accept items when unpowered
* Remove RotationComponent, change references to IBodyManagerComponent
* Add a bloodstream to humans
* More cleanups
* Add body conduits, connections, connectors substances and valves
* Revert "Add body conduits, connections, connectors substances and valves"
This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.
* Implement the heart mechanism behavior with the circulatory network
* Added network property to mechanism behaviors
* Changed human organ sprites and added missing ones
* Fix tests
* Add individual body part sprite rendering
* Fix error where dropped mechanisms are not initialized
* Implement client/server body damage
* Make DamageContainer take care of raising events
* Reimplement medical scanner with the new body system
* Improve the medical scanner ui
* Merge conflict fixes
* Fix crash when colliding with something
* Fix microwave suicides and eyes sprite rendering
* Fix nullable reference error
* Fix up surgery client side
* Fix missing using from merge conflict
* Add breathing
*inhale
* Merge conflict fixes
* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold
https://github.com/space-wizards/space-station-14/pull/1617
* Use and add to the new AtmosHelpers
* Fix feet
* Add proper coloring to dropped body parts
* Fix Urist's lungs being too strong
* Merge conflict fixes
* Merge conflict fixes
* Merge conflict fixes
Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
|
|
|
using Content.Shared.Damage;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Damage;
|
2021-02-26 04:31:06 +03:00
|
|
|
using Content.Shared.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Shared.Interfaces;
|
2020-07-18 22:51:56 -07:00
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.Audio;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-08-22 19:37:23 +02:00
|
|
|
using Robust.Shared.Localization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Timing;
|
2019-04-15 21:11:38 -06:00
|
|
|
using Robust.Shared.ViewVariables;
|
2018-05-27 16:44:50 +02:00
|
|
|
|
2020-08-13 14:40:27 +02:00
|
|
|
namespace Content.Server.GameObjects.Components.Power.ApcNetComponents.PowerReceiverUsers
|
2018-05-27 16:44:50 +02:00
|
|
|
{
|
2019-03-22 23:59:13 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Component that represents a wall light. It has a light bulb that can be replaced when broken.
|
|
|
|
|
/// </summary>
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2021-02-26 04:31:06 +03:00
|
|
|
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing, IMapInit, ISignalReceiver<bool>, ISignalReceiver<ToggleSignal>, IGhostBooAffected
|
2018-05-27 16:44:50 +02:00
|
|
|
{
|
2020-11-21 14:02:00 +01:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2020-09-01 16:18:46 +02:00
|
|
|
|
2018-05-27 16:44:50 +02:00
|
|
|
public override string Name => "PoweredLight";
|
|
|
|
|
|
2019-03-20 01:12:38 +01:00
|
|
|
private static readonly TimeSpan _thunkDelay = TimeSpan.FromSeconds(2);
|
2021-02-26 04:31:06 +03:00
|
|
|
// time to blink light when ghost made boo nearby
|
|
|
|
|
private static readonly TimeSpan ghostBlinkingTime = TimeSpan.FromSeconds(10);
|
|
|
|
|
private static readonly TimeSpan ghostBlinkingCooldown = TimeSpan.FromSeconds(60);
|
|
|
|
|
|
|
|
|
|
[ComponentDependency]
|
|
|
|
|
private readonly AppearanceComponent? _appearance;
|
|
|
|
|
|
2019-03-20 01:12:38 +01:00
|
|
|
private TimeSpan _lastThunk;
|
2021-02-26 04:31:06 +03:00
|
|
|
private TimeSpan? _lastGhostBlink;
|
2019-03-20 01:12:38 +01:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("hasLampOnSpawn")]
|
|
|
|
|
private bool _hasLampOnSpawn = true;
|
2020-02-22 17:39:00 -06:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables] [DataField("on")]
|
|
|
|
|
private bool _on = true;
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
private bool _currentLit;
|
|
|
|
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
private bool _isBlinking;
|
|
|
|
|
|
|
|
|
|
[ViewVariables] [DataField("ignoreGhostsBoo")]
|
|
|
|
|
private bool _ignoreGhostsBoo;
|
|
|
|
|
|
|
|
|
|
[DataField("bulb")]
|
2019-03-22 23:59:13 +01:00
|
|
|
private LightBulbType BulbType = LightBulbType.Tube;
|
2021-02-02 05:20:24 -06:00
|
|
|
[ViewVariables] private ContainerSlot _lightBulbContainer = default!;
|
2020-09-01 16:18:46 +02:00
|
|
|
|
2019-03-22 23:59:13 +01:00
|
|
|
[ViewVariables]
|
2021-02-02 05:20:24 -06:00
|
|
|
private LightBulbComponent? LightBulb
|
2018-05-27 16:44:50 +02:00
|
|
|
{
|
2019-03-22 23:59:13 +01:00
|
|
|
get
|
|
|
|
|
{
|
2019-03-23 22:30:05 +01:00
|
|
|
if (_lightBulbContainer.ContainedEntity == null) return null;
|
2019-03-22 23:59:13 +01:00
|
|
|
|
2021-02-02 05:20:24 -06:00
|
|
|
_lightBulbContainer.ContainedEntity.TryGetComponent(out LightBulbComponent? bulb);
|
2019-03-22 23:59:13 +01:00
|
|
|
|
|
|
|
|
return bulb;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 17:41:23 +02:00
|
|
|
// TODO CONSTRUCTION make this use a construction graph
|
2020-07-02 14:50:57 -07:00
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
2020-05-23 17:23:25 +02:00
|
|
|
return InsertBulb(eventArgs.Using);
|
2019-03-22 23:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
2021-02-02 05:20:24 -06:00
|
|
|
if (!eventArgs.User.TryGetComponent(out IDamageableComponent? damageableComponent))
|
2019-04-06 17:11:51 +02:00
|
|
|
{
|
|
|
|
|
Eject();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-02-02 05:20:24 -06:00
|
|
|
if(eventArgs.User.TryGetComponent(out HeatResistanceComponent? heatResistanceComponent))
|
2019-04-06 17:11:51 +02:00
|
|
|
{
|
|
|
|
|
if(CanBurn(heatResistanceComponent.GetHeatResistance()))
|
|
|
|
|
{
|
|
|
|
|
Burn();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Eject();
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
bool CanBurn(int heatResistance)
|
|
|
|
|
{
|
2021-02-02 05:20:24 -06:00
|
|
|
if (LightBulb == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-03-03 16:27:23 +01:00
|
|
|
return _currentLit && heatResistance < LightBulb.BurningTemperature;
|
2019-04-06 17:11:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Burn()
|
|
|
|
|
{
|
2020-08-29 03:33:42 -07:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("You burn your hand!"));
|
Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.
* Updated submodule and also lost some progress cause I fucked it up xd
* First unfinished draft of the BodySystem. Doesn't compile.
* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.
* Many cleanup changes.
* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"
This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.
* Commit human.yml
* Updated a lot of things to be more classy, more progress overall, etc. etc.
* Latest update with many changes
* Minor changes
* Fixed Travis build bug
* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)
* Commit rest of stuff
* Latest changes
* Latest changes again
* 14 naked cowboys
* Yay!
* Latest changes (probably doesnt compile)
* Surgery!!!!!!!!!~1116y
* Cleaned some stuff up
* More cleanup
* Refactoring of code. Basic surgery path now done.
* Removed readme, has been added to HackMD
* Fixes typo (and thus test errors)
* WIP changes, committing so I can pull latest master changes
* Still working on that god awful merge
* Latest changes
* Latest changes!!
* Beginning of refactor to BoundUserInterface
* Surgery!
* Latest changes - fixes pr change requests and random fixes
* oops
* Fixes bodypart recursion
* Beginning of work on revamping the damage system.
* More latest changes
* Latest changes
* Finished merge
* Commit before removing old healthcode
* Almost done with removing speciescomponent...
* It compiles!!!
* yahoo more work
* Fixes to make it work
* Merge conflict fixes
* Deleting species visualizer was a mistake
* IDE warnings are VERBOTEN
* makes the server not kill itself on startup, some cleanup (#1)
* Namespaces, comments and exception fixes
* Fix conveyor and conveyor switch serialization
SS14 in reactive when
* Move damage, acts and body to shared
Damage cleanup
Comment cleanup
* Rename SpeciesComponent to RotationComponent and cleanup
Damage cleanup
Comment cleanup
* Fix nullable warnings
* Address old reviews
Fix off welder suicide damage type, deathmatch and suspicion
* Fix new test fail with units being able to accept items when unpowered
* Remove RotationComponent, change references to IBodyManagerComponent
* Add a bloodstream to humans
* More cleanups
* Add body conduits, connections, connectors substances and valves
* Revert "Add body conduits, connections, connectors substances and valves"
This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.
* Implement the heart mechanism behavior with the circulatory network
* Added network property to mechanism behaviors
* Changed human organ sprites and added missing ones
* Fix tests
* Add individual body part sprite rendering
* Fix error where dropped mechanisms are not initialized
* Implement client/server body damage
* Make DamageContainer take care of raising events
* Reimplement medical scanner with the new body system
* Improve the medical scanner ui
* Merge conflict fixes
* Fix crash when colliding with something
* Fix microwave suicides and eyes sprite rendering
* Fix nullable reference error
* Fix up surgery client side
* Fix missing using from merge conflict
* Add breathing
*inhale
* Merge conflict fixes
* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold
https://github.com/space-wizards/space-station-14/pull/1617
* Use and add to the new AtmosHelpers
* Fix feet
* Add proper coloring to dropped body parts
* Fix Urist's lungs being too strong
* Merge conflict fixes
* Merge conflict fixes
* Merge conflict fixes
Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
|
|
|
damageableComponent.ChangeDamage(DamageType.Heat, 20, false, Owner);
|
2020-05-31 12:40:36 -05:00
|
|
|
var audioSystem = EntitySystem.Get<AudioSystem>();
|
2020-07-07 13:19:00 -04:00
|
|
|
audioSystem.PlayFromEntity("/Audio/Effects/lightburn.ogg", Owner);
|
2019-04-06 17:11:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Eject()
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
2019-04-05 19:27:39 +02:00
|
|
|
EjectBulb(eventArgs.User);
|
2019-03-22 23:59:13 +01:00
|
|
|
UpdateLight();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 22:30:05 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Inserts the bulb if possible.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>True if it could insert it, false if it couldn't.</returns>
|
|
|
|
|
private bool InsertBulb(IEntity bulb)
|
|
|
|
|
{
|
|
|
|
|
if (LightBulb != null) return false;
|
2021-02-02 05:20:24 -06:00
|
|
|
if (!bulb.TryGetComponent(out LightBulbComponent? lightBulb)) return false;
|
2019-03-23 22:30:05 +01:00
|
|
|
if (lightBulb.Type != BulbType) return false;
|
|
|
|
|
|
|
|
|
|
var inserted = _lightBulbContainer.Insert(bulb);
|
|
|
|
|
|
|
|
|
|
lightBulb.OnLightBulbStateChange += UpdateLight;
|
|
|
|
|
lightBulb.OnLightColorChange += UpdateLight;
|
|
|
|
|
|
|
|
|
|
UpdateLight();
|
|
|
|
|
|
|
|
|
|
return inserted;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-22 23:59:13 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Ejects the bulb to a mob's hand if possible.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void EjectBulb(IEntity user)
|
|
|
|
|
{
|
|
|
|
|
if (LightBulb == null) return;
|
|
|
|
|
|
|
|
|
|
var bulb = LightBulb;
|
2018-05-27 16:44:50 +02:00
|
|
|
|
2019-03-23 22:30:05 +01:00
|
|
|
bulb.OnLightBulbStateChange -= UpdateLight;
|
|
|
|
|
bulb.OnLightColorChange -= UpdateLight;
|
|
|
|
|
|
|
|
|
|
if (!_lightBulbContainer.Remove(bulb.Owner)) return;
|
2019-03-22 23:59:13 +01:00
|
|
|
|
2021-02-02 05:20:24 -06:00
|
|
|
if (!user.TryGetComponent(out HandsComponent? hands)
|
2019-03-22 23:59:13 +01:00
|
|
|
|| !hands.PutInHand(bulb.Owner.GetComponent<ItemComponent>()))
|
2020-09-06 16:11:53 +02:00
|
|
|
bulb.Owner.Transform.Coordinates = user.Transform.Coordinates;
|
2019-03-22 23:59:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// For attaching UpdateLight() to events.
|
|
|
|
|
/// </summary>
|
2021-02-02 05:20:24 -06:00
|
|
|
public void UpdateLight(object? sender, EventArgs? e)
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
|
|
|
|
UpdateLight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the light's power drain, sprite and actual light state.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UpdateLight()
|
|
|
|
|
{
|
2020-06-28 09:23:26 -06:00
|
|
|
var powerReceiver = Owner.GetComponent<PowerReceiverComponent>();
|
2021-02-26 04:31:06 +03:00
|
|
|
|
2019-03-22 23:59:13 +01:00
|
|
|
if (LightBulb == null) // No light bulb.
|
2018-05-27 16:44:50 +02:00
|
|
|
{
|
2021-03-03 16:27:23 +01:00
|
|
|
_currentLit = false;
|
2020-06-28 09:23:26 -06:00
|
|
|
powerReceiver.Load = 0;
|
2021-02-26 04:31:06 +03:00
|
|
|
_appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Empty);
|
2019-03-22 23:59:13 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (LightBulb.State)
|
|
|
|
|
{
|
|
|
|
|
case LightBulbState.Normal:
|
2020-08-29 03:33:42 -07:00
|
|
|
if (powerReceiver.Powered && _on)
|
2019-03-22 23:59:13 +01:00
|
|
|
{
|
2021-03-03 16:27:23 +01:00
|
|
|
_currentLit = true;
|
2020-08-29 03:33:42 -07:00
|
|
|
powerReceiver.Load = LightBulb.PowerUse;
|
2021-02-26 04:31:06 +03:00
|
|
|
_appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.On);
|
|
|
|
|
_appearance?.SetData(PoweredLightVisuals.BulbColor, LightBulb.Color);
|
2020-09-01 16:18:46 +02:00
|
|
|
var time = _gameTiming.CurTime;
|
2019-03-22 23:59:13 +01:00
|
|
|
if (time > _lastThunk + _thunkDelay)
|
|
|
|
|
{
|
2019-03-25 13:01:03 +01:00
|
|
|
_lastThunk = time;
|
2020-07-07 13:19:00 -04:00
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Machines/light_tube_on.ogg", Owner, AudioParams.Default.WithVolume(-10f));
|
2019-03-22 23:59:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2019-03-20 01:12:38 +01:00
|
|
|
{
|
2021-03-03 16:27:23 +01:00
|
|
|
_currentLit = false;
|
2021-02-26 04:31:06 +03:00
|
|
|
_appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Off);
|
2019-03-20 01:12:38 +01:00
|
|
|
}
|
2019-03-22 23:59:13 +01:00
|
|
|
break;
|
|
|
|
|
case LightBulbState.Broken:
|
2021-03-03 16:27:23 +01:00
|
|
|
_currentLit = false;
|
2021-02-26 04:31:06 +03:00
|
|
|
_appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Broken);
|
2019-03-22 23:59:13 +01:00
|
|
|
break;
|
|
|
|
|
case LightBulbState.Burned:
|
2021-03-03 16:27:23 +01:00
|
|
|
_currentLit = false;
|
2021-02-26 04:31:06 +03:00
|
|
|
_appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Burned);
|
2019-03-22 23:59:13 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-03-01 15:24:46 -08:00
|
|
|
_lightBulbContainer = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, "light_bulb");
|
2018-05-27 16:44:50 +02:00
|
|
|
}
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-02-02 05:20:24 -06:00
|
|
|
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
2021-01-03 09:13:01 -06:00
|
|
|
base.HandleMessage(message, component);
|
|
|
|
|
switch (message)
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
2021-01-03 09:13:01 -06:00
|
|
|
case PowerChangedMessage:
|
|
|
|
|
UpdateLight();
|
|
|
|
|
break;
|
2021-02-16 11:40:43 +03:00
|
|
|
case DamageChangedMessage msg:
|
|
|
|
|
TryDestroyBulb(msg);
|
|
|
|
|
break;
|
2020-08-22 22:29:20 +02:00
|
|
|
}
|
2020-06-28 09:23:26 -06:00
|
|
|
}
|
2020-07-30 23:59:40 +02:00
|
|
|
|
2021-02-16 11:40:43 +03:00
|
|
|
private void TryDestroyBulb(DamageChangedMessage msg)
|
|
|
|
|
{
|
|
|
|
|
if (!msg.TookDamage)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (LightBulb == null || LightBulb.State == LightBulbState.Broken)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LightBulb.State = LightBulbState.Broken;
|
|
|
|
|
LightBulb.PlayBreakSound();
|
|
|
|
|
UpdateLight();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 23:59:40 +02:00
|
|
|
void IMapInit.MapInit()
|
|
|
|
|
{
|
2021-02-07 02:05:53 +03:00
|
|
|
if (_hasLampOnSpawn)
|
2020-07-30 23:59:40 +02:00
|
|
|
{
|
2021-02-07 02:05:53 +03:00
|
|
|
var prototype = BulbType switch
|
|
|
|
|
{
|
|
|
|
|
LightBulbType.Bulb => "LightBulb",
|
|
|
|
|
LightBulbType.Tube => "LightTube",
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
|
|
|
};
|
2020-07-30 23:59:40 +02:00
|
|
|
|
2021-02-07 02:05:53 +03:00
|
|
|
var entity = Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.Coordinates);
|
|
|
|
|
_lightBulbContainer.Insert(entity);
|
|
|
|
|
UpdateLight();
|
|
|
|
|
}
|
2020-07-30 23:59:40 +02:00
|
|
|
}
|
2020-10-30 19:46:19 +01:00
|
|
|
|
|
|
|
|
public void TriggerSignal(bool signal)
|
|
|
|
|
{
|
|
|
|
|
_on = signal;
|
|
|
|
|
UpdateLight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TriggerSignal(ToggleSignal signal)
|
|
|
|
|
{
|
|
|
|
|
_on = !_on;
|
|
|
|
|
UpdateLight();
|
|
|
|
|
}
|
2021-02-26 04:31:06 +03:00
|
|
|
|
|
|
|
|
public void ToggleBlinkingLight(bool isNowBlinking)
|
|
|
|
|
{
|
|
|
|
|
if (_isBlinking == isNowBlinking)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_isBlinking = isNowBlinking;
|
|
|
|
|
_appearance?.SetData(PoweredLightVisuals.Blinking, _isBlinking);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AffectedByGhostBoo(InstantActionEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (_ignoreGhostsBoo)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// check cooldown first to prevent abuse
|
|
|
|
|
var time = _gameTiming.CurTime;
|
|
|
|
|
if (_lastGhostBlink != null)
|
|
|
|
|
{
|
|
|
|
|
if (time <= _lastGhostBlink + ghostBlinkingCooldown)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
_lastGhostBlink = time;
|
|
|
|
|
|
|
|
|
|
ToggleBlinkingLight(true);
|
|
|
|
|
Owner.SpawnTimer(ghostBlinkingTime, () => {
|
|
|
|
|
ToggleBlinkingLight(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-05-27 16:44:50 +02:00
|
|
|
}
|
|
|
|
|
}
|