Skip to content

Commit a3c37ed

Browse files
authored
use parts crates for rewards, show rewards in ui (space-wizards#17374)
Co-authored-by: deltanedas <@deltanedas:kde.org>
1 parent eb11467 commit a3c37ed

File tree

11 files changed

+93
-215
lines changed

11 files changed

+93
-215
lines changed

‎Content.Client/Salvage/UI/SalvageExpeditionWindow.xaml.cs‎

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Content.Client.UserInterface.Controls;
55
using Content.Shared.CCVar;
66
using Content.Shared.Parallax.Biomes;
7-
using Content.Shared.Procedural.Loot;
87
using Content.Shared.Salvage;
98
using Content.Shared.Salvage.Expeditions.Modifiers;
109
using Content.Shared.Shuttles.BUIStates;
@@ -191,29 +190,17 @@ public void UpdateState(SalvageExpeditionConsoleState state)
191190

192191
lBox.AddChild(new Label()
193192
{
194-
Text = Loc.GetString("salvage-expedition-window-loot")
193+
Text = Loc.GetString("salvage-expedition-window-rewards")
195194
});
196195

197-
if (mission.Loot.Count == 0)
198-
{
199-
lBox.AddChild(new Label()
200-
{
201-
Text = Loc.GetString("salvage-expedition-window-none"),
202-
FontColorOverride = StyleNano.ConcerningOrangeFore,
203-
HorizontalAlignment = HAlignment.Left,
204-
Margin = new Thickness(0f, 0f, 0f, 5f),
205-
});
206-
}
207-
else
196+
// there will always be 3 rewards so no need for 0 check
197+
lBox.AddChild(new Label()
208198
{
209-
lBox.AddChild(new Label()
210-
{
211-
Text = string.Join("\n", mission.Loot.Select(o => "- " + _prototype.Index<SalvageLootPrototype>(o.Key).Description + (o.Value > 1 ? $" x {o.Value}" : ""))).TrimEnd(),
212-
FontColorOverride = StyleNano.ConcerningOrangeFore,
213-
HorizontalAlignment = HAlignment.Left,
214-
Margin = new Thickness(0f, 0f, 0f, 5f),
215-
});
216-
}
199+
Text = string.Join("\n", mission.Rewards.Select(id => "- " + _prototype.Index<EntityPrototype>(id).Name)),
200+
FontColorOverride = StyleNano.ConcerningOrangeFore,
201+
HorizontalAlignment = HAlignment.Left,
202+
Margin = new Thickness(0f, 0f, 0f, 5f)
203+
});
217204

218205
// Claim
219206
var claimButton = new Button()

‎Content.Server/Salvage/Expeditions/SalvageExpeditionComponent.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Content.Shared.Random;
22
using Content.Shared.Salvage;
33
using Robust.Shared.Audio;
4+
using Robust.Shared.Prototypes;
45
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
56
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
7+
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
68

79
namespace Content.Server.Salvage.Expeditions;
810

@@ -56,6 +58,12 @@ public sealed class SalvageExpeditionComponent : Component
5658
/// </summary>
5759
[ViewVariables(VVAccess.ReadWrite), DataField("difficulty")]
5860
public DifficultyRating Difficulty;
61+
62+
/// <summary>
63+
/// List of items to order on mission completion
64+
/// </summary>
65+
[ViewVariables(VVAccess.ReadWrite), DataField("rewards", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
66+
public List<string> Rewards = default!;
5967
}
6068

6169
public enum ExpeditionStage : byte

‎Content.Server/Salvage/SalvageSystem.Expeditions.cs‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -286,42 +286,12 @@ private void GiveRewards(SalvageExpeditionComponent comp)
286286
return;
287287
}
288288

289-
var ids = RewardsForDifficulty(comp.Difficulty);
290-
foreach (var id in ids)
289+
foreach (var reward in comp.Rewards)
291290
{
292-
// pick a random reward to give
293-
var rewards = _prototypeManager.Index<WeightedRandomPrototype>(id);
294-
var reward = rewards.Pick(_random);
295-
296291
var sender = Loc.GetString("cargo-gift-default-sender");
297292
var desc = Loc.GetString("salvage-expedition-reward-description");
298293
var dest = Loc.GetString("cargo-gift-default-dest");
299294
_cargo.AddAndApproveOrder(cargoDb, reward, 0, 1, sender, desc, dest);
300295
}
301296
}
302-
303-
/// <summary>
304-
/// Get a list of WeightedRandomPrototype IDs with the rewards for a certain difficulty.
305-
/// </summary>
306-
private string[] RewardsForDifficulty(DifficultyRating rating)
307-
{
308-
var common = "SalvageRewardCommon";
309-
var rare = "SalvageRewardRare";
310-
var epic = "SalvageRewardEpic";
311-
switch (rating)
312-
{
313-
case DifficultyRating.Minimal:
314-
return new string[] { common, common, common };
315-
case DifficultyRating.Minor:
316-
return new string[] { common, common, rare };
317-
case DifficultyRating.Moderate:
318-
return new string[] { common, rare, rare };
319-
case DifficultyRating.Hazardous:
320-
return new string[] { rare, rare, epic };
321-
case DifficultyRating.Extreme:
322-
return new string[] { rare, epic, epic };
323-
default:
324-
throw new NotImplementedException();
325-
}
326-
}
327297
}

