A unique perk implementation named PerkZoomContinuously. It gradually increases the player's camera distance over time, applies that as a multiplicative modifier to the PlayerStat.CameraDistance, and shows a percentage display string of how far it has increased.
using System;
using Sandbox;
[Perk( Rarity.Unique, locked: true, minUnlocksReq: 5, alwaysOfferDebug: false )]
public class PerkZoomContinuously : Perk
{
private float _cameraDistance;
static PerkZoomContinuously()
{
Register<PerkZoomContinuously>(
name: "Grand Perspective",
imagePath: "textures/icons/vector/zoom_continuously.png",
description: level => $"Camera distance\ncontinously increases"
);
}
public override void Start()
{
base.Start();
_cameraDistance = 1f;
ShouldUpdate = true;
}
public override void Refresh()
{
base.Refresh();
}
public override void Update( float dt )
{
base.Update( dt );
float ZOOM_SPEED = 0.00165f;
_cameraDistance += dt * ZOOM_SPEED;
Player.Modify( this, PlayerStat.CameraDistance, _cameraDistance, ModifierType.Mult );
DisplayText = $"+{MathX.FloorToInt( (_cameraDistance - 1f) * 100f )}%";
}
}