Plant genetics (#11407)

This commit is contained in:
Kevin Zheng
2022-10-15 23:25:41 -07:00
committed by GitHub
parent cb2f3a058b
commit 7fc357afd2
14 changed files with 519 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ using Content.Server.Atmos.EntitySystems;
using Content.Server.Botany.Systems;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Hands.Components;
using Content.Server.Ghost.Roles.Components;
using Content.Shared.Botany;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
@@ -127,6 +128,13 @@ namespace Content.Server.Botany.Components
// todo ecs.
var botanySystem = EntitySystem.Get<BotanySystem>();
// Process mutations
if (MutationLevel > 0)
{
Mutate(Math.Min(MutationLevel, 25));
MutationLevel = 0;
}
// Weeds like water and nutrients! They may appear even if there's not a seed planted.
if (WaterLevel > 10 && NutritionLevel > 2 && _random.Prob(Seed == null ? 0.05f : 0.01f))
{
@@ -192,6 +200,13 @@ namespace Content.Server.Botany.Components
var healthMod = _random.Next(1, 3) * HydroponicsSpeedMultiplier;
// Make sure genetics are viable.
if (!Seed.Viable)
{
AffectGrowth(-1);
Health -= 6*healthMod;
}
// Make sure the plant is not starving.
if (_random.Prob(0.35f))
{
@@ -374,6 +389,13 @@ namespace Content.Server.Botany.Components
CheckLevelSanity();
if (Seed.Sentient)
{
var comp = _entMan.EnsureComponent<GhostTakeoverAvailableComponent>(Owner);
comp.RoleName = _entMan.GetComponent<MetaDataComponent>(Owner).EntityName;
comp.RoleDescription = Loc.GetString("station-event-random-sentience-role-description", ("name", comp.RoleName));
}
if (_updateSpriteAfterUpdate)
UpdateSprite();
}
@@ -535,15 +557,7 @@ namespace Content.Server.Botany.Components
if (!solutionSystem.TryGetSolution(Owner, SoilSolutionName, out var solution))
return;
if (solution.TotalVolume <= 0 || MutationLevel >= 25)
{
if (MutationLevel >= 0)
{
Mutate(Math.Min(MutationLevel, 25));
MutationLevel = 0;
}
}
else
if (solution.TotalVolume > 0 && MutationLevel < 25)
{
var amt = FixedPoint2.New(1);
foreach (var (reagentId, quantity) in solutionSystem.RemoveEachReagent(Owner, solution, amt))
@@ -558,13 +572,28 @@ namespace Content.Server.Botany.Components
private void Mutate(float severity)
{
// TODO: Coming soon in "Botany 2: Plant boogaloo".
if (Seed != null)
{
EnsureUniqueSeed();
_entMan.System<MutationSystem>().MutateSeed(Seed, severity);
}
}
public void UpdateSprite()
{
_updateSpriteAfterUpdate = false;
if (Seed != null && Seed.Bioluminescent)
{
var light = _entMan.EnsureComponent<PointLightComponent>(Owner);
light.Radius = Seed.BioluminescentRadius;
light.Color = Seed.BioluminescentColor;
}
else
{
_entMan.RemoveComponent<PointLightComponent>(Owner);
}
if (!_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
return;