123
This commit is contained in:
@@ -5,14 +5,12 @@ using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Input;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client._CP14.Fishing;
|
||||
|
||||
public sealed class CP14FishingSystem : CP14SharedFishingSystem
|
||||
{
|
||||
[Dependency] private readonly InputSystem _input = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly HandsSystem _hands = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
|
||||
|
||||
@@ -27,9 +25,6 @@ public sealed class CP14FishingSystem : CP14SharedFishingSystem
|
||||
{
|
||||
base.Update(dt);
|
||||
|
||||
if (!_gameTiming.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
var heldUid = _hands.GetActiveHandEntity();
|
||||
|
||||
if (!TryComp<CP14FishingRodComponent>(heldUid, out var fishingRodComponent))
|
||||
|
||||
@@ -2,7 +2,6 @@ using Content.Client.Resources;
|
||||
using Content.Shared._CP14.Fishing;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
@@ -10,20 +10,28 @@ public abstract partial class CP14FishBaseBehavior
|
||||
/// <summary>
|
||||
/// Calculates fish position
|
||||
/// </summary>
|
||||
/// <param name="random"> Robust random</param>
|
||||
/// <param name="fishCords"> Current fish coordinates</param>
|
||||
/// <param name="random"> Robust random </param>
|
||||
/// <param name="fishCords"> Current fish coordinates </param>
|
||||
/// <returns> Calculated fish coordinates </returns>
|
||||
public abstract Vector2 TryCalculatePosition(IRobustRandom random, Vector2 fishCords);
|
||||
public Vector2 TryCalculatePosition(IRobustRandom random, Vector2 fishCords)
|
||||
{
|
||||
var speed = CalculateSpeed(random);
|
||||
var nextPos = float.Lerp(fishCords.X, fishCords.Y, speed);
|
||||
|
||||
return new Vector2(nextPos, fishCords.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Speed which fish uses when going from A to B +- 0.2 * Speed
|
||||
/// Formula to calculate fish speed
|
||||
/// </summary>
|
||||
public abstract float CalculateSpeed(IRobustRandom random);
|
||||
|
||||
[DataField]
|
||||
public float Speed = 0.25f;
|
||||
|
||||
/// <summary>
|
||||
/// How long fish will be in point B until selecting next point B +- 0.2 * Difficulty
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan Difficulty = TimeSpan.FromSeconds(0.2);
|
||||
public float Difficulty = 2f;
|
||||
|
||||
[DataField]
|
||||
public TimeSpan BaseWaitTime = TimeSpan.FromSeconds(5);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Behaviors;
|
||||
|
||||
public sealed partial class CP14FishDartBehaviour : CP14FishBaseBehavior
|
||||
{
|
||||
public override float CalculateSpeed(IRobustRandom random)
|
||||
{
|
||||
return Speed * (0.5f + random.NextFloat() * Difficulty);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Behaviors;
|
||||
|
||||
public sealed partial class CP14FishLerpBehaviour : CP14FishBaseBehavior
|
||||
{
|
||||
public override Vector2 TryCalculatePosition(IRobustRandom random, Vector2 fishCords)
|
||||
{
|
||||
var speed = Speed + Speed * 0.2f * random.NextFloat(-1, 1);
|
||||
var nextPos = float.Lerp(fishCords.X, fishCords.Y, speed);
|
||||
|
||||
return new Vector2(nextPos, fishCords.Y);
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,12 @@ using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing;
|
||||
@@ -55,28 +52,56 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
var query = EntityQueryEnumerator<CP14FishingRodComponent>();
|
||||
|
||||
// Seeding prediction doesnt work
|
||||
_random.SetSeed((int)curTime.Ticks);
|
||||
while (query.MoveNext(out var uid, out var component))
|
||||
{
|
||||
_random.SetSeed((int)_gameTiming.CurTick.Value + GetNetEntity(uid).Id);
|
||||
if (component.User is null)
|
||||
continue;
|
||||
|
||||
RevalidateFishing(uid, component);
|
||||
|
||||
if (!IsFishingValid(component))
|
||||
continue;
|
||||
|
||||
TryToCatchFish(uid, component, curTime);
|
||||
UpdateFishWaitingStatus(uid, component, curTime);
|
||||
UpdatePositions(uid, component, curTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does all possible null checks to not duplicate code
|
||||
/// </summary>
|
||||
private bool IsFishingValid(CP14FishingRodComponent fishingRodComponent)
|
||||
{
|
||||
if (fishingRodComponent.User is null)
|
||||
return false;
|
||||
|
||||
if (fishingRodComponent.FishingFloat is null)
|
||||
return false;
|
||||
|
||||
if (fishingRodComponent.Target is null)
|
||||
return false;
|
||||
|
||||
var fish = fishingRodComponent.CaughtFish;
|
||||
|
||||
if (fish is null)
|
||||
return true;
|
||||
|
||||
TryComp(fish, out CP14FishComponent? fishComponent);
|
||||
|
||||
if (fishComponent is null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles float and fish positions updates
|
||||
/// Please burn it down
|
||||
/// </summary>
|
||||
private void UpdatePositions(EntityUid fishingRod, CP14FishingRodComponent fishingRodComponent, TimeSpan curTime)
|
||||
{
|
||||
if (_netManager.IsClient && !_gameTiming.IsFirstTimePredicted)
|
||||
return;
|
||||
|
||||
if (fishingRodComponent.CaughtFish is null)
|
||||
return;
|
||||
|
||||
@@ -87,9 +112,6 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
|
||||
TryComp(fish, out CP14FishComponent? fishComponent);
|
||||
|
||||
if (fishComponent is null)
|
||||
return;
|
||||
|
||||
_prototypeManager.Resolve(fishingRodComponent.FishingMinigame, out var minigamePrototype);
|
||||
|
||||
if (minigamePrototype is null)
|
||||
@@ -101,43 +123,25 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
|
||||
if (fishingRodComponent.Reeling)
|
||||
{
|
||||
if (floatSpeed + floatPosition < maxCord)
|
||||
{
|
||||
fishingRodComponent.FloatPosition += fishingRodComponent.FloatSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
fishingRodComponent.FloatPosition = maxCord;
|
||||
}
|
||||
Math.Clamp(floatPosition + floatSpeed, 0, maxCord);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (floatPosition - floatSpeed > 0f)
|
||||
{
|
||||
fishingRodComponent.FloatPosition -= floatSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
fishingRodComponent.FloatPosition = 0;
|
||||
}
|
||||
Math.Clamp(floatPosition - floatSpeed, 0, maxCord);
|
||||
}
|
||||
|
||||
var fishPos = fishComponent.FishPosAndDestination.X;
|
||||
var fishPos = fishComponent!.FishPosAndDestination.X;
|
||||
var fishDest = fishComponent.FishPosAndDestination.Y;
|
||||
var fishDiff = fishComponent.FishBehavior.Difficulty;
|
||||
var fishBaseWaitTime = fishComponent.FishBehavior.BaseWaitTime;
|
||||
|
||||
if (Math.Abs(fishPos - fishDest) < 0.1f)
|
||||
{
|
||||
UpdateFishDestination(fish.Value, fishComponent, curTime, maxCord);
|
||||
fishComponent.FishSelectPosTime = curTime + fishBaseWaitTime + fishBaseWaitTime * 0.2 * _random.NextFloat(-1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fishComponent.FishPosAndDestination = fishComponent.FishBehavior.TryCalculatePosition(_random, fishComponent.FishPosAndDestination);
|
||||
|
||||
if (Math.Abs(fishPos - fishDest) < 0.1f)
|
||||
{
|
||||
fishComponent.FishSelectPosTime = curTime + fishDiff * 0.2 * _random.NextFloat(-1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
DirtyField(fishingRod, fishingRodComponent, nameof(CP14FishingRodComponent.FloatPosition));
|
||||
@@ -170,9 +174,6 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
var fish = fishingRodComponent.CaughtFish;
|
||||
TryComp(fish, out CP14FishComponent? fishComponent);
|
||||
|
||||
if (fishComponent is null)
|
||||
return;
|
||||
|
||||
if (fishingRodComponent.Reeling)
|
||||
{
|
||||
fishingRodComponent.FishHooked = true;
|
||||
@@ -183,7 +184,7 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (curTime < fishComponent.FishGetAwayTime)
|
||||
if (curTime < fishComponent!.FishGetAwayTime)
|
||||
return;
|
||||
|
||||
fishingRodComponent.CaughtFish = null;
|
||||
@@ -205,15 +206,6 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
if (curTime < fishingRodComponent.FishingTime)
|
||||
return;
|
||||
|
||||
if (fishingRodComponent.User is null)
|
||||
return;
|
||||
|
||||
if (fishingRodComponent.FishingFloat is null)
|
||||
return;
|
||||
|
||||
if (fishingRodComponent.Target is null)
|
||||
return;
|
||||
|
||||
var pond = fishingRodComponent.Target;
|
||||
TryComp(pond, out CP14FishingPondComponent? pondComponent);
|
||||
|
||||
@@ -231,7 +223,7 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
EnsurePausedMap();
|
||||
var fish = PredictedSpawnAtPosition(fishId, new EntityCoordinates(_map.GetMap(_mapId!.Value), Vector2.Zero));
|
||||
|
||||
_playerManager.TryGetSessionByEntity(fishingRodComponent.User.Value, out var session);
|
||||
_playerManager.TryGetSessionByEntity(fishingRodComponent.User!.Value, out var session);
|
||||
|
||||
if (session is null)
|
||||
return;
|
||||
@@ -240,11 +232,8 @@ public abstract class CP14SharedFishingSystem : EntitySystem
|
||||
|
||||
TryComp(fish, out CP14FishComponent? fishComponent);
|
||||
|
||||
if (fishComponent is null)
|
||||
return;
|
||||
|
||||
fishingRodComponent.CaughtFish = fish;
|
||||
fishComponent.FishGetAwayTime = curTime;
|
||||
fishComponent!.FishGetAwayTime = curTime;
|
||||
fishComponent.FishGetAwayTime += TimeSpan.FromSeconds(_random.NextDouble(fishingRodComponent.MinAwaitTime, fishingRodComponent.MaxAwaitTime));
|
||||
DirtyField(fishingRod, fishingRodComponent, nameof(CP14FishingRodComponent.CaughtFish));
|
||||
DirtyField(fish, fishComponent, nameof(CP14FishComponent.FishGetAwayTime));
|
||||
|
||||
@@ -98,4 +98,4 @@
|
||||
- FootstepSound
|
||||
- CP14Mosquito
|
||||
- type: CP14Fish
|
||||
fishBehavior: !type:CP14FishLerpBehaviour
|
||||
fishBehavior: !type:CP14FishDartBehaviour
|
||||
Reference in New Issue
Block a user