Add card inventory classes and helpers
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.Data.CardSystem
|
||||
namespace Data.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages the player's card collection, booster packs, and related operations.
|
||||
@@ -138,8 +139,9 @@ namespace AppleHills.Data.CardSystem
|
||||
private void AddCardToInventory(CardData card)
|
||||
{
|
||||
// Check if the player already has this card type (definition)
|
||||
if (playerInventory.CollectedCards.TryGetValue(card.DefinitionId, out CardData existingCard))
|
||||
if (playerInventory.HasCard(card.DefinitionId))
|
||||
{
|
||||
CardData existingCard = playerInventory.GetCard(card.DefinitionId);
|
||||
existingCard.CopiesOwned++;
|
||||
|
||||
// Check if the card can be upgraded
|
||||
@@ -153,7 +155,7 @@ namespace AppleHills.Data.CardSystem
|
||||
else
|
||||
{
|
||||
// Add new card
|
||||
playerInventory.CollectedCards.Add(card.DefinitionId, new CardData(card));
|
||||
playerInventory.AddCard(card);
|
||||
OnCardCollected?.Invoke(card);
|
||||
|
||||
Debug.Log($"[CardSystemManager] Added new card '{card.Name}' to collection.");
|
||||
@@ -227,12 +229,23 @@ namespace AppleHills.Data.CardSystem
|
||||
/// </summary>
|
||||
public List<CardData> GetAllCollectedCards()
|
||||
{
|
||||
List<CardData> result = new List<CardData>();
|
||||
foreach (var card in playerInventory.CollectedCards.Values)
|
||||
{
|
||||
result.Add(card);
|
||||
}
|
||||
return result;
|
||||
return playerInventory.GetAllCards();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns cards from a specific zone
|
||||
/// </summary>
|
||||
public List<CardData> GetCardsByZone(CardZone zone)
|
||||
{
|
||||
return playerInventory.GetCardsByZone(zone);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns cards of a specific rarity
|
||||
/// </summary>
|
||||
public List<CardData> GetCardsByRarity(CardRarity rarity)
|
||||
{
|
||||
return playerInventory.GetCardsByRarity(rarity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -248,17 +261,30 @@ namespace AppleHills.Data.CardSystem
|
||||
/// </summary>
|
||||
public bool IsCardCollected(string definitionId)
|
||||
{
|
||||
return playerInventory.CollectedCards.ContainsKey(definitionId);
|
||||
return playerInventory.HasCard(definitionId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets total unique card count
|
||||
/// </summary>
|
||||
public int GetUniqueCardCount()
|
||||
{
|
||||
return playerInventory.GetUniqueCardCount();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets completion percentage for a specific zone (0-100)
|
||||
/// </summary>
|
||||
public float GetZoneCompletionPercentage(CardZone zone)
|
||||
{
|
||||
// Count available cards in this zone
|
||||
int totalInZone = availableCards.FindAll(c => c.Zone == zone).Count;
|
||||
if (totalInZone == 0) return 0;
|
||||
|
||||
// Count collected cards in this zone
|
||||
int collectedInZone = playerInventory.GetCardsByZone(zone).Count;
|
||||
|
||||
return (float)collectedInZone / totalInZone * 100f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializable class to store the player's card inventory
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CardInventory
|
||||
{
|
||||
public Dictionary<string, CardData> CollectedCards = new Dictionary<string, CardData>();
|
||||
public int BoosterPackCount;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user