You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
130 lines
2.5 KiB
130 lines
2.5 KiB
using System.Collections.Generic; |
|
using Ai; |
|
using Equip; |
|
using UnityEngine; |
|
using Utils; |
|
|
|
namespace Meta |
|
{ |
|
public class PlayerResources : MonoSingleton<PlayerResources> |
|
{ |
|
public MainCharacter Player { get; set; } |
|
public UiResources UiResources { get; set; } |
|
public bool AlreadyUnlocked { get; set; } |
|
|
|
private int _currentExp; |
|
private int _currentCoins; |
|
public int CurrentCoins |
|
{ |
|
get { return _currentCoins; } |
|
} |
|
|
|
private readonly List<EquipItem> _items = new List<EquipItem>(); |
|
public List<EquipItem> Items |
|
{ |
|
get { return _items; } |
|
} |
|
|
|
private int _currentLevel; |
|
|
|
private float _expMult = 1; |
|
public float ExpMult |
|
{ |
|
get { return _expMult + _skinExp; } |
|
set { _expMult = value; } |
|
} |
|
|
|
private float _skinExp; |
|
public float SkinExp |
|
{ |
|
set { _skinExp = value; } |
|
} |
|
|
|
private float _coinsMult = 1; |
|
public float CoinsMult |
|
{ |
|
get { return _coinsMult; } |
|
set { _coinsMult = value; } |
|
} |
|
|
|
private float _equipChance; |
|
public float EquipChance |
|
{ |
|
get { return _equipChance; } |
|
set { _equipChance = value; } |
|
} |
|
|
|
private static readonly int[] EXP_TABLE = { |
|
100, |
|
300, |
|
550, |
|
900, |
|
1200, |
|
1500, |
|
1800, |
|
2100, |
|
2500 |
|
}; |
|
|
|
private float _npcHitPoints = 1f; |
|
public float NPCHitPoints |
|
{ |
|
get { return _npcHitPoints; } |
|
set { _npcHitPoints = value; } |
|
} |
|
|
|
protected override void Init() |
|
{ |
|
base.Init(); |
|
Debug.LogWarning("init player resources"); |
|
DontDestroyOnLoad(this); |
|
} |
|
|
|
public void Repaint() |
|
{ |
|
if (UiResources != null) |
|
UiResources.SetExp(EXP_TABLE[_currentLevel], _currentExp); |
|
|
|
if (UiResources != null) |
|
UiResources.SetCoins(_currentCoins); |
|
} |
|
|
|
public void AddExp(int exp) |
|
{ |
|
_currentExp += (int)(exp * ExpMult); |
|
if (_currentExp >= EXP_TABLE[_currentLevel]) |
|
{ |
|
_currentExp -= EXP_TABLE[_currentLevel]; |
|
GameBoard.Instance.LevelUp(); |
|
_currentLevel++; |
|
FlyingText.Init("LVL UP", FlyingText.State.Normal, AiController.Instance.PlayerPosition, Color.yellow); |
|
} |
|
|
|
if (UiResources != null) |
|
UiResources.SetExp(EXP_TABLE[_currentLevel], _currentExp); |
|
} |
|
|
|
public void AddCoins(int coins) |
|
{ |
|
_currentCoins += (int)(coins * _coinsMult); |
|
} |
|
public void Clear() |
|
{ |
|
_currentCoins = 0; |
|
_currentExp = 0; |
|
_currentLevel = 0; |
|
_expMult = 1; |
|
_coinsMult = 1; |
|
AlreadyUnlocked = true; |
|
Instance.NPCHitPoints = 1; |
|
MainCharacter.Clear(); |
|
} |
|
|
|
public void AddItem(EquipItem item) |
|
{ |
|
_items.Add(item); |
|
AlreadyUnlocked = true; |
|
} |
|
|
|
} |
|
}
|
|
|