Semi-working rarity upgrades

This commit is contained in:
Michal Pikulski
2025-11-06 23:06:41 +01:00
parent d23c000347
commit a705b3a829
7 changed files with 969 additions and 70 deletions

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AppleHills.Data.CardSystem;
using Bootstrap;
using Core;
using Core.SaveLoad;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Data.CardSystem
{
@@ -150,6 +146,7 @@ namespace Data.CardSystem
/// <summary>
/// Opens a booster pack and returns the newly obtained cards
/// NOTE: Cards are NOT added to inventory immediately - they're added after the reveal interaction
/// </summary>
public List<CardData> OpenBoosterPack()
{
@@ -165,11 +162,9 @@ namespace Data.CardSystem
// Draw 3 cards based on rarity distribution
List<CardData> drawnCards = DrawRandomCards(3);
// Add cards to the inventory
foreach (var card in drawnCards)
{
AddCardToInventory(card);
}
// NOTE: Cards are NOT added to inventory here anymore
// They will be added after the player interacts with each revealed card
// This allows us to show new/repeat status before adding to collection
// Notify listeners
OnBoosterOpened?.Invoke(drawnCards);
@@ -177,33 +172,56 @@ namespace Data.CardSystem
Logging.Debug($"[CardSystemManager] Opened a booster pack and obtained {drawnCards.Count} cards. Remaining boosters: {playerInventory.BoosterPackCount}");
return drawnCards;
}
/// <summary>
/// Check if a card is new to the player's collection at the specified rarity
/// </summary>
/// <param name="cardData">The card to check</param>
/// <param name="existingCard">Out parameter - the existing card if found, null otherwise</param>
/// <returns>True if this is a new card at this rarity, false if already owned</returns>
public bool IsCardNew(CardData cardData, out CardData existingCard)
{
if (playerInventory.HasCard(cardData.DefinitionId, cardData.Rarity))
{
existingCard = playerInventory.GetCard(cardData.DefinitionId, cardData.Rarity);
return false;
}
existingCard = null;
return true;
}
/// <summary>
/// Adds a card to the player's inventory after reveal (delayed add)
/// Public wrapper for AddCardToInventory to support delayed inventory updates
/// </summary>
public void AddCardToInventoryDelayed(CardData card)
{
AddCardToInventory(card);
}
/// <summary>
/// Adds a card to the player's inventory, handles duplicates
/// </summary>
private void AddCardToInventory(CardData card)
{
// Check if the player already has this card type (definition)
if (playerInventory.HasCard(card.DefinitionId))
// Check if the player already has this card at this rarity
if (playerInventory.HasCard(card.DefinitionId, card.Rarity))
{
CardData existingCard = playerInventory.GetCard(card.DefinitionId);
CardData existingCard = playerInventory.GetCard(card.DefinitionId, card.Rarity);
existingCard.CopiesOwned++;
// Check if the card can be upgraded
if (existingCard.TryUpgradeRarity())
{
OnCardRarityUpgraded?.Invoke(existingCard);
}
// Note: Upgrades are now handled separately in BoosterOpeningPage
// We don't auto-upgrade here anymore
Logging.Debug($"[CardSystemManager] Added duplicate card '{card.Name}'. Now have {existingCard.CopiesOwned} copies.");
Logging.Debug($"[CardSystemManager] Added duplicate card '{card.Name}' ({card.Rarity}). Now have {existingCard.CopiesOwned} copies.");
}
else
{
// Add new card
// Add new card at this rarity
playerInventory.AddCard(card);
OnCardCollected?.Invoke(card);
Logging.Debug($"[CardSystemManager] Added new card '{card.Name}' to collection.");
Logging.Debug($"[CardSystemManager] Added new card '{card.Name}' ({card.Rarity}) to collection.");
}
}
@@ -300,11 +318,17 @@ namespace Data.CardSystem
}
/// <summary>
/// Returns whether a specific card definition has been collected
/// Returns whether a specific card definition has been collected (at any rarity)
/// </summary>
public bool IsCardCollected(string definitionId)
{
return playerInventory.HasCard(definitionId);
// Check if the card exists at any rarity
foreach (CardRarity rarity in System.Enum.GetValues(typeof(CardRarity)))
{
if (playerInventory.HasCard(definitionId, rarity))
return true;
}
return false;
}
/// <summary>