Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Port] Snowball #199

Merged
merged 5 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public sealed partial class SpillBehavior : IThresholdBehavior
[DataField]
public string? Solution;

// WWDP-Start
[DataField]
public bool SpillSound = true;
// WWDP-End

/// <summary>
/// If there is a SpillableComponent on EntityUidowner use it to create a puddle/smear.
/// Or whatever solution is specified in the behavior itself.
Expand All @@ -35,7 +40,7 @@ public void Execute(EntityUid owner, DestructibleSystem system, EntityUid? cause
else if (Solution != null &&
solutionContainerSystem.TryGetSolution(owner, Solution, out _, out var behaviorSolution))
{
spillableSystem.TrySplashSpillAt(owner, coordinates, behaviorSolution, out _, user: cause);
spillableSystem.TrySplashSpillAt(owner, coordinates, behaviorSolution, out _, SpillSound, user: cause); // WWDP-Edit
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Content.Shared.DoAfter;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

namespace Content.Shared._White.FromTileCrafter.Components;

[RegisterComponent, NetworkedComponent]
public sealed partial class FromTileCrafterComponent : Component
{
/// <summary>
/// Object that will be created
/// </summary>
[DataField, ViewVariables(VVAccess.ReadOnly)]
[ValidatePrototypeId<EntityPrototype>]
public string EntityToSpawn;

/// <summary>
/// Tiles that allowed to use to craft an object
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public HashSet<string> AllowedTileIds = new();

/// <summary>
/// The time it takes to craft.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float Delay = 1f;

/// <summary>
/// How far spawned item can offset from tile center
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float Spread = 0.3f;
}

[Serializable, NetSerializable]
public sealed partial class FromTileCraftDoAfterEvent : DoAfterEvent
{
public NetEntity Grid;
public Vector2i GridTile;

public FromTileCraftDoAfterEvent(NetEntity grid, Vector2i gridTile)
{
Grid = grid;
GridTile = gridTile;
}

public override DoAfterEvent Clone()
{
return new FromTileCraftDoAfterEvent(Grid, GridTile);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System.Numerics;
using Content.Shared._White.FromTileCrafter.Components;
using Content.Shared.DoAfter;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
using Robust.Shared.Random;


namespace Content.Shared._White.FromTileCrafter.Systems;

public sealed class FromTileCrafterSystem : EntitySystem
{
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedMapSystem _maps = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly INetManager _netManager = default!;

public override void Initialize()
{
SubscribeLocalEvent<FromTileCrafterComponent, FromTileCraftDoAfterEvent>(OnFromTileCraftComplete);
SubscribeLocalEvent<FromTileCrafterComponent, AfterInteractEvent>(OnAfterInteract);
}

private void OnFromTileCraftComplete(Entity<FromTileCrafterComponent> ent, ref FromTileCraftDoAfterEvent args)
{
if (_netManager.IsClient)
return;

if (args.Handled || args.Cancelled)
return;

var comp = ent.Comp;

var gridUid = GetEntity(args.Grid);
if (!TryComp<MapGridComponent>(gridUid, out var grid))
return;

var tileRef = _maps.GetTileRef(gridUid, grid, args.GridTile);
var coords = _maps.ToCoordinates(tileRef, grid);

var offset = new Vector2(
((_robustRandom.NextFloat() - 0.5f) * comp.Spread + 0.5f) * grid.TileSize,
((_robustRandom.NextFloat() - 0.5f) * comp.Spread + 0.5f) * grid.TileSize);

Spawn(ent.Comp.EntityToSpawn, coords.Offset(offset));
}

private void OnAfterInteract(Entity<FromTileCrafterComponent> ent, ref AfterInteractEvent args)
{
if (args.Handled || args.Target != null)
return;

var comp = ent.Comp;

if (!_mapManager.TryFindGridAt(_transformSystem.ToMapCoordinates(args.ClickLocation), out var gridUid, out var mapGrid))
return;

var tileRef = _maps.GetTileRef(gridUid, mapGrid, args.ClickLocation);
var tileId = _tileDefManager[tileRef.Tile.TypeId].ID;

if (!comp.AllowedTileIds.Contains(tileId))
return;

var coordinates = _maps.GridTileToLocal(gridUid, mapGrid, tileRef.GridIndices);
if (!_interactionSystem.InRangeUnobstructed(args.User, coordinates, popup: false))
return;

var doAfterEvent = new FromTileCraftDoAfterEvent(GetNetEntity(gridUid), tileRef.GridIndices);
var doAfterArgs = new DoAfterArgs(EntityManager, args.User, comp.Delay, doAfterEvent, ent, used: ent)
{
BreakOnUserMove = true,
BlockDuplicate = true,
DuplicateCondition = DuplicateConditions.SameTool,
};
_doAfterSystem.TryStartDoAfter(doAfterArgs, out _);
}
}
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/_white/flavors/flavors.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flavor-base-snow = как снег
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ent-ItemSnowballMaker = снежколеп
.desc = Позволяет быстро лепить снежки из снега (или из астро-снега, когда сезон не тот).
ent-ItemSnowball = снежок
.desc = Небольшой комочек снега, что можно бросить в кого-то.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
- WeaponCapacitorRechargerCircuitboard
- HandheldStationMap
- ClothingHeadHatWelding
- SnowballMaker # WWDP
- type: EmagLatheRecipes
emagStaticRecipes:
- BoxLethalshot
Expand Down
77 changes: 77 additions & 0 deletions Resources/Prototypes/_White/Entities/Fun/snowball.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
- type: entity
parent: BaseItem
id: ItemSnowballMaker
name: snowball maker
description: Makes snowballs.
components:
- type: Sprite
sprite: _White/Objects/Misc/snowball_maker.rsi
layers:
- state: snowball-maker
- type: Item
- type: PhysicalComposition
materialComposition:
Plastic: 200
- type: FromTileCrafter
delay: 0.5
entityToSpawn: ItemSnowball
allowedTileIds:
- FloorAstroSnow
- FloorSnow
- FloorSnowDug
- PlatingSnow

- type: entity
parent: [BaseItem, FoodBase]
id: ItemSnowball
name: snowball
description: Iced.
components:
- type: Damageable
damageContainer: Inorganic
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 1
behaviors:
- !type:SpillBehavior
solution: snowball
spillSound: False
- !type:PlaySoundBehavior
sound:
path: /Audio/Effects/chop.ogg
- !type:DoActsBehavior
acts: ["Destruction"]
- type: DamageOnLand
damage:
types:
Blunt: 3
- type: StaminaDamageOnCollide
damage: 8.1
- type: Sprite
sprite: _White/Objects/Misc/snowball.rsi
state: snowball
- type: Item
size: Tiny
- type: SolutionContainerManager
solutions:
snowball:
maxVol: 10
reagents:
- ReagentId: Water
Quantity: 5
- type: FlavorProfile
flavors:
- snow
ignoreReagents:
- Water
- type: Food
solution: snowball
- type: MixableSolution
solution: snowball
- type: InjectableSolution
solution: snowball
- type: RefillableSolution
solution: snowball
# - type: LandAtCursor
3 changes: 3 additions & 0 deletions Resources/Prototypes/_White/Flavors/flavors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- type: flavor
id: snow
description: flavor-base-snow
6 changes: 6 additions & 0 deletions Resources/Prototypes/_White/Recipes/Lathes/Misc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- type: latheRecipe
id: SnowballMaker
result: ItemSnowballMaker
completetime: 2
materials:
Plastic: 200
14 changes: 14 additions & 0 deletions Resources/Textures/_White/Objects/Misc/snowball.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Made by RedTerror (Discord, id 748161739056611428)",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "snowball"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Made by RedTerror (Discord, id 748161739056611428)",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "snowball-maker"
},
{
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading