-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Снежки (#179) * snowballs * nah * reviewe * oops + better offset * a * migrate * fixiki * namespaces * edit flavors --------- Co-authored-by: csqrb <[email protected]>
- Loading branch information
1 parent
3a865cb
commit e55275d
Showing
15 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Content.Shared/_White/FromTileCrafter/Components/FromTileCrafterComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
Content.Shared/_White/FromTileCrafter/Systems/FromTileCrafterSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 _); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flavor-base-snow = как снег |
5 changes: 5 additions & 0 deletions
5
Resources/Locale/ru-RU/_white/prototypes/entities/objects/misc/snowball.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ent-ItemSnowballMaker = снежколеп | ||
.desc = Позволяет быстро лепить снежки из снега (или из астро-снега, когда сезон не тот). | ||
ent-ItemSnowball = снежок | ||
.desc = Небольшой комочек снега, что можно бросить в кого-то. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- type: flavor | ||
id: snow | ||
description: flavor-base-snow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
Resources/Textures/_White/Objects/Misc/snowball.rsi/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Binary file added
BIN
+344 Bytes
Resources/Textures/_White/Objects/Misc/snowball_maker.rsi/inhand-left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+349 Bytes
Resources/Textures/_White/Objects/Misc/snowball_maker.rsi/inhand-right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions
22
Resources/Textures/_White/Objects/Misc/snowball_maker.rsi/meta.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} |
Binary file added
BIN
+420 Bytes
Resources/Textures/_White/Objects/Misc/snowball_maker.rsi/snowball-maker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.