69 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.LogWarning($"Не заполнен набор реплик {type}");
return false;
}
return Random.Range(0f, 1f) < set.PlayProbability;
}
}
}