Demiplan polishing (#524)

* 10 -> 20 sharpening stone durability

* auto destroy demiplans try 2 (better)

* start demiplan protection time

* buying demiplan key

* increase island size
This commit is contained in:
Ed
2024-11-01 09:23:22 +03:00
committed by GitHub
parent 5c4b5d1572
commit f9fea9e6ed
19 changed files with 201 additions and 94 deletions

View File

@@ -73,10 +73,18 @@ public sealed partial class CP14DemiplaneSystem
if (generator.Comp.LocationConfig is null)
return;
//We cant open demiplan in another demiplan
if (HasComp<CP14DemiplaneComponent>(Transform(generator).MapUid))
{
_popup.PopupEntity(Loc.GetString("cp14-demiplan-cannot-open", ("name", MetaData(generator).EntityName)), generator, args.User);
return;
}
SpawnRandomDemiplane(generator.Comp.LocationConfig.Value, out var demiplane, out var mapId);
//Admin log needed
//TEST
EnsureComp<CP14DemiplaneDestroyWithoutPlayersComponent>(demiplane);
EnsureComp<CP14DemiplaneDestroyWithoutStabilizationComponent>(demiplane);
var tempRift = EntityManager.Spawn("CP14DemiplaneTimedRadiusPassway");
var tempRift2 = EntityManager.Spawn("CP14DemiplanRiftCore");
@@ -93,8 +101,6 @@ public sealed partial class CP14DemiplaneSystem
private void GeneratorMapInit(Entity<CP14DemiplaneGeneratorDataComponent> generator, ref MapInitEvent args)
{
// Here, a unique Demiplan config should be generated based on the CP14DemiplanGeneratorDataComponent
//Location generation
HashSet<CP14DemiplaneLocationPrototype> suitableConfigs = new();
foreach (var locationConfig in _proto.EnumeratePrototypes<CP14DemiplaneLocationPrototype>())

View File

@@ -0,0 +1,61 @@
using Content.Shared._CP14.Demiplane.Components;
using Content.Shared.Mobs.Systems;
namespace Content.Server._CP14.Demiplane;
public sealed partial class CP14DemiplaneSystem
{
private readonly TimeSpan _checkFrequency = TimeSpan.FromSeconds(15f);
private TimeSpan _nextCheckTime = TimeSpan.Zero;
[Dependency] private readonly MobStateSystem _mobState = default!;
private void InitStabilization()
{
_nextCheckTime = _timing.CurTime + _checkFrequency;
SubscribeLocalEvent<CP14DemiplaneDestroyWithoutStabilizationComponent, MapInitEvent>(OnStabilizationMapInit);
}
private void OnStabilizationMapInit(Entity<CP14DemiplaneDestroyWithoutStabilizationComponent> ent, ref MapInitEvent args)
{
ent.Comp.EndProtectionTime = _timing.CurTime + ent.Comp.ProtectedSpawnTime;
}
private void UpdateStabilization(float frameTime)
{
if (_timing.CurTime < _nextCheckTime)
return;
_nextCheckTime = _timing.CurTime + _checkFrequency;
HashSet<EntityUid> stabilizedMaps = new();
var query = EntityQueryEnumerator<CP14DemiplaneStabilizerComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var stabilizer, out var transform))
{
var map = transform.MapUid;
if (map is null)
continue;
if (stabilizer.RequireAlive && !(_mobState.IsAlive(uid) || _mobState.IsCritical(uid)))
continue;
if (stabilizedMaps.Contains(map.Value))
continue;
stabilizedMaps.Add(map.Value);
}
var query2 = EntityQueryEnumerator<CP14DemiplaneComponent, CP14DemiplaneDestroyWithoutStabilizationComponent>();
while (query2.MoveNext(out var uid, out var demiplan, out var stabilization))
{
if (_timing.CurTime < stabilization.EndProtectionTime)
continue;
if (!stabilizedMaps.Contains(uid))
QueueDel(uid);
}
}
}

View File

