Files
crystall-punk-14/Content.Shared/_CP14/SpawnOnTileTool/SharedCP14SpawnOnTileToolSystem.cs
Ed 8cbd26ae2f Farming WIP (#269)
* setup planting doafter

* spawn plants after use seed

* some work

* move comps to separate folder

* public check daylight

* daylight plant energy regeneration

* some fixes

* bruh, im thinking

* added ingame soil

* added hoe

* attaching plants

* hoe system

* block plant dublicating

* some planting refactor

* shovel as pant + soil remover

* plant growing visualizer

* soil resprite

* split farming system to second partial class

* update throught event refactor

* tring sync update plant with update visuals

* finish visual sync

* plants growing

* more partial splitting, naming work, clean up

* Update FARMINGTEST.yml

* Update FARMINGTEST.yml

* fix typo

* prototype value validating

* Оно бухает воду!

* solution visualizer in soil

* forgot some fix

* part of Tornado review fix

* destroy RemovePlantComponent

* more fixes

* simple harvesting

* refactor plant component values changing

* harvest redo

* gather on destroyByTool

* sickle resprite

* plant fading

* fading per minute!

* wheat sprites

* YML restruct

* fixes

* auto root plants

* add comments

* move sprites

* split structures from object textures

* wheat farming!

* Update CP14FarmingSystem.Interactions.cs

* seedbed (#297)

seedbed :^)

* a

* Update soil.yml

---------

Co-authored-by: Jaraten <116667537+Jaraten@users.noreply.github.com>
2024-07-15 23:58:03 +03:00

59 lines
2.1 KiB
C#

using System.Linq;
using Content.Shared._CP14.Farming;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Maps;
using Content.Shared.Popups;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
namespace Content.Shared._CP14.SpawnOnTileTool;
public partial class SharedCP14SpawnOnTileToolSystem : EntitySystem
{
[Dependency] private readonly SharedMapSystem _map = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly ITileDefinitionManager _tileDef = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
public override void Initialize()
{
SubscribeLocalEvent<CP14SpawnOnTileToolComponent, AfterInteractEvent>(OnAfterInteract);
}
private void OnAfterInteract(Entity<CP14SpawnOnTileToolComponent> tool, ref AfterInteractEvent args)
{
var grid = _transform.GetGrid(args.ClickLocation);
if (grid == null || !TryComp<MapGridComponent>(grid, out var gridComp))
return;
var tile = _map.GetTileRef(grid.Value, gridComp, args.ClickLocation);
var tileDef = (ContentTileDefinition) _tileDef[tile.Tile.TypeId];
if (tool.Comp.NeedEmptySpace && _map.GetAnchoredEntities(grid.Value, gridComp, args.ClickLocation).Count() > 0)
{
_popup.PopupClient(Loc.GetString("cp14-insufficient-space"), args.ClickLocation, args.User);
return;
}
foreach (var pair in tool.Comp.Spawns)
{
if (tileDef.ID != pair.Key)
continue;
var doAfterArgs =
new DoAfterArgs(EntityManager, args.User, tool.Comp.DoAfter, new SpawnOnTileToolAfterEvent(EntityManager, args.ClickLocation, pair.Value), tool)
{
BreakOnDamage = true,
BlockDuplicate = true,
BreakOnMove = true,
BreakOnHandChange = true
};
_doAfter.TryStartDoAfter(doAfterArgs);
break;
}
}
}