nightward/Assets/Resources/Prefabs/HorseRush/Script/HorseRushManager.cs

205 lines
5.9 KiB
C#

using System;
using System.Collections;
using UnityEngine;
public class HorseRushManager : MonoBehaviour
{
[SerializeField] HorseRushPanel _horseRushPanel;
int _horseRushEntryCount;
public int HorseRushEntryCount => _horseRushEntryCount;
int _horseRushFreeEntryCount;
public int HorseRushFreeEntryCount => _horseRushFreeEntryCount;
DateTime _horseRushResetTime;
public DateTime HorseRushResetTime => _horseRushResetTime;
long _maxScore;
public long MaxScore => _maxScore;
int _maxFever;
public int MaxFever => _maxFever;
int _playCount;
public int PlayCount => _playCount;
int _missionFeverCount = 5;
public int MissionFeverCount => _missionFeverCount;
#region LifeCycle
//override protected void Start()
void Start()
{
StartCoroutine(Init());
}
IEnumerator Init()
{
_horseRushEntryCount = 1;
_horseRushFreeEntryCount = 1;
_horseRushResetTime = DateTime.MinValue;
//_maxScore = AuthManager.Instance.Me.User.MaxScore;
//_maxFever = AuthManager.Instance.Me.User.MaxFever;
//_playCount = AuthManager.Instance.Me.User.GamePlayCount;
SetMissionFeverCount();
yield break;
}
#endregion
#region Entry Management Method
// 입장 초기화
public void ResetEntry()
{
DateTime now = DateTime.Now.Date;
// 만약 오늘의 날짜가 초기화 시간보다 크다면
if (now > _horseRushResetTime.Date)
{
_horseRushEntryCount = 2;
_horseRushFreeEntryCount = 2;
_horseRushResetTime = now;
}
}
public bool CanEnterHorseRush(bool isFree, bool isPay)
{
if (isFree)
{
return _horseRushFreeEntryCount > 0;
}
else
{
if (isPay)
{
return true;
}
else
{
return _horseRushEntryCount > 0;
}
}
}
public void SetMissionFeverCount()
{
//int missionFeverCount = DataManager.Instance.GlobalValue<int>("MISSION_FEVER_COUNT");
//if (GameManager.Instance.IsPackageCPurchased())
//{
// _missionFeverCount = missionFeverCount - 2;
//}
//else
//{
// _missionFeverCount = missionFeverCount;
//}
}
public void GameStart(bool isFreeSweep, bool isPay)
{
SetMissionFeverCount();
_horseRushPanel.gameObject.SetActive(true);
_horseRushPanel.GameStart(isFreeSweep);
}
public void GameOver(bool isFreeSweep, long score, int normalDoubleScoreCount, int maxFeverStreak, int missionSuccessPhotoID)
{
if (isFreeSweep)
{
_horseRushFreeEntryCount--;
}
else
{
_horseRushEntryCount--;
}
if (score > _maxScore)
{
_maxScore = score;
}
// _horseRushPanel.gameObject.SetActive(false);
GetReward(score, normalDoubleScoreCount, maxFeverStreak, missionSuccessPhotoID);
}
public void GetReward(long coinAmount, int rubyAmount, int maxFeverStreak, int missionSuccessPhotoID)
{
// 갑자기 하트 관련 보상 기획이 변경되어서 임시 주석 언제 다시 추가할지 모르겠음
// int heartAmount = GetHeartAmount(maxFeverStreak);
_playCount++;
_maxFever = maxFeverStreak > _maxFever ? maxFeverStreak : _maxFever;
_maxScore = coinAmount > _maxScore ? coinAmount : _maxScore;
//bool isPackage = GameManager.Instance.IsPackageBPurchased();
//CurrencyManager.Instance.AddGoods(101, coinAmount * (isPackage ? 2 : 1));
//CurrencyManager.Instance.AddGoods(102, rubyAmount);
//// CurrencyManager.Instance.AddGoods(103, heartAmount);
//if (maxFeverStreak >= _missionFeverCount && missionSuccessPhotoID != -1)
//{
// DataManager.Instance.PhotoBoost.IncreaseQuantity(missionSuccessPhotoID, 1);
// int albumID = DataManager.Instance.GetPhotoData(missionSuccessPhotoID).AlbumID;
// bool isFullCollection = true;
// int fullCollectionPhotoId = -1;
// var photos = DataManager.Instance.GetPhotoDatasByAlbumID(albumID);
// foreach (var photo in photos.Values)
// {
// if (photo.CollectionMethod == CollectionMethod.FullCollection)
// {
// fullCollectionPhotoId = photo.ID;
// continue;
// }
// if (DataManager.Instance.PhotoBoost.GetQuantity(photo.ID) == 0)
// {
// isFullCollection = false;
// }
// }
// if (isFullCollection && DataManager.Instance.PhotoBoost.GetLevel(fullCollectionPhotoId) == 0)
// {
// DataManager.Instance.PhotoBoost.IncreaseQuantity(fullCollectionPhotoId, 1);
// UIEvents.ShowToast(Local.GetLocalizedUIString("COLLECTION_REWARD_RECEIVED"));
// }
//}
//GameManager.Instance.Save();
//UIEvents.OnOpenMiniGameResultModal(coinAmount, rubyAmount, maxFeverStreak, missionSuccessPhotoID);
}
int GetHeartAmount(int maxFeverStreak)
{
if (maxFeverStreak == 0)
{
return 0;
}
// 각 피버 스트릭 단계별 꽝 확률
float failureChance = maxFeverStreak switch
{
1 => 0.5f, // 50%
2 => 0.3f, // 30%
3 => 0.25f, // 25%
4 => 0.2f, // 20%
5 => 0.1666f, // 16.66%
_ => 1f // 기본값
};
// 꽝 확률 체크
if (UnityEngine.Random.value < failureChance)
{
return 0;
}
// 꽝이 아닌 경우, 1부터 maxFeverStreak까지의 랜덤한 개수 반환
return UnityEngine.Random.Range(1, maxFeverStreak + 1);
}
#endregion
}