Files
crystall-punk-14/Content.Server/_CP14/Fishing/CP14FishingProcessSystem.cs

122 lines
3.7 KiB
C#
Raw Normal View History

2024-12-15 00:40:43 +10:00
using Content.Shared._CP14.Fishing.Components;
2024-12-09 02:29:33 +10:00
using Content.Shared._CP14.Fishing.Core;
using Content.Shared._CP14.Fishing.Core.Behaviors;
2024-12-15 00:40:43 +10:00
using Content.Shared._CP14.Fishing.Events;
using Content.Shared._CP14.Fishing.Systems;
using Content.Shared.Throwing;
2024-12-09 02:29:33 +10:00
using Robust.Shared.Random;
using Robust.Shared.Timing;
2024-12-15 00:40:43 +10:00
namespace Content.Server._CP14.Fishing;
2024-12-09 02:29:33 +10:00
2024-12-15 00:40:43 +10:00
public sealed class CP14FishingProcessSystem : CP14SharedFishingProcessSystem
2024-12-09 02:29:33 +10:00
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IRobustRandom _random = default!;
2024-12-15 00:40:43 +10:00
[Dependency] private readonly ThrowingSystem _throwing = default!;
2024-12-09 02:29:33 +10:00
[Dependency] private readonly CP14FishingPoolSystem _pool = default!;
2024-12-15 02:21:40 +10:00
/*
private readonly TimeSpan _dirtyDelay = TimeSpan.FromTicks(10000000000000);
private TimeSpan _dirtyDelayTime;
*/
2024-12-09 02:29:33 +10:00
public override void Update(float frameTime)
{
2024-12-15 02:21:40 +10:00
// DON'T CALL BASE METHOD!!!
2024-12-09 02:29:33 +10:00
var query = EntityQueryEnumerator<CP14FishingProcessComponent>();
while (query.MoveNext(out var entityUid, out var processComponent))
{
2024-12-15 02:21:40 +10:00
Update((entityUid, processComponent), frameTime * 2);
2024-12-09 02:29:33 +10:00
}
}
2024-12-15 02:21:40 +10:00
public override void FishPreUpdate(Entity<CP14FishingProcessComponent> process, Fish fish, float frameTime)
2024-12-09 02:29:33 +10:00
{
2024-12-15 02:21:40 +10:00
base.FishPreUpdate(process, fish, frameTime);
2024-12-09 02:29:33 +10:00
2024-12-15 02:21:40 +10:00
fish.UpdateSpeed(_random, _timing);
2024-12-15 00:40:43 +10:00
Dirty(process);
}
2024-12-15 02:21:40 +10:00
public override void UpdateDirty(Entity<CP14FishingProcessComponent> process)
2024-12-15 00:40:43 +10:00
{
2024-12-15 02:21:40 +10:00
base.UpdateDirty(process);
2024-12-15 00:40:43 +10:00
2024-12-15 02:21:40 +10:00
/*
if (_timing.CurTime < _dirtyDelayTime)
2024-12-15 01:16:29 +10:00
return;
2024-12-15 02:21:40 +10:00
_dirtyDelayTime = _timing.CurTime + _dirtyDelay;
2024-12-15 00:40:43 +10:00
Dirty(process);
2024-12-15 02:21:40 +10:00
*/
2024-12-09 02:29:33 +10:00
}
2024-12-15 02:21:40 +10:00
public override void Finish(Entity<CP14FishingProcessComponent> process, bool success)
2024-12-09 02:29:33 +10:00
{
2024-12-15 02:21:40 +10:00
base.Finish(process, success);
2024-12-15 00:40:43 +10:00
if (success)
{
Reward(process);
}
2024-12-09 02:29:33 +10:00
2024-12-15 00:40:43 +10:00
// Raising events before deletion
var ev = new CP14FishingFinishedEvent(success);
RaiseLocalEvent(process, ref ev, true);
2024-12-09 02:29:33 +10:00
2024-12-15 00:40:43 +10:00
// Either way, we need to delete the process
Stop(process);
2024-12-09 02:29:33 +10:00
}
2024-12-15 02:21:40 +10:00
public override void Reward(Entity<CP14FishingProcessComponent> process)
2024-12-09 02:29:33 +10:00
{
2024-12-15 02:21:40 +10:00
base.Reward(process);
2024-12-15 00:40:43 +10:00
var pool = GetPool(process);
var rod = GetRod(process);
2024-12-09 02:29:33 +10:00
2024-12-15 00:40:43 +10:00
var coordinates = Transform(pool).Coordinates;
var targetCoordinates = Transform(process.Comp.User!.Value).Coordinates;
2024-12-09 02:29:33 +10:00
2024-12-15 00:40:43 +10:00
var loot = Spawn(process.Comp.LootProtoId, coordinates);
_throwing.TryThrow(loot, targetCoordinates, rod.Comp.ThrowPower);
2024-12-09 02:29:33 +10:00
}
2024-12-15 02:21:40 +10:00
public Entity<CP14FishingProcessComponent> Start(
Entity<CP14FishingRodComponent> fishingRod,
Entity<CP14FishingPoolComponent> fishingPool,
EntityUid user)
{
var process = CreateProcess(fishingRod.Owner);
var loot = _pool.GetLootPrototypeId(fishingPool);
var style = GetStyle(fishingRod);
// 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(), _timing.CurTime + TimeSpan.FromSeconds(0.5f));
process.Comp.LootProtoId = loot;
process.Comp.StyleSheet = style;
Dirty(process);
Log.Debug($"Started new fishing process at {process}");
return process;
}
public Entity<CP14FishingProcessComponent> CreateProcess(EntityUid parent)
{
var entityUid = SpawnAttachedTo(null, Transform(parent).Coordinates);
var ensureComponent = AddComp<CP14FishingProcessComponent>(entityUid);
return (entityUid, ensureComponent);
}
2024-12-09 02:29:33 +10:00
}