‎Content.Server/Salvage/SpawnSalvageMissionJob.cs‎

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ protected override async Task<bool> Process()
135135
expedition.EndTime = _timing.CurTime + mission.Duration;
136136
expedition.MissionParams = _missionParams;
137137
expedition.Difficulty = _missionParams.Difficulty;
138+
expedition.Rewards = mission.Rewards;
138139

139140
// Don't want consoles to have the incorrect name until refreshed.
140141
var ftlUid = _entManager.CreateEntityUninitialized("FTLPoint", new EntityCoordinates(mapUid, Vector2.Zero));
@@ -216,14 +217,6 @@ await WaitAsyncTask(_dungeon.GenerateDungeonAsync(dungeonConfig, mapUid, grid, (
216217
await SpawnDungeonLoot(dungeon, lootProto, mapUid, grid, random, reservedTiles);
217218
}
218219

219-
foreach (var (loot, count) in mission.Loot)
220-
{
221-
for (var i = 0; i < count; i++)
222-
{
223-
var lootProto = _prototypeManager.Index<SalvageLootPrototype>(loot);
224-
await SpawnDungeonLoot(dungeon, lootProto, mapUid, grid, random, reservedTiles);
225-
}
226-
}
227220
return true;
228221
}
229222

@@ -251,62 +244,10 @@ private async Task SpawnDungeonLoot(Dungeon? dungeon, SalvageLootPrototype loot,
251244
}
252245
}
253246
break;
254-
// Spawns a cluster (like an ore vein) nearby.
255-
case DungeonClusterLoot clusterLoot:
256-
await SpawnDungeonClusterLoot(dungeon!, clusterLoot, grid, random, reservedTiles);
257-
break;
258247
}
259248
}
260249
}
261250

262-
#region Loot
263-
264-
private async Task SpawnDungeonClusterLoot(
265-
Dungeon dungeon,
266-
DungeonClusterLoot loot,
267-
MapGridComponent grid,
268-
Random random,
269-
List<Vector2i> reservedTiles)
270-
{
271-
var spawnTiles = new HashSet<Vector2i>();
272-
273-
for (var i = 0; i < loot.Points; i++)
274-
{
275-
var room = dungeon.Rooms[random.Next(dungeon.Rooms.Count)];
276-
var clusterAmount = loot.ClusterAmount;
277-
var spots = room.Tiles.ToList();
278-
random.Shuffle(spots);
279-
280-
foreach (var spot in spots)
281-
{
282-
if (reservedTiles.Contains(spot))
283-
continue;
284-
285-
var anchored = grid.GetAnchoredEntitiesEnumerator(spot);
286-
287-
if (anchored.MoveNext(out _))
288-
{
289-
continue;
290-
}
291-
292-
clusterAmount--;
293-
spawnTiles.Add(spot);
294-
295-
if (clusterAmount == 0)
296-
break;
297-
}
298-
}
299-
300-
foreach (var tile in spawnTiles)
301-
{
302-
await SuspendIfOutOfTime();
303-
var proto = _prototypeManager.Index<WeightedRandomPrototype>(loot.Prototype).Pick(random);
304-
_entManager.SpawnEntity(proto, grid.GridTileToLocal(tile));
305-
}
306-
}
307-
308-
#endregion
309-
310251
#region Mission Specific
311252

