From 26e4088cdd66040c8c49193d8720159425ed3ccf Mon Sep 17 00:00:00 2001 From: Ed <96445749+TheShuEd@users.noreply.github.com> Date: Thu, 15 May 2025 00:37:42 +0300 Subject: [PATCH] Silva Photosynthes returns + Carcat guidebook page (#1269) * f * restore silva feature * carcat guidebook * day cycle --- .../Farming/CP14FarmingSystem.Resourse.cs | 4 +- .../MagicEnergy/CP14MagicEnergySystem.Draw.cs | 14 +-- .../_CP14/DayCycle/CP14DayCycleComponent.cs | 11 ++ .../_CP14/DayCycle/CP14DayCycleSystem.cs | 118 ++++++++++++++++++ .../_CP14/Entities/Mobs/Species/silva.yml | 6 +- .../_CP14/Guidebook/Eng/species.yml | 8 ++ .../Prototypes/_CP14/Guidebook/Ru/species.yml | 8 ++ .../_CP14/Guidebook_EN/SpeciesTabs/Carcat.xml | 18 +++ .../_CP14/Guidebook_EN/SpeciesTabs/Silva.xml | 2 +- .../_CP14/Guidebook_RU/SpeciesTabs/Carcat.xml | 18 +++ .../_CP14/Guidebook_RU/SpeciesTabs/Silva.xml | 2 +- 11 files changed, 192 insertions(+), 17 deletions(-) create mode 100644 Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs create mode 100644 Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs create mode 100644 Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Carcat.xml create mode 100644 Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Carcat.xml diff --git a/Content.Server/_CP14/Farming/CP14FarmingSystem.Resourse.cs b/Content.Server/_CP14/Farming/CP14FarmingSystem.Resourse.cs index 74de9da51e..88a51510f7 100644 --- a/Content.Server/_CP14/Farming/CP14FarmingSystem.Resourse.cs +++ b/Content.Server/_CP14/Farming/CP14FarmingSystem.Resourse.cs @@ -1,3 +1,4 @@ +using Content.Shared._CP14.DayCycle; using Content.Shared._CP14.Farming.Components; using Content.Shared.Chemistry.Components.SolutionManager; @@ -5,6 +6,7 @@ namespace Content.Server._CP14.Farming; public sealed partial class CP14FarmingSystem { + [Dependency] private readonly CP14DayCycleSystem _dayCycle = default!; private void InitializeResources() { SubscribeLocalEvent(OnTakeEnergyFromLight); @@ -16,7 +18,7 @@ public sealed partial class CP14FarmingSystem private void OnTakeEnergyFromLight(Entity regeneration, ref CP14PlantUpdateEvent args) { var gainEnergy = false; - var daylight = true;//_dayCycle.UnderSunlight(regeneration); + var daylight = _dayCycle.UnderSunlight(regeneration); if (regeneration.Comp.Daytime && daylight) gainEnergy = true; diff --git a/Content.Server/_CP14/MagicEnergy/CP14MagicEnergySystem.Draw.cs b/Content.Server/_CP14/MagicEnergy/CP14MagicEnergySystem.Draw.cs index b4dc1f04b2..61a377e14c 100644 --- a/Content.Server/_CP14/MagicEnergy/CP14MagicEnergySystem.Draw.cs +++ b/Content.Server/_CP14/MagicEnergy/CP14MagicEnergySystem.Draw.cs @@ -1,15 +1,16 @@ using Content.Server._CP14.MagicEnergy.Components; +using Content.Shared._CP14.DayCycle; using Content.Shared._CP14.MagicEnergy.Components; using Content.Shared.Damage; using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Systems; -using Robust.Shared.Map.Components; namespace Content.Server._CP14.MagicEnergy; public partial class CP14MagicEnergySystem { [Dependency] private readonly MobStateSystem _mobState = default!; + [Dependency] private readonly CP14DayCycleSystem _dayCycle = default!; private void InitializeDraw() { @@ -75,16 +76,7 @@ public partial class CP14MagicEnergySystem draw.NextUpdateTime = _gameTiming.CurTime + TimeSpan.FromSeconds(draw.Delay); - var daylight = false; - - //if (TryComp(Transform(uid).MapUid, out var mapLight)) - //{ - // var color = mapLight.AmbientLightColor; - // var medium = (color.R + color.G + color.B) / 3f; - // - // if (medium > draw.LightThreshold) - // daylight = true; - //} + var daylight = _dayCycle.UnderSunlight(uid); ChangeEnergy((uid, magicContainer), daylight ? draw.DaylightEnergy : draw.DarknessEnergy, out _, out _, true); } diff --git a/Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs b/Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs new file mode 100644 index 0000000000..9dde02714a --- /dev/null +++ b/Content.Shared/_CP14/DayCycle/CP14DayCycleComponent.cs @@ -0,0 +1,11 @@ +namespace Content.Shared._CP14.DayCycle; + + +[RegisterComponent] +public sealed partial class CP14DayCycleComponent : Component +{ + public double LastLightLevel = 0f; + + [DataField] + public double Threshold = 0.5f; +} diff --git a/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs b/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs new file mode 100644 index 0000000000..090a707425 --- /dev/null +++ b/Content.Shared/_CP14/DayCycle/CP14DayCycleSystem.cs @@ -0,0 +1,118 @@ +using Content.Shared.GameTicking; +using Content.Shared.Light.Components; +using Content.Shared.Storage.Components; +using Content.Shared.Weather; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Timing; + +namespace Content.Shared._CP14.DayCycle; + +/// +/// This is an add-on to the LightCycle system that helps you determine what time of day it is on the map +/// +public sealed class CP14DayCycleSystem : EntitySystem +{ + [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly MetaDataSystem _metaData = default!; + [Dependency] private readonly SharedGameTicker _ticker = default!; + [Dependency] private readonly SharedMapSystem _maps = default!; + [Dependency] private readonly SharedWeatherSystem _weather = default!; + + private EntityQuery _mapGridQuery; + private EntityQuery _storageQuery; + + + public override void Initialize() + { + base.Initialize(); + + _mapGridQuery = GetEntityQuery(); + _storageQuery = GetEntityQuery(); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var lightCycle, out var dayCycle, out var map)) + { + var oldLightLevel = dayCycle.LastLightLevel; + var newLightLevel = GetLightLevel((uid, lightCycle)); + + dayCycle.LastLightLevel = newLightLevel; + + // Going into darkness + if (oldLightLevel < newLightLevel && oldLightLevel > dayCycle.Threshold && newLightLevel < dayCycle.Threshold) + { + var ev = new CP14StartNightEvent(map.MapId); + RaiseLocalEvent(uid, ref ev, true); + } + + // Going into light + if (oldLightLevel > newLightLevel && oldLightLevel < dayCycle.Threshold && newLightLevel > dayCycle.Threshold) + { + var ev = new CP14StartDayEvent(map.MapId); + RaiseLocalEvent(uid, ref ev, true); + } + } + } + + public double GetLightLevel(Entity map) + { + if (!Resolve(map.Owner, ref map.Comp, false)) + return 0; + + var time = (float) _timing.CurTime + .Add(map.Comp.Offset) + .Subtract(_ticker.RoundStartTimeSpan) + .Subtract(_metaData.GetPauseTime(map)) + .TotalSeconds; + + var normalizedTime = time % map.Comp.Duration.TotalSeconds; + var lightLevel = Math.Sin((normalizedTime / map.Comp.Duration.TotalSeconds) * MathF.PI); + return lightLevel; + } + + /// + /// Checks to see if the specified entity is on the map where it's daytime. + /// + /// An entity being tested to see if it is in daylight + public bool UnderSunlight(EntityUid target) + { + if (_storageQuery.HasComp(target)) + return false; + + var xform = Transform(target); + + if (xform.MapUid is null || xform.GridUid is null) + return false; + + var day = GetLightLevel(xform.MapUid.Value) > 0.5f; + + var grid = xform.GridUid; + if (grid is null) + return day; + + if (!_mapGridQuery.TryComp(grid, out var gridComp)) + return day; + + if (!_weather.CanWeatherAffect(grid.Value, gridComp, _maps.GetTileRef(xform.GridUid.Value, gridComp, xform.Coordinates))) + return false; + + return day; + } +} + +[ByRefEvent] +public record struct CP14StartNightEvent(MapId Map) +{ + public readonly MapId Map = Map; +} + +[ByRefEvent] +public record struct CP14StartDayEvent(MapId Map) +{ + public readonly MapId Map = Map; +} diff --git a/Resources/Prototypes/_CP14/Entities/Mobs/Species/silva.yml b/Resources/Prototypes/_CP14/Entities/Mobs/Species/silva.yml index 8f1b9a0dad..d0af01551e 100644 --- a/Resources/Prototypes/_CP14/Entities/Mobs/Species/silva.yml +++ b/Resources/Prototypes/_CP14/Entities/Mobs/Species/silva.yml @@ -73,9 +73,9 @@ spawned: - id: CP14FoodMeatHuman # Replace it with silva meat, heh. amount: 5 - #- type: CP14MagicEnergyPhotosynthesis # Silva special feature #Disabled until sunlight fixed - #- type: CP14MagicEnergyDraw #Enabled default mana regen until sunlight fixed - # enable: false + - type: CP14MagicEnergyPhotosynthesis # Silva special feature #Disabled until sunlight fixed + - type: CP14MagicEnergyDraw #Enabled default mana regen until sunlight fixed + enable: false - type: Body prototype: CP14Silva requiredLegs: 2 diff --git a/Resources/Prototypes/_CP14/Guidebook/Eng/species.yml b/Resources/Prototypes/_CP14/Guidebook/Eng/species.yml index e7083ab0f4..c941f90507 100644 --- a/Resources/Prototypes/_CP14/Guidebook/Eng/species.yml +++ b/Resources/Prototypes/_CP14/Guidebook/Eng/species.yml @@ -9,6 +9,7 @@ - CP14_EN_Elf - CP14_EN_Tiefling - CP14_EN_Goblin + - CP14_EN_Carcat filterEnabled: True - type: guideEntry @@ -44,4 +45,11 @@ id: CP14_EN_Goblin name: Goblin text: "/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Goblin.xml" + filterEnabled: True + +- type: guideEntry + crystallPunkAllowed: true + id: CP14_EN_Carcat + name: Carcat + text: "/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Carcat.xml" filterEnabled: True \ No newline at end of file diff --git a/Resources/Prototypes/_CP14/Guidebook/Ru/species.yml b/Resources/Prototypes/_CP14/Guidebook/Ru/species.yml index fdd7c8f88e..8e97498483 100644 --- a/Resources/Prototypes/_CP14/Guidebook/Ru/species.yml +++ b/Resources/Prototypes/_CP14/Guidebook/Ru/species.yml @@ -9,6 +9,7 @@ - CP14_RU_Elf - CP14_RU_Tiefling - CP14_RU_Goblin + - CP14_RU_Carcat filterEnabled: True - type: guideEntry @@ -44,4 +45,11 @@ id: CP14_RU_Goblin name: Гоблин text: "/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Goblin.xml" + filterEnabled: True + +- type: guideEntry + crystallPunkAllowed: true + id: CP14_RU_Carcat + name: Каркат + text: "/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Carcat.xml" filterEnabled: True \ No newline at end of file diff --git a/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Carcat.xml b/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Carcat.xml new file mode 100644 index 0000000000..db3e23340a --- /dev/null +++ b/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Carcat.xml @@ -0,0 +1,18 @@ + +# Carcats + + + + + +TODO: Lorekeeper awaiting + +## Night vision + +As natural predators, darkness is no problem for the Carkat. + +## Soft feet + +The unusual shape of a Carkat's feet is both an advantage and a disadvantage. The soft pads make for a silent footstep. But the inability to wear shoes makes their paws vulnerable to sharp objects. + + \ No newline at end of file diff --git a/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Silva.xml b/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Silva.xml index 103d64ec06..1ad0e6f9f5 100644 --- a/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Silva.xml +++ b/Resources/ServerInfo/_CP14/Guidebook_EN/SpeciesTabs/Silva.xml @@ -7,7 +7,7 @@ The Silva are a race of humanoid plants living in deep relic forests. Emerging from the mother tree in the centre of their cities, the Silvas do not travel the world very often. -## Magical photosynthesis (TEMPORARILY DISABLED) +## Magical photosynthesis Silvas regenerate [protodata="CP14MobSilva" comp="CP14MagicEnergyPhotosynthesis" member="DaylightEnergy"/] mana while in sunlight, but without it, mana regeneration is completely absent. diff --git a/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Carcat.xml b/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Carcat.xml new file mode 100644 index 0000000000..69dbadaecb --- /dev/null +++ b/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Carcat.xml @@ -0,0 +1,18 @@ + +# Каркаты + + + + + +TODO: Ожидаем лор лороведов + +## Ночное зрение + +Будучи прирожденными хищниками, темнота для Каркатов - не помеха. + +## Мягкая поступь + +Необычная форма ног у Каркатов, одновременно является их преимуществом и недостатком. Мягкие подушечки обеспечивают абсолютно бесшумную поступь. Но невозможность носить обувь делает их лапы уязвимыми для острых предметов. + + \ No newline at end of file diff --git a/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Silva.xml b/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Silva.xml index 1b6b066263..65545e4d43 100644 --- a/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Silva.xml +++ b/Resources/ServerInfo/_CP14/Guidebook_RU/SpeciesTabs/Silva.xml @@ -7,7 +7,7 @@ Сильва - раса гуманоидных растений обитающих в глубоких реликтовых лесах. Появляясь в центре своих городов из материнского дерева, Сильвы не особо часто путешествуют по миру. -## Магический фотосинтез (ВРЕМЕННО ОТКЛЮЧЕНО) +## Магический фотосинтез Сильвы регенерируют [protodata="CP14MobSilva" comp="CP14MagicEnergyPhotosynthesis" member="DaylightEnergy"/] маны находясь под солнечным светом, но без него регенерация маны полностью отсутствует.