Expeditions rework (#18960)
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
using Content.Shared.Salvage;
|
||||
|
||||
namespace Content.Server.Salvage.Expeditions.Structure;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks expedition data for <see cref="SalvageMissionType.Elimination"/>
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(SalvageSystem), typeof(SpawnSalvageMissionJob))]
|
||||
public sealed partial class SalvageEliminationExpeditionComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// List of mobs that need to be killed for the mission to be complete.
|
||||
/// </summary>
|
||||
[DataField("megafauna")]
|
||||
public List<EntityUid> Megafauna = new();
|
||||
}
|
||||
@@ -49,16 +49,4 @@ public sealed partial class SalvageExpeditionComponent : SharedSalvageExpedition
|
||||
{
|
||||
Params = AudioParams.Default.WithVolume(-5),
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The difficulty this mission had or, in the future, was selected.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("difficulty")]
|
||||
public DifficultyRating Difficulty;
|
||||
|
||||
/// <summary>
|
||||
/// List of items to order on mission completion
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("rewards", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
|
||||
public List<string> Rewards = default!;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using Content.Shared.Salvage;
|
||||
|
||||
namespace Content.Server.Salvage.Expeditions;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks expedition data for <see cref="SalvageMissionType.Mining"/>
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(SalvageSystem))]
|
||||
public sealed partial class SalvageMiningExpeditionComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Entities that were present on the shuttle and match the loot tax.
|
||||
/// </summary>
|
||||
[DataField("exemptEntities")]
|
||||
public List<EntityUid> ExemptEntities = new();
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
using Content.Shared.Salvage;
|
||||
|
||||
namespace Content.Server.Salvage.Expeditions.Structure;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks expedition data for <see cref="SalvageMissionType.Structure"/>
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(SalvageSystem), typeof(SpawnSalvageMissionJob))]
|
||||
public sealed partial class SalvageStructureExpeditionComponent : Component
|
||||
{
|
||||
[DataField("structures")]
|
||||
public List<EntityUid> Structures = new();
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Shared.Procedural;
|
||||
using Content.Shared.Salvage;
|
||||
using Content.Shared.Salvage.Expeditions;
|
||||
|
||||
@@ -18,7 +19,7 @@ public sealed partial class SalvageSystem
|
||||
SpawnMission(missionparams, station.Value);
|
||||
|
||||
data.ActiveMission = args.Index;
|
||||
var mission = GetMission(missionparams.MissionType, missionparams.Difficulty, missionparams.Seed);
|
||||
var mission = GetMission(_prototypeManager.Index<SalvageDifficultyPrototype>(missionparams.Difficulty), missionparams.Seed);
|
||||
data.NextOffer = _timing.CurTime + mission.Duration + TimeSpan.FromSeconds(1);
|
||||
UpdateConsoles(data);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Robust.Shared.CPUJob.JobQueues;
|
||||
using Robust.Shared.CPUJob.JobQueues.Queues;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Shared.Procedural;
|
||||
using Content.Shared.Salvage.Expeditions;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
@@ -26,7 +27,6 @@ public sealed partial class SalvageSystem
|
||||
private const double SalvageJobTime = 0.002;
|
||||
|
||||
private float _cooldown;
|
||||
private float _failedCooldown;
|
||||
|
||||
private void InitializeExpeditions()
|
||||
{
|
||||
@@ -43,9 +43,7 @@ public sealed partial class SalvageSystem
|
||||
SubscribeLocalEvent<SalvageStructureComponent, ExaminedEvent>(OnStructureExamine);
|
||||
|
||||
_cooldown = _configurationManager.GetCVar(CCVars.SalvageExpeditionCooldown);
|
||||
_failedCooldown = _configurationManager.GetCVar(CCVars.SalvageExpeditionFailedCooldown);
|
||||
_configurationManager.OnValueChanged(CCVars.SalvageExpeditionCooldown, SetCooldownChange);
|
||||
_configurationManager.OnValueChanged(CCVars.SalvageExpeditionFailedCooldown, SetFailedCooldownChange);
|
||||
}
|
||||
|
||||
private void OnExpeditionGetState(EntityUid uid, SalvageExpeditionComponent component, ref ComponentGetState args)
|
||||
@@ -59,7 +57,6 @@ public sealed partial class SalvageSystem
|
||||
private void ShutdownExpeditions()
|
||||
{
|
||||
_configurationManager.UnsubValueChanged(CCVars.SalvageExpeditionCooldown, SetCooldownChange);
|
||||
_configurationManager.UnsubValueChanged(CCVars.SalvageExpeditionFailedCooldown, SetFailedCooldownChange);
|
||||
}
|
||||
|
||||
private void SetCooldownChange(float obj)
|
||||
@@ -77,20 +74,6 @@ public sealed partial class SalvageSystem
|
||||
_cooldown = obj;
|
||||
}
|
||||
|
||||
private void SetFailedCooldownChange(float obj)
|
||||
{
|
||||
var diff = obj - _failedCooldown;
|
||||
|
||||
var query = AllEntityQuery<SalvageExpeditionDataComponent>();
|
||||
|
||||
while (query.MoveNext(out var comp))
|
||||
{
|
||||
comp.NextOffer += TimeSpan.FromSeconds(diff);
|
||||
}
|
||||
|
||||
_failedCooldown = obj;
|
||||
}
|
||||
|
||||
private void OnExpeditionShutdown(EntityUid uid, SalvageExpeditionComponent component, ComponentShutdown args)
|
||||
{
|
||||
component.Stream?.Stop();
|
||||
@@ -110,7 +93,7 @@ public sealed partial class SalvageSystem
|
||||
// Finish mission
|
||||
if (TryComp<SalvageExpeditionDataComponent>(component.Station, out var data))
|
||||
{
|
||||
FinishExpedition(data, uid, component, null);
|
||||
FinishExpedition(data, uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,109 +135,29 @@ public sealed partial class SalvageSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void FinishExpedition(SalvageExpeditionDataComponent component, EntityUid uid, SalvageExpeditionComponent expedition, EntityUid? shuttle)
|
||||
private void FinishExpedition(SalvageExpeditionDataComponent component, EntityUid uid)
|
||||
{
|
||||
// Finish mission cleanup.
|
||||
switch (expedition.MissionParams.MissionType)
|
||||
{
|
||||
// Handles the mining taxation.
|
||||
case SalvageMissionType.Mining:
|
||||
expedition.Completed = true;
|
||||
|
||||
if (shuttle != null && TryComp<SalvageMiningExpeditionComponent>(uid, out var mining))
|
||||
{
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var entities = new List<EntityUid>();
|
||||
MiningTax(entities, shuttle.Value, mining, xformQuery);
|
||||
|
||||
var tax = GetMiningTax(expedition.MissionParams.Difficulty);
|
||||
_random.Shuffle(entities);
|
||||
|
||||
// TODO: urgh this pr is already taking so long I'll do this later
|
||||
for (var i = 0; i < Math.Ceiling(entities.Count * tax); i++)
|
||||
{
|
||||
// QueueDel(entities[i]);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle payout after expedition has finished
|
||||
if (expedition.Completed)
|
||||
{
|
||||
Log.Debug($"Completed mission {expedition.MissionParams.MissionType} with seed {expedition.MissionParams.Seed}");
|
||||
component.NextOffer = _timing.CurTime + TimeSpan.FromSeconds(_cooldown);
|
||||
Announce(uid, Loc.GetString("salvage-expedition-mission-completed"));
|
||||
GiveRewards(expedition);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Debug($"Failed mission {expedition.MissionParams.MissionType} with seed {expedition.MissionParams.Seed}");
|
||||
component.NextOffer = _timing.CurTime + TimeSpan.FromSeconds(_failedCooldown);
|
||||
Announce(uid, Loc.GetString("salvage-expedition-mission-failed"));
|
||||
}
|
||||
|
||||
component.NextOffer = _timing.CurTime + TimeSpan.FromSeconds(_cooldown);
|
||||
Announce(uid, Loc.GetString("salvage-expedition-mission-completed"));
|
||||
component.ActiveMission = 0;
|
||||
component.Cooldown = true;
|
||||
UpdateConsoles(component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deducts ore tax for mining.
|
||||
/// </summary>
|
||||
private void MiningTax(List<EntityUid> entities, EntityUid entity, SalvageMiningExpeditionComponent mining, EntityQuery<TransformComponent> xformQuery)
|
||||
{
|
||||
if (!mining.ExemptEntities.Contains(entity))
|
||||
{
|
||||
entities.Add(entity);
|
||||
}
|
||||
|
||||
var xform = xformQuery.GetComponent(entity);
|
||||
var children = xform.ChildEnumerator;
|
||||
|
||||
while (children.MoveNext(out var child))
|
||||
{
|
||||
MiningTax(entities, child.Value, mining, xformQuery);
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateMissions(SalvageExpeditionDataComponent component)
|
||||
{
|
||||
component.Missions.Clear();
|
||||
var configs = Enum.GetValues<SalvageMissionType>().ToList();
|
||||
|
||||
// Temporarily removed coz it SUCKS
|
||||
configs.Remove(SalvageMissionType.Mining);
|
||||
|
||||
// this doesn't support having more missions than types of ratings
|
||||
// but the previous system didn't do that either.
|
||||
var allDifficulties = Enum.GetValues<DifficultyRating>();
|
||||
_random.Shuffle(allDifficulties);
|
||||
var difficulties = allDifficulties.Take(MissionLimit).ToList();
|
||||
difficulties.Sort();
|
||||
|
||||
if (configs.Count == 0)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < MissionLimit; i++)
|
||||
{
|
||||
_random.Shuffle(configs);
|
||||
var rating = difficulties[i];
|
||||
|
||||
foreach (var config in configs)
|
||||
var mission = new SalvageMissionParams
|
||||
{
|
||||
var mission = new SalvageMissionParams
|
||||
{
|
||||
Index = component.NextIndex,
|
||||
MissionType = config,
|
||||
Seed = _random.Next(),
|
||||
Difficulty = rating,
|
||||
};
|
||||
Index = component.NextIndex,
|
||||
Seed = _random.Next(),
|
||||
Difficulty = "Moderate",
|
||||
};
|
||||
|
||||
component.Missions[component.NextIndex++] = mission;
|
||||
break;
|
||||
}
|
||||
component.Missions[component.NextIndex++] = mission;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,13 +174,13 @@ public sealed partial class SalvageSystem
|
||||
SalvageJobTime,
|
||||
EntityManager,
|
||||
_timing,
|
||||
_logManager,
|
||||
_mapManager,
|
||||
_prototypeManager,
|
||||
_anchorable,
|
||||
_biome,
|
||||
_dungeon,
|
||||
_metaData,
|
||||
this,
|
||||
station,
|
||||
missionParams,
|
||||
cancelToken.Token);
|
||||
@@ -290,19 +193,4 @@ public sealed partial class SalvageSystem
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("salvage-expedition-structure-examine"));
|
||||
}
|
||||
|
||||
private void GiveRewards(SalvageExpeditionComponent comp)
|
||||
{
|
||||
// send it to cargo, no rewards otherwise.
|
||||
if (!TryComp<StationCargoOrderDatabaseComponent>(comp.Station, out var cargoDb))
|
||||
return;
|
||||
|
||||
foreach (var reward in comp.Rewards)
|
||||
{
|
||||
var sender = Loc.GetString("cargo-gift-default-sender");
|
||||
var desc = Loc.GetString("salvage-expedition-reward-description");
|
||||
var dest = Loc.GetString("cargo-gift-default-dest");
|
||||
_cargo.AddAndApproveOrder(comp.Station, reward, 0, 1, sender, desc, dest, cargoDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public sealed partial class SalvageSystem
|
||||
// TODO: This is terrible but need bluespace harnesses or something.
|
||||
var query = EntityQueryEnumerator<HumanoidAppearanceComponent, MobStateComponent, TransformComponent>();
|
||||
|
||||
while (query.MoveNext(out var uid, out var _, out var mobState, out var mobXform))
|
||||
while (query.MoveNext(out var uid, out _, out var mobState, out var mobXform))
|
||||
{
|
||||
if (mobXform.MapUid != xform.MapUid)
|
||||
continue;
|
||||
@@ -109,22 +109,11 @@ public sealed partial class SalvageSystem
|
||||
Announce(args.MapUid, Loc.GetString("salvage-expedition-announcement-dungeon", ("direction", component.DungeonLocation.GetDir())));
|
||||
|
||||
component.Stage = ExpeditionStage.Running;
|
||||
Dirty(component);
|
||||
Dirty(args.MapUid, component);
|
||||
}
|
||||
|
||||
private void OnFTLStarted(ref FTLStartedEvent ev)
|
||||
{
|
||||
// Started a mining mission so work out exempt entities
|
||||
if (TryComp<SalvageMiningExpeditionComponent>(
|
||||
_mapManager.GetMapEntityId(ev.TargetCoordinates.ToMap(EntityManager, _transform).MapId),
|
||||
out var mining))
|
||||
{
|
||||
var ents = new List<EntityUid>();
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
MiningTax(ents, ev.Entity, mining, xformQuery);
|
||||
mining.ExemptEntities = ents;
|
||||
}
|
||||
|
||||
if (!TryComp<SalvageExpeditionComponent>(ev.FromMapUid, out var expedition) ||
|
||||
!TryComp<SalvageExpeditionDataComponent>(expedition.Station, out var station))
|
||||
{
|
||||
@@ -169,7 +158,7 @@ public sealed partial class SalvageSystem
|
||||
Dirty(uid, comp);
|
||||
Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(2).Minutes)));
|
||||
}
|
||||
else if (comp.Stage < ExpeditionStage.Countdown && remaining < TimeSpan.FromMinutes(5))
|
||||
else if (comp.Stage < ExpeditionStage.Countdown && remaining < TimeSpan.FromMinutes(4))
|
||||
{
|
||||
comp.Stage = ExpeditionStage.Countdown;
|
||||
Dirty(uid, comp);
|
||||
@@ -210,72 +199,5 @@ public sealed partial class SalvageSystem
|
||||
QueueDel(uid);
|
||||
}
|
||||
}
|
||||
|
||||
// Mining missions: NOOP since it's handled after ftling
|
||||
|
||||
// Structure missions
|
||||
var structureQuery = EntityQueryEnumerator<SalvageStructureExpeditionComponent, SalvageExpeditionComponent>();
|
||||
|
||||
while (structureQuery.MoveNext(out var uid, out var structure, out var comp))
|
||||
{
|
||||
if (comp.Completed)
|
||||
continue;
|
||||
|
||||
var structureAnnounce = false;
|
||||
|
||||
for (var i = 0; i < structure.Structures.Count; i++)
|
||||
{
|
||||
var objective = structure.Structures[i];
|
||||
|
||||
if (Deleted(objective))
|
||||
{
|
||||
structure.Structures.RemoveSwap(i);
|
||||
structureAnnounce = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (structureAnnounce)
|
||||
{
|
||||
Announce(uid, Loc.GetString("salvage-expedition-structure-remaining", ("count", structure.Structures.Count)));
|
||||
}
|
||||
|
||||
if (structure.Structures.Count == 0)
|
||||
{
|
||||
comp.Completed = true;
|
||||
Announce(uid, Loc.GetString("salvage-expedition-completed"));
|
||||
}
|
||||
}
|
||||
|
||||
// Elimination missions
|
||||
var eliminationQuery = EntityQueryEnumerator<SalvageEliminationExpeditionComponent, SalvageExpeditionComponent>();
|
||||
while (eliminationQuery.MoveNext(out var uid, out var elimination, out var comp))
|
||||
{
|
||||
if (comp.Completed)
|
||||
continue;
|
||||
|
||||
var announce = false;
|
||||
|
||||
for (var i = 0; i < elimination.Megafauna.Count; i++)
|
||||
{
|
||||
var mob = elimination.Megafauna[i];
|
||||
|
||||
if (Deleted(mob) || _mobState.IsDead(mob))
|
||||
{
|
||||
elimination.Megafauna.RemoveSwap(i);
|
||||
announce = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (announce)
|
||||
{
|
||||
Announce(uid, Loc.GetString("salvage-expedition-megafauna-remaining", ("count", elimination.Megafauna.Count)));
|
||||
}
|
||||
|
||||
if (elimination.Megafauna.Count == 0)
|
||||
{
|
||||
comp.Completed = true;
|
||||
Announce(uid, Loc.GetString("salvage-expedition-completed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace Content.Server.Salvage
|
||||
[Dependency] private readonly IChatManager _chat = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly ILogManager _logManager = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly AnchorableSystem _anchorable = default!;
|
||||
[Dependency] private readonly BiomeSystem _biome = default!;
|
||||
[Dependency] private readonly CargoSystem _cargo = default!;
|
||||
[Dependency] private readonly DungeonSystem _dungeon = default!;
|
||||
[Dependency] private readonly MapLoaderSystem _map = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading;
|
||||
@@ -19,6 +20,7 @@ using Content.Shared.Parallax.Biomes;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Procedural;
|
||||
using Content.Shared.Procedural.Loot;
|
||||
using Content.Shared.Random;
|
||||
using Content.Shared.Salvage;
|
||||
using Content.Shared.Salvage.Expeditions;
|
||||
using Content.Shared.Salvage.Expeditions.Modifiers;
|
||||
@@ -29,6 +31,7 @@ using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
@@ -42,22 +45,23 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
private readonly BiomeSystem _biome;
|
||||
private readonly DungeonSystem _dungeon;
|
||||
private readonly MetaDataSystem _metaData;
|
||||
private readonly SalvageSystem _salvage;
|
||||
|
||||
public readonly EntityUid Station;
|
||||
private readonly SalvageMissionParams _missionParams;
|
||||
|
||||
private readonly ISawmill _sawmill;
|
||||
|
||||
public SpawnSalvageMissionJob(
|
||||
double maxTime,
|
||||
IEntityManager entManager,
|
||||
IGameTiming timing,
|
||||
ILogManager logManager,
|
||||
IMapManager mapManager,
|
||||
IPrototypeManager protoManager,
|
||||
AnchorableSystem anchorable,
|
||||
BiomeSystem biome,
|
||||
DungeonSystem dungeon,
|
||||
MetaDataSystem metaData,
|
||||
SalvageSystem salvage,
|
||||
EntityUid station,
|
||||
SalvageMissionParams missionParams,
|
||||
CancellationToken cancellation = default) : base(maxTime, cancellation)
|
||||
@@ -70,15 +74,17 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
_biome = biome;
|
||||
_dungeon = dungeon;
|
||||
_metaData = metaData;
|
||||
_salvage = salvage;
|
||||
Station = station;
|
||||
_missionParams = missionParams;
|
||||
_sawmill = logManager.GetSawmill("salvage_job");
|
||||
#if !DEBUG
|
||||
_sawmill.Level = LogLevel.Info;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override async Task<bool> Process()
|
||||
{
|
||||
Logger.DebugS("salvage", $"Spawning salvage mission with seed {_missionParams.Seed}");
|
||||
var config = _missionParams.MissionType;
|
||||
_sawmill.Debug("salvage", $"Spawning salvage mission with seed {_missionParams.Seed}");
|
||||
var mapId = _mapManager.CreateMap();
|
||||
var mapUid = _mapManager.GetMapEntityId(mapId);
|
||||
_mapManager.AddUninitializedMap(mapId);
|
||||
@@ -88,16 +94,17 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
|
||||
// Setup mission configs
|
||||
// As we go through the config the rating will deplete so we'll go for most important to least important.
|
||||
var difficultyId = "Moderate";
|
||||
var difficultyProto = _prototypeManager.Index<SalvageDifficultyPrototype>(difficultyId);
|
||||
|
||||
var mission = _entManager.System<SharedSalvageSystem>()
|
||||
.GetMission(_missionParams.MissionType, _missionParams.Difficulty, _missionParams.Seed);
|
||||
.GetMission(difficultyProto, _missionParams.Seed);
|
||||
|
||||
var missionBiome = _prototypeManager.Index<SalvageBiomeMod>(mission.Biome);
|
||||
BiomeComponent? biome = null;
|
||||
var missionBiome = _prototypeManager.Index<SalvageBiomeModPrototype>(mission.Biome);
|
||||
|
||||
if (missionBiome.BiomePrototype != null)
|
||||
{
|
||||
biome = _entManager.AddComponent<BiomeComponent>(mapUid);
|
||||
var biome = _entManager.AddComponent<BiomeComponent>(mapUid);
|
||||
var biomeSystem = _entManager.System<BiomeSystem>();
|
||||
biomeSystem.SetTemplate(biome, _prototypeManager.Index<BiomeTemplatePrototype>(missionBiome.BiomePrototype));
|
||||
biomeSystem.SetSeed(biome, mission.Seed);
|
||||
@@ -125,7 +132,7 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
{
|
||||
var lighting = _entManager.EnsureComponent<MapLightComponent>(mapUid);
|
||||
lighting.AmbientLightColor = mission.Color.Value;
|
||||
_entManager.Dirty(lighting);
|
||||
_entManager.Dirty(mapUid, lighting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,8 +144,6 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
expedition.Station = Station;
|
||||
expedition.EndTime = _timing.CurTime + mission.Duration;
|
||||
expedition.MissionParams = _missionParams;
|
||||
expedition.Difficulty = _missionParams.Difficulty;
|
||||
expedition.Rewards = mission.Rewards;
|
||||
|
||||
// Don't want consoles to have the incorrect name until refreshed.
|
||||
var ftlUid = _entManager.CreateEntityUninitialized("FTLPoint", new EntityCoordinates(mapUid, grid.TileSizeHalfVector));
|
||||
@@ -151,29 +156,23 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
// We'll use the dungeon rotation as the spawn angle
|
||||
var dungeonRotation = _dungeon.GetDungeonRotation(_missionParams.Seed);
|
||||
|
||||
Dungeon dungeon = default!;
|
||||
var maxDungeonOffset = minDungeonOffset + 12;
|
||||
var dungeonOffsetDistance = minDungeonOffset + (maxDungeonOffset - minDungeonOffset) * random.NextFloat();
|
||||
var dungeonOffset = new Vector2(0f, dungeonOffsetDistance);
|
||||
dungeonOffset = dungeonRotation.RotateVec(dungeonOffset);
|
||||
var dungeonMod = _prototypeManager.Index<SalvageDungeonModPrototype>(mission.Dungeon);
|
||||
var dungeonConfig = _prototypeManager.Index<DungeonConfigPrototype>(dungeonMod.Proto);
|
||||
var dungeon = await WaitAsyncTask(_dungeon.GenerateDungeonAsync(dungeonConfig, mapUid, grid, (Vector2i) dungeonOffset,
|
||||
_missionParams.Seed));
|
||||
|
||||
if (config != SalvageMissionType.Mining)
|
||||
// Aborty
|
||||
if (dungeon.Rooms.Count == 0)
|
||||
{
|
||||
var maxDungeonOffset = minDungeonOffset + 12;
|
||||
var dungeonOffsetDistance = minDungeonOffset + (maxDungeonOffset - minDungeonOffset) * random.NextFloat();
|
||||
var dungeonOffset = new Vector2(0f, dungeonOffsetDistance);
|
||||
dungeonOffset = dungeonRotation.RotateVec(dungeonOffset);
|
||||
var dungeonMod = _prototypeManager.Index<SalvageDungeonMod>(mission.Dungeon);
|
||||
var dungeonConfig = _prototypeManager.Index<DungeonConfigPrototype>(dungeonMod.Proto);
|
||||
dungeon =
|
||||
await WaitAsyncTask(_dungeon.GenerateDungeonAsync(dungeonConfig, mapUid, grid, (Vector2i) dungeonOffset,
|
||||
_missionParams.Seed));
|
||||
|
||||
// Aborty
|
||||
if (dungeon.Rooms.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
expedition.DungeonLocation = dungeonOffset;
|
||||
return false;
|
||||
}
|
||||
|
||||
expedition.DungeonLocation = dungeonOffset;
|
||||
|
||||
List<Vector2i> reservedTiles = new();
|
||||
|
||||
foreach (var tile in grid.GetTilesIntersecting(new Circle(Vector2.Zero, landingPadRadius), false))
|
||||
@@ -184,24 +183,14 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
reservedTiles.Add(tile.GridIndices);
|
||||
}
|
||||
|
||||
// Mission setup
|
||||
switch (config)
|
||||
{
|
||||
case SalvageMissionType.Mining:
|
||||
await SetupMining(mission, mapUid);
|
||||
break;
|
||||
case SalvageMissionType.Destruction:
|
||||
await SetupStructure(mission, dungeon, mapUid, grid, random);
|
||||
break;
|
||||
case SalvageMissionType.Elimination:
|
||||
await SetupElimination(mission, dungeon, mapUid, grid, random);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
var budgetEntries = new List<IBudgetEntry>();
|
||||
|
||||
/*
|
||||
* GUARANTEED LOOT
|
||||
*/
|
||||
|
||||
// Handle loot
|
||||
// We'll always add this loot if possible
|
||||
// mainly used for ore layers.
|
||||
foreach (var lootProto in _prototypeManager.EnumeratePrototypes<SalvageLootPrototype>())
|
||||
{
|
||||
if (!lootProto.Guaranteed)
|
||||
@@ -210,10 +199,104 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
await SpawnDungeonLoot(dungeon, missionBiome, lootProto, mapUid, grid, random, reservedTiles);
|
||||
}
|
||||
|
||||
// Handle boss loot (when relevant).
|
||||
|
||||
// Handle mob loot.
|
||||
|
||||
// Handle remaining loot
|
||||
|
||||
/*
|
||||
* MOB SPAWNS
|
||||
*/
|
||||
|
||||
var mobBudget = difficultyProto.MobBudget;
|
||||
var faction = _prototypeManager.Index<SalvageFactionPrototype>(mission.Faction);
|
||||
var randomSystem = _entManager.System<RandomSystem>();
|
||||
|
||||
foreach (var entry in faction.MobGroups)
|
||||
{
|
||||
budgetEntries.Add(entry);
|
||||
}
|
||||
|
||||
var probSum = budgetEntries.Sum(x => x.Prob);
|
||||
|
||||
while (mobBudget > 0f)
|
||||
{
|
||||
var entry = randomSystem.GetBudgetEntry(ref mobBudget, ref probSum, budgetEntries, random);
|
||||
if (entry == null)
|
||||
break;
|
||||
|
||||
await SpawnRandomEntry(grid, entry, dungeon, random);
|
||||
}
|
||||
|
||||
var allLoot = _prototypeManager.Index<SalvageLootPrototype>(SharedSalvageSystem.ExpeditionsLootProto);
|
||||
var lootBudget = difficultyProto.LootBudget;
|
||||
|
||||
foreach (var rule in allLoot.LootRules)
|
||||
{
|
||||
switch (rule)
|
||||
{
|
||||
case RandomSpawnsLoot randomLoot:
|
||||
budgetEntries.Clear();
|
||||
|
||||
foreach (var entry in randomLoot.Entries)
|
||||
{
|
||||
budgetEntries.Add(entry);
|
||||
}
|
||||
|
||||
probSum = budgetEntries.Sum(x => x.Prob);
|
||||
|
||||
while (lootBudget > 0f)
|
||||
{
|
||||
var entry = randomSystem.GetBudgetEntry(ref lootBudget, ref probSum, budgetEntries, random);
|
||||
if (entry == null)
|
||||
break;
|
||||
|
||||
_sawmill.Debug($"Spawning dungeon loot {entry.Proto}");
|
||||
await SpawnRandomEntry(grid, entry, dungeon, random);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task SpawnDungeonLoot(Dungeon? dungeon, SalvageBiomeMod biomeMod, SalvageLootPrototype loot, EntityUid gridUid, MapGridComponent grid, Random random, List<Vector2i> reservedTiles)
|
||||
private async Task SpawnRandomEntry(MapGridComponent grid, IBudgetEntry entry, Dungeon dungeon, Random random)
|
||||
{
|
||||
await SuspendIfOutOfTime();
|
||||
|
||||
var availableRooms = new ValueList<DungeonRoom>(dungeon.Rooms);
|
||||
var availableTiles = new List<Vector2i>();
|
||||
|
||||
while (availableRooms.Count > 0)
|
||||
{
|
||||
availableTiles.Clear();
|
||||
var roomIndex = random.Next(availableRooms.Count);
|
||||
var room = availableRooms.RemoveSwap(roomIndex);
|
||||
availableTiles.AddRange(room.Tiles);
|
||||
|
||||
while (availableTiles.Count > 0)
|
||||
{
|
||||
var tile = availableTiles.RemoveSwap(random.Next(availableTiles.Count));
|
||||
|
||||
if (!_anchorable.TileFree(grid, tile, (int) CollisionGroup.MachineLayer,
|
||||
(int) CollisionGroup.MachineLayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_entManager.SpawnAtPosition(entry.Proto, grid.GridTileToLocal(tile));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// oh noooooooooooo
|
||||
}
|
||||
|
||||
private async Task SpawnDungeonLoot(Dungeon dungeon, SalvageBiomeModPrototype biomeMod, SalvageLootPrototype loot, EntityUid gridUid, MapGridComponent grid, Random random, List<Vector2i> reservedTiles)
|
||||
{
|
||||
for (var i = 0; i < loot.LootRules.Count; i++)
|
||||
{
|
||||
@@ -241,150 +324,4 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Mission Specific
|
||||
|
||||
private async Task SetupMining(
|
||||
SalvageMission mission,
|
||||
EntityUid gridUid)
|
||||
{
|
||||
var faction = _prototypeManager.Index<SalvageFactionPrototype>(mission.Faction);
|
||||
|
||||
if (_entManager.TryGetComponent<BiomeComponent>(gridUid, out var biome))
|
||||
{
|
||||
// TODO: Better
|
||||
for (var i = 0; i < _salvage.GetDifficulty(mission.Difficulty); i++)
|
||||
{
|
||||
_biome.AddMarkerLayer(biome, faction.Configs["Mining"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetupStructure(
|
||||
SalvageMission mission,
|
||||
Dungeon dungeon,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
Random random)
|
||||
{
|
||||
var structureComp = _entManager.EnsureComponent<SalvageStructureExpeditionComponent>(gridUid);
|
||||
var availableRooms = dungeon.Rooms.ToList();
|
||||
var faction = _prototypeManager.Index<SalvageFactionPrototype>(mission.Faction);
|
||||
await SpawnMobsRandomRooms(mission, dungeon, faction, grid, random);
|
||||
|
||||
var structureCount = _salvage.GetStructureCount(mission.Difficulty);
|
||||
var shaggy = faction.Configs["DefenseStructure"];
|
||||
var validSpawns = new List<Vector2i>();
|
||||
|
||||
// Spawn the objectives
|
||||
for (var i = 0; i < structureCount; i++)
|
||||
{
|
||||
var structureRoom = availableRooms[random.Next(availableRooms.Count)];
|
||||
validSpawns.Clear();
|
||||
validSpawns.AddRange(structureRoom.Tiles);
|
||||
random.Shuffle(validSpawns);
|
||||
|
||||
while (validSpawns.Count > 0)
|
||||
{
|
||||
var spawnTile = validSpawns[^1];
|
||||
validSpawns.RemoveAt(validSpawns.Count - 1);
|
||||
|
||||
if (!_anchorable.TileFree(grid, spawnTile, (int) CollisionGroup.MachineLayer,
|
||||
(int) CollisionGroup.MachineLayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var spawnPosition = grid.GridTileToLocal(spawnTile);
|
||||
var uid = _entManager.SpawnEntity(shaggy, spawnPosition);
|
||||
_entManager.AddComponent<SalvageStructureComponent>(uid);
|
||||
structureComp.Structures.Add(uid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SetupElimination(
|
||||
SalvageMission mission,
|
||||
Dungeon dungeon,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
Random random)
|
||||
{
|
||||
// spawn megafauna in a random place
|
||||
var roomIndex = random.Next(dungeon.Rooms.Count);
|
||||
var room = dungeon.Rooms[roomIndex];
|
||||
var tile = room.Tiles.ElementAt(random.Next(room.Tiles.Count));
|
||||
var position = grid.GridTileToLocal(tile);
|
||||
|
||||
var faction = _prototypeManager.Index<SalvageFactionPrototype>(mission.Faction);
|
||||
var prototype = faction.Configs["Megafauna"];
|
||||
var uid = _entManager.SpawnEntity(prototype, position);
|
||||
// not removing ghost role since its 1 megafauna, expect that you won't be able to cheese it.
|
||||
var eliminationComp = _entManager.EnsureComponent<SalvageEliminationExpeditionComponent>(gridUid);
|
||||
eliminationComp.Megafauna.Add(uid);
|
||||
|
||||
// spawn less mobs than usual since there's megafauna to deal with too
|
||||
await SpawnMobsRandomRooms(mission, dungeon, faction, grid, random, 0.5f);
|
||||
}
|
||||
|
||||
private async Task SpawnMobsRandomRooms(SalvageMission mission, Dungeon dungeon, SalvageFactionPrototype faction, MapGridComponent grid, Random random, float scale = 1f)
|
||||
{
|
||||
// scale affects how many groups are spawned, not the size of the groups themselves
|
||||
var groupSpawns = _salvage.GetSpawnCount(mission.Difficulty) * scale;
|
||||
var groupSum = faction.MobGroups.Sum(o => o.Prob);
|
||||
var validSpawns = new List<Vector2i>();
|
||||
|
||||
for (var i = 0; i < groupSpawns; i++)
|
||||
{
|
||||
var roll = random.NextFloat() * groupSum;
|
||||
var value = 0f;
|
||||
|
||||
foreach (var group in faction.MobGroups)
|
||||
{
|
||||
value += group.Prob;
|
||||
|
||||
if (value < roll)
|
||||
continue;
|
||||
|
||||
var mobGroupIndex = random.Next(faction.MobGroups.Count);
|
||||
var mobGroup = faction.MobGroups[mobGroupIndex];
|
||||
|
||||
var spawnRoomIndex = random.Next(dungeon.Rooms.Count);
|
||||
var spawnRoom = dungeon.Rooms[spawnRoomIndex];
|
||||
validSpawns.Clear();
|
||||
validSpawns.AddRange(spawnRoom.Tiles);
|
||||
random.Shuffle(validSpawns);
|
||||
|
||||
foreach (var entry in EntitySpawnCollection.GetSpawns(mobGroup.Entries, random))
|
||||
{
|
||||
while (validSpawns.Count > 0)
|
||||
{
|
||||
var spawnTile = validSpawns[^1];
|
||||
validSpawns.RemoveAt(validSpawns.Count - 1);
|
||||
|
||||
if (!_anchorable.TileFree(grid, spawnTile, (int) CollisionGroup.MachineLayer,
|
||||
(int) CollisionGroup.MachineLayer))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var spawnPosition = grid.GridTileToLocal(spawnTile);
|
||||
|
||||
var uid = _entManager.CreateEntityUninitialized(entry, spawnPosition);
|
||||
_entManager.RemoveComponent<GhostTakeoverAvailableComponent>(uid);
|
||||
_entManager.RemoveComponent<GhostRoleComponent>(uid);
|
||||
_entManager.InitializeAndStartEntity(uid);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user