312253
private async Task SetupMining(

‎Content.Shared/Procedural/Loot/DungeonClusterLoot.cs‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎Content.Shared/Salvage/SalvageExpeditions.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public sealed record SalvageMission(
103103
string Air,
104104
Color? Color,
105105
TimeSpan Duration,
106-
Dictionary<string, int> Loot,
106+
List<string> Rewards,
107107
List<string> Modifiers)
108108
{
109109
/// <summary>
@@ -151,7 +151,10 @@ public sealed record SalvageMission(
151151
/// </summary>
152152
public TimeSpan Duration = Duration;
153153

154-
public Dictionary<string, int> Loot = Loot;
154+
/// <summary>
155+
/// The list of items to order on mission completion.
156+
/// </summary>
157+
public List<string> Rewards = Rewards;
155158

156159
/// <summary>
157160
/// Modifiers (outside of the above) applied to the mission.

‎Content.Shared/Salvage/SharedSalvageSystem.cs‎

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using Content.Shared.Dataset;
3-
using Content.Shared.Procedural.Loot;
43
using Content.Shared.Random;
54
using Content.Shared.Random.Helpers;
65
using Content.Shared.Salvage.Expeditions;
@@ -124,8 +123,8 @@ public SalvageMission GetMission(SalvageMissionType config, DifficultyRating dif
124123
mods.Add(time.Description);
125124
}
126125

127-
var loots = GetLoot(config, _proto.EnumeratePrototypes<SalvageLootPrototype>().Where(o => !o.Guaranteed).ToList(), GetDifficulty(difficulty), seed);
128-
return new SalvageMission(seed, difficulty, dungeon.ID, faction.ID, config, biome.ID, air.ID, light.Color, duration, loots, mods);
126+
var rewards = GetRewards(difficulty, rand);
127+
return new SalvageMission(seed, difficulty, dungeon.ID, faction.ID, config, biome.ID, air.ID, light.Color, duration, rewards, mods);
129128
}
130129

131130
// TODO: probably worth putting the biome whitelist thing in a common thing then having a getmod overload for it
@@ -208,28 +207,43 @@ public T GetMod<T>(System.Random rand, ref float rating) where T : class, IProto
208207
throw new InvalidOperationException();
209208
}
210209

211-
private Dictionary<string, int> GetLoot(SalvageMissionType mission, List<SalvageLootPrototype> loots, int count, int seed)
210+
private List<string> GetRewards(DifficultyRating difficulty, System.Random rand)
212211
{
213-
var results = new Dictionary<string, int>();
214-
var adjustedSeed = new System.Random(seed + 2);
215-
216-
for (var i = 0; i < count; i++)
212+
var rewards = new List<string>(3);
213+
var ids = RewardsForDifficulty(difficulty);
214+
foreach (var id in ids)
217215
{
218-
adjustedSeed.Shuffle(loots);
216+
// pick a random reward to give
217+
var weights = _proto.Index<WeightedRandomPrototype>(id);
218+
rewards.Add(weights.Pick(rand));
219+
}
219220

220-
foreach (var loot in loots)
221-
{
222-
if (loot.Blacklist.Contains(mission))
223-
continue;
221+
return rewards;
222+
}
224223

225-
var weh = results.GetOrNew(loot.ID);
226-
weh++;
227-
results[loot.ID] = weh;
228-
break;
229-
}
224+
/// <summary>
225+
/// Get a list of WeightedRandomPrototype IDs with the rewards for a certain difficulty.
226+
/// </summary>
227+
private string[] RewardsForDifficulty(DifficultyRating rating)
228+
{
229+
var common = "SalvageRewardCommon";
230+
var rare = "SalvageRewardRare";
231+
var epic = "SalvageRewardEpic";
232+
switch (rating)
233+
{
234+
case DifficultyRating.Minimal:
235+
return new string[] { common, common, common };
236+
case DifficultyRating.Minor:
237+
return new string[] { common, common, rare };
238+
case DifficultyRating.Moderate:
239+
return new string[] { common, rare, rare };
240+
case DifficultyRating.Hazardous:
241+
return new string[] { rare, rare, epic };
242+
case DifficultyRating.Extreme:
243+
return new string[] { rare, epic, epic };
244+
default:
245+
throw new NotImplementedException();
230246
}
231-
232-
return results;
233247
}
234248
}
235249

‎Resources/Locale/en-US/procedural/expeditions.ftl‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ salvage-expedition-window-hostiles = Hostiles:
1313
salvage-expedition-window-duration = Duration:
1414
salvage-expedition-window-biome = Biome:
1515
salvage-expedition-window-modifiers = Modifiers:
16-
salvage-expedition-window-loot = Loot:
17-
salvage-expedition-window-none = N/A
16+
salvage-expedition-window-rewards = Rewards:
1817
salvage-expedition-window-claimed = Claimed
1918
salvage-expedition-window-claim = Claim
2019

‎Resources/Prototypes/Catalog/Fills/Crates/salvage.yml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,35 @@
114114
- id: WeaponRevolverMateba
115115
prob: 0.0001
116116

117+
- type: entity
118+
parent: CrateGenericSteel
119+
id: CratePartsT3
120+
name: tier 3 parts crate
121+
description: Contains 5 random tier 3 parts for upgrading machines.
122+
components:
123+
- type: StorageFill
124+
contents:
125+
- id: SalvagePartsT3Spawner
126+
amount: 5
127+
128+
- type: entity
129+
parent: CrateGenericSteel
130+
id: CratePartsT3T4
131+
name: tier 3/4 parts crate
132+
description: Contains 5 random tier 3 or 4 parts for upgrading machines.
133+
components:
134+
- type: StorageFill
135+
contents:
136+
- id: SalvagePartsT3T4Spawner
137+
amount: 5
138+
139+
- type: entity
140+
parent: CrateGenericSteel
141+
id: CratePartsT4
142+
name: tier 4 parts crate
143+
description: Contains 5 random tier 4 parts for upgrading machines.
144+
components:
145+
- type: StorageFill
146+
contents:
147+
- id: SalvagePartsT4Spawner
148+
amount: 5

0 commit comments

Comments
 (0)