98 lines
3.9 KiB
C#
98 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BlueWater.Items;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
|
|
namespace BlueWater
|
|
{
|
|
[CreateAssetMenu(fileName = "CardTable", menuName = "ScriptableObjects/CardTable")]
|
|
|
|
public class CardDataSo : DataSo<CardData>
|
|
{
|
|
private Dictionary<string, int> _selectedCard = new Dictionary<string, int>(); // 선택된 카드를 저장함. <key = Idx / int = val>
|
|
|
|
public CardData GetCardData(string idxKey)
|
|
{
|
|
return GetDataByIdx(idxKey);
|
|
}
|
|
|
|
public CardData GetRandCardData()
|
|
{
|
|
var rand = Random.Range(0, 100); // 범위를 0-100으로 조정
|
|
var checkAdd = 0;
|
|
foreach (var element in _datas.Values)
|
|
{
|
|
checkAdd += element.Ratio; // Ratio를 더하고 비교하도록 수정
|
|
if (checkAdd > rand) return element;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// 카드를 선택했을 때 호출
|
|
public void AddToSelectedCard(CardData cardData)
|
|
{
|
|
if (_selectedCard.ContainsKey(cardData.Idx))
|
|
{
|
|
_selectedCard[cardData.Idx] += 1;
|
|
}
|
|
else // 신규
|
|
{
|
|
_selectedCard[cardData.Idx] = 1; // TryAdd를 사용하지 않고 대입
|
|
}
|
|
}
|
|
|
|
//(임시) 카드 종류를 탐색해서 치환하는 작업 (리퀴드와 가니쉬에 해당함)
|
|
//확률적으로 문제가 있기 때문에, 해당 확률를 고려해서 카드를 변경시키는 기능
|
|
//EX -> 10레벨 상태에서 AddLiquidE 가 나왔을 경우 B, C 둘중 하나로 치환함
|
|
//만약에 5레벨보다 작으면 null값 리턴
|
|
public CardData SubstitutionLiquid(CardData cardData, LevelData levelData)
|
|
{
|
|
if (cardData.Idx.Equals("AddLiquidB") || cardData.Idx.Equals("AddLiquidC") || cardData.Idx.Equals("AddLiquidD") ||
|
|
cardData.Idx.Equals("AddLiquidE") || cardData.Idx.Equals("AddGarnish1") || cardData.Idx.Equals("AddGarnish2") || cardData.Idx.Equals("AllLiquidAdd"))
|
|
{
|
|
int levelIdx = int.Parse(levelData.Idx);
|
|
|
|
if (levelIdx <= 5)
|
|
{
|
|
return null;
|
|
}
|
|
else if (cardData.Idx.Equals("AllLiquidAdd"))
|
|
{
|
|
return cardData;
|
|
}
|
|
|
|
List<CardData> activeLiquid = new List<CardData>();
|
|
|
|
if (levelIdx > 5) activeLiquid.Add(GetCardData("AddLiquidB"));
|
|
if (levelIdx > 10) activeLiquid.Add(GetCardData("AddLiquidC"));
|
|
if (levelIdx > 15) activeLiquid.Add(GetCardData("AddLiquidD"));
|
|
if (levelIdx > 20) activeLiquid.Add(GetCardData("AddLiquidE"));
|
|
if (levelIdx > 25) activeLiquid.Add(GetCardData("AddGarnish1"));
|
|
if (levelIdx > 30) activeLiquid.Add(GetCardData("AddGarnish2"));
|
|
|
|
// 액체 목록에서 랜덤하게 선택하여 반환
|
|
return activeLiquid[Random.Range(0, activeLiquid.Count)];
|
|
}
|
|
return cardData; // 해당 사항이 없으면 치환하지 않음
|
|
}
|
|
|
|
// 카드가 MAX값인지 확인할 때 - MAX값이면 true를 리턴
|
|
public bool CardMaxCheck(CardData cardData)
|
|
{
|
|
return _selectedCard.TryGetValue(cardData.Idx, out var value) && cardData.Max != 0 && value >= cardData.Max;
|
|
}
|
|
|
|
public Dictionary<string, int> GetselectedCard()
|
|
{
|
|
return _selectedCard;
|
|
}
|
|
|
|
// 카드가 처음 선택되었는지 확인할 때 - 0값이면 true를 리턴
|
|
public bool CardFirstCheck(string idx)
|
|
{
|
|
return _datas.ContainsKey(idx) && !_selectedCard.ContainsKey(idx);
|
|
}
|
|
}
|
|
} |