Files

222 lines
8.1 KiB
C#
Raw Permalink Normal View History

using Content.Server.Botany.Components;
using Content.Server.Chemistry.Containers.EntitySystems;
using Content.Server.Kitchen.Components;
2022-12-18 13:12:28 -05:00
using Content.Server.Popups;
using Content.Shared.Botany;
using Content.Shared.Examine;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
2022-10-15 23:25:41 -07:00
using Content.Shared.Slippery;
using Content.Shared.StepTrigger.Components;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
2022-12-18 13:12:28 -05:00
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace Content.Server.Botany.Systems;
2022-12-18 13:12:28 -05:00
public sealed partial class BotanySystem : EntitySystem
{
2022-12-18 13:12:28 -05:00
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
2023-09-11 19:18:06 +10:00
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedPointLightSystem _light = default!;
2022-12-18 13:12:28 -05:00
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly FixtureSystem _fixtureSystem = default!;
[Dependency] private readonly CollisionWakeSystem _colWakeSystem = default!;
[Dependency] private readonly RandomHelperSystem _randomHelper = default!;
2022-12-18 13:12:28 -05:00
public override void Initialize()
{
2022-12-18 13:12:28 -05:00
base.Initialize();
SubscribeLocalEvent<SeedComponent, ExaminedEvent>(OnExamined);
}
public bool TryGetSeed(SeedComponent comp, [NotNullWhen(true)] out SeedData? seed)
{
if (comp.Seed != null)
{
seed = comp.Seed;
return true;
}
if (comp.SeedId != null
&& _prototypeManager.TryIndex(comp.SeedId, out SeedPrototype? protoSeed))
{
seed = protoSeed;
return true;
}
seed = null;
return false;
}
public bool TryGetSeed(ProduceComponent comp, [NotNullWhen(true)] out SeedData? seed)
{
if (comp.Seed != null)
{
seed = comp.Seed;
return true;
}
if (comp.SeedId != null
&& _prototypeManager.TryIndex(comp.SeedId, out SeedPrototype? protoSeed))
{
seed = protoSeed;
return true;
}
seed = null;
return false;
}
private void OnExamined(EntityUid uid, SeedComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
return;
if (!TryGetSeed(component, out var seed))
return;
using (args.PushGroup(nameof(SeedComponent)))
{
var name = Loc.GetString(seed.DisplayName);
args.PushMarkup(Loc.GetString($"seed-component-description", ("seedName", name)));
args.PushMarkup(Loc.GetString($"seed-component-plant-yield-text", ("seedYield", seed.Yield)));
args.PushMarkup(Loc.GetString($"seed-component-plant-potency-text", ("seedPotency", seed.Potency)));
}
}
#region SeedPrototype prototype stuff
/// <summary>
/// Spawns a new seed packet on the floor at a position, then tries to put it in the user's hands if possible.
/// </summary>
Апстрим некоторого из ботаники (#415) * Rainbow Weed (#25759) * rainbow weed * Lipolicide * psicodine + mannitol * happiness * ground + dried + smokables * damn you notepad++ * fix WHY NOT TELL ME ALL THE PROBLEMS AT THE SAME TIME!!! * work * work i beg you * recipe good * possibly fix merge conflict * remove reagents * Psicodine, Mannitol, Lipolicide and Happiness (#27134) * reagents * Update Resources/Locale/en-US/reagents/meta/narcotics.ftl --------- Co-authored-by: Kara <lunarautomaton6@gmail.com> * fix cannabis * Killer tomatoes (#26053) * make tomatoes * many friends! many mommies * finish * renaming system * fix * Update miscellaneous.yml * Update Content.Server/NPC/Systems/NPCImpritingBehaviourSystem.cs Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com> * N * deleete exception? * merge conflict fix * fix? * fuck you * sloth fixes * fixess? * fix --------- Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * Small tomato killer tweak (#27265) * Update miscellaneous.yml * Update mobspawn.yml * Update miscellaneous.yml * Update miscellaneous.yml * Spaceman's Trumpet and Lily (#25090) * trumpet + lily +polypy * trumbet * Change plant clipping mechanics (#25326) Make seeds from clipped plants inherit the decreased health from parents. Also require one growth stage before clipping. * fixes * Resprite & hand position correction of Nettle & Death Nettle (#25421) Resprite of Nettle & Death Nettle. Corrected R & L hand locations for all orientations of both plants. * Remake hairflowers (#25475) * Add more lily usage (orange hairflower and flowercrown) * comit 2 * ee * more fixes * w * im stupid * bring poppy in authodrobe * weh --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Revert "Remake hairflowers (#25475)" This reverts commit 6b2a9b96b18a6c854c3aea149611d7dd496518c0. * Make Holy Water more like Water (#27068) holy water can now be used to satiate thirst, water plants, and extinguish fires. * New plant mutation: Pyrotton (#27200) * WIP * sprites n stuff * flavour * maybe fix * add stack * fix parent * Rewords plant/effect descriptions for clarity (#28156) (#28169) * Rewords plant/effect descriptions for clarity (#28156) * Forgot Robust Harvest. * Update Resources/Locale/en-US/guidebook/chemistry/effects.ftl --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> --------- Co-authored-by: potato1234_x <79580518+potato1234x@users.noreply.github.com> Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Flesh <62557990+PolterTzi@users.noreply.github.com> Co-authored-by: MjrLandWhale <brandonemitch@gmail.com> Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Ghagliiarghii <68826635+Ghagliiarghii@users.noreply.github.com> Co-authored-by: Ubaser <134914314+UbaserB@users.noreply.github.com> Co-authored-by: alex-georgeff <54858069+taurie@users.noreply.github.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
2024-07-02 23:23:12 +03:00
public EntityUid SpawnSeedPacket(SeedData proto, EntityCoordinates coords, EntityUid user, float? healthOverride = null)
{
var seed = Spawn(proto.PacketPrototype, coords);
var seedComp = EnsureComp<SeedComponent>(seed);
seedComp.Seed = proto;
Апстрим некоторого из ботаники (#415) * Rainbow Weed (#25759) * rainbow weed * Lipolicide * psicodine + mannitol * happiness * ground + dried + smokables * damn you notepad++ * fix WHY NOT TELL ME ALL THE PROBLEMS AT THE SAME TIME!!! * work * work i beg you * recipe good * possibly fix merge conflict * remove reagents * Psicodine, Mannitol, Lipolicide and Happiness (#27134) * reagents * Update Resources/Locale/en-US/reagents/meta/narcotics.ftl --------- Co-authored-by: Kara <lunarautomaton6@gmail.com> * fix cannabis * Killer tomatoes (#26053) * make tomatoes * many friends! many mommies * finish * renaming system * fix * Update miscellaneous.yml * Update Content.Server/NPC/Systems/NPCImpritingBehaviourSystem.cs Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com> * N * deleete exception? * merge conflict fix * fix? * fuck you * sloth fixes * fixess? * fix --------- Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> * Small tomato killer tweak (#27265) * Update miscellaneous.yml * Update mobspawn.yml * Update miscellaneous.yml * Update miscellaneous.yml * Spaceman's Trumpet and Lily (#25090) * trumpet + lily +polypy * trumbet * Change plant clipping mechanics (#25326) Make seeds from clipped plants inherit the decreased health from parents. Also require one growth stage before clipping. * fixes * Resprite & hand position correction of Nettle & Death Nettle (#25421) Resprite of Nettle & Death Nettle. Corrected R & L hand locations for all orientations of both plants. * Remake hairflowers (#25475) * Add more lily usage (orange hairflower and flowercrown) * comit 2 * ee * more fixes * w * im stupid * bring poppy in authodrobe * weh --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Revert "Remake hairflowers (#25475)" This reverts commit 6b2a9b96b18a6c854c3aea149611d7dd496518c0. * Make Holy Water more like Water (#27068) holy water can now be used to satiate thirst, water plants, and extinguish fires. * New plant mutation: Pyrotton (#27200) * WIP * sprites n stuff * flavour * maybe fix * add stack * fix parent * Rewords plant/effect descriptions for clarity (#28156) (#28169) * Rewords plant/effect descriptions for clarity (#28156) * Forgot Robust Harvest. * Update Resources/Locale/en-US/guidebook/chemistry/effects.ftl --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> --------- Co-authored-by: potato1234_x <79580518+potato1234x@users.noreply.github.com> Co-authored-by: Kara <lunarautomaton6@gmail.com> Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: faint <46868845+ficcialfaint@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com> Co-authored-by: Flesh <62557990+PolterTzi@users.noreply.github.com> Co-authored-by: MjrLandWhale <brandonemitch@gmail.com> Co-authored-by: lzk <124214523+lzk228@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Ghagliiarghii <68826635+Ghagliiarghii@users.noreply.github.com> Co-authored-by: Ubaser <134914314+UbaserB@users.noreply.github.com> Co-authored-by: alex-georgeff <54858069+taurie@users.noreply.github.com> Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
2024-07-02 23:23:12 +03:00
seedComp.HealthOverride = healthOverride;
var name = Loc.GetString(proto.Name);
var noun = Loc.GetString(proto.Noun);
var val = Loc.GetString("botany-seed-packet-name", ("seedName", name), ("seedNoun", noun));
_metaData.SetEntityName(seed, val);
// try to automatically place in user's other hand
_hands.TryPickupAnyHand(user, seed);
return seed;
}
public IEnumerable<EntityUid> AutoHarvest(SeedData proto, EntityCoordinates position, int yieldMod = 1)
{
if (position.IsValid(EntityManager) &&
proto.ProductPrototypes.Count > 0)
return GenerateProduct(proto, position, yieldMod);
return Enumerable.Empty<EntityUid>();
}
public IEnumerable<EntityUid> Harvest(SeedData proto, EntityUid user, int yieldMod = 1)
{
if (proto.ProductPrototypes.Count == 0 || proto.Yield <= 0)
{
_popupSystem.PopupCursor(Loc.GetString("botany-harvest-fail-message"), user, PopupType.Medium);
return Enumerable.Empty<EntityUid>();
}
var name = Loc.GetString(proto.DisplayName);
_popupSystem.PopupCursor(Loc.GetString("botany-harvest-success-message", ("name", name)), user, PopupType.Medium);
return GenerateProduct(proto, Transform(user).Coordinates, yieldMod);
}
public IEnumerable<EntityUid> GenerateProduct(SeedData proto, EntityCoordinates position, int yieldMod = 1)
{
var totalYield = 0;
if (proto.Yield > -1)
{
if (yieldMod < 0)
totalYield = proto.Yield;
else
totalYield = proto.Yield * yieldMod;
totalYield = Math.Max(1, totalYield);
}
var products = new List<EntityUid>();
if (totalYield > 1 || proto.HarvestRepeat != HarvestType.NoRepeat)
proto.Unique = false;
for (var i = 0; i < totalYield; i++)
{
var product = _robustRandom.Pick(proto.ProductPrototypes);
var entity = Spawn(product, position);
_randomHelper.RandomOffset(entity, 0.25f);
products.Add(entity);
var produce = EnsureComp<ProduceComponent>(entity);
produce.Seed = proto;
ProduceGrown(entity, produce);
2022-12-18 13:12:28 -05:00
_appearance.SetData(entity, ProduceVisuals.Potency, proto.Potency);
if (proto.Mysterious)
{
var metaData = MetaData(entity);
_metaData.SetEntityName(entity, metaData.EntityName + "?", metaData);
_metaData.SetEntityDescription(entity,
metaData.EntityDescription + " " + Loc.GetString("botany-mysterious-description-addon"), metaData);
}
2022-10-15 23:25:41 -07:00
if (proto.Bioluminescent)
{
2023-09-11 19:18:06 +10:00
var light = _light.EnsureLight(entity);
_light.SetRadius(entity, proto.BioluminescentRadius, light);
_light.SetColor(entity, proto.BioluminescentColor, light);
// TODO: Ayo why you copy-pasting code between here and plantholder?
_light.SetCastShadows(entity, false, light); // this is expensive, and botanists make lots of plants
2022-10-15 23:25:41 -07:00
}
if (proto.Slip)
{
var slippery = EnsureComp<SlipperyComponent>(entity);
2023-09-11 19:18:06 +10:00
Dirty(entity, slippery);
2022-10-15 23:25:41 -07:00
EnsureComp<StepTriggerComponent>(entity);
// Need a fixture with a slip layer in order to actually do the slipping
var fixtures = EnsureComp<FixturesComponent>(entity);
var body = EnsureComp<PhysicsComponent>(entity);
var shape = fixtures.Fixtures["fix1"].Shape;
_fixtureSystem.TryCreateFixture(entity, shape, "slips", 1, false, (int) CollisionGroup.SlipLayer, manager: fixtures, body: body);
// Need to disable collision wake so that mobs can collide with and slip on it
var collisionWake = EnsureComp<CollisionWakeComponent>(entity);
_colWakeSystem.SetEnabled(entity, false, collisionWake);
2022-10-15 23:25:41 -07:00
}
}
return products;
}
public bool CanHarvest(SeedData proto, EntityUid? held = null)
{
return !proto.Ligneous || proto.Ligneous && held != null && HasComp<SharpComponent>(held);
}
#endregion
}