Alchemy fun mechanics (#246)
* heating solution refactor * chromium slime effect refactor * guidebook hint * hint chance fix * убираем ненужное
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
using Content.Server._CP14.Temperature;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Chemistry.Components;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.Power.Components;
|
||||
@@ -94,26 +92,5 @@ public sealed class SolutionHeaterSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//CrystallPunk bonfire
|
||||
var flammablequery = EntityQueryEnumerator<CP14FlammableSolutionHeaterComponent, ItemPlacerComponent, FlammableComponent>();
|
||||
while (flammablequery.MoveNext(out _, out var heater, out var placer, out var flammable))
|
||||
{
|
||||
foreach (var heatingEntity in placer.PlacedEntities)
|
||||
{
|
||||
if (!flammable.OnFire)
|
||||
continue;
|
||||
|
||||
if (!TryComp<SolutionContainerManagerComponent>(heatingEntity, out var container))
|
||||
continue;
|
||||
|
||||
var energy = flammable.FireStacks * frameTime * 300;
|
||||
foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((heatingEntity, container)))
|
||||
{
|
||||
_solutionContainer.AddThermalEnergy(soln, energy);
|
||||
}
|
||||
}
|
||||
}
|
||||
//CrystallPunk bonfire end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Content.Shared.Chemistry.Components;
|
||||
using Content.Shared.Chemistry.EntitySystems;
|
||||
using Content.Shared.Chemistry.Reagent;
|
||||
using Content.Shared.FixedPoint;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Chemistry.ReagentEffect;
|
||||
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public sealed partial class CP14InverseEffect : Shared.Chemistry.Reagent.ReagentEffect
|
||||
{
|
||||
[DataField]
|
||||
public Dictionary<ProtoId<ReagentPrototype>, ProtoId<ReagentPrototype>> Inversion = new();
|
||||
protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
|
||||
{
|
||||
return Loc.GetString("cp14-reagent-effect-guidebook-inverse-effect", ("chance", Probability));
|
||||
}
|
||||
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
if (args.Source == null)
|
||||
return;
|
||||
|
||||
if (!args.EntityManager.TryGetComponent<SolutionComponent>(args.SolutionEntity, out var solutionComp))
|
||||
return;
|
||||
|
||||
var solutionContainer = args.EntityManager.System<SharedSolutionContainerSystem>();
|
||||
|
||||
var ent = new Entity<SolutionComponent>(args.SolutionEntity, solutionComp);
|
||||
|
||||
Dictionary<ReagentId, FixedPoint2> taskList = new();
|
||||
|
||||
foreach (var reagent in args.Source.Contents)
|
||||
{
|
||||
if (Inversion.ContainsKey(reagent.Reagent.Prototype))
|
||||
taskList.Add(reagent.Reagent, reagent.Quantity);
|
||||
}
|
||||
|
||||
foreach (var task in taskList)
|
||||
{
|
||||
solutionContainer.RemoveReagent(ent, task.Key, task.Value);
|
||||
solutionContainer.TryAddReagent(ent, Inversion[task.Key.Prototype].Id, task.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
|
||||
namespace Content.Server._CP14.Temperature;
|
||||
|
||||
/// <summary>
|
||||
/// Adds thermal energy from FlammableComponent to solutions placed on it.
|
||||
/// allows you to heat the temperature of solutions depending on the number of stacks of fire
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(SolutionHeaterSystem))]
|
||||
[RegisterComponent, Access(typeof(CP14SolutionTemperatureSystem))]
|
||||
public sealed partial class CP14FlammableSolutionHeaterComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public float DegreesPerStack = 100f;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Content.Server._CP14.Temperature;
|
||||
|
||||
/// <summary>
|
||||
/// passively returns the solution temperature to the standard
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(CP14SolutionTemperatureSystem))]
|
||||
public sealed partial class CP14SolutionTemperatureComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public float StandardTemp = 300f;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Shared.Chemistry.Components.SolutionManager;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Placeable;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._CP14.Temperature;
|
||||
|
||||
public sealed partial class CP14SolutionTemperatureSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainer = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
private TimeSpan _updateTick = TimeSpan.FromSeconds(1f);
|
||||
private TimeSpan _timeToNextUpdate = TimeSpan.Zero;
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
if (_timing.CurTime <= _timeToNextUpdate)
|
||||
return;
|
||||
|
||||
_timeToNextUpdate = _timing.CurTime + _updateTick;
|
||||
|
||||
FlammableHeating();
|
||||
NormalizeTemperature();
|
||||
}
|
||||
|
||||
private void NormalizeTemperature()
|
||||
{
|
||||
var query = EntityQueryEnumerator<CP14SolutionTemperatureComponent, SolutionContainerManagerComponent>();
|
||||
while (query.MoveNext(out var uid, out var temp, out var container))
|
||||
{
|
||||
foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((uid, container)))
|
||||
{
|
||||
if (TryAffectTemp(soln.Comp.Solution.Temperature, temp.StandardTemp, soln.Comp.Solution.Volume, out var newT, power: 0.05f))
|
||||
_solutionContainer.SetTemperature(soln, newT);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void FlammableHeating()
|
||||
{
|
||||
var query =
|
||||
EntityQueryEnumerator<CP14FlammableSolutionHeaterComponent, ItemPlacerComponent, FlammableComponent>();
|
||||
while (query.MoveNext(out _, out var heater, out var itemPlacer, out var flammable))
|
||||
{
|
||||
foreach (var heatingEntity in itemPlacer.PlacedEntities)
|
||||
{
|
||||
if (!flammable.OnFire)
|
||||
continue;
|
||||
|
||||
if (!TryComp<SolutionContainerManagerComponent>(heatingEntity, out var container))
|
||||
continue;
|
||||
|
||||
var targetT = flammable.FireStacks * heater.DegreesPerStack;
|
||||
foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((heatingEntity, container)))
|
||||
{
|
||||
if (TryAffectTemp(soln.Comp.Solution.Temperature, targetT, soln.Comp.Solution.Volume, out var newT))
|
||||
_solutionContainer.SetTemperature(soln, newT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryAffectTemp(float oldT, float targetT, FixedPoint2 mass, out float newT, float power = 1)
|
||||
{
|
||||
newT = oldT;
|
||||
|
||||
if (mass == 0)
|
||||
return false;
|
||||
|
||||
newT = (float) (oldT + ((targetT - oldT) / mass) * power);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user