Compare commits
1 Commits
LocalHelpe
...
revert-359
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7423e62d1c |
@@ -5,11 +5,10 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Content.Server._CP14.BiomeSpawner.EntitySystems;
|
|
||||||
using Content.Shared.Parallax.Biomes;
|
using Content.Shared.Parallax.Biomes;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server._CP14.BiomeSpawner.Components;
|
namespace Content.Server._CP14.BiomeSpawner;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// fills the tile in which it is located with the contents of the biome. Includes: tile, decals and entities
|
/// fills the tile in which it is located with the contents of the biome. Includes: tile, decals and entities
|
||||||
95
Content.Server/_CP14/BiomeSpawner/CP14BiomeSpawnerSystem.cs
Normal file
95
Content.Server/_CP14/BiomeSpawner/CP14BiomeSpawnerSystem.cs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* All right reserved to CrystallPunk.
|
||||||
|
*
|
||||||
|
* BUT this file is sublicensed under MIT License
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Numerics;
|
||||||
|
using Content.Server.Decals;
|
||||||
|
using Content.Server.GameTicking;
|
||||||
|
using Content.Server.Parallax;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Map.Components;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Server._CP14.BiomeSpawner;
|
||||||
|
|
||||||
|
public sealed class CP14BiomeSpawnerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||||
|
[Dependency] private readonly BiomeSystem _biome = default!;
|
||||||
|
[Dependency] private readonly TransformSystem _transform = default!;
|
||||||
|
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||||
|
[Dependency] private readonly DecalSystem _decals = default!;
|
||||||
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
|
||||||
|
private int _seed = 27;
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<RoundStartAttemptEvent>(OnRoundStartAttempt);
|
||||||
|
SubscribeLocalEvent<CP14BiomeSpawnerComponent, MapInitEvent>(OnMapInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRoundStartAttempt(RoundStartAttemptEvent ev)
|
||||||
|
{
|
||||||
|
_seed = _random.Next(100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMapInit(Entity<CP14BiomeSpawnerComponent> spawner, ref MapInitEvent args)
|
||||||
|
{
|
||||||
|
SpawnBiome(spawner);
|
||||||
|
QueueDel(spawner);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SpawnBiome(Entity<CP14BiomeSpawnerComponent> spawner)
|
||||||
|
{
|
||||||
|
var biome = _proto.Index(spawner.Comp.Biome);
|
||||||
|
var parent = _transform.GetParent(spawner);
|
||||||
|
|
||||||
|
if (parent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var gridUid = parent.Owner;
|
||||||
|
|
||||||
|
if (!TryComp<MapGridComponent>(gridUid, out var map))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var v2i = _transform.GetGridOrMapTilePosition(spawner);
|
||||||
|
if (!_biome.TryGetTile(v2i, biome.Layers, _seed, map, out var tile))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Set new tile
|
||||||
|
_maps.SetTile(gridUid, map, v2i, tile.Value);
|
||||||
|
|
||||||
|
// Remove old decals
|
||||||
|
var oldDecals = _decals.GetDecalsInRange(gridUid, v2i + new Vector2(0.5f, 0.5f));
|
||||||
|
foreach (var (id, _) in oldDecals)
|
||||||
|
{
|
||||||
|
_decals.RemoveDecal(gridUid, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add decals
|
||||||
|
if (_biome.TryGetDecals(v2i, biome.Layers, _seed, map, out var decals))
|
||||||
|
{
|
||||||
|
foreach (var decal in decals)
|
||||||
|
{
|
||||||
|
_decals.TryAddDecal(decal.ID, new EntityCoordinates(gridUid, decal.Position), out _);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO maybe need remove anchored entities here
|
||||||
|
|
||||||
|
//Add entities
|
||||||
|
if (_biome.TryGetEntity(v2i, biome.Layers, tile.Value, _seed, map, out var entityProto))
|
||||||
|
{
|
||||||
|
var ent = _entManager.SpawnEntity(entityProto,
|
||||||
|
new EntityCoordinates(gridUid, v2i + map.TileSizeHalfVector));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
* All right reserved to CrystallPunk.
|
|
||||||
*
|
|
||||||
* BUT this file is sublicensed under MIT License
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using Content.Server._CP14.BiomeSpawner.Components;
|
|
||||||
using Content.Server._CP14.RoundSeed;
|
|
||||||
using Content.Server.Decals;
|
|
||||||
using Content.Server.Parallax;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Shared.Map;
|
|
||||||
using Robust.Shared.Map.Components;
|
|
||||||
using Robust.Shared.Prototypes;
|
|
||||||
|
|
||||||
namespace Content.Server._CP14.BiomeSpawner.EntitySystems;
|
|
||||||
|
|
||||||
public sealed class CP14BiomeSpawnerSystem : EntitySystem
|
|
||||||
{
|
|
||||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
|
||||||
[Dependency] private readonly BiomeSystem _biome = default!;
|
|
||||||
[Dependency] private readonly TransformSystem _transform = default!;
|
|
||||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
|
||||||
[Dependency] private readonly DecalSystem _decals = default!;
|
|
||||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
|
||||||
[Dependency] private readonly CP14RoundSeedSystem _roundSeed = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
SubscribeLocalEvent<CP14BiomeSpawnerComponent, MapInitEvent>(OnMapInit);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnMapInit(Entity<CP14BiomeSpawnerComponent> ent, ref MapInitEvent args)
|
|
||||||
{
|
|
||||||
SpawnBiome(ent);
|
|
||||||
QueueDel(ent);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SpawnBiome(Entity<CP14BiomeSpawnerComponent> ent)
|
|
||||||
{
|
|
||||||
var biome = _proto.Index(ent.Comp.Biome);
|
|
||||||
var spawnerTransform = Transform(ent);
|
|
||||||
|
|
||||||
var gridUid = spawnerTransform.ParentUid;
|
|
||||||
|
|
||||||
if (!TryComp<MapGridComponent>(gridUid, out var map))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!_roundSeed.TryGetSeed(out var seed))
|
|
||||||
{
|
|
||||||
Log.Warning("Missing RoundSeed. Seed set to 0");
|
|
||||||
seed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
var vec = _transform.GetGridOrMapTilePosition(ent);
|
|
||||||
|
|
||||||
if (!_biome.TryGetTile(vec, biome.Layers, seed.Value, map, out var tile))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Set new tile
|
|
||||||
_maps.SetTile(gridUid, map, vec, tile.Value);
|
|
||||||
|
|
||||||
var tileCenterVec = vec + map.TileSizeHalfVector;
|
|
||||||
|
|
||||||
// Remove old decals
|
|
||||||
var oldDecals = _decals.GetDecalsInRange(gridUid, tileCenterVec);
|
|
||||||
foreach (var (id, _) in oldDecals)
|
|
||||||
{
|
|
||||||
_decals.RemoveDecal(gridUid, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add decals
|
|
||||||
if (_biome.TryGetDecals(vec, biome.Layers, seed.Value, map, out var decals))
|
|
||||||
{
|
|
||||||
foreach (var decal in decals)
|
|
||||||
{
|
|
||||||
_decals.TryAddDecal(decal.ID, new EntityCoordinates(gridUid, decal.Position), out _);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove entities
|
|
||||||
var oldEntities = _lookup.GetEntitiesInRange(spawnerTransform.Coordinates, 0.48f);
|
|
||||||
// TODO: Replace this shit with GetEntitiesInBox2
|
|
||||||
foreach (var entToRemove in oldEntities.Concat(new[] { ent.Owner })) // Do not remove self
|
|
||||||
{
|
|
||||||
QueueDel(entToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_biome.TryGetEntity(vec, biome.Layers, tile.Value, seed.Value, map, out var entityProto))
|
|
||||||
Spawn(entityProto, new EntityCoordinates(gridUid, tileCenterVec));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* All right reserved to CrystallPunk.
|
|
||||||
*
|
|
||||||
* BUT this file is sublicensed under MIT License
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Content.Server._CP14.RoundSeed;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is used for round seed
|
|
||||||
/// </summary>
|
|
||||||
[RegisterComponent, Access(typeof(CP14RoundSeedSystem))]
|
|
||||||
public sealed partial class CP14RoundSeedComponent : Component
|
|
||||||
{
|
|
||||||
[ViewVariables]
|
|
||||||
public static int MaxValue = 10000;
|
|
||||||
|
|
||||||
[ViewVariables]
|
|
||||||
public int Seed;
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* All right reserved to CrystallPunk.
|
|
||||||
*
|
|
||||||
* BUT this file is sublicensed under MIT License
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using JetBrains.Annotations;
|
|
||||||
using Robust.Shared.Random;
|
|
||||||
|
|
||||||
namespace Content.Server._CP14.RoundSeed;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides a round seed for another systems
|
|
||||||
/// </summary>
|
|
||||||
public sealed class CP14RoundSeedSystem : EntitySystem
|
|
||||||
{
|
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
|
||||||
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
SubscribeLocalEvent<CP14RoundSeedComponent, ComponentStartup>(OnComponentStartup);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnComponentStartup(Entity<CP14RoundSeedComponent> ent, ref ComponentStartup args)
|
|
||||||
{
|
|
||||||
ent.Comp.Seed = _random.Next(CP14RoundSeedComponent.MaxValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
[PublicAPI]
|
|
||||||
public bool TryGetSeed([NotNullWhen(true)] out int? seed)
|
|
||||||
{
|
|
||||||
seed = null;
|
|
||||||
var query = EntityQuery<CP14RoundSeedComponent>();
|
|
||||||
foreach (var comp in query)
|
|
||||||
{
|
|
||||||
seed = comp.Seed;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
components:
|
components:
|
||||||
- type: GameRule
|
- type: GameRule
|
||||||
cP14Allowed: true
|
cP14Allowed: true
|
||||||
- type: CP14RoundSeed
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: CP14ResourceHarvesting
|
id: CP14ResourceHarvesting
|
||||||
@@ -18,4 +17,4 @@
|
|||||||
- CP14ExpeditionCollectObjectiveGroup
|
- CP14ExpeditionCollectObjectiveGroup
|
||||||
CP14Mercenary:
|
CP14Mercenary:
|
||||||
- CP14PersonalCurrencyCollectObjectiveGroup
|
- CP14PersonalCurrencyCollectObjectiveGroup
|
||||||
# antags
|
# antags
|
||||||
Reference in New Issue
Block a user