Fix again
This commit is contained in:
@@ -16,17 +16,75 @@ 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)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
// DON'T CALL BASE METHOD!!!
|
||||
|
||||
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
|
||||
while (query.MoveNext(out var entityUid, out var processComponent))
|
||||
{
|
||||
Update((entityUid, processComponent), frameTime);
|
||||
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);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Reward(process);
|
||||
}
|
||||
|
||||
// Raising events before deletion
|
||||
var ev = new CP14FishingFinishedEvent(success);
|
||||
RaiseLocalEvent(process, ref ev, true);
|
||||
|
||||
// Either way, we need to delete the process
|
||||
Stop(process);
|
||||
}
|
||||
|
||||
public override void Reward(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
base.Reward(process);
|
||||
|
||||
var pool = GetPool(process);
|
||||
var rod = GetRod(process);
|
||||
|
||||
var coordinates = Transform(pool).Coordinates;
|
||||
var targetCoordinates = Transform(process.Comp.User!.Value).Coordinates;
|
||||
|
||||
var loot = Spawn(process.Comp.LootProtoId, coordinates);
|
||||
|
||||
_throwing.TryThrow(loot, targetCoordinates, rod.Comp.ThrowPower);
|
||||
}
|
||||
|
||||
public Entity<CP14FishingProcessComponent> Start(
|
||||
Entity<CP14FishingRodComponent> fishingRod,
|
||||
Entity<CP14FishingPoolComponent> fishingPool,
|
||||
@@ -42,7 +100,7 @@ public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
process.Comp.User = user;
|
||||
|
||||
process.Comp.Player = new Player(fishingRod.Comp.Size);
|
||||
process.Comp.Fish = new Fish(new MixedBehavior(), _random, _timing);
|
||||
process.Comp.Fish = new Fish(new MixedBehavior(), _timing.CurTime + TimeSpan.FromSeconds(0.5f));
|
||||
|
||||
process.Comp.LootProtoId = loot;
|
||||
process.Comp.StyleSheet = style;
|
||||
@@ -53,112 +111,11 @@ public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
return process;
|
||||
}
|
||||
|
||||
public void Stop(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
var rod = GetRod(process);
|
||||
rod.Comp.Process = null;
|
||||
Dirty(rod);
|
||||
|
||||
Del(process);
|
||||
}
|
||||
|
||||
public Entity<CP14FishingProcessComponent> CreateProcess(EntityUid parent)
|
||||
{
|
||||
var entityUid = SpawnAttachedTo("MobHuman", Transform(parent).Coordinates);
|
||||
var entityUid = SpawnAttachedTo(null, Transform(parent).Coordinates);
|
||||
var ensureComponent = AddComp<CP14FishingProcessComponent>(entityUid);
|
||||
|
||||
return (entityUid, ensureComponent);
|
||||
}
|
||||
|
||||
private void UpdateReeling(Entity<CP14FishingProcessComponent> process,
|
||||
Entity<CP14FishingRodComponent> fishingRod,
|
||||
float frameTime)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
if (fishingRod.Comp.Reeling)
|
||||
{
|
||||
player.Velocity += fishingRod.Comp.Speed * frameTime;
|
||||
return;
|
||||
}
|
||||
|
||||
player.Velocity -= fishingRod.Comp.Gravity * frameTime;
|
||||
}
|
||||
|
||||
private void UpdateVelocity(Entity<CP14FishingProcessComponent> process,
|
||||
Entity<CP14FishingRodComponent> fishingRod)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
player.Velocity *= fishingRod.Comp.Drag;
|
||||
player.Velocity = Math.Clamp(player.Velocity,
|
||||
fishingRod.Comp.MinVelocity,
|
||||
fishingRod.Comp.MaxVelocity);
|
||||
}
|
||||
|
||||
private void UpdatePosition(Entity<CP14FishingProcessComponent> process,
|
||||
float frameTime)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
player.Position += process.Comp.Player.Velocity * frameTime;
|
||||
|
||||
var halfSize = process.Comp.Player.HalfSize;
|
||||
process.Comp.Player.Position = Math.Clamp(process.Comp.Player.Position, halfSize, 1 - halfSize);
|
||||
}
|
||||
|
||||
private void Update(Entity<CP14FishingProcessComponent> process, float frameTime)
|
||||
{
|
||||
if (process.Comp.Player is not { } player || process.Comp.Fish is not { } fish)
|
||||
return;
|
||||
|
||||
var fishingRod = GetRod(process);
|
||||
|
||||
UpdateReeling(process, fishingRod, frameTime);
|
||||
UpdateVelocity(process, fishingRod);
|
||||
UpdatePosition(process, frameTime);
|
||||
|
||||
fish.Update(frameTime);
|
||||
|
||||
var collides = Collide(fish, player);
|
||||
|
||||
var progressAdditive = collides ? 0.1f : -0.2f;
|
||||
process.Comp.Progress = Math.Clamp(process.Comp.Progress + progressAdditive * frameTime, 0, 1);
|
||||
|
||||
Dirty(process);
|
||||
|
||||
//if (process.Comp.Progress is 1 or 0)
|
||||
// Finish(process, process.Comp.Progress is 1);
|
||||
}
|
||||
|
||||
private void Finish(Entity<CP14FishingProcessComponent> process, bool success)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
Reward(process);
|
||||
}
|
||||
|
||||
// Raising events before deletion
|
||||
var ev = new CP14FishingFinishedEvent(success);
|
||||
RaiseLocalEvent(process, ref ev, true);
|
||||
|
||||
// Either way, we need to delete the process
|
||||
Stop(process);
|
||||
}
|
||||
|
||||
private void Reward(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
var pool = GetPool(process);
|
||||
var rod = GetRod(process);
|
||||
|
||||
var coordinates = Transform(pool).Coordinates;
|
||||
var targetCoordinates = Transform(process.Comp.User!.Value).Coordinates;
|
||||
|
||||
var loot = Spawn(process.Comp.LootProtoId, coordinates);
|
||||
|
||||
_throwing.TryThrow(loot, targetCoordinates, rod.Comp.ThrowPower);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public sealed partial class CP14FishingRodComponent : Component
|
||||
public bool Reeling;
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public float Speed = 0.05f;
|
||||
public float Speed = 0.1f;
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public float Gravity = 0.075f;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Content.Shared._CP14.Fishing.Core.Behaviors;
|
||||
public abstract partial class Behavior
|
||||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Speed { get; set; } = 0.05f;
|
||||
public float Speed { get; set; } = 0.25f;
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Difficulty { get; set; } = 2f;
|
||||
|
||||
@@ -17,31 +17,20 @@ public sealed class Fish
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private readonly Behavior _behavior;
|
||||
|
||||
[NonSerialized]
|
||||
private readonly IRobustRandom _random;
|
||||
|
||||
[NonSerialized]
|
||||
private readonly IGameTiming _timing;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float _speed;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan _updateSpeedTime;
|
||||
|
||||
public Fish(Behavior behavior, IRobustRandom random, IGameTiming timing)
|
||||
public Fish(Behavior behavior, TimeSpan updateSpeedTime)
|
||||
{
|
||||
_behavior = behavior;
|
||||
_random = random;
|
||||
_timing = timing;
|
||||
_updateSpeedTime = updateSpeedTime;
|
||||
}
|
||||
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
// Update speed
|
||||
if (_timing.CurTime > _updateSpeedTime)
|
||||
UpdateSpeed();
|
||||
|
||||
// Update position
|
||||
Position += _speed * frameTime;
|
||||
|
||||
@@ -49,9 +38,12 @@ public sealed class Fish
|
||||
Position = Math.Clamp(Position, MinPosition, MaxPosition);
|
||||
}
|
||||
|
||||
private void UpdateSpeed()
|
||||
public void UpdateSpeed(IRobustRandom random, IGameTiming timing)
|
||||
{
|
||||
_speed = _behavior.CalculateSpeed(_random);
|
||||
_updateSpeedTime = _timing.CurTime + TimeSpan.FromSeconds(_random.NextFloat(1f / _behavior.Difficulty, 1f - 1f / _behavior.Difficulty));
|
||||
if (_updateSpeedTime > timing.CurTime)
|
||||
return;
|
||||
|
||||
_speed = _behavior.CalculateSpeed(random);
|
||||
_updateSpeedTime = timing.CurTime + TimeSpan.FromSeconds(random.NextFloat(1.5f - 1f / _behavior.Difficulty, 2.5f - 1f / _behavior.Difficulty));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Core;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
@@ -19,6 +20,110 @@ public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
FishingPool = GetEntityQuery<CP14FishingPoolComponent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
|
||||
while (query.MoveNext(out var entityUid, out var processComponent))
|
||||
{
|
||||
Update((entityUid, processComponent), frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateReeling(Entity<CP14FishingProcessComponent> process,
|
||||
Entity<CP14FishingRodComponent> fishingRod,
|
||||
float frameTime)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
if (fishingRod.Comp.Reeling)
|
||||
{
|
||||
player.Velocity += fishingRod.Comp.Speed * frameTime;
|
||||
return;
|
||||
}
|
||||
|
||||
player.Velocity -= fishingRod.Comp.Gravity * frameTime;
|
||||
}
|
||||
|
||||
private void UpdateVelocity(Entity<CP14FishingProcessComponent> process,
|
||||
Entity<CP14FishingRodComponent> fishingRod)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
player.Velocity *= fishingRod.Comp.Drag;
|
||||
player.Velocity = Math.Clamp(player.Velocity,
|
||||
fishingRod.Comp.MinVelocity,
|
||||
fishingRod.Comp.MaxVelocity);
|
||||
}
|
||||
|
||||
private void UpdatePosition(Entity<CP14FishingProcessComponent> process,
|
||||
float frameTime)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
player.Position += process.Comp.Player.Velocity * frameTime;
|
||||
|
||||
var halfSize = process.Comp.Player.HalfSize;
|
||||
process.Comp.Player.Position = Math.Clamp(process.Comp.Player.Position, halfSize, 1 - halfSize);
|
||||
}
|
||||
|
||||
public void Update(Entity<CP14FishingProcessComponent> process, float frameTime)
|
||||
{
|
||||
if (process.Comp.Player is not { } player)
|
||||
return;
|
||||
|
||||
var fishingRod = GetRod(process);
|
||||
|
||||
UpdateReeling(process, fishingRod, frameTime);
|
||||
UpdateVelocity(process, fishingRod);
|
||||
UpdatePosition(process, frameTime);
|
||||
|
||||
if (process.Comp.Fish is { } fish)
|
||||
{
|
||||
FishPreUpdate(process, fish, frameTime);
|
||||
|
||||
fish.Update(frameTime);
|
||||
var collides = Collide(fish, player);
|
||||
|
||||
var progressAdditive = collides ? 0.1f : -0.2f;
|
||||
process.Comp.Progress = Math.Clamp(process.Comp.Progress + progressAdditive * frameTime, 0, 1);
|
||||
}
|
||||
|
||||
UpdateDirty(process);
|
||||
|
||||
if (process.Comp.Progress is 1 or 0)
|
||||
Finish(process, process.Comp.Progress is 1);
|
||||
}
|
||||
|
||||
public virtual void FishPreUpdate(Entity<CP14FishingProcessComponent> process, Fish fish, float frameTime)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void UpdateDirty(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Finish(Entity<CP14FishingProcessComponent> process, bool success)
|
||||
{
|
||||
}
|
||||
|
||||
public void Stop(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
var rod = GetRod(process);
|
||||
rod.Comp.Process = null;
|
||||
Dirty(rod);
|
||||
|
||||
Del(process);
|
||||
}
|
||||
|
||||
public virtual void Reward(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
}
|
||||
|
||||
public bool TryGetByUser(EntityUid userEntityUid, [NotNullWhen(true)] out Entity<CP14FishingProcessComponent>? process)
|
||||
{
|
||||
process = null;
|
||||
|
||||
Reference in New Issue
Block a user