-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
deBurboun
committed
Mar 23, 2024
1 parent
8ba1fcf
commit 8ec5ea1
Showing
14 changed files
with
587 additions
and
1 deletion.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
Content.Server/Backmen/Traitor/SurplusBundle/WizardSurplusBundleSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System.Linq; | ||
using Content.Server.Store.Systems; | ||
using Content.Server.Storage.EntitySystems; | ||
using Content.Shared.Store; | ||
using Content.Shared.FixedPoint; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server.Traitor.Uplink.SurplusBundle; | ||
|
||
public sealed class WizardSurplusBundleSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly EntityStorageSystem _entityStorage = default!; | ||
[Dependency] private readonly StoreSystem _store = default!; | ||
|
||
private ListingData[] _listings = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<WizardSurplusBundleComponent, MapInitEvent>(OnMapInit); | ||
|
||
SubscribeLocalEvent<WizardSurplusBundleComponent, ComponentInit>(OnInit); | ||
} | ||
|
||
private void OnInit(EntityUid uid, WizardSurplusBundleComponent component, ComponentInit args) | ||
{ | ||
var storePreset = _prototypeManager.Index<StorePresetPrototype>(component.StorePreset); | ||
|
||
_listings = _store.GetAvailableListings(uid, null, storePreset.Categories).ToArray(); | ||
|
||
Array.Sort(_listings, (a, b) => (int) (b.Cost.Values.Sum() - a.Cost.Values.Sum())); //this might get weird with multicurrency but don't think about it | ||
} | ||
|
||
private void OnMapInit(EntityUid uid, WizardSurplusBundleComponent component, MapInitEvent args) | ||
{ | ||
FillStorage(uid, component); | ||
} | ||
|
||
private void FillStorage(EntityUid uid, WizardSurplusBundleComponent? component = null) | ||
{ | ||
if (!Resolve(uid, ref component)) | ||
return; | ||
|
||
var cords = Transform(uid).Coordinates; | ||
|
||
var content = GetRandomContent(component.TotalPrice); | ||
foreach (var item in content) | ||
{ | ||
var ent = EntityManager.SpawnEntity(item.ProductEntity, cords); | ||
_entityStorage.Insert(ent, component.Owner); | ||
} | ||
} | ||
|
||
// wow, is this leetcode reference? | ||
private List<ListingData> GetRandomContent(FixedPoint2 targetCost) | ||
{ | ||
var ret = new List<ListingData>(); | ||
if (_listings.Length == 0) | ||
return ret; | ||
|
||
var totalCost = FixedPoint2.Zero; | ||
var index = 0; | ||
while (totalCost < targetCost) | ||
{ | ||
// All data is sorted in price descending order | ||
// Find new item with the lowest acceptable price | ||
// All expansive items will be before index, all acceptable after | ||
var remainingBudget = targetCost - totalCost; | ||
while (_listings[index].Cost.Values.Sum() > remainingBudget) | ||
{ | ||
index++; | ||
if (index >= _listings.Length) | ||
{ | ||
// Looks like no cheap items left | ||
// It shouldn't be case for ss14 content | ||
// Because there are 1 TC items | ||
return ret; | ||
} | ||
} | ||
|
||
// Select random listing and add into crate | ||
var randomIndex = _random.Next(index, _listings.Length); | ||
var randomItem = _listings[randomIndex]; | ||
ret.Add(randomItem); | ||
totalCost += randomItem.Cost.Values.Sum(); | ||
} | ||
|
||
return ret; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Content.Server/Backmen/Traitor/Uplink/SurplusBundle/WizardSurplusBundleComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Content.Shared.Store; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; | ||
|
||
namespace Content.Server.Traitor.Uplink.SurplusBundle; | ||
|
||
/// <summary> | ||
/// Fill crate with a random wizard items. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class WizardSurplusBundleComponent : Component | ||
{ | ||
/// <summary> | ||
/// Total price of all content inside bundle. | ||
/// </summary> | ||
[ViewVariables(VVAccess.ReadOnly)] | ||
[DataField("totalPrice")] | ||
public int TotalPrice = 20; | ||
|
||
/// <summary> | ||
/// The preset that will be used to get all the listings. | ||
/// Currently just defaults to the basic uplink. | ||
/// </summary> | ||
[DataField("storePreset", customTypeSerializer: typeof(PrototypeIdSerializer<StorePresetPrototype>))] | ||
public string StorePreset = "WizardStorePresetUplink"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
Resources/Prototypes/Backmen/Catalog/Fills/Crates/antagonist.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- type: entity | ||
id: CrateWizardSurplus | ||
parent: CrateGenericSteel | ||
components: | ||
- type: WizardSurplusBundle | ||
totalPrice: 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Resources/Prototypes/Backmen/Entities/Clothing/Head/magic.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
- type: entity | ||
parent: ClothingHeadHatVioletwizard | ||
id: ClothingHeadHatVioletwizardReal | ||
|
||
|
||
- type: entity | ||
parent: ClothingHeadHatWizard | ||
id: ClothingHeadHatWizardReal | ||
|
||
|
||
- type: entity | ||
parent: ClothingHeadHatRedwizard | ||
id: ClothingHeadHatRedwizardReal | ||
suffix: magical |
14 changes: 14 additions & 0 deletions
14
Resources/Prototypes/Backmen/Entities/Clothing/OuterClothing/magic.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
- type: entity | ||
parent: ClothingOuterWizardViolet | ||
id: ClothingOuterWizardVioletReal | ||
suffix: magical | ||
|
||
- type: entity | ||
parent: ClothingOuterWizard | ||
id: ClothingOuterWizardReal | ||
suffix: magical | ||
|
||
- type: entity | ||
parent: ClothingOuterWizardRed | ||
id: ClothingOuterWizardRedReal | ||
suffix: magical |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
- type: entity | ||
id: HealingSpellbook | ||
name: healing spellbook | ||
parent: BaseSpellbook | ||
components: | ||
- type: Sprite | ||
netsync: false | ||
sprite: Objects/Magic/spellbooks.rsi | ||
layers: | ||
- state: spellbook | ||
- type: Spellbook | ||
entitySpells: | ||
HealingSpell: -1 | ||
learnTime: 0.75 |
Oops, something went wrong.