ShopManager.cs
using Sandbox;
using System.Collections.Generic;
using System.Linq;
public class PushItem
{
public string Id { get; set; }
public string NameRu { get; set; }
public string NameEn { get; set; }
public int Cost { get; set; }
public float ForceMultiplier { get; set; }
public string Key { get; set; }
public bool IsUnlocked { get; set; }
public string GetName( string lang ) => lang == "EN" ? NameEn : NameRu;
}
public class ShopManager : Component
{
public static ShopManager Instance { get; private set; }
public List<PushItem> Items { get; private set; } = new()
{
new PushItem { Id = "basic", NameRu = "Обычный", NameEn = "Basic", Cost = 0, ForceMultiplier = 1.0f, Key = "1", IsUnlocked = true },
new PushItem { Id = "heavy", NameRu = "Тяжелый", NameEn = "Heavy", Cost = 10, ForceMultiplier = 1.5f, Key = "2", IsUnlocked = false },
new PushItem { Id = "force", NameRu = "Импульс", NameEn = "Impulse", Cost = 25, ForceMultiplier = 2.2f, Key = "3", IsUnlocked = false },
new PushItem { Id = "mega", NameRu = "Мега-толчок", NameEn = "Mega Push", Cost = 50, ForceMultiplier = 3.5f, Key = "4", IsUnlocked = false }
};
public PushItem SelectedItem { get; private set; }
protected override void OnStart()
{
Instance = this;
SelectedItem = Items.FirstOrDefault( x => x.IsUnlocked );
}
protected override void OnUpdate()
{
if ( Input.Pressed( "slot1" ) ) SelectByKey( "1" );
if ( Input.Pressed( "slot2" ) ) SelectByKey( "2" );
if ( Input.Pressed( "slot3" ) ) SelectByKey( "3" );
if ( Input.Pressed( "slot4" ) ) SelectByKey( "4" );
}
public void SelectByKey( string key )
{
var item = Items.FirstOrDefault( x => x.Key == key );
if ( item != null ) TryBuyOrSelect( item );
}
public bool TryBuyOrSelect( PushItem item )
{
if ( item.IsUnlocked )
{
SelectedItem = item;
return true;
}
int currentScore = ScoreManager.Instance?.Score ?? 0;
if ( currentScore >= item.Cost )
{
item.IsUnlocked = true;
SelectedItem = item;
return true;
}
return false;
}
public float GetCurrentForceMultiplier()
{
return SelectedItem?.ForceMultiplier ?? 1.0f;
}
}