Skip to content

Commit

Permalink
Update chemical effects
Browse files Browse the repository at this point in the history
  • Loading branch information
PraxisMapper committed Sep 19, 2024
1 parent feeeaf3 commit e68cb5a
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Diagnostics.CodeAnalysis;

namespace Content.Server.EntityEffects.Effects.PlantMetabolism;
Expand Down Expand Up @@ -32,14 +31,12 @@ public abstract partial class PlantAdjustAttribute : EntityEffect
/// <param name="entityManager">The entity manager</param>
/// <param name="mustHaveAlivePlant">Whether to check if it has an alive plant or not</param>
/// <returns></returns>
public bool CanMetabolize(EntityUid plantHolder, [NotNullWhen(true)] out PlantHolderComponent? plantHolderComponent,
public bool CanMetabolize(EntityUid plant, [NotNullWhen(true)] out PlantComponent? plantComponent,
IEntityManager entityManager,
bool mustHaveAlivePlant = true)
{
plantHolderComponent = null;

if (!entityManager.TryGetComponent(plantHolder, out plantHolderComponent)
|| mustHaveAlivePlant && (plantHolderComponent.Seed == null || plantHolderComponent.Dead))
if (!entityManager.TryGetComponent(plant, out plantComponent)
|| (mustHaveAlivePlant && plantComponent.Dead))
return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;

Expand All @@ -6,16 +7,18 @@ namespace Content.Server.EntityEffects.Effects.PlantMetabolism;
public sealed partial class PlantAdjustHealth : PlantAdjustAttribute
{
public override string GuidebookAttributeName { get; set; } = "plant-attribute-health";

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
if (!CanMetabolize(args.TargetEntity, out PlantComponent? plantComp, args.EntityManager))
return;

var plantHolder = args.EntityManager.System<PlantHolderSystem>();

plantHolderComp.Health += Amount;
plantHolder.CheckHealth(args.TargetEntity, plantHolderComp);
plantComp.Health += Amount;
if (plantComp.Health <= 0)
{
var plant = args.EntityManager.System<PlantSystem>();
plant.Die(args.TargetEntity);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;

namespace Content.Server.EntityEffects.Effects.PlantMetabolism;
Expand All @@ -8,9 +9,9 @@ public sealed partial class PlantAdjustMutationLevel : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
if (!CanMetabolize(args.TargetEntity, out PlantComponent? plantComp, args.EntityManager))
return;

plantHolderComp.MutationLevel += Amount * plantHolderComp.MutationMod;
plantComp.MutationLevel += Amount * plantComp.MutationMod;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;

Expand All @@ -10,10 +11,10 @@ public sealed partial class PlantAdjustMutationMod : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
if (!CanMetabolize(args.TargetEntity, out PlantComponent? plantComp, args.EntityManager))
return;

plantHolderComp.MutationMod += Amount;
plantComp.MutationMod = Math.Clamp(plantComp.MutationMod + Amount, 1f, 3f);
}
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
Expand All @@ -11,11 +12,8 @@ public sealed partial class PlantAdjustNutrition : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager, mustHaveAlivePlant: false))
return;

var plantComp = args.EntityManager.GetComponent<PlantComponent>(args.TargetEntity);
var plantHolder = args.EntityManager.System<PlantHolderSystem>();

plantHolder.AdjustNutrient(args.TargetEntity, Amount, plantHolderComp);
plantHolder.AdjustNutrient(plantComp.PlantHolderUid, Amount);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;

Expand All @@ -11,10 +12,9 @@ public sealed partial class PlantAdjustPests : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
return;

plantHolderComp.PestLevel += Amount;
var plantComp = args.EntityManager.GetComponent<PlantComponent>(args.TargetEntity);
var plantHolderComp = args.EntityManager.GetComponent<PlantHolderComponent>(plantComp.PlantHolderUid);
plantHolderComp.PestLevel = Math.Clamp(plantHolderComp.PestLevel + Amount, 0, 10);
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Content.Server.Botany.Systems;
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;

namespace Content.Server.EntityEffects.Effects.PlantMetabolism;
Expand All @@ -13,16 +13,12 @@ public sealed partial class PlantAdjustPotency : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantComponent? plantComp)
|| plantComp.Dead || plantComp.Seed == null || plantComp.Seed.Immutable)
{
return;
}

if (plantHolderComp.Seed == null)
return;

var plantHolder = args.EntityManager.System<PlantHolderSystem>();

plantHolder.EnsureUniqueSeed(args.TargetEntity, plantHolderComp);

plantHolderComp.Seed.Potency = Math.Max(plantHolderComp.Seed.Potency + Amount, 1);
plantComp.Seed.Potency = Math.Max(plantComp.Seed.Potency + Amount, 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;

Expand All @@ -11,9 +12,8 @@ public sealed partial class PlantAdjustToxins : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
return;

var plantComp = args.EntityManager.GetComponent<PlantComponent>(args.TargetEntity);
var plantHolderComp = args.EntityManager.GetComponent<PlantHolderComponent>(plantComp.PlantHolderUid);
plantHolderComp.Toxins += Amount;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
Expand All @@ -11,12 +12,9 @@ public sealed partial class PlantAdjustWater : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager, mustHaveAlivePlant: false))
return;

var plantComp = args.EntityManager.GetComponent<PlantComponent>(args.TargetEntity);
var plantHolder = args.EntityManager.System<PlantHolderSystem>();

plantHolder.AdjustWater(args.TargetEntity, Amount, plantHolderComp);
plantHolder.AdjustWater(plantComp.PlantHolderUid, Amount);
}
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;

