Skip to content
Draft
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
@@ -0,0 +1,3 @@
// тут мог бы быть ваш код)
// но я криворукий бэкэндер который в душе не чает как работать нормально с визуалом поэтому тут пусто
// TODO : сделать нормальное отображение потопления, а не тот костыль который я сделаю
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Content.Server.Shuttles.Components;
using Content.Server.Shuttles.Systems;
using Content.Shared.Imperial.Medieval.Ships.Anchor;

namespace Content.Server.Imperial.Medieval.Ships.Anchor;

/// <summary>
/// This handles...
/// </summary>
public sealed class ServerMedievalAnchorSystem : EntitySystem
{
[Dependency] private readonly ShuttleSystem _shuttleSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<MedievalAnchorComponent, UseAnchorEvent>(OnUseAnchor);
}

private void OnUseAnchor(EntityUid uid, MedievalAnchorComponent component, UseAnchorEvent args)
{
if (args.Target == null || args.Cancelled)
return;

var target = component.Owner;

var enabled = component.Enabled;

ShuttleComponent? shuttleComponent = default;

var transform = Transform(target);
var grid = transform.GridUid;
if (!grid.HasValue || !transform.Anchored || !Resolve(grid.Value, ref shuttleComponent))
return;

if (!enabled)
{
_shuttleSystem.Disable(grid.Value);
}
else
{
_shuttleSystem.Enable(grid.Value);
}

shuttleComponent.Enabled = !enabled;
component.Enabled = !enabled;
}
}
76 changes: 76 additions & 0 deletions Content.Server/Imperial/Medieval/Ships/Helm/HelmSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Numerics;
using Content.Server.Administration.Logs;
using Content.Shared._RD.Weight.Systems;
using Content.Shared.Database;
using Content.Shared.DoAfter;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Imperial.Medieval.Skills;
using Content.Shared.Popups;
using NetCord;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Random;
using Robust.Shared.Timing;

namespace Content.Server.Imperial.Medieval.Ships.Helm;

/// <summary>
/// This handles...
/// </summary>
public sealed class HelmSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedSkillsSystem _skills = default!;
[Dependency] private readonly EntityManager _entManager = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly RDWeightSystem _rdWeight = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAdminLogManager _adminLog = default!;

public void RotateShip(EntityUid boat, EntityUid helm, float helmForce)
{
_physics.WakeBody(boat);
var helmAngle = _transform.GetWorldRotation(helm);
var entities = _lookup.GetEntitiesIntersecting(boat);
EntityUid? steeringOar = null;
foreach (var e in entities)
{
if (HasComp<SteeringOarComponent>(e))
{
steeringOar = e;
break;
}
}
if (steeringOar == null)
return;
var steeringOarAngle = _transform.GetWorldRotation(steeringOar.Value);
var diff = (float)steeringOarAngle*180 - (float)helmAngle*180;
diff *= -1;
if (helmForce > 0)
{
_physics.ApplyAngularImpulse(boat, diff);
return;
}
if (helmForce < 0)
{
_physics.ApplyAngularImpulse(boat, -diff);
return;
}
}