@@ -2,10 +2,12 @@ using Content.Server.Flash;
using Content.Server.Procedural;
using Content.Shared._CP14.Demiplane;
using Content.Shared._CP14.Demiplane.Components;
using Content.Shared.Popups;
using Robust.Server.Audio;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Server._CP14.Demiplane;
@@ -21,6 +23,8 @@ public sealed partial class CP14DemiplaneSystem : CP14SharedDemiplaneSystem
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly FlashSystem _flash = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
@@ -28,6 +32,7 @@ public sealed partial class CP14DemiplaneSystem : CP14SharedDemiplaneSystem
InitGeneration();
InitConnections();
InitStabilization();
SubscribeLocalEvent<CP14DemiplaneComponent, ComponentShutdown>(OnDemiplanShutdown);
}
@@ -37,8 +42,8 @@ public sealed partial class CP14DemiplaneSystem : CP14SharedDemiplaneSystem
base.Update(frameTime);
UpdateGeneration(frameTime);
UpdateStabilization(frameTime);
}
/// <summary>
/// Teleports the entity inside the demiplane, to one of the random entry points.
/// </summary>
@@ -61,10 +66,6 @@ public sealed partial class CP14DemiplaneSystem : CP14SharedDemiplaneSystem
_transform.SetCoordinates(entity.Value, targetCoord);
_audio.PlayGlobal(demiplane.Comp.ArrivalSound, entity.Value);
var ev = new CP14DemiplanEntityEnterEvent(entity.Value);
RaiseLocalEvent(demiplane, ev);
return true;
}
@@ -93,9 +94,6 @@ public sealed partial class CP14DemiplaneSystem : CP14SharedDemiplaneSystem
_transform.SetCoordinates(entity.Value, targetCoord);
_audio.PlayGlobal(demiplane.Comp.DepartureSound, entity.Value);
var ev = new CP14DemiplanEntityLeaveEvent(entity.Value);
RaiseLocalEvent(demiplane, ev);
return true;
}

View File

@@ -1,10 +1,12 @@
using Content.Server._CP14.Demiplane;
using Content.Server.Mind;
using Content.Server.Popups;
using Content.Shared._CP14.Demiplane;
using Content.Shared._CP14.Demiplane.Components;
using Content.Shared._CP14.DemiplaneTraveling;
using Content.Shared.Ghost;
using Content.Shared.Movement.Pulling.Components;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Random;
using Robust.Shared.Timing;
@@ -17,6 +19,8 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly MindSystem _mind = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
@@ -32,15 +36,15 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
//Radius passway
var query = EntityQueryEnumerator<CP14DemiplaneRadiusTimedPasswayComponent, CP14DemiplaneRiftComponent>();
while (query.MoveNext(out var uid, out var passway, out var rift))
while (query.MoveNext(out var uid, out var passWay, out var rift))
{
if (_timing.CurTime < passway.NextTimeTeleport)
if (_timing.CurTime < passWay.NextTimeTeleport)
continue;
passway.NextTimeTeleport = _timing.CurTime + passway.Delay;
passWay.NextTimeTeleport = _timing.CurTime + passWay.Delay;
HashSet<EntityUid> teleportedEnts = new();
var nearestEnts = _lookup.GetEntitiesInRange(uid, passway.Radius);
var nearestEnts = _lookup.GetEntitiesInRange(uid, passWay.Radius);
foreach (var ent in nearestEnts)
{
if (HasComp<GhostComponent>(ent))
@@ -52,7 +56,7 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
teleportedEnts.Add(ent);
}
while (teleportedEnts.Count > passway.MaxEntities)
while (teleportedEnts.Count > passWay.MaxEntities)
{
teleportedEnts.Remove(_random.Pick(teleportedEnts));
}
@@ -69,6 +73,7 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
_demiplan.TryTeleportOutDemiplane((map.Value, demiplan), puller.Pulling);
_demiplan.TryTeleportOutDemiplane((map.Value, demiplan), ent);
_audio.PlayPvs(passWay.ArrivalSound, ent);
}
}
else
@@ -84,9 +89,11 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
_demiplan.TryTeleportIntoDemiplane(rift.Demiplan.Value, puller.Pulling);
_demiplan.TryTeleportIntoDemiplane(rift.Demiplan.Value, ent);
_audio.PlayPvs(passWay.ArrivalSound, ent);
}
}
}
_audio.PlayPvs(passWay.DepartureSound, Transform(uid).Coordinates);
QueueDel(uid);
}
}
@@ -94,6 +101,7 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
private void RadiusMapInit(Entity<CP14DemiplaneRadiusTimedPasswayComponent> radiusPassWay, ref MapInitEvent args)
{
radiusPassWay.Comp.NextTimeTeleport = _timing.CurTime + radiusPassWay.Comp.Delay;
//Popup caution here
}
private void OnOpenRiftInteractDoAfter(Entity<CP14DemiplaneRiftOpenedComponent> passWay, ref CP14DemiplanPasswayUseDoAfter args)
@@ -121,13 +129,19 @@ public sealed partial class CP14DemiplaneTravelingSystem : EntitySystem
}
}
if (passWay.Comp.MaxUse > 0 && used)
if (used)
{
passWay.Comp.MaxUse--;
if (passWay.Comp.MaxUse == 0)
QueueDel(passWay);
_audio.PlayPvs(passWay.Comp.DepartureSound, Transform(passWay).Coordinates);
_audio.PlayPvs(passWay.Comp.ArrivalSound, args.User);
if (passWay.Comp.MaxUse > 0)
{
passWay.Comp.MaxUse--;
if (passWay.Comp.MaxUse == 0)
QueueDel(passWay);
}
}
args.Handled = true;
}
}