fish-station/Content.Server/Botany/Systems/BotanySystem.Seed.cs
Vigers Ray 95b86d7a4b Merge remote-tracking branch 'space-wizards/master'
# Conflicts:
#	Content.Client/Construction/UI/ConstructionMenu.xaml
#	Content.Client/Construction/UI/ConstructionMenu.xaml.cs
#	Content.Client/Construction/UI/ConstructionMenuPresenter.cs
#	Content.Server/Warps/WarpPointSystem.cs
#	Content.Server/Weapons/Ranged/Systems/GunSystem.Battery.cs
#	Content.Server/Weapons/Ranged/Systems/GunSystem.cs
#	Content.Shared/Construction/Steps/ArbitraryInsertConstructionGraphStep.cs
#	Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs
#	Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs
#	Content.Shared/Inventory/InventorySystem.Relay.cs
#	Content.Shared/Weapons/Reflect/ReflectSystem.cs
#	Resources/Locale/en-US/_strings/plants/mutations.ftl
#	Resources/Locale/en-US/_strings/stack/stacks.ftl
#	Resources/Locale/en-US/_strings/teleportation/teleportation-menu-gui.ftl
#	Resources/Prototypes/Catalog/Fills/Backpacks/duffelbag.yml
#	Resources/Prototypes/Catalog/Fills/Lockers/heads.yml
#	Resources/Prototypes/Catalog/VendingMachines/Inventories/winterdrobe.yml
#	Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
#	Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml
#	Resources/Prototypes/Entities/Objects/Power/powercells.yml
#	Resources/Prototypes/Entities/Objects/Specific/Cargo/cargo_pallet.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Projectiles/shotgun.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml
#	Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml
#	Resources/Prototypes/Entities/Stations/base.yml
#	Resources/Prototypes/Entities/Structures/Machines/nuke.yml
#	Resources/Prototypes/Reagents/toxins.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/clothing/clown_banana.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/machines/computer.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/mechs/hamtr_construction.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/mechs/honker_construction.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/mechs/ripley_construction.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/mechs/vim_construction.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/airlock.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/airlock_clockwork.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/blast_door.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/conveyor.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/firelock.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/glassbox.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/secretdoor.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/shutter.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/shuttle.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/structures/windoor.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/tools/logic_gate.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/APC.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/air_alarms.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/disposal_machines.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/intercom.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/lighting.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/solarpanel.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/station_maps.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/wallmount_generator.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/utilities/wallmount_substation.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/bladed_hats.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/bola.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/improvised_arrow.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/modular_grenade.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/modular_mine.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/shiv.yml
#	Resources/Prototypes/Recipes/Construction/Graphs/weapons/spear.yml
#	Resources/Prototypes/Recipes/Construction/structures.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/bots/cleanbot.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/bots/firebot.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/bots/honkbot.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/bots/medibot.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/bots/mimebot.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/bots/supplybot.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/firebomb.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/improvised_shotgun.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/improvised_shotgun_shell.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/makeshiftstunprod.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/pipebomb.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/pneumatic_cannon.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/improvised/potato.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/storage/cratefreezer.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/storage/tallbox.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/strawhat.yml
#	Resources/Prototypes/Recipes/Crafting/Graphs/toys.yml
#	Resources/Prototypes/Recipes/Crafting/improvised.yml
#	Resources/Prototypes/Recipes/Reactions/medicine.yml
#	Resources/Prototypes/Roles/Jobs/CentComm/official.yml
#	Resources/Textures/Clothing/Neck/mantles/cemantle.rsi/equipped-NECK.png
#	Resources/Textures/Clothing/Neck/mantles/cemantle.rsi/icon.png
#	Resources/Textures/Clothing/Neck/mantles/cemantle.rsi/meta.json
#	Resources/Textures/Clothing/Uniforms/Jumpskirt/mime.rsi/equipped-INNERCLOTHING.png
#	Resources/Textures/Clothing/Uniforms/Jumpskirt/mime.rsi/icon.png
#	Resources/Textures/Clothing/Uniforms/Jumpskirt/mime.rsi/inhand-left.png
#	Resources/Textures/Clothing/Uniforms/Jumpskirt/mime.rsi/inhand-right.png
#	Resources/Textures/Clothing/Uniforms/Jumpskirt/mime.rsi/meta.json
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/mime.rsi/equipped-INNERCLOTHING.png
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/mime.rsi/icon.png
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/mime.rsi/inhand-left.png
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/mime.rsi/inhand-right.png
#	Resources/Textures/Clothing/Uniforms/Jumpsuit/mime.rsi/meta.json
2025-05-04 23:13:12 +03:00

206 lines
7.1 KiB
C#

using Content.Server.Botany.Components;
using Content.Server.Kitchen.Components;
using Content.Server.Popups;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Botany;
using Content.Shared.Examine;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Popups;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Administration.Logs;
using Content.Shared.Database;
namespace Content.Server.Botany.Systems;
public sealed partial class BotanySystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainerSystem = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly RandomHelperSystem _randomHelper = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SeedComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ProduceComponent, ExaminedEvent>(OnProduceExamined);
}
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), 1))
{
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>
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;
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)
{
if (proto.HarvestLogImpact != null)
_adminLogger.Add(LogType.Botany, proto.HarvestLogImpact.Value, $"Auto-harvested {Loc.GetString(proto.Name):seed} at Pos:{position}.");
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);
if (proto.HarvestLogImpact != null)
_adminLogger.Add(LogType.Botany, proto.HarvestLogImpact.Value, $"{ToPrettyString(user):player} harvested {Loc.GetString(proto.Name):seed} at Pos:{Transform(user).Coordinates}.");
return GenerateProduct(proto, Transform(user).Coordinates, yieldMod);
}
public IEnumerable<EntityUid> GenerateProduct(SeedData proto, EntityCoordinates position, int yieldMod = 1)
{
var totalYield = CalculateTotalYield(proto.Yield, yieldMod);
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);
_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);
}
}
return products;
}
public bool CanHarvest(SeedData proto, EntityUid? held = null)
{
return !proto.Ligneous || proto.Ligneous && held != null && HasComp<SharpComponent>(held);
}
public static int CalculateTotalYield(int yield, int yieldMod)
{
var totalYield = 0;
if (yield > -1)
{
if (yieldMod < 0)
totalYield = yield;
else
totalYield = yield * yieldMod;
totalYield = Math.Max(1, totalYield);
}
return totalYield;
}
#endregion
}