1 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
14 private Color lightColor;
18 private float lightBrightness;
19 private float blinkFrequency;
20 private float pulseFrequency, pulseAmount;
22 private float flicker, flickerSpeed;
23 private bool castShadows;
24 private bool drawBehindSubs;
26 private double lastToggleSignalTime;
28 private string prevColorSignal;
36 [
Serialize(100.0f,
IsPropertySaveable.Yes, description:
"The range of the emitted light. Higher values are more performance-intensive.", alwaysUseInstanceValues:
true),
37 Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f)]
43 range = MathHelper.Clamp(value, 0.0f, 4096.0f);
51 private float rotation;
54 get {
return rotation; }
58 SetLightSourceTransformProjSpecific();
63 "Disabling shadows increases the performance of the game, and is recommended for lights with a short range. Lights that are set to be drawn behind subs don't cast shadows, regardless of this setting.", alwaysUseInstanceValues:
true)]
66 get {
return castShadows; }
76 [
Editable,
Serialize(
false,
IsPropertySaveable.Yes, description:
"Lights drawn behind submarines don't cast any shadows and are much faster to draw than shadow-casting lights. " +
77 "It's recommended to enable this on decorative lights outside the submarine's hull.", alwaysUseInstanceValues:
true)]
80 get {
return drawBehindSubs; }
83 drawBehindSubs = value;
96 if (isOn == value &&
IsActive == value) {
return; }
99 SetLightSourceState(value, value ? lightBrightness : 0.0f);
104 [
Editable,
Serialize(0.0f,
IsPropertySaveable.No, description:
"How heavily the light flickers. 0 = no flickering, 1 = the light will alternate between completely dark and full brightness.")]
107 get {
return flicker; }
110 flicker = MathHelper.Clamp(value, 0.0f, 1.0f);
120 get {
return flickerSpeed; }
123 flickerSpeed = value;
133 get {
return pulseFrequency; }
136 pulseFrequency = MathHelper.Clamp(value, 0.0f, 60.0f);
143 [
Editable(MinValueFloat = 0.0f, MaxValueFloat = 1.0f, DecimalCount = 2),
Serialize(0.0f,
IsPropertySaveable.Yes, description:
"How much light pulsates (in Hz). 0 = not at all, 1 = alternates between full brightness and off.")]
146 get {
return pulseAmount; }
149 pulseAmount = MathHelper.Clamp(value, 0.0f, 1.0f);
159 get {
return blinkFrequency; }
162 blinkFrequency = MathHelper.Clamp(value, 0.0f, 60.0f);
169 [
InGameEditable(FallBackTextTag =
"connection.setcolor"),
Serialize(
"255,255,255,255",
IsPropertySaveable.Yes, description:
"The color of the emitted light (R,G,B,A).", alwaysUseInstanceValues:
true)]
172 get {
return lightColor; }
177 prevColorSignal =
string.Empty;
181 Light.
Color =
IsOn ? lightColor.Multiply(lightColorMultiplier) : Color.Transparent;
187 [
Serialize(
false,
IsPropertySaveable.No, description:
"If enabled, the component will ignore continuous signals received in the toggle input (i.e. a continuous signal will only toggle it once).")]
194 [
Serialize(
true,
IsPropertySaveable.No, description:
"Should the light sprite be drawn on the item using alpha blending, in addition to being rendered in the light map? Can be used to make the light sprite stand out more.")]
219 public override void Move(Vector2 amount,
bool ignoreContacts =
false)
230 return base.IsActive;
235 if (base.IsActive == value) {
return; }
236 base.IsActive = isOn = value;
237 SetLightSourceState(value, value ? lightBrightness : 0.0f);
242 : base(
item, element)
250 IsBackground = drawBehindSubs,
268 SetLightSourceState(
IsActive, lightBrightness);
299 base.IsActive =
false;
311 lightBrightness = 1.0f;
312 SetLightSourceState(
true, lightBrightness);
316 lightBrightness = 0.0f;
317 SetLightSourceState(
false, 0.0f);
320 SetLightSourceTransformProjSpecific();
321 base.IsActive =
false;
328 base.IsActive =
true;
347 bool visibleInContainer;
353 visibleInContainer =
false;
360 if ((
item.
Container !=
null && !visibleInContainer && ownerCharacter ==
null) ||
361 (ownerCharacter !=
null && ownerCharacter.InvisibleTimer > 0.0f))
363 lightBrightness = 0.0f;
364 SetLightSourceState(
false, 0.0f);
367 SetLightSourceTransformProjSpecific();
370 if (body !=
null && !body.
Enabled && !visibleInContainer)
372 lightBrightness = 0.0f;
373 SetLightSourceState(
false, 0.0f);
388 lightBrightness = 0.0f;
392 lightBrightness = MathHelper.Lerp(lightBrightness,
powerConsumption <= 0.0f ? 1.0f : Math.Min(
Voltage, 1.0f), 0.1f);
395 SetLightSourceState(
true, lightBrightness);
400 SetLightSourceState(
false, 0.0f);
408 partial
void OnStateChanged();
412 switch (connection.
Name)
415 if (signal.
value !=
"0")
421 lastToggleSignalTime = Timing.TotalTime;
428 if (signal.
value != prevColorSignal)
432 SetLightSourceState(
Light.
Enabled, lightColorMultiplier);
434 prevColorSignal = signal.
value;
440 private void UpdateAITarget(
AITarget target)
443 if (target.MaxSightRange <= 0)
445 target.MaxSightRange =
Range * 5;
455 partial
void SetLightSourceState(
bool enabled,
float brightness);
459 SetLightSourceTransformProjSpecific();
462 partial
void SetLightSourceTransformProjSpecific();
void ResetCachedVisibleSize()
Inventory ParentInventory
override Vector2? Position
Inventory FindParentInventory(Func< Inventory, bool > predicate)
Entity GetRootInventoryOwner()
readonly Dictionary< ActionType, List< StatusEffect > > statusEffectLists
List< PropertyConditional > IsActiveConditionals
void SetLightSourceTransform()
bool IsRed
Returns true if the red component of the light is twice as bright as the blue and green....
override bool Use(float deltaTime, Character character=null)
void CheckIfNeedsUpdate()
bool IsGreen
Returns true if the green component of the light is twice as bright as the red and blue....
override void OnMapLoaded()
Called when all items have been loaded. Use to initialize connections between items.
override void Drop(Character dropper, bool setTransform=true)
a Character has dropped the item
override void Update(float deltaTime, Camera cam)
override void Move(Vector2 amount, bool ignoreContacts=false)
float TemporaryFlickerTimer
bool IgnoreContinuousToggle
bool IsBlue
Returns true if the blue component of the light is twice as bright as the red and green....
LightComponent(Item item, ContentXElement element)
override void UpdateBroken(float deltaTime, Camera cam)
override void ReceiveSignal(Signal signal, Connection connection)
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
float powerConsumption
The maximum amount of power the item can draw from connected items
void UpdateOnActiveEffects(float deltaTime)
LightSourceParams LightSourceParams
bool IsBackground
Background lights are drawn behind submarines and they don't cast shadows.
bool IsHidden
Is the entity hidden due to HiddenInGame being enabled or the layer the entity is in being hidden?
Interface for entities that the server can send events to the clients
ActionType
ActionTypes define when a StatusEffect is executed.