Skip to content

Commit

Permalink
resomi jumping system
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinary1 committed Feb 22, 2025
1 parent 314e1b4 commit 54a4795
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Content.Server/Abilities/Resomi/ResomiSkillComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Shared.Alert;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;

namespace Content.Server.Abilities.Resomi
{
[RegisterComponent]
public sealed partial class ResomiSkillComponent : Component
{
[DataField("actionJumpId", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string ActionJumpId = "Jump";

[DataField]
public float MaxThrow = 10f;
}
}
56 changes: 56 additions & 0 deletions Content.Server/Abilities/Resomi/ResomiSkillSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Server.Actions;
using Content.Shared.Abilities.Resomi;
using Content.Shared.Throwing;
using Robust.Shared.Prototypes;
using Robust.Shared.Map;

namespace Content.Server.Abilities.Resomi;

public sealed class ResomiSkillSystem : EntitySystem
{
[Dependency] private readonly ActionsSystem _action = default!;
[Dependency] private readonly ThrowingSystem _throwing = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly IMapManager _mapMan = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ResomiSkillComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<ResomiSkillComponent, ResomiJumpActionEvent>(OnResomiJump);
}

private void OnStartup(EntityUid uid, ResomiSkillComponent component, ComponentStartup args) => _action.AddAction(uid, component.ActionJumpId);

private void OnResomiJump(EntityUid uid, ResomiSkillComponent component, ResomiJumpActionEvent args)
{
//idea taked from VigersRay

if (args.Handled)
return;

var userTransform = Transform(uid);

if (!_mapMan.TryFindGridAt(vampirePosition, out _, out var grid))
return;

if (!_mapSystem.TryGetTileRef(uid, grid, userTransform.Coordinates, out var tileRef))
return;

if (tileRef.Tile.IsEmpty || tileRef.IsSpace() || tileRef.Tile.GetContentTileDefinition().ID == "Lattice")
return;

args.Handled = true;

var targetPlace = args.Target.ToMap(EntityManager, _transform);

var targetDirection = targetPlace.Position - userTransform.MapPosition.Position;

if (targetDirection.Length() > component.MaxThrow)
targetDirection = targetDirection.Normalized() * component.MaxThrow;

_throwing.TryThrow(uid, targetDirection, 7F, uid, 10F);
}
}

0 comments on commit 54a4795

Please sign in to comment.