116 lines
3.5 KiB
C#
116 lines
3.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace AppleHills.Data.CardSystem
|
|
{
|
|
[Serializable]
|
|
public class CardData
|
|
{
|
|
// Core data (serialized)
|
|
public string Id; // Auto-generated unique ID (GUID)
|
|
public string DefinitionId; // ID of the card definition this instance was created from
|
|
public CardRarity Rarity; // Current rarity (may be upgraded from original)
|
|
public int CopiesOwned; // Number of copies the player has (for stacking)
|
|
|
|
// Reference back to the definition (not serialized)
|
|
[NonSerialized]
|
|
private CardDefinition _definition;
|
|
|
|
// Properties that reference definition data
|
|
public string Name => _definition?.Name;
|
|
public string Description => _definition?.Description;
|
|
public CardZone Zone => _definition?.Zone ?? CardZone.AppleHills;
|
|
public int CollectionIndex => _definition?.CollectionIndex ?? 0;
|
|
public Sprite CardImage => _definition?.CardImage;
|
|
|
|
// Derived properties
|
|
public Color BackgroundColor => _definition?.GetBackgroundColor() ?? Color.white;
|
|
|
|
// Get frame shape based on rarity
|
|
public string GetFrameShapeName()
|
|
{
|
|
return $"Frame_{Rarity}";
|
|
}
|
|
|
|
// Default constructor
|
|
public CardData()
|
|
{
|
|
Id = Guid.NewGuid().ToString();
|
|
CopiesOwned = 0;
|
|
}
|
|
|
|
// Constructor from definition
|
|
public CardData(CardDefinition definition)
|
|
{
|
|
Id = Guid.NewGuid().ToString();
|
|
DefinitionId = definition.Id;
|
|
Rarity = definition.Rarity;
|
|
CopiesOwned = 1;
|
|
_definition = definition;
|
|
}
|
|
|
|
// Copy constructor
|
|
public CardData(CardData other)
|
|
{
|
|
Id = other.Id;
|
|
DefinitionId = other.DefinitionId;
|
|
Rarity = other.Rarity;
|
|
CopiesOwned = other.CopiesOwned;
|
|
_definition = other._definition;
|
|
}
|
|
|
|
// Method to link this card data to its definition
|
|
public void SetDefinition(CardDefinition definition)
|
|
{
|
|
if (definition != null)
|
|
{
|
|
_definition = definition;
|
|
DefinitionId = definition.Id;
|
|
}
|
|
}
|
|
|
|
// Method to upgrade rarity when enough copies are collected
|
|
public bool TryUpgradeRarity()
|
|
{
|
|
// Simple implementation - each rarity needs twice as many copies to upgrade
|
|
int requiredCopies = (int)Rarity * 2 + 1;
|
|
|
|
if (CopiesOwned >= requiredCopies && Rarity < CardRarity.Legendary)
|
|
{
|
|
Rarity += 1;
|
|
CopiesOwned -= requiredCopies;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// ToString method for debugging
|
|
public override string ToString()
|
|
{
|
|
return $"CardData [ID: {Id}, Name: {Name}, Rarity: {Rarity}, Zone: {Zone}, " +
|
|
$"DefinitionID: {DefinitionId}, Copies: {CopiesOwned}, " +
|
|
$"Has Definition: {_definition != null}, Has Image: {CardImage != null}]";
|
|
}
|
|
}
|
|
|
|
// Enums for card attributes
|
|
public enum CardRarity
|
|
{
|
|
Common = 0,
|
|
Uncommon = 1,
|
|
Rare = 2,
|
|
Epic = 3,
|
|
Legendary = 4
|
|
}
|
|
|
|
public enum CardZone
|
|
{
|
|
AppleHills,
|
|
Quarry,
|
|
Forest,
|
|
Mountain,
|
|
Beach
|
|
}
|
|
}
|