@@ -16,6 +16,43 @@ public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
[Dependency] private readonly CP14FishingPoolSystem _pool = default!;
|
||||
|
||||
/*
|
||||
private readonly TimeSpan _dirtyDelay = TimeSpan.FromTicks(10000000000000);
|
||||
private TimeSpan _dirtyDelayTime;
|
||||
*/
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
// DON'T CALL BASE METHOD!!!
|
||||
|
||||
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
|
||||
while (query.MoveNext(out var entityUid, out var processComponent))
|
||||
{
|
||||
Update((entityUid, processComponent), frameTime * 2);
|
||||
}
|
||||
}
|
||||
|
||||
public override void FishPreUpdate(Entity<CP14FishingProcessComponent> process, Fish fish, float frameTime)
|
||||
{
|
||||
base.FishPreUpdate(process, fish, frameTime);
|
||||
|
||||
fish.UpdateSpeed(_random, _timing);
|
||||
Dirty(process);
|
||||
}
|
||||
|
||||
public override void UpdateDirty(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
base.UpdateDirty(process);
|
||||
|
||||
/*
|
||||
if (_timing.CurTime < _dirtyDelayTime)
|
||||
return;
|
||||
|
||||
_dirtyDelayTime = _timing.CurTime + _dirtyDelay;
|
||||
Dirty(process);
|
||||
*/
|
||||
}
|
||||
|
||||
public override void Finish(Entity<CP14FishingProcessComponent> process, bool success)
|
||||
{
|
||||
base.Finish(process, success);
|
||||
@@ -64,7 +101,6 @@ public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
|
||||
process.Comp.Player = new Player(fishingRod.Comp.Size);
|
||||
process.Comp.Fish = new Fish(new MixedBehavior(), _timing.CurTime + TimeSpan.FromSeconds(0.5f));
|
||||
process.Comp.Fish.Init(_random);
|
||||
|
||||
process.Comp.LootProtoId = loot;
|
||||
process.Comp.StyleSheet = style;
|
||||
|
||||
@@ -15,9 +15,4 @@ public abstract partial class Behavior
|
||||
public float Difficulty { get; set; } = 2f;
|
||||
|
||||
public abstract float CalculateSpeed(IRobustRandom random);
|
||||
|
||||
public virtual TimeSpan CalculateDelay(IRobustRandom random)
|
||||
{
|
||||
return TimeSpan.FromSeconds(random.NextFloat(1.5f - 1f / Difficulty, 2.5f - 1f / Difficulty));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,74 +11,39 @@ public sealed class Fish
|
||||
private const float MaxPosition = 1f;
|
||||
private const float MinPosition = 0f;
|
||||
|
||||
private const int SpeedLoopSize = 8;
|
||||
private const int DelayLoopSize = 12;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Position { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private readonly Behavior _behavior;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan _delay;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float _speed;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float[] _speedLoop = new float[SpeedLoopSize];
|
||||
private TimeSpan _updateSpeedTime;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan[] _delayLoop = new TimeSpan[DelayLoopSize];
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _speedIndex;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private int _delayIndex;
|
||||
|
||||
public Fish(Behavior behavior, TimeSpan delay)
|
||||
public Fish(Behavior behavior, TimeSpan updateSpeedTime)
|
||||
{
|
||||
_behavior = behavior;
|
||||
_delay = delay;
|
||||
}
|
||||
|
||||
public void Init(IRobustRandom random)
|
||||
{
|
||||
for (var i = 0; i < SpeedLoopSize; i++)
|
||||
{
|
||||
_speedLoop[i] = _behavior.CalculateSpeed(random);
|
||||
}
|
||||
|
||||
for (var i = 0; i < DelayLoopSize; i++)
|
||||
{
|
||||
_delayLoop[i] = _behavior.CalculateDelay(random);
|
||||
}
|
||||
_updateSpeedTime = updateSpeedTime;
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
// Update position
|
||||
Position += _speed * frameTime;
|
||||
|
||||
// Clamp position
|
||||
Position = Math.Clamp(Position, MinPosition, MaxPosition);
|
||||
}
|
||||
|
||||
public void UpdateSpeed(IGameTiming timing)
|
||||
public void UpdateSpeed(IRobustRandom random, IGameTiming timing)
|
||||
{
|
||||
if (_delay > timing.CurTime)
|
||||
if (_updateSpeedTime > timing.CurTime)
|
||||
return;
|
||||
|
||||
_speed = GetNextSpeed();
|
||||
_delay = GetNextDelay(timing);
|
||||
}
|
||||
|
||||
private float GetNextSpeed()
|
||||
{
|
||||
return _speedLoop[_speedIndex++ % _speedLoop.Length];
|
||||
}
|
||||
|
||||
private TimeSpan GetNextDelay(IGameTiming timing)
|
||||
{
|
||||
return timing.CurTime + _delayLoop[_delayIndex++ % _delayLoop.Length];
|
||||
_speed = _behavior.CalculateSpeed(random);
|
||||
_updateSpeedTime = timing.CurTime + TimeSpan.FromSeconds(random.NextFloat(1.5f - 1f / _behavior.Difficulty, 2.5f - 1f / _behavior.Difficulty));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,16 @@
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Core;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
|
||||
public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
|
||||
protected EntityQuery<CP14FishingRodComponent> FishingRod;
|
||||
protected EntityQuery<CP14FishingPoolComponent> FishingPool;
|
||||
|
||||
private int _frames;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -33,8 +29,6 @@ public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
{
|
||||
Update((entityUid, processComponent), frameTime);
|
||||
}
|
||||
|
||||
Log.Debug($"Frame {_frames++} FrameTime: {frameTime}");
|
||||
}
|
||||
|
||||
private void UpdateReeling(Entity<CP14FishingProcessComponent> process,
|
||||
@@ -90,9 +84,9 @@ public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
|
||||
if (process.Comp.Fish is { } fish)
|
||||
{
|
||||
fish.Update(frameTime);
|
||||
fish.UpdateSpeed(_timing);
|
||||
FishPreUpdate(process, fish, frameTime);
|
||||
|
||||
fish.Update(frameTime);
|
||||
var collides = Collide(fish, player);
|
||||
|
||||
var progressAdditive = collides ? 0.1f : -0.2f;
|
||||
|
||||
Reference in New Issue
Block a user