Semi-working rarity upgrades
This commit is contained in:
@@ -11,9 +11,17 @@ namespace AppleHills.Data.CardSystem
|
||||
[Serializable]
|
||||
public class CardInventory
|
||||
{
|
||||
// Dictionary of collected cards indexed by definition ID
|
||||
// Dictionary of collected cards indexed by definition ID + rarity (e.g., "Pikachu_Normal", "Pikachu_Rare")
|
||||
[SerializeField] private Dictionary<string, CardData> collectedCards = new Dictionary<string, CardData>();
|
||||
|
||||
/// <summary>
|
||||
/// Generate a unique key for a card based on definition ID and rarity
|
||||
/// </summary>
|
||||
private string GetCardKey(string definitionId, CardRarity rarity)
|
||||
{
|
||||
return $"{definitionId}_{rarity}";
|
||||
}
|
||||
|
||||
// Number of unopened booster packs the player has
|
||||
[SerializeField] private int boosterPackCount;
|
||||
|
||||
@@ -96,7 +104,9 @@ namespace AppleHills.Data.CardSystem
|
||||
{
|
||||
if (card == null) return;
|
||||
|
||||
if (collectedCards.TryGetValue(card.DefinitionId, out CardData existingCard))
|
||||
string key = GetCardKey(card.DefinitionId, card.Rarity);
|
||||
|
||||
if (collectedCards.TryGetValue(key, out CardData existingCard))
|
||||
{
|
||||
// Increase copies of existing card
|
||||
existingCard.CopiesOwned++;
|
||||
@@ -105,7 +115,7 @@ namespace AppleHills.Data.CardSystem
|
||||
{
|
||||
// Add new card to collection
|
||||
var newCard = new CardData(card);
|
||||
collectedCards[card.DefinitionId] = newCard;
|
||||
collectedCards[key] = newCard;
|
||||
|
||||
// Add to lookup dictionaries
|
||||
cardsByZone[newCard.Zone].Add(newCard);
|
||||
@@ -133,19 +143,21 @@ namespace AppleHills.Data.CardSystem
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a specific card from the collection by definition ID
|
||||
/// Get a specific card from the collection by definition ID and rarity
|
||||
/// </summary>
|
||||
public CardData GetCard(string definitionId)
|
||||
public CardData GetCard(string definitionId, CardRarity rarity)
|
||||
{
|
||||
return collectedCards.TryGetValue(definitionId, out CardData card) ? card : null;
|
||||
string key = GetCardKey(definitionId, rarity);
|
||||
return collectedCards.TryGetValue(key, out CardData card) ? card : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the player has a specific card
|
||||
/// Check if the player has a specific card at a specific rarity
|
||||
/// </summary>
|
||||
public bool HasCard(string definitionId)
|
||||
public bool HasCard(string definitionId, CardRarity rarity)
|
||||
{
|
||||
return collectedCards.ContainsKey(definitionId);
|
||||
string key = GetCardKey(definitionId, rarity);
|
||||
return collectedCards.ContainsKey(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user