Skip to content

Commit

Permalink
Доделать
Browse files Browse the repository at this point in the history
  • Loading branch information
deBurboun committed Mar 23, 2024
1 parent 8ba1fcf commit 8ec5ea1
Show file tree
Hide file tree
Showing 14 changed files with 587 additions and 1 deletion.
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;
}
}
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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,22 @@
- type: StorageFill
contents:
- id: AntiPsiGrenade
amount: 20
amount: 20

- type: entity
parent: ClothingBackpackDuffelSyndicateBundle
id: ClothingBackpackDuffelWizard
name: wizard outfit bag
description: "Contains 3 wizard outfits."
components:
- type: StorageFill
contents:
- id: ClothingOuterWizardReal
- id: ClothingHeadHatWizardReal
- id: ClothingOuterWizardVioletReal
- id: ClothingHeadHatVioletwizardReal
- id: ClothingOuterWizardRedReal
- id: ClothingHeadHatRedwizardReal
- id: ClothingShoesWizard
- id: BedsheetWiz
amount: 3
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
121 changes: 121 additions & 0 deletions Resources/Prototypes/Backmen/Catalog/uplink_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,124 @@
Telecrystal: 2
categories:
- UplinkAllies


# Books
- type: listing
id: WizardSpawnBook
name: uplink-book-spawnbook-name
description: uplink-book-spawnbook-desc
productEntity: SpawnSpellbook
cost:
MaterialBluespace: 8
categories:
- WizardBooks

- type: listing
id: WizardWallBook
name: uplink-book-forcewall-name
description: uplink-book-forcewall-desc
productEntity: ForceWallSpellbook
cost:
MaterialBluespace: 10
categories:
- WizardBooks

- type: listing
id: WizardBlinkBook
name: uplink-book-blink-name
description: uplink-book-blink-desc
productEntity: BlinkBook
cost:
MaterialBluespace: 16
categories:
- WizardBooks

- type: listing
id: WizardSmiteBook
name: uplink-book-smite-name
description: uplink-book-smite-desc
productEntity: SmiteBook
cost:
MaterialBluespace: 50
categories:
- WizardBooks

- type: listing
id: WizardKnockBook
name: uplink-book-knok-name
description: uplink-book-knok-desc
productEntity: KnockSpellbook
cost:
MaterialBluespace: 14
categories:
- WizardBooks

- type: listing
id: WizardFireballBook
name: uplink-book-fireball-name
description: uplink-book-fireball-desc
productEntity: FireballSpellbook
cost:
MaterialBluespace: 16
categories:
- WizardBooks

- type: listing
id: WizardHealingBook
name: uplink-book-heal-name
description: uplink-book-heal-desc
productEntity: HealingSpellbook
cost:
MaterialBluespace: 8
categories:
- WizardBooks

# Wands


# Armor
- type: listing
id: WizardHardsuit
name: uplink-armor-hardsuit-name
description: uplink-armor-hardsuit-desc
productEntity: ClothingOuterHardsuitWizard
cost:
MaterialBluespace: 6
categories:
- WizardArmor

# Utility
- type: listing
id: WizardSpellBelt
name: uplink-utility-spellbelt-name
description: uplink-utility-spellbelt-desc
productEntity: ClothingBeltWand
cost:
MaterialBluespace: 4
categories:
- WizardUtility

# Bundles
- type: listing
id: WizardSurplusCrate30BS
name: uplink-bundles-wizarsurpluscrate30bs-name
description: uplink-bundles-wizarsurpluscrate30bs-desc
productEntity: CrateWizardSurplus
cost:
MaterialBluespace: 30
categories:
- WizardBundles

# Miscellanious

# Pointless
- type: listing
id: WizardBurger
name: uplink-pointless-spellburger-name
description: uplink-pointless-spellburger-desc
productEntity: FoodBurgerSpell
cost:
MaterialBluespace: 1
categories:
- WizardPointless
14 changes: 14 additions & 0 deletions Resources/Prototypes/Backmen/Entities/Clothing/Head/magic.yml
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
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
14 changes: 14 additions & 0 deletions Resources/Prototypes/Backmen/Entities/Magic/books.yml
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
Loading

0 comments on commit 8ec5ea1

Please sign in to comment.