A Perk class named PerkLessAmmoLongerLifetime that registers a mythic perk called "More Propellant". It increases bullet lifetime multiplicatively and reduces max ammo additively based on perk level, and provides text descriptions for the perk and its upgrades.
using System;
using Sandbox;
[Perk( Rarity.Mythic, locked: true, alwaysOfferDebug: false )]
public class PerkLessAmmoLongerLifetime : Perk
{
private enum Mod { BulletLifetime, MaxAmmoCount };
static PerkLessAmmoLongerLifetime()
{
Register<PerkLessAmmoLongerLifetime>(
name: "More Propellant",
imagePath: "textures/icons/vector/less_ammo_longer_lifetime.png",
description: level => $"+{GetValue( level, Mod.BulletLifetime, true )}% bullet lifetime\n-{GetValue( level, Mod.MaxAmmoCount )} ammo",
upgradeDescription: level => $"+{GetValue( level - 1, Mod.BulletLifetime, true )}%→{GetValue( level, Mod.BulletLifetime, true )}% bullet lifetime\n-{GetValue( level - 1, Mod.MaxAmmoCount )}→-{GetValue( level, Mod.MaxAmmoCount )} ammo"
);
}
public override void Start()
{
base.Start();
}
public override void Refresh()
{
base.Refresh();
Player.Modify( this, PlayerStat.BulletLifetime, GetValue( Level, Mod.BulletLifetime ), ModifierType.Mult );
Player.Modify( this, PlayerStat.MaxAmmoCount, -GetValue( Level, Mod.MaxAmmoCount ), ModifierType.Add );
}
private static float GetValue( int level, Mod mod, bool isPercent = false )
{
switch ( mod )
{
case Mod.BulletLifetime:
default:
return isPercent
? 10f + 20f * level
: 1f + (0.10f + 0.20f * level);
case Mod.MaxAmmoCount:
return level;
}
}
}