Meta progression manager for the game. Holds credits, upgrade levels, prestige, cosmetics and daily contracts, awards coins at end of round and saves/loads everything as JSON in FileSystem.Data.
using Sandbox;
using System;
using System.Collections.Generic;
using System.Linq;
public sealed class MetaProgression : Component
{
public static MetaProgression Instance { get; private set; }
[Property] public int Credits { get; private set; } = 0;
// Meta Upgrades
[Property] public int ForceLevel { get; private set; } = 0;
[Property] public int MassLevel { get; private set; } = 0;
[Property] public int EnergyLevel { get; private set; } = 0;
// Prestige
[Property] public int PrestigeLevel { get; private set; } = 0;
[Property] public int PrestigeTokens { get; private set; } = 0;
// Utilities Unlocked (Flashlight, Speed Booster, Radar)
[Property] public bool HasFlashlight { get; set; } = true;
[Property] public bool HasSpeedJuice { get; set; } = true;
[Property] public bool HasRadar { get; set; } = true;
// Cosmetic Trails / Slashes
[Property] public string EquippedCosmetic { get; set; } = "None";
public List<string> UnlockedCosmetics { get; private set; } = new() { "None" };
// Daily Contracts & Flow Combo Stats
public List<DailyContract> Contracts { get; private set; } = new();
[Property] public int BestFlowCombo { get; private set; } = 0;
public const int REQUIRED_TOTAL_LEVELS_FOR_PRESTIGE = 15;
private const string SAVE_FILE = "one_more_push_meta.json";
public struct RoundRewardBreakdown
{
public int SurvivalSeconds;
public int SurvivalCoins;
public int RevivesCount;
public int ReviveCoins;
public bool Victory;
public int VictoryCoins;
public float FlowMultiplierApplied;
public bool ExtractedBonusApplied;
public int TotalCoinsEarned;
}
public RoundRewardBreakdown LastRewardBreakdown { get; private set; }
protected override void OnAwake()
{
Instance = this;
}
protected override void OnStart()
{
Instance = this;
LoadProgress();
}
public void UpdateBestFlowCombo( int combo )
{
if ( combo > BestFlowCombo )
{
BestFlowCombo = combo;
SaveProgress();
}
}
public void AddCredits( int amount )
{
float prestigeMult = 1.0f + (PrestigeLevel * 0.5f);
float flowMult = (amount > 0 && PlayerAbilities.LocalInstance.IsValid())
? MathF.Max( 1.0f, PlayerAbilities.LocalInstance.FlowMultiplier )
: 1.0f;
Credits += (int)MathF.Round( amount * prestigeMult * flowMult );
SaveProgress();
}
public RoundRewardBreakdown AwardRoundRewards( float survivalSeconds, int revivesCount, bool victory, bool extractedBonus = false )
{
int survSec = Math.Max( 0, (int)survivalSeconds );
int survivalCoins = (survSec / 10) * 5;
int reviveCoins = revivesCount * 25;
int victoryCoins = victory ? 100 : 0;
float prestigeMult = 1.0f + (PrestigeLevel * 0.5f);
float flowMult = PlayerAbilities.LocalInstance.IsValid()
? MathF.Max( 1.0f, PlayerAbilities.LocalInstance.FlowMultiplier )
: 1.0f;
float extractionMult = extractedBonus ? 2.0f : 1.0f;
int subtotal = survivalCoins + reviveCoins + victoryCoins;
int totalCoins = (int)MathF.Round( subtotal * prestigeMult * flowMult * extractionMult );
Credits += totalCoins;
var breakdown = new RoundRewardBreakdown
{
SurvivalSeconds = survSec,
SurvivalCoins = survivalCoins,
RevivesCount = revivesCount,
ReviveCoins = reviveCoins,
Victory = victory,
VictoryCoins = victoryCoins,
FlowMultiplierApplied = flowMult,
ExtractedBonusApplied = extractedBonus,
TotalCoinsEarned = totalCoins
};
LastRewardBreakdown = breakdown;
// Progress Daily Contracts
ProgressContract( ContractType.SurvivalSeconds, survSec );
if ( revivesCount > 0 )
{
ProgressContract( ContractType.Revives, revivesCount );
}
SaveProgress();
return breakdown;
}
public void InitDefaultContracts()
{
Contracts = new List<DailyContract>
{
new DailyContract
{
Type = ContractType.Revives,
TitleRu = "Спаситель: Реанимируйте 3 союзников",
TitleEn = "Lifesaver: Revive 3 teammates",
Target = 3,
Current = 0,
RewardCoins = 150
},
new DailyContract
{
Type = ContractType.SurvivalSeconds,
TitleRu = "Живучий: Выживите 120 секунд в раунде",
TitleEn = "Survivor: Survive for 120 seconds",
Target = 120,
Current = 0,
RewardCoins = 100
},
new DailyContract
{
Type = ContractType.CloseCalls,
TitleRu = "На волоске: Совершите 5 уклонений (Close Call)",
TitleEn = "Daredevil: Perform 5 Close Calls with Nextbots",
Target = 5,
Current = 0,
RewardCoins = 120
}
};
}
public void ProgressContract( ContractType type, int amount )
{
if ( Contracts == null || Contracts.Count == 0 )
{
InitDefaultContracts();
}
var contract = Contracts.FirstOrDefault( c => c.Type == type );
if ( contract == null || contract.IsCompleted ) return;
contract.Current = Math.Min( contract.Target, contract.Current + amount );
if ( contract.Current >= contract.Target )
{
contract.IsCompleted = true;
PushHud.LocalInstance?.AddMessage( "CONTRACT COMPLETE", $"'{contract.TitleEn}' complete! Claim in menu." );
}
SaveProgress();
}
public bool ClaimContract( int index )
{
if ( Contracts == null || index < 0 || index >= Contracts.Count ) return false;
var c = Contracts[index];
if ( !c.IsCompleted || c.IsClaimed ) return false;
c.IsClaimed = true;
AddCredits( c.RewardCoins );
SaveProgress();
return true;
}
public int GetUpgradeCost( int currentLevel )
{
return (int)(100 * Math.Pow( 1.5, currentLevel ));
}
public bool TryUpgradeForce()
{
int cost = GetUpgradeCost( ForceLevel );
if ( Credits >= cost )
{
Credits -= cost;
ForceLevel++;
SaveProgress();
return true;
}
return false;
}
public bool TryUpgradeMass()
{
int cost = GetUpgradeCost( MassLevel );
if ( Credits >= cost )
{
Credits -= cost;
MassLevel++;
SaveProgress();
return true;
}
return false;
}
public bool TryUpgradeEnergy()
{
int cost = GetUpgradeCost( EnergyLevel );
if ( Credits >= cost )
{
Credits -= cost;
EnergyLevel++;
SaveProgress();
return true;
}
return false;
}
public bool TryBuyUtility( string utilityId, int cost )
{
if ( Credits < cost ) return false;
bool success = false;
if ( utilityId == "flashlight" && !HasFlashlight )
{
HasFlashlight = true;
success = true;
}
else if ( utilityId == "speed_juice" && !HasSpeedJuice )
{
HasSpeedJuice = true;
success = true;
}
else if ( utilityId == "radar" && !HasRadar )
{
HasRadar = true;
success = true;
}
if ( success )
{
Credits -= cost;
SaveProgress();
return true;
}
return false;
}
public bool TryBuyCosmetic( string cosmeticId, int cost )
{
if ( UnlockedCosmetics.Contains( cosmeticId ) )
{
EquippedCosmetic = cosmeticId;
SaveProgress();
return true;
}
if ( Credits >= cost )
{
Credits -= cost;
UnlockedCosmetics.Add( cosmeticId );
EquippedCosmetic = cosmeticId;
SaveProgress();
return true;
}
return false;
}
public void EquipCosmetic( string cosmeticId )
{
if ( UnlockedCosmetics.Contains( cosmeticId ) )
{
EquippedCosmetic = cosmeticId;
SaveProgress();
}
}
public bool CanPrestige()
{
int totalLevels = ForceLevel + MassLevel + EnergyLevel;
return totalLevels >= REQUIRED_TOTAL_LEVELS_FOR_PRESTIGE;
}
public bool TryPrestige()
{
if ( !CanPrestige() ) return false;
ForceLevel = 0;
MassLevel = 0;
EnergyLevel = 0;
Credits = 0;
PrestigeLevel++;
PrestigeTokens += 1;
SaveProgress();
return true;
}
public void SaveProgress()
{
var data = new ProgressData
{
Credits = this.Credits,
ForceLevel = this.ForceLevel,
MassLevel = this.MassLevel,
EnergyLevel = this.EnergyLevel,
PrestigeLevel = this.PrestigeLevel,
PrestigeTokens = this.PrestigeTokens,
HasFlashlight = this.HasFlashlight,
HasSpeedJuice = this.HasSpeedJuice,
HasRadar = this.HasRadar,
EquippedCosmetic = this.EquippedCosmetic,
UnlockedCosmetics = this.UnlockedCosmetics,
Contracts = this.Contracts,
BestFlowCombo = this.BestFlowCombo
};
FileSystem.Data.WriteJson( SAVE_FILE, data );
}
public void LoadProgress()
{
if ( FileSystem.Data.FileExists( SAVE_FILE ) )
{
var data = FileSystem.Data.ReadJson<ProgressData>( SAVE_FILE );
if ( data != null )
{
Credits = data.Credits;
ForceLevel = data.ForceLevel;
MassLevel = data.MassLevel;
EnergyLevel = data.EnergyLevel;
PrestigeLevel = data.PrestigeLevel;
PrestigeTokens = data.PrestigeTokens;
HasFlashlight = data.HasFlashlight;
HasSpeedJuice = data.HasSpeedJuice;
HasRadar = data.HasRadar;
BestFlowCombo = data.BestFlowCombo;
EquippedCosmetic = string.IsNullOrEmpty( data.EquippedCosmetic ) ? "None" : data.EquippedCosmetic;
if ( data.UnlockedCosmetics != null && data.UnlockedCosmetics.Count > 0 )
{
UnlockedCosmetics = data.UnlockedCosmetics;
}
if ( !UnlockedCosmetics.Contains( "None" ) )
{
UnlockedCosmetics.Insert( 0, "None" );
}
if ( data.Contracts != null && data.Contracts.Count > 0 )
{
Contracts = data.Contracts;
}
else
{
InitDefaultContracts();
}
}
}
else
{
InitDefaultContracts();
}
}
private class ProgressData
{
public int Credits { get; set; }
public int ForceLevel { get; set; }
public int MassLevel { get; set; }
public int EnergyLevel { get; set; }
public int PrestigeLevel { get; set; }
public int PrestigeTokens { get; set; }
public bool HasFlashlight { get; set; } = true;
public bool HasSpeedJuice { get; set; } = true;
public bool HasRadar { get; set; } = true;
public string EquippedCosmetic { get; set; } = "None";
public List<string> UnlockedCosmetics { get; set; } = new();
public List<DailyContract> Contracts { get; set; } = new();
public int BestFlowCombo { get; set; } = 0;
}
}
public enum ContractType
{
Revives,
SurvivalSeconds,
CloseCalls
}
public class DailyContract
{
public ContractType Type { get; set; }
public string TitleRu { get; set; }
public string TitleEn { get; set; }
public int Target { get; set; }
public int Current { get; set; }
public int RewardCoins { get; set; }
public bool IsCompleted { get; set; }
public bool IsClaimed { get; set; }
}