Expand All @@ -11,9 +12,12 @@ public sealed partial class PlantAdjustWeeds : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantComponent? plantComp))
return;

plantHolderComp.WeedLevel += Amount;
if (!args.EntityManager.TryGetComponent(plantComp.PlantHolderUid, out PlantHolderComponent? plantHolderComp))
return;

plantHolderComp.WeedLevel = Math.Clamp(plantHolderComp.WeedLevel + Amount, 0f, 10f);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
Expand All @@ -11,12 +12,11 @@ public sealed partial class PlantAffectGrowth : PlantAdjustAttribute

public override void Effect(EntityEffectBaseArgs args)
{
if (!CanMetabolize(args.TargetEntity, out var plantHolderComp, args.EntityManager))
if (!CanMetabolize(args.TargetEntity, out PlantComponent? plantComp, args.EntityManager))
return;

var plantHolder = args.EntityManager.System<PlantHolderSystem>();

plantHolder.AffectGrowth(args.TargetEntity, (int) Amount, plantHolderComp);
var plant = args.EntityManager.System<PlantSystem>();
plant.AffectGrowth(args.TargetEntity, (int)Amount, plantComp);
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
Expand All @@ -12,20 +13,21 @@ public sealed partial class PlantCryoxadone : EntityEffect
{
public override void Effect(EntityEffectBaseArgs args)
{
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead)
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantComponent? plantComp)
|| plantComp.Dead || plantComp.Seed == null || plantComp.Seed.Immutable)
return;

var deviation = 0;
var seed = plantHolderComp.Seed;
var seed = plantComp.Seed;
var random = IoCManager.Resolve<IRobustRandom>();
if (plantHolderComp.Age > seed.Maturation)
deviation = (int) Math.Max(seed.Maturation - 1, plantHolderComp.Age - random.Next(7, 10));
if (plantComp.Age > seed.Maturation)
deviation = (int)Math.Max(seed.Maturation - 1, plantComp.Age - random.Next(7, 10));
else
deviation = (int) (seed.Maturation / seed.GrowthStages);
plantHolderComp.Age -= deviation;
plantHolderComp.SkipAging++;
plantHolderComp.ForceUpdate = true;
deviation = (int)(seed.Maturation / seed.GrowthStages);
plantComp.Age -= deviation;
plantComp.SkipAging++;
var plantSys = args.EntityManager.System<PlantSystem>();
plantSys.Update(args.TargetEntity, plantComp);
}

protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-cryoxadone", ("chance", Probability));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Server.Botany.Components;
using Content.Shared.EntityEffects;
using Content.Shared.Popups;
using Robust.Shared.Prototypes;
Expand All @@ -14,26 +13,19 @@ public sealed partial class PlantDestroySeeds : EntityEffect
{
public override void Effect(EntityEffectBaseArgs args)
{
if (
!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null
|| plantHolderComp.Dead
|| plantHolderComp.Seed.Immutable
)
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantComponent? plantComp)
|| plantComp.Dead || plantComp.Seed == null || plantComp.Seed.Immutable)
return;

var plantHolder = args.EntityManager.System<PlantHolderSystem>();
var popupSystem = args.EntityManager.System<SharedPopupSystem>();

if (plantHolderComp.Seed.Seedless == false)
if (plantComp.Seed != null && plantComp.Seed.Seedless == false)
{
plantHolder.EnsureUniqueSeed(args.TargetEntity, plantHolderComp);
var popupSystem = args.EntityManager.System<SharedPopupSystem>();
popupSystem.PopupEntity(
Loc.GetString("botany-plant-seedsdestroyed"),
args.TargetEntity,
PopupType.SmallCaution
);
plantHolderComp.Seed.Seedless = true;
plantComp.Seed.Seedless = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.EntityEffects;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
Expand All @@ -13,29 +12,22 @@ public sealed partial class PlantDiethylamine : EntityEffect
{
public override void Effect(EntityEffectBaseArgs args)
{
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead ||
plantHolderComp.Seed.Immutable)
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantComponent? plantComp)
|| plantComp.Dead || plantComp.Seed == null || plantComp.Seed.Immutable)
return;


var plantHolder = args.EntityManager.System<PlantHolderSystem>();

var random = IoCManager.Resolve<IRobustRandom>();

if (random.Prob(0.1f))
{
plantHolder.EnsureUniqueSeed(args.TargetEntity, plantHolderComp);
plantHolderComp.Seed.Lifespan++;
plantComp.Seed.Lifespan++;
}

if (random.Prob(0.1f))
{
plantHolder.EnsureUniqueSeed(args.TargetEntity, plantHolderComp);
plantHolderComp.Seed.Endurance++;
plantComp.Seed.Endurance++;
}
}

protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-diethylamine", ("chance", Probability));
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ public sealed partial class PlantPhalanximine : EntityEffect
{
public override void Effect(EntityEffectBaseArgs args)
{
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantHolderComponent? plantHolderComp)
|| plantHolderComp.Seed == null || plantHolderComp.Dead ||
plantHolderComp.Seed.Immutable)
if (!args.EntityManager.TryGetComponent(args.TargetEntity, out PlantComponent? plantComp)
|| plantComp.Dead || plantComp.Seed == null || plantComp.Seed.Immutable)
return;

plantHolderComp.Seed.Viable = true;
plantComp.Seed.Viable = true;
}

protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys) => Loc.GetString("reagent-effect-guidebook-plant-phalanximine", ("chance", Probability));
Expand Down
Loading

0 comments on commit e68cb5a

Please sign in to comment.