Инкапсулированы методы появления и ухода персонажа Инкапсулирована работа с аниматором Работа с репликами вынесена в ScriptableObject Логика MessageBox вынесена в отдельный класс Переработан event bus персонажей Сложность и призовой модуль вынесены в отдельные классы Character.cs приведён к Single Responsibility Principle.
68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace CharacterSystem
|
||
{
|
||
[CreateAssetMenu(fileName = "ReplicasContainer", menuName = "Scriptable Objects/ReplicasContainer")]
|
||
public class ReplicasContainer : ScriptableObject
|
||
{
|
||
[SerializeField] private ReplicasSet _appearReplicas;
|
||
[SerializeField] private ReplicasSet _playerTurnReplicas;
|
||
[SerializeField] private ReplicasSet _botTurnReplicas;
|
||
[SerializeField] private ReplicasSet _playerWinReplicas;
|
||
[SerializeField] private ReplicasSet _botWinReplicas;
|
||
[SerializeField] private ReplicasSet _returnReplicas;
|
||
[SerializeField] private ReplicasSet _drawReplicas;
|
||
|
||
private Dictionary<GameEvent, ReplicasSet> _replicaDictionary;
|
||
private bool _isInit = false;
|
||
|
||
public static readonly IReadOnlyDictionary<GameEvent, bool> ShouldForceMessage =
|
||
new Dictionary<GameEvent, bool>
|
||
{
|
||
{ GameEvent.Appear, false },
|
||
{ GameEvent.PlayerTurn, false },
|
||
{ GameEvent.BotTurn, false },
|
||
{ GameEvent.PlayerWin, true },
|
||
{ GameEvent.BotWin, true },
|
||
{ GameEvent.Return, true },
|
||
{ GameEvent.Draw, true }
|
||
};
|
||
|
||
public void Initialize()
|
||
{
|
||
_replicaDictionary = new Dictionary<GameEvent, ReplicasSet>
|
||
{
|
||
{ GameEvent.Appear, _appearReplicas },
|
||
{ GameEvent.PlayerTurn, _playerTurnReplicas },
|
||
{ GameEvent.BotTurn, _botTurnReplicas },
|
||
{ GameEvent.PlayerWin, _playerWinReplicas },
|
||
{ GameEvent.BotWin, _botWinReplicas },
|
||
{ GameEvent.Return, _returnReplicas },
|
||
{ GameEvent.Draw, _drawReplicas }
|
||
};
|
||
_isInit = true;
|
||
}
|
||
|
||
public Replica GetNextReplica(GameEvent type)
|
||
=> _replicaDictionary[type].GetNext();
|
||
|
||
public bool WillPlay(GameEvent type)
|
||
{
|
||
if (_isInit == false)
|
||
{
|
||
Debug.LogError($"Не инициализирован контейнер реплик {name}");
|
||
return false;
|
||
}
|
||
|
||
var set = _replicaDictionary[type];
|
||
if (set == null)
|
||
{
|
||
Debug.LogError($"Не заполнен набор реплик {type}");
|
||
return false;
|
||
}
|
||
|
||
return Random.Range(0f, 1f) < set.playProbability;
|
||
}
|
||
}
|
||
} |