public float CheckForce(EntityUid boat, EntityUid helm)
{
var boatAngle = (float)_transform.GetWorldRotation(boat)*180;
var helmcos = MathF.Cos(boatAngle);
var helmsin = MathF.Sin(boatAngle);
var helmVector = _physics.GetMapLinearVelocity(boat);
var helmForce = Math.Abs(helmVector.X) + Math.Abs(helmVector.Y);
_adminLog.Add(LogType.Action, LogImpact.Extreme, $"хельма {helmForce}");
return helmForce;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server.Imperial.Medieval.Ships.Helm;

/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class SteeringOarComponent : Component
{

}
131 changes: 131 additions & 0 deletions Content.Server/Imperial/Medieval/Ships/Oar/ServerOarSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Numerics;
using Content.Shared._RD.Weight.Components;
using Content.Shared._RD.Weight.Systems;
using Content.Shared.Coordinates;
using Content.Shared.DoAfter;
using Content.Shared.Imperial.Medieval.Skills;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;


using Content.Shared.Database;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Imperial.Medieval.Ships.Oar;
using Content.Shared.Interaction.Components;
using Content.Shared.Movement.Components;


namespace Content.Server.Imperial.Medieval.Ships.Oar;

/// <summary>
/// This handles...
/// </summary>
public sealed class OarSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedSkillsSystem _skills = default!;
[Dependency] private readonly EntityManager _entManager = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
[Dependency] private readonly RDWeightSystem _rdWeight = default!;
public override void Initialize()
{
SubscribeLocalEvent<OarComponent, OnOarDoAfterEvent>(OnOarDoAfter);
}

private void OnOarDoAfter(EntityUid uid, OarComponent component, ref OnOarDoAfterEvent args)
{
if (args.Cancelled)
{
RemComp<NoRotateOnInteractComponent>(args.User);
RemComp<NoRotateOnMoveComponent>(args.User);
}

var item = _hands.GetActiveItem(args.User);
if (args.Cancelled || args.Handled || item == null)
return;

if (!TryComp<OarComponent>(item, out var comp))
return;

Push(item.Value, comp.Direction, comp.Power, args.User);
args.Handled = true;
args.Repeat = true;
}

private void Push(EntityUid item, Angle direction, float power, EntityUid player)
{
power += power * (-10 + _skills.GetSkillLevel(player, "Strength")) * 0.1f;

var boat = _transform.GetParentUid(player);

var boatAngle = _transform.GetWorldRotation(boat);

var playerAngle = _transform.GetWorldRotation(player);

var entities = _lookup.GetEntitiesIntersecting(boat);

if (entities.Count > 1000)
return;

var weight = _rdWeight.GetTotal(boat);

foreach (var entity in entities)
{
if (HasComp<RDWeightComponent>(entity))
weight += _rdWeight.GetTotal(entity);
}

if (weight == 0)
weight = 10;

var directionVec = Vector2.Zero;
while (direction > 2)
{
direction -= 2;
}


direction += Angle.FromDegrees(45);
// от 0 до 0.5 (1,0)
// от 0.5 до 1 (0,1)
// от 1 до 1,5 (0,-1)
// от 1,5 до 0 (-1,0)
if (direction > 1)
{
if (direction > 1.5)
directionVec = new Vector2(-1,0);
else
{
directionVec = new Vector2(0,-1);
}
}
else
{
if (direction > 0.5)
directionVec = new Vector2(0,1);
else
{
directionVec = new Vector2(1,0);
}
}

directionVec = playerAngle.RotateVec(directionVec);
var impulse = directionVec * (power / weight);
var angleimpulse = (power / weight);

if (EntityManager.TryGetComponent(boat, out PhysicsComponent? body))
{
_physics.WakeBody(boat);
_physics.ApplyLinearImpulse(boat, impulse, body: body);
// _physics.ApplyAngularImpulse(boat, angleimpulse, body: body);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Server.Imperial.Medieval.Ships.PlayerDrowning;

/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class DrownerComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Content.Server.Imperial.Medieval.Ships.PlayerDrowning;

/// <summary>
/// This is used for...
/// </summary>
[RegisterComponent]
public sealed partial class PlayerDrowningComponent : Component
{
[DataField("drownTime")]
public int DrownTime;

[DataField("Undrowable")]
public bool Undrowable;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Systems;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Timing;

namespace Content.Server.Imperial.Medieval.Ships.PlayerDrowning;

/// <summary>
/// This handles...
/// </summary>
public sealed class PlayerDrowningSystem : EntitySystem
{
private const float DefaultReloadTimeSeconds = 1f;
private const int DrownTimeMax = 15;
private TimeSpan _nextCheckTime;

[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly EntityManager _entityManager = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly SharedStaminaSystem _staminaSystem = default!;

/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
_nextCheckTime = _timing.CurTime + TimeSpan.FromSeconds(DefaultReloadTimeSeconds);

}

public override void Update(float frameTime)
{
base.Update(frameTime);

var curTime = _timing.CurTime;

if (curTime > _nextCheckTime)
{
_nextCheckTime = curTime + TimeSpan.FromSeconds(DefaultReloadTimeSeconds);

foreach (var component in EntityManager.EntityQuery<DrownerComponent>())
{
if (!TryComp<TransformComponent>(component.Owner, out var transform))
continue;
var childBasement = transform.ChildEnumerator;
while (childBasement.MoveNext(out var childUid))
EnsureComp<PlayerDrowningComponent>(childUid);
}

foreach (var component in EntityManager.EntityQuery<PlayerDrowningComponent>())
{
if (HasComp<DrownerComponent>(_transform.GetParentUid(component.Owner)))
{
ProcessDrowning(component.Owner);
continue;
}
if (component.DrownTime > 0)
component.DrownTime -= 1;
else
RemComp<PlayerDrowningComponent>(component.Owner);

}

}
}

private void ProcessDrowning(EntityUid uid)
{
if (HasComp<MapGridComponent>(uid))
return;

if (!TryComp<PlayerDrowningComponent>(uid, out var drowner))
EnsureComp<PlayerDrowningComponent>(uid);
else
{
if (drowner.Undrowable)
return;
if (HasComp<UndrowableComponent>(uid))
return;

if (TryComp<StaminaComponent>(uid, out var stamina))
{
if (stamina.Critical)
{
_entityManager.DeleteEntity(uid);
return;
}

if (_staminaSystem.TryTakeStamina(uid, 10, ignoreResist: true))
return;

}
if (drowner.DrownTime >= DrownTimeMax)
{
_entityManager.DeleteEntity(uid);
}
drowner.DrownTime += 1;
}
}
}
Loading
Loading