99 lines
No EOL
3.5 KiB
C#
99 lines
No EOL
3.5 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Defines a single reward entry that can be granted after purchase, ad, or event.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class RewardDefinition
|
|
{
|
|
[Header("Reward Info")]
|
|
public RewardType rewardType;
|
|
|
|
public int amount;
|
|
public int characterId = -1;
|
|
public Sprite icon;
|
|
|
|
/// <summary>
|
|
/// Returns a human-readable reward description (for debug or UI display).
|
|
/// </summary>
|
|
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"
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Grants the reward to the appropriate data system.
|
|
/// </summary>
|
|
public void Give()
|
|
{
|
|
// Retrieve the centralized data service
|
|
var dataService = ServiceLocator.Get<IDataService>();
|
|
if (dataService == null)
|
|
{
|
|
Debug.LogError("[RewardDefinition] ❌ IDataService not found via ServiceLocator!");
|
|
return;
|
|
}
|
|
|
|
switch (rewardType)
|
|
{
|
|
// Currency rewards
|
|
case RewardType.Gold:
|
|
dataService.Get<EconomyData>().GrantReward(CurrencyType.Gold, amount, "reward");
|
|
break;
|
|
|
|
case RewardType.Gems:
|
|
dataService.Get<EconomyData>().GrantReward(CurrencyType.Gems, amount, "reward");
|
|
break;
|
|
|
|
case RewardType.Ticket:
|
|
dataService.Get<EconomyData>().GrantReward(CurrencyType.RewardedTicket, amount, "reward");
|
|
break;
|
|
|
|
case RewardType.Energy:
|
|
dataService.Get<EconomyData>().GrantReward(CurrencyType.Energy, amount, "reward");
|
|
break;
|
|
|
|
case RewardType.Key:
|
|
dataService.Get<EconomyData>().GrantReward(CurrencyType.Keys, amount, "reward");
|
|
break;
|
|
|
|
// Character unlock
|
|
case RewardType.Character:
|
|
dataService.Get<InventoryData>().UnlockCharacter(characterId);
|
|
Debug.Log($"[Reward] 🧙♂️ Character #{characterId} unlocked!");
|
|
break;
|
|
|
|
// Remove Ads
|
|
case RewardType.RemoveAds:
|
|
dataService.Get<StoreData>().SetRemoveAds(true);
|
|
Debug.Log("[Reward] 🚫 Ads removed successfully.");
|
|
break;
|
|
|
|
// Default / Custom
|
|
default:
|
|
Debug.LogWarning($"[Reward] ⚠️ Unknown reward type: {rewardType}");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |