use parts crates for rewards, show rewards in ui (#17374)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-06-17 02:00:54 +00:00
committed by GitHub
parent eb114677ad
commit a3c37edd69
11 changed files with 94 additions and 216 deletions

View File

@@ -1,8 +1,10 @@
using Content.Shared.Random;
using Content.Shared.Salvage;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Server.Salvage.Expeditions;
@@ -56,6 +58,12 @@ public sealed class SalvageExpeditionComponent : Component
/// </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!;
}
public enum ExpeditionStage : byte

View File

@@ -286,42 +286,12 @@ public sealed partial class SalvageSystem
return;
}
var ids = RewardsForDifficulty(comp.Difficulty);
foreach (var id in ids)
foreach (var reward in comp.Rewards)
{
// pick a random reward to give
var rewards = _prototypeManager.Index<WeightedRandomPrototype>(id);
var reward = rewards.Pick(_random);
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(cargoDb, reward, 0, 1, sender, desc, dest);
}
}
/// <summary>
/// Get a list of WeightedRandomPrototype IDs with the rewards for a certain difficulty.
/// </summary>
private string[] RewardsForDifficulty(DifficultyRating rating)
{
var common = "SalvageRewardCommon";
var rare = "SalvageRewardRare";
var epic = "SalvageRewardEpic";
switch (rating)
{
case DifficultyRating.Minimal:
return new string[] { common, common, common };
case DifficultyRating.Minor:
return new string[] { common, common, rare };
case DifficultyRating.Moderate:
return new string[] { common, rare, rare };
case DifficultyRating.Hazardous:
return new string[] { rare, rare, epic };
case DifficultyRating.Extreme:
return new string[] { rare, epic, epic };
default:
throw new NotImplementedException();
}
}
}

View File

@@ -135,6 +135,7 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
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, Vector2.Zero));
@@ -216,14 +217,6 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
await SpawnDungeonLoot(dungeon, lootProto, mapUid, grid, random, reservedTiles);
}
foreach (var (loot, count) in mission.Loot)
{
for (var i = 0; i < count; i++)
{
var lootProto = _prototypeManager.Index<SalvageLootPrototype>(loot);
await SpawnDungeonLoot(dungeon, lootProto, mapUid, grid, random, reservedTiles);
}
}
return true;
}
@@ -251,62 +244,10 @@ public sealed class SpawnSalvageMissionJob : Job<bool>
}
}
break;
// Spawns a cluster (like an ore vein) nearby.
case DungeonClusterLoot clusterLoot:
await SpawnDungeonClusterLoot(dungeon!, clusterLoot, grid, random, reservedTiles);
break;
}
}
}
#region Loot
private async Task SpawnDungeonClusterLoot(
Dungeon dungeon,
DungeonClusterLoot loot,
MapGridComponent grid,
Random random,
List<Vector2i> reservedTiles)
{
var spawnTiles = new HashSet<Vector2i>();
for (var i = 0; i < loot.Points; i++)
{
var room = dungeon.Rooms[random.Next(dungeon.Rooms.Count)];
var clusterAmount = loot.ClusterAmount;
var spots = room.Tiles.ToList();
random.Shuffle(spots);
foreach (var spot in spots)
{
if (reservedTiles.Contains(spot))
continue;
var anchored = grid.GetAnchoredEntitiesEnumerator(spot);
if (anchored.MoveNext(out _))
{
continue;
}
clusterAmount--;
spawnTiles.Add(spot);
if (clusterAmount == 0)
break;
}
}
foreach (var tile in spawnTiles)
{
await SuspendIfOutOfTime();
var proto = _prototypeManager.Index<WeightedRandomPrototype>(loot.Prototype).Pick(random);
_entManager.SpawnEntity(proto, grid.GridTileToLocal(tile));
}
}
#endregion
#region Mission Specific
private async Task SetupMining(