[Serializable] public class HeroDetails : ObservableObject { public static IHeroService Service { get; set; } public string Id; public string StoreId; public string Name; public string Description; public string Special; public string Price; public Sprite Icon; public GameObject DisplayPrefab; public GameObject GamePrefab;
public int MaxLevel = 20;
public int Level = 0;
public float LevelPercent
{
get {
return (float)Level / (float)MaxLevel;
}
}
private bool _isLocked = true;
public bool IsLocked
{
get { return _isLocked; }
set
{
if (_isLocked == value)
return;
_isLocked = value;
NotifyProperty("IsLocked", value);
}
}
public List<HeroUpgrade> Upgrades;
public void CalculateLevel()
{
MaxLevel = Upgrades.Sum(o => o.MaxLevel);
Level = Upgrades.Sum(o => o.Level);
NotifyProperty("LevelPercent", LevelPercent);
NotifyProperty("Level", Level);
NotifyProperty("MaxLevel", MaxLevel);
}
}
[Serializable]
public class HeroUpgrade : ObservableObject
{
public static IHeroService Service
{
get { return HeroDetails.Service; }
}
public bool Disabled;
public string Id;
public string Name;
public string Description;
public Sprite Icon;
public int CostBase = 100;
[Range(0, 1)]
public float CostIncrease = .5f;
[Range(0, 10)]
public int MaxLevel = 5;
private int _level;
public int Level
{
get { return _level; }
set
{
if (_level == value)
return;
_level = value;
NotifyProperty("Level", value);
NotifyProperty("Cost", Cost);
NotifyProperty("Percent", Percent);
NotifyProperty("IsMaxed", IsMaxed);
NotifyProperty("CanPurchase", CanPurchase);
}
}
public bool CanPurchase
{
get { return Level < MaxLevel && Cost <= Service.Money; }
}
public int Cost
{
get { return GetPriceForLevel(Level); }
}
public bool IsMaxed
{
get { return Level == MaxLevel; }
}
public float Percent
{
get { return Level / MaxLevel; }
}
public int GetPriceForLevel(int level)
{
//0 Fix
level++;
return Mathf.RoundToInt((CostBase * level) + (CostBase * level * (CostIncrease + (CostIncrease * level))));
}
/// <summary>
/// Update Properties
/// </summary>
public void Refresh()
{
NotifyProperty("CanPurchase", CanPurchase);
}
}