Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.Humanoid.Components;
using Content.Server.Spawners.Components;
using Content.Server.Storage.Components;
using Content.Server.Storage.Events;
using Content.Shared.Item;
using Content.Shared.Prototypes;
using Content.Shared.Storage;
Expand Down Expand Up @@ -85,6 +86,11 @@ private void FillStorage(Entity<StorageFillComponent?, StorageComponent?> entity
ClearCantFillReasons();
Del(ent);
}

// Frontier - we raise an event to let other systems know their storages have completed filling
var StoreFillEv = new StorageFilledEvent();
RaiseLocalEvent(uid, ref StoreFillEv, broadcast: true);
// End Frontier
}

private void FillEntityStorage(Entity<StorageFillComponent?, EntityStorageComponent?> entity)
Expand Down Expand Up @@ -118,5 +124,9 @@ private void FillEntityStorage(Entity<StorageFillComponent?, EntityStorageCompon
Log.Error($"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
Del(ent);
}
// Frontier - we raise an event to let other systems know their storages have completed filling
var StoreFillEv = new StorageFilledEvent();
RaiseLocalEvent(uid, ref StoreFillEv, broadcast: true);
// End Frontier
}
}
7 changes: 7 additions & 0 deletions Content.Server/_NF/Storage/StorageFilledEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.Storage.Events;

/// <summary>
/// Raised when a <see cref="StorageFillComponent"/> is finished filling the storage
/// </summary>
[ByRefEvent]
public record struct StorageFilledEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Content.Server._NF.Weapons.Rarity;

/// <summary>
/// This component is added to weapon cases that transform the containing spawned weapon into a weapon with rare markers.
/// </summary>
[RegisterComponent]
public sealed partial class RareWeaponSpawnerCaseComponent : Component
{
[DataField]
public int Rarity = 1;

[DataField]
public bool RandomRarity = false;
}
140 changes: 140 additions & 0 deletions Content.Server/_NF/Weapons/Rarity/WeaponRaritySystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
using Content.Server.Storage.Events;
using Content.Shared.Dataset;
using Content.Shared.Storage;
using Content.Shared.Weapons.Ranged.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server._NF.Weapons.Rarity;

/// <summary>
/// A stand-alone system intended to modularly sit atop the existing gun and weapon systems to create dynamic weapon rarities.
/// </summary>
public sealed partial class WeaponRaritySystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly IPrototypeManager _protoMan = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RareWeaponSpawnerCaseComponent, StorageFilledEvent>(OnCaseSpawn);
}

private void OnCaseSpawn(Entity<RareWeaponSpawnerCaseComponent> ent, ref StorageFilledEvent args)
{
var comp = ent.Comp;
if (!TryComp<StorageComponent>(ent, out StorageComponent? storage))
return;

var contents = storage.StoredItems;
GunComponent? gunComp = null;
EntityUid gun = default;
foreach (var item in contents)
{
if (TryComp(item.Key, out gunComp))
{
gun = item.Key;
break;
}
}

if (gunComp == null || !gun.IsValid() )
return;

//Basic functionality of 3 rarity levels
var rarity = comp.Rarity;
if (comp.RandomRarity)
{
rarity = _random.Next(0, 4);
}

RenameGun(gun, rarity);

while (rarity > 0)
{
var chance = _random.Next(1, 4);
switch (chance)
{
case 1:
ImproveAccuracy(gun, gunComp);
break;
case 2:
ImproveFireRate(gun, gunComp);
break;
case 3:
ImproveProjectileSpeed(gun, gunComp);
break;
}
rarity--;
}
}

private void ImproveAccuracy(EntityUid gun, GunComponent? gunComp)
{
if (!Resolve(gun, ref gunComp))
return;

var buff = 1 - _random.NextFloat(0.15f, 0.35f);

gunComp.MinAngle *= buff;
gunComp.MinAngleModified *= buff;
gunComp.MaxAngle *= buff;
gunComp.MaxAngleModified *= buff;
gunComp.AngleIncrease *= buff;
gunComp.AngleIncreaseModified *= buff;
gunComp.AngleDecay *= 1 / buff;
gunComp.AngleDecayModified *= 1 / buff;
}

private void ImproveFireRate(EntityUid gun, GunComponent? gunComp)
{
if (!Resolve(gun, ref gunComp))
return;

var buff = 1 + _random.NextFloat(0.15f, 0.35f);

gunComp.FireRate *= buff;
gunComp.FireRateModified *= buff;
}

private void ImproveProjectileSpeed(EntityUid gun, GunComponent? gunComp)
{
if (!Resolve(gun, ref gunComp))
return;

var buff = 1 + _random.NextFloat(0.15f, 0.35f);

gunComp.ProjectileSpeed *= buff;
gunComp.ProjectileSpeedModified *= buff;
}

private void RenameGun(EntityUid gun, int rarity)
{
var datasetUncommon = _protoMan.Index<LocalizedDatasetPrototype>("NFNamesGunsUncommon");
var datasetRare = _protoMan.Index<LocalizedDatasetPrototype>("NFNamesGunsRare");
var datasetEpic = _protoMan.Index<LocalizedDatasetPrototype>("NFNamesGunsEpic");

var meta = MetaData(gun);

if (rarity == 1)
{
var pick = _random.Pick(datasetUncommon.Values);
var newName = Loc.GetString(pick) + " " + meta.EntityName;
_metaSystem.SetEntityName(gun, newName, meta, false);
}
else if (rarity == 2)
{
var pick1 = _random.Pick(datasetUncommon.Values);
var pick2 = _random.Pick(datasetRare.Values);
var newName = Loc.GetString(pick2) + " " + Loc.GetString(pick1)+ " " + meta.EntityName;
_metaSystem.SetEntityName(gun, newName, meta, false);
}
else if (rarity >= 3)
{
var pick = _random.Pick(datasetEpic.Values);
_metaSystem.SetEntityName(gun, Loc.GetString(pick), meta, false);
}
}
}
39 changes: 39 additions & 0 deletions Resources/Locale/en-US/_NF/datasets/names/guns.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
adjectives-nf-gun-uncommon-1 = Sturdy
adjectives-nf-gun-uncommon-2 = Keen
adjectives-nf-gun-uncommon-3 = Swift
adjectives-nf-gun-uncommon-4 = Resilient
adjectives-nf-gun-uncommon-5 = Hardened
adjectives-nf-gun-uncommon-6 = Steady
adjectives-nf-gun-uncommon-7 = Tactical
adjectives-nf-gun-uncommon-8 = Precision
adjectives-nf-gun-uncommon-9 = Enhanced
adjectives-nf-gun-uncommon-10 = Refined
adjectives-nf-gun-uncommon-11 = Reinforced
adjectives-nf-gun-uncommon-12 = Stabilized

adjectives-nf-gun-rare-1 = Deadly
adjectives-nf-gun-rare-2 = Lethal
adjectives-nf-gun-rare-3 = Killer
adjectives-nf-gun-rare-4 = Legendary
adjectives-nf-gun-rare-5 = Pristine

names-nf-gun-epic-1 = Blaster Master 9000
names-nf-gun-epic-2 = Chrono-Trigger
names-nf-gun-epic-3 = The Big Bang
names-nf-gun-epic-4 = Rekt-ifier
names-nf-gun-epic-5 = Boomstick
names-nf-gun-epic-6 = Shooty McShooterton
names-nf-gun-epic-7 = Insurance Policy
names-nf-gun-epic-8 = Big Friendly Gun
names-nf-gun-epic-9 = Little Friend
names-nf-gun-epic-10 = Second Opinion
names-nf-gun-epic-11 = The Negotiator
names-nf-gun-epic-12 = Chamber of Justice
names-nf-gun-epic-13 = Ms. Fire
names-nf-gun-epic-14 = The Long Shot
names-nf-gun-epic-15 = The Last Resort
names-nf-gun-epic-16 = Big Bertha
names-nf-gun-epic-17 = Voight-Kampf
names-nf-gun-epic-18 = Rooty Tooty Big And Shooty
names-nf-gun-epic-19 = Plan B
names-nf-gun-epic-20 = Plan C
Loading
Loading