This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
forked from estacaoespacialpirata/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionado sistema para mudar o clima de mapas e modificações no glacier
- Loading branch information
Showing
9 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Content.Shared.Weather; | ||
using System.ComponentModel.DataAnnotations; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.Weather | ||
{ | ||
[RegisterComponent] | ||
public sealed partial class WeatherCycleComponent : Component | ||
{ | ||
[ViewVariables(VVAccess.ReadWrite), DataField("isEnabled")] | ||
public bool IsEnabled = true; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("weatherCicleDuration")] | ||
public int WeatherCicleDuration = 9; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("weatherCicleStart")] | ||
public int WeatherCicleStart = 19; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("minDuration")] | ||
public int MinDuration = 3; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("maxDuration")] | ||
public int MaxDuration = 8; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("minStartHour")] | ||
public int MinStartHour = 1; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("maxStartHour")] | ||
public int MaxStartHour = 23; | ||
[ViewVariables(VVAccess.ReadWrite), DataField("weatherIds")] | ||
public List<string> WeatherIds { get; set; } = new(); | ||
public bool IsCycleActive { get; set; } = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System.Linq; | ||
using Content.Server.Chat.Systems; | ||
using Content.Server.Weather; | ||
using Content.Shared.CCVar; | ||
using Content.Shared.Weather; | ||
using Content.Shared.Coordinates; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Timing; | ||
|
||
namespace Content.Server.Time | ||
{ | ||
public sealed partial class WeatherCycleSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IConfigurationManager _configuration = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly IEntityManager _entityManager = default!; | ||
[Dependency] private readonly IMapManager _mapManager = default!; | ||
[Dependency] private readonly IEntitySystemManager _entitySystem = default!; | ||
[Dependency] private readonly SharedWeatherSystem _weatherSystem = default!; | ||
[Dependency] private readonly IGameTiming _timing = default!; | ||
private TimeSystem? _timeSystem; | ||
private int _currentHour; | ||
private double _deltaTime; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<WeatherCycleComponent, ComponentInit>(OnMapInit); | ||
_timeSystem = _entitySystem.GetEntitySystem<TimeSystem>(); | ||
} | ||
|
||
private void OnMapInit(EntityUid uid, WeatherCycleComponent comp, ComponentInit args) | ||
{ | ||
comp.IsEnabled = _configuration.GetCVar(CCVars.CycleEnabled); | ||
SetNewWeather(comp); | ||
SetRandomCycleValues(comp); | ||
comp.IsEnabled = true; | ||
} | ||
|
||
private void SetRandomCycleValues(WeatherCycleComponent comp) | ||
{ | ||
int previousDuration = comp.WeatherCicleDuration; | ||
int previousStart = comp.WeatherCicleStart; | ||
|
||
int newDuration = _random.Next(comp.MinDuration, comp.MaxDuration); | ||
int newStartHour = _random.Next(comp.MinStartHour, comp.MaxStartHour); | ||
|
||
if (Math.Abs(newDuration - previousDuration) < 2) | ||
{ | ||
comp.WeatherCicleDuration = newDuration >= comp.MaxDuration ? newDuration - 1 : newDuration + 1; | ||
} | ||
else | ||
{ | ||
comp.WeatherCicleDuration = newDuration; | ||
} | ||
|
||
if (Math.Abs(newStartHour - previousStart) < 2) | ||
{ | ||
comp.WeatherCicleStart = newStartHour >= comp.MaxStartHour ? newStartHour - 1 : newStartHour + 1; | ||
} | ||
else | ||
{ | ||
comp.WeatherCicleStart = newStartHour; | ||
} | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
if (_deltaTime >= 1.0) | ||
{ | ||
_deltaTime = 0; | ||
_currentHour = _timeSystem!.GetStationTime().Hours; | ||
foreach (var comp in EntityQuery<WeatherCycleComponent>()) | ||
{ | ||
if (comp.IsEnabled) | ||
{ | ||
int endHour = (comp.WeatherCicleStart + comp.WeatherCicleDuration) % 24; | ||
bool isWithinCycle; | ||
|
||
if (comp.WeatherCicleDuration >= 24) | ||
{ | ||
isWithinCycle = true; | ||
} | ||
else if (comp.WeatherCicleStart + comp.WeatherCicleDuration < 24) | ||
{ | ||
isWithinCycle = _currentHour >= comp.WeatherCicleStart && _currentHour < endHour; | ||
} | ||
else | ||
{ | ||
isWithinCycle = _currentHour >= comp.WeatherCicleStart || _currentHour < endHour; | ||
} | ||
|
||
if (!comp.IsCycleActive && isWithinCycle) | ||
{ | ||
SetNewWeather(comp); | ||
comp.IsCycleActive = true; | ||
} | ||
else if (comp.IsCycleActive && !isWithinCycle) | ||
{ | ||
SetNewWeather(comp, true); | ||
SetRandomCycleValues(comp); | ||
comp.IsCycleActive = false; | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
_deltaTime += frameTime; | ||
} | ||
} | ||
|
||
private void SetNewWeather(WeatherCycleComponent comp, bool? clean = null) | ||
{ | ||
if (comp.WeatherIds.Count == 0) | ||
return; | ||
|
||
var curTime = _timing.CurTime; | ||
var maxTime = TimeSpan.MaxValue; | ||
|
||
var mapId = comp.Owner.ToCoordinates().GetMapId(_entityManager); | ||
|
||
if (!_mapManager.MapExists(mapId)) | ||
return; | ||
|
||
if (clean == true) | ||
{ | ||
_weatherSystem.SetWeather(mapId, null, null); | ||
return; | ||
} | ||
|
||
var climaId = _random.Pick(comp.WeatherIds); | ||
|
||
if (TryComp<WeatherComponent>(_mapManager.GetMapEntityId(mapId), out var weatherComp) && | ||
weatherComp.Weather.TryGetValue(climaId, out var existing)) | ||
{ | ||
maxTime = curTime - existing.StartTime; | ||
} | ||
|
||
if (!_prototypeManager.TryIndex<WeatherPrototype>(climaId, out var clima)) | ||
return; | ||
|
||
_weatherSystem.SetWeather(mapId, clima, null); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+906 Bytes
Resources/Textures/Clothing/Neck/Misc/raincoat.rsi/equipped-NECK.png
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.
18 changes: 18 additions & 0 deletions
18
Resources/Textures/Clothing/Neck/Misc/raincoat.rsi/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"version": 1, | ||
"license": "CC-BY-SA-3.0", | ||
"copyright": "taken from https://github.com/vgstation-coders/vgstation13/blob/HEAD/icons/mob/suit.dmi", | ||
"size": { | ||
"x": 32, | ||
"y": 32 | ||
}, | ||
"states": [ | ||
{ | ||
"name": "icon" | ||
}, | ||
{ | ||
"name": "equipped-NECK", | ||
"directions": 4 | ||
} | ||
] | ||
} |