Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,51 @@
using System.Threading.Tasks;
using Content.Server.Storage.Components;
using Content.Shared.Audio;
using Content.Shared.Interaction;
using Content.Shared.Notification;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.ViewVariables;
namespace Content.Server.Plants.Components
{
[RegisterComponent]
public class PottedPlantHideComponent : Component, IInteractUsing, IInteractHand
{
public override string Name => "PottedPlantHide";
[ViewVariables] private SecretStashComponent _secretStash = default!;
public override void Initialize()
{
base.Initialize();
_secretStash = Owner.EnsureComponent<SecretStashComponent>();
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
Rustle();
return _secretStash.TryHideItem(eventArgs.User, eventArgs.Using);
}
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
{
Rustle();
var gotItem = _secretStash.TryGetItem(eventArgs.User);
if (!gotItem)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("You root around in the roots."));
}
return gotItem;
}
private void Rustle()
{
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Effects/plant_rustle.ogg", Owner, AudioHelpers.WithVariation(0.25f));
}
}
}

View File

@@ -0,0 +1,78 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Plants.Components
{
[RegisterComponent]
public class RandomPottedPlantComponent : Component, IMapInit
{
public override string Name => "RandomPottedPlant";
private static readonly string[] RegularPlantStates;
private static readonly string[] PlasticPlantStates;
[DataField("selected")]
private string? _selectedState;
[DataField("plastic")]
private bool _plastic;
// for shared string dict, since we don't define these anywhere in content
[UsedImplicitly]
public static readonly string[] plantIdStrings =
{
"plant-01", "plant-02", "plant-03", "plant-04", "plant-05",
"plant-06", "plant-07", "plant-08", "plant-09", "plant-10",
"plant-11", "plant-12", "plant-13", "plant-14", "plant-15",
"plant-16", "plant-17", "plant-18", "plant-19", "plant-20",
"plant-21", "plant-22", "plant-23", "plant-24", "plant-25",
"plant-26", "plant-27", "plant-28", "plant-29", "plant-30",
};
static RandomPottedPlantComponent()
{
// ReSharper disable once StringLiteralTypo
var states = new List<string> {"applebush"};
for (var i = 1; i < 25; i++)
{
states.Add($"plant-{i:D2}");
}
RegularPlantStates = states.ToArray();
states.Clear();
for (var i = 26; i < 30; i++)
{
states.Add($"plant-{i:D2}");
}
PlasticPlantStates = states.ToArray();
}
protected override void Startup()
{
base.Startup();
if (_selectedState != null)
{
Owner.GetComponent<SpriteComponent>().LayerSetState(0, _selectedState);
}
}
public void MapInit()
{
var random = IoCManager.Resolve<IRobustRandom>();
var list = _plastic ? PlasticPlantStates : RegularPlantStates;
_selectedState = random.Pick(list);
Owner.GetComponent<SpriteComponent>().LayerSetState(0, _selectedState);
}
}
}

View File

@@ -0,0 +1,81 @@
using System.Collections.Generic;
using Content.Server.Botany;
using Content.Server.Botany.Components;
using Content.Shared.GameTicking;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Plants
{
[UsedImplicitly]
public class PlantSystem : EntitySystem, IResettingEntitySystem
{
[Dependency] private readonly IComponentManager _componentManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private int _nextUid = 0;
private readonly Dictionary<int, Seed> _seeds = new();
private float _timer = 0f;
public IReadOnlyDictionary<int, Seed> Seeds => _seeds;
public override void Initialize()
{
base.Initialize();
PopulateDatabase();
}
private void PopulateDatabase()
{
_nextUid = 0;
_seeds.Clear();
foreach (var seed in _prototypeManager.EnumeratePrototypes<Seed>())
{
AddSeedToDatabase(seed);
}
}
public bool AddSeedToDatabase(Seed seed)
{
// If it's not -1, it's already in the database. Probably.
if (seed.Uid != -1)
return false;
seed.Uid = GetNextSeedUid();
_seeds[seed.Uid] = seed;
return true;
}
private int GetNextSeedUid()
{
return _nextUid++;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_timer += frameTime;
if (_timer < 3f)
return;
_timer = 0f;
foreach (var plantHolder in _componentManager.EntityQuery<PlantHolderComponent>(true))
{
plantHolder.Update();
}
}
public void Reset()
{
PopulateDatabase();
}
}
}