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

Commit

Permalink
Adicionado sistema para mudar o clima de mapas e modificações no glacier
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno469 committed Sep 5, 2024
1 parent 58d24c9 commit 6d281c4
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Content.Server/Weather/WeatherCycleComponent.cs
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;
}
}
151 changes: 151 additions & 0 deletions Content.Server/Weather/WeatherCycleSystem.cs
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);
}

}
}
7 changes: 7 additions & 0 deletions Resources/Maps/glacier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ entities:
fixtures: {}
- type: OccluderTree
- type: SpreaderGrid
- type: WeatherCycle
IsEnabled: true
weatherIds:
- SnowfallLight
- SnowfallMedium
- SnowfallHeavy
- Hail
- type: Shuttle
- type: GridPathfinding
- type: Gravity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
ClothingUniformJumpskirtColegialUniformJPNYellow: 2
ClothingSimpleUnderwear: 4
ClothingEyesGlassesCheapSunglasses: 3
ClothingNeckRaincoat: 2
# DO NOT ADD MORE, USE UNIFORM DYING
contrabandInventory:
ClothingMaskNeckGaiter: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ClothingOuterCoatBomber: 3
ClothingHeadHatSantahat: 2
ClothingHeadHatXmasCrown: 2
ClothingNeckRaincoat: 5

emaggedInventory:
ClothingNeckScarfStripedSyndieGreen: 3
Expand Down
15 changes: 15 additions & 0 deletions Resources/Prototypes/Entities/Clothing/Neck/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,18 @@
event: !type:StethoscopeActionEvent
checkCanInteract: false
priority: -1

- type: entity
parent: ClothingNeckBase
id: ClothingNeckRaincoat
name: Raincoat
description: for rainy days!
components:
- type: Armor
modifiers:
coefficients:
Heat: 0.10
- type: Sprite
sprite: Clothing/Neck/Misc/raincoat.rsi
- type: Clothing
sprite: Clothing/Neck/Misc/raincoat.rsi
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 Resources/Textures/Clothing/Neck/Misc/raincoat.rsi/meta.json
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
}
]
}

0 comments on commit 6d281c4

Please sign in to comment.