using System; using ShiroginSDK.Runtime.Modules.Data.Scripts; using ShiroginSDK.Runtime.Modules.Data.Scripts.Enums; using ShiroginSDK.Runtime.Modules.IAP.Enums; using ShiroginSDK.Runtime.Services.Base; using ShiroginSDK.Runtime.Services.Interfaces; using UnityEngine; namespace ShiroginSDK.Runtime.Modules.IAP.Scripts.Definitions { /// /// Defines a single reward entry that can be granted after purchase, ad, or event. /// [Serializable] public class RewardDefinition { [Header("Reward Info")] public RewardType rewardType; public int amount; public int characterId = -1; public Sprite icon; /// /// Returns a human-readable reward description (for debug or UI display). /// public string GetDescription() { return rewardType switch { RewardType.Gold => $"{amount} Gold", RewardType.Gems => $"{amount} Gems", RewardType.Ticket => $"{amount} Tickets", RewardType.Energy => $"{amount} Energy", RewardType.Key => $"{amount} Key(s)", RewardType.Character => icon != null ? icon.name.Substring(icon.name.LastIndexOf('_') + 1) : $"Character #{characterId}", RewardType.RemoveAds => "Remove Ads", _ => "Unknown Reward" }; } /// /// Grants the reward to the appropriate data system. /// public void Give() { // Retrieve the centralized data service var dataService = ServiceLocator.Get(); if (dataService == null) { Debug.LogError("[RewardDefinition] ❌ IDataService not found via ServiceLocator!"); return; } switch (rewardType) { // Currency rewards case RewardType.Gold: dataService.Get().GrantReward(CurrencyType.Gold, amount, "reward"); break; case RewardType.Gems: dataService.Get().GrantReward(CurrencyType.Gems, amount, "reward"); break; case RewardType.Ticket: dataService.Get().GrantReward(CurrencyType.RewardedTicket, amount, "reward"); break; case RewardType.Energy: dataService.Get().GrantReward(CurrencyType.Energy, amount, "reward"); break; case RewardType.Key: dataService.Get().GrantReward(CurrencyType.Keys, amount, "reward"); break; // Character unlock case RewardType.Character: dataService.Get().UnlockCharacter(characterId); Debug.Log($"[Reward] 🧙‍♂️ Character #{characterId} unlocked!"); break; // Remove Ads case RewardType.RemoveAds: dataService.Get().SetRemoveAds(true); Debug.Log("[Reward] 🚫 Ads removed successfully."); break; // Default / Custom default: Debug.LogWarning($"[Reward] ⚠️ Unknown reward type: {rewardType}"); break; } } } }