AI/Guests/Guest.Stats.cs
using Sandbox.Diagnostics;
using System;
namespace HC3;
public partial class Guest
{
/// <summary>
/// How much money I've got to spend.
/// </summary>
[Sync( SyncFlags.FromHost )]
public int Money { get; set; }
/// <summary>
/// How much of a delinquent this guest is from 0-1. A higher value makes the guest
/// more likely to commit a crime, and the higher the value, the more serious a crime
/// they may commit.
/// </summary>
[Sync( SyncFlags.FromHost )]
public float Delinquency { get; set; }
[Property] public HashSet<Building> BuildingsVisited { get; set; } = new();
private void SetupStats()
{
// Most guests have a low delinquency value. In rare cases, a guest
// will have a super high value. In other cases it'll be non-linearly distributed.
var r = Random.Shared.Float( 0f, 1f );
Delinquency = (r < 0.95f) ? MathF.Pow( r, 2f ) : Random.Shared.Float( 0.6f, 1f );
Money = Random.Shared.Int( 800, 10_000 );
}
public bool GiveMoney( int amount )
{
Assert.True( Networking.IsHost );
if ( amount < 0 ) return false;
Money += amount;
if ( Stats.Get( "guest.highest_money" ) < Money )
{
Stats.Set( "guest.highest_money", Money );
}
return true;
}
public bool TakeMoney( int amount )
{
Assert.True( Networking.IsHost );
if ( amount < 0 ) return false;
if ( Money < amount ) return false;
Money -= amount;
return true;
}
}