FUUUUCK
This commit is contained in:
@@ -22,7 +22,7 @@ public sealed class CP14FishingOverlay : Overlay
|
||||
|
||||
private readonly SpriteSystem _sprite;
|
||||
private readonly TransformSystem _transform;
|
||||
private readonly CP14FishingProcessSystem _fishingProcess;
|
||||
private readonly CP14SharedFishingProcessSystem _sharedFishingProcess;
|
||||
|
||||
private Texture _backgroundTexture = default!;
|
||||
private Texture _handleTopTexture = default!;
|
||||
@@ -48,7 +48,7 @@ public sealed class CP14FishingOverlay : Overlay
|
||||
|
||||
_sprite = _entity.System<SpriteSystem>();
|
||||
_transform = _entity.System<TransformSystem>();
|
||||
_fishingProcess = _entity.System<CP14FishingProcessSystem>();
|
||||
_sharedFishingProcess = _entity.System<CP14SharedFishingProcessSystem>();
|
||||
}
|
||||
|
||||
protected override void Draw(in OverlayDrawArgs args)
|
||||
@@ -56,7 +56,7 @@ public sealed class CP14FishingOverlay : Overlay
|
||||
if (_player.LocalEntity is not { } localEntity)
|
||||
return;
|
||||
|
||||
if (!_fishingProcess.TryGetByUser(localEntity, out var fishingProcess))
|
||||
if (!_sharedFishingProcess.TryGetByUser(localEntity, out var fishingProcess))
|
||||
return;
|
||||
|
||||
// Refresh the texture cache, with a new fishing process
|
||||
@@ -100,7 +100,7 @@ public sealed class CP14FishingOverlay : Overlay
|
||||
private void DrawProgress(DrawingHandleWorld handle, Vector2 position, Vector2 size, float progress)
|
||||
{
|
||||
var vectorA = position;
|
||||
var vectorB = position + size with { Y = size.Y * progress };
|
||||
var vectorB = position + new Vector2(size.X, size.Y * progress);
|
||||
var box = new Box2(vectorA, vectorB);
|
||||
|
||||
handle.DrawRect(box, Color.Aqua);
|
||||
|
||||
5
Content.Client/_CP14/Fishing/CP14FishingProcessSystem.cs
Normal file
5
Content.Client/_CP14/Fishing/CP14FishingProcessSystem.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using Content.Shared._CP14.Fishing.Systems;
|
||||
|
||||
namespace Content.Client._CP14.Fishing;
|
||||
|
||||
public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem;
|
||||
@@ -1,31 +1,21 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Core;
|
||||
using Content.Shared._CP14.Fishing.Core.Behaviors;
|
||||
using Content.Shared._CP14.Fishing.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Content.Shared._CP14.Fishing.Events;
|
||||
using Content.Shared._CP14.Fishing.Systems;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
namespace Content.Server._CP14.Fishing;
|
||||
|
||||
public sealed class CP14FishingProcessSystem : EntitySystem
|
||||
public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
[Dependency] private readonly CP14FishingPoolSystem _pool = default!;
|
||||
|
||||
private EntityQuery<CP14FishingRodComponent> _fishingRod;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_fishingRod = GetEntityQuery<CP14FishingRodComponent>();
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
@@ -37,20 +27,47 @@ public sealed class CP14FishingProcessSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
private void Update(Entity<CP14FishingProcessComponent> process, float frameTime)
|
||||
public Entity<CP14FishingProcessComponent> Start(
|
||||
Entity<CP14FishingRodComponent> fishingRod,
|
||||
Entity<CP14FishingPoolComponent> fishingPool,
|
||||
EntityUid user)
|
||||
{
|
||||
var fishingRod = GetRod(process);
|
||||
var process = CreateProcess(fishingRod);
|
||||
var loot = _pool.GetLootPrototypeId(fishingPool);
|
||||
var style = GetStyle(fishingRod);
|
||||
|
||||
UpdateReeling(process, fishingRod, frameTime);
|
||||
UpdateVelocity(process, fishingRod);
|
||||
UpdatePosition(process, frameTime);
|
||||
// Save entities
|
||||
process.Comp.FishingRod = fishingRod;
|
||||
process.Comp.FishingPool = fishingPool;
|
||||
process.Comp.User = user;
|
||||
|
||||
process.Comp.Fish.Update(frameTime);
|
||||
process.Comp.Player = new Player(fishingRod.Comp.Size);
|
||||
process.Comp.Fish = new Fish(new MixedBehavior(), _random, _timing);
|
||||
|
||||
var collides = Collide(process.Comp.Fish, process.Comp.Player);
|
||||
process.Comp.LootProtoId = loot;
|
||||
process.Comp.StyleSheet = style;
|
||||
|
||||
var progressAdditive = collides ? 0.05f : -0.1f;
|
||||
process.Comp.Progress = Math.Clamp(process.Comp.Progress + progressAdditive * frameTime, 0, 1);
|
||||
Dirty(process);
|
||||
|
||||
Log.Debug($"Started new fishing process at {process}");
|
||||
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 ensureComponent = AddComp<CP14FishingProcessComponent>(entityUid);
|
||||
|
||||
return (entityUid, ensureComponent);
|
||||
}
|
||||
|
||||
private void UpdateReeling(Entity<CP14FishingProcessComponent> process,
|
||||
@@ -84,79 +101,52 @@ public sealed class CP14FishingProcessSystem : EntitySystem
|
||||
process.Comp.Player.Position = Math.Clamp(process.Comp.Player.Position, halfSize, 1 - halfSize);
|
||||
}
|
||||
|
||||
public bool TryGetByUser(EntityUid userEntityUid, [NotNullWhen(true)] out Entity<CP14FishingProcessComponent>? process)
|
||||
private void Update(Entity<CP14FishingProcessComponent> process, float frameTime)
|
||||
{
|
||||
process = null;
|
||||
var fishingRod = GetRod(process);
|
||||
|
||||
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
|
||||
while (query.MoveNext(out var entityUid, out var processComponent))
|
||||
UpdateReeling(process, fishingRod, frameTime);
|
||||
UpdateVelocity(process, fishingRod);
|
||||
UpdatePosition(process, frameTime);
|
||||
|
||||
process.Comp.Fish.Update(frameTime);
|
||||
|
||||
var collides = Collide(process.Comp.Fish, process.Comp.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)
|
||||
{
|
||||
if (processComponent.User != userEntityUid)
|
||||
continue;
|
||||
|
||||
process = (entityUid, processComponent);
|
||||
return true;
|
||||
Reward(process);
|
||||
}
|
||||
|
||||
return false;
|
||||
// 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 void Finish(Entity<CP14FishingProcessComponent?> 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;
|
||||
|
||||
public Entity<CP14FishingProcessComponent> Start(
|
||||
Entity<CP14FishingRodComponent> fishingRod,
|
||||
Entity<CP14FishingPoolComponent> fishingPool,
|
||||
EntityUid user)
|
||||
{
|
||||
var process = CreateProcess();
|
||||
var loot = _pool.GetLootPrototypeId(fishingPool);
|
||||
var style = GetStyle(fishingRod);
|
||||
var loot = Spawn(process.Comp.LootProtoId, coordinates);
|
||||
|
||||
// Save entities
|
||||
process.Comp.FishingRod = fishingRod;
|
||||
process.Comp.FishingPool = fishingPool;
|
||||
process.Comp.User = user;
|
||||
|
||||
process.Comp.Player = new Player(fishingRod.Comp.Size);
|
||||
process.Comp.Fish = new Fish(new MixedBehavior(), _random, _timing);
|
||||
|
||||
process.Comp.LootProtoId = loot;
|
||||
process.Comp.StyleSheet = style;
|
||||
|
||||
return process;
|
||||
}
|
||||
|
||||
private Entity<CP14FishingProcessComponent> CreateProcess()
|
||||
{
|
||||
var entityUid = Spawn();
|
||||
var ensureComponent = EnsureComp<CP14FishingProcessComponent>(entityUid);
|
||||
|
||||
return (entityUid, ensureComponent);
|
||||
}
|
||||
|
||||
private Entity<CP14FishingRodComponent> GetRod(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
var entityUid = process.Comp.FishingRod!.Value;
|
||||
var component = _fishingRod.GetComponent(process.Comp.FishingRod!.Value);
|
||||
return (entityUid, component);
|
||||
}
|
||||
|
||||
private CP14FishingProcessStyleSheetPrototype GetStyle(Entity<CP14FishingRodComponent> fishingRod)
|
||||
{
|
||||
if (_prototype.TryIndex(fishingRod.Comp.Style, out var style))
|
||||
return style;
|
||||
|
||||
Log.Error($"Failed to retrieve fishing rod style, {fishingRod.Comp.Style} not found. Reverting to default style.");
|
||||
return _prototype.Index(CP14FishingRodComponent.DefaultStyle);
|
||||
}
|
||||
|
||||
private static bool Collide(Fish fish, Player player)
|
||||
{
|
||||
var playerMin = player.Position - player.HalfSize;
|
||||
var playerMax = player.Position + player.HalfSize;
|
||||
return fish.Position >= playerMin && fish.Position <= playerMax;
|
||||
_throwing.TryThrow(loot, targetCoordinates, rod.Comp.ThrowPower);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,31 @@
|
||||
using Content.Shared._CP14.Fishing.Systems;
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Systems;
|
||||
using Content.Shared.Interaction;
|
||||
|
||||
namespace Content.Server._CP14.Fishing;
|
||||
|
||||
public sealed class CP14FishingRodSystem : CP14SharedFishingRodSystem;
|
||||
public sealed class CP14FishingRodSystem : CP14SharedFishingRodSystem
|
||||
{
|
||||
[Dependency] private readonly CP14FishingProcessSystem _fishingProcess = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<CP14FishingPoolComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
}
|
||||
|
||||
private void OnAfterInteractUsing(Entity<CP14FishingPoolComponent> entity, ref AfterInteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach)
|
||||
return;
|
||||
|
||||
if (!TryComp<CP14FishingRodComponent>(args.Used, out var fishingRodComponent))
|
||||
return;
|
||||
|
||||
if (fishingRodComponent.Process is not null)
|
||||
return;
|
||||
|
||||
fishingRodComponent.Process = _fishingProcess.Start((args.Used, fishingRodComponent), entity, args.User);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(CP14FishingProcessSystem))]
|
||||
[Access(typeof(CP14SharedFishingProcessSystem))]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
public sealed partial class CP14FishingProcessComponent : Component
|
||||
{
|
||||
/**
|
||||
@@ -32,13 +33,13 @@ public sealed partial class CP14FishingProcessComponent : Component
|
||||
*/
|
||||
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public EntityUid? FishingRod;
|
||||
public EntityUid? FishingRod = null;
|
||||
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public EntityUid? User;
|
||||
public EntityUid? User = null;
|
||||
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public EntityUid? FishingPool;
|
||||
public EntityUid? FishingPool = null;
|
||||
|
||||
/**
|
||||
* Loot
|
||||
|
||||
@@ -37,6 +37,9 @@ public sealed partial class CP14FishingRodComponent : Component
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public float Size = 0.25f;
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public float ThrowPower = 10f;
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public ProtoId<CP14FishingProcessStyleSheetPrototype> Style = DefaultStyle;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Core.Behaviors;
|
||||
|
||||
[ImplicitDataDefinitionForInheritors, MeansImplicitUse]
|
||||
[Serializable, NetSerializable]
|
||||
public abstract partial class Behavior
|
||||
{
|
||||
[DataField]
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Speed { get; set; } = 0.05f;
|
||||
|
||||
[DataField]
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Difficulty { get; set; } = 2f;
|
||||
|
||||
public abstract float CalculateSpeed(IRobustRandom random);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Core.Behaviors;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class MixedBehavior : Behavior
|
||||
{
|
||||
public override float CalculateSpeed(IRobustRandom random)
|
||||
|
||||
@@ -11,13 +11,19 @@ public sealed class Fish
|
||||
private const float MaxPosition = 1f;
|
||||
private const float MinPosition = 0f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Position { get; private set; }
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private readonly Behavior _behavior;
|
||||
|
||||
private readonly IRobustRandom _random;
|
||||
private readonly IGameTiming _timing;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private float _speed;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private TimeSpan _updateSpeedTime;
|
||||
|
||||
public Fish(Behavior behavior, IRobustRandom random, IGameTiming timing)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Content.Shared._CP14.Fishing.Events;
|
||||
|
||||
[ByRefEvent]
|
||||
public readonly struct CP14FishingFinishedEvent
|
||||
{
|
||||
public readonly bool Success;
|
||||
|
||||
public CP14FishingFinishedEvent(bool success)
|
||||
{
|
||||
Success = success;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared._CP14.Fishing.Core;
|
||||
using Content.Shared._CP14.Fishing.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
|
||||
public abstract partial class CP14SharedFishingProcessSystem
|
||||
{
|
||||
protected Entity<CP14FishingRodComponent> GetRod(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
var entityUid = process.Comp.FishingRod!.Value;
|
||||
var component = FishingRod.GetComponent(entityUid);
|
||||
return (entityUid, component);
|
||||
}
|
||||
|
||||
protected Entity<CP14FishingPoolComponent> GetPool(Entity<CP14FishingProcessComponent> process)
|
||||
{
|
||||
var entityUid = process.Comp.FishingPool!.Value;
|
||||
var component = FishingPool.GetComponent(entityUid);
|
||||
return (entityUid, component);
|
||||
}
|
||||
|
||||
protected CP14FishingProcessStyleSheetPrototype GetStyle(Entity<CP14FishingRodComponent> fishingRod)
|
||||
{
|
||||
if (_prototype.TryIndex(fishingRod.Comp.Style, out var style))
|
||||
return style;
|
||||
|
||||
Log.Error($"Failed to retrieve fishing rod style, {fishingRod.Comp.Style} not found. Reverting to default style.");
|
||||
return _prototype.Index(CP14FishingRodComponent.DefaultStyle);
|
||||
}
|
||||
|
||||
protected static bool Collide(Fish fish, Player player)
|
||||
{
|
||||
var playerMin = player.Position - player.HalfSize;
|
||||
var playerMax = player.Position + player.HalfSize;
|
||||
return fish.Position >= playerMin && fish.Position <= playerMax;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
|
||||
public abstract partial class CP14SharedFishingProcessSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
|
||||
protected EntityQuery<CP14FishingRodComponent> FishingRod;
|
||||
protected EntityQuery<CP14FishingPoolComponent> FishingPool;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
FishingRod = GetEntityQuery<CP14FishingRodComponent>();
|
||||
FishingPool = GetEntityQuery<CP14FishingPoolComponent>();
|
||||
}
|
||||
|
||||
public bool TryGetByUser(EntityUid userEntityUid, [NotNullWhen(true)] out Entity<CP14FishingProcessComponent>? process)
|
||||
{
|
||||
process = null;
|
||||
|
||||
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
|
||||
while (query.MoveNext(out var entityUid, out var processComponent))
|
||||
{
|
||||
if (processComponent.User != userEntityUid)
|
||||
continue;
|
||||
|
||||
process = (entityUid, processComponent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,18 @@
|
||||
using Content.Shared._CP14.Fishing.Components;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._CP14.Fishing.Systems;
|
||||
|
||||
public abstract class CP14SharedFishingRodSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly CP14FishingProcessSystem _fishingProcess = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeAllEvent<RequestFishingRodReelMessage>(OnReel);
|
||||
|
||||
SubscribeLocalEvent<CP14FishingPoolComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
|
||||
SubscribeLocalEvent<CP14FishingRodComponent, HandDeselectedEvent>(OnDeselected);
|
||||
}
|
||||
|
||||
private void OnReel(RequestFishingRodReelMessage msg, EntitySessionEventArgs args)
|
||||
@@ -35,18 +32,12 @@ public abstract class CP14SharedFishingRodSystem : EntitySystem
|
||||
Dirty(hands.ActiveHandEntity.Value, fishingRodComponent);
|
||||
}
|
||||
|
||||
private void OnAfterInteractUsing(Entity<CP14FishingPoolComponent> entity, ref AfterInteractUsingEvent args)
|
||||
private void OnDeselected(Entity<CP14FishingRodComponent> entity, ref HandDeselectedEvent args)
|
||||
{
|
||||
if (args.Handled || !args.CanReach)
|
||||
return;
|
||||
|
||||
if (!TryComp<CP14FishingRodComponent>(args.Used, out var fishingRodComponent))
|
||||
return;
|
||||
|
||||
fishingRodComponent.Process = _fishingProcess.Start((args.Used, fishingRodComponent), entity, args.User);
|
||||
entity.Comp.Reeling = false;
|
||||
Dirty(entity);
|
||||
}
|
||||
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class RequestFishingRodReelMessage : EntityEventArgs
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
- type: CP14FishingPoolLootTable
|
||||
id: Default
|
||||
prototypes:
|
||||
- CP14FloorWater
|
||||
- CP14BaseLockpick
|
||||
|
||||
Reference in New Issue
Block a user