56 lines
1.0 KiB
C#
56 lines
1.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
public class CoreCurrenciesController
|
|
{
|
|
public CoreCurrenciesDef Def { get; private set; }
|
|
|
|
public int CurrenciesWon { get; private set; }
|
|
|
|
public bool CurrenciesMultiplied { get; private set; }
|
|
|
|
public event Action<int, Transform> onWinCurrencies;
|
|
|
|
public event Action onMultiplyCurrencies;
|
|
|
|
public void Setup(CoreCurrenciesDef def)
|
|
{
|
|
Def = def;
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
CurrenciesWon = 0;
|
|
CurrenciesMultiplied = false;
|
|
}
|
|
|
|
public void WinCurrency(int count, Transform from)
|
|
{
|
|
CurrenciesWon += count;
|
|
if (this.onWinCurrencies != null)
|
|
{
|
|
this.onWinCurrencies(count, from);
|
|
}
|
|
}
|
|
|
|
public void MultiplyCurrencies(Transform from)
|
|
{
|
|
if (CurrenciesMultiplied)
|
|
{
|
|
return;
|
|
}
|
|
int multiplier = Def.currencyMultiplier;
|
|
int before = CurrenciesWon;
|
|
CurrenciesWon = multiplier * before;
|
|
if (this.onWinCurrencies != null)
|
|
{
|
|
this.onWinCurrencies((multiplier - 1) * before, from);
|
|
}
|
|
CurrenciesMultiplied = true;
|
|
if (this.onMultiplyCurrencies != null)
|
|
{
|
|
this.onMultiplyCurrencies();
|
|
}
|
|
}
|
|
}
|