Playvoi/Assets/ShiroginSDK/Runtime/Modules/Data/Scripts/PlayerData.cs
2025-10-30 22:48:16 +03:00

83 lines
No EOL
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Assets/ShiroginSDK/Runtime/Data/PlayerData.cs
using System;
using System.Collections.Generic;
using UnityEngine;
namespace ShiroginSDK.Runtime.Modules.Data.Scripts
{
[Serializable]
public class PlayerData : BaseData
{
public string PlayerId = ""; // Cihaz ID veya backend id eşlemesi
public int Level = 1;
public int Xp;
// Basit bir xp eğrisi için parametreler (istersen Data/RemoteConfig'ten çekebilirsin)
public int BaseXpPerLevel = 100;
public float XpGrowth = 1.25f; // her level için gereksinim büyür
public int TutorialStep; // Lineer öğretici adımı
public List<string> CompletedFlags = new(); // "first_boss", "saw_shop" gibi bayraklar
protected override string PrefsKey => "PLAYER_DATA";
public void SetPlayerId(string id)
{
PlayerId = id;
Save();
}
public int GetRequiredXpForLevel(int targetLevel)
{
if (targetLevel <= 1) return BaseXpPerLevel;
// Basit üstel artış (örnek)
var req = BaseXpPerLevel * Math.Pow(XpGrowth, targetLevel - 1);
return Mathf.Max(1, (int)Math.Round(req));
}
public void AddXp(int amount)
{
if (amount <= 0) return;
Xp += amount;
// Level atlat
var leveled = false;
while (Xp >= GetRequiredXpForLevel(Level))
{
Xp -= GetRequiredXpForLevel(Level);
Level++;
leveled = true;
}
if (leveled) Debug.Log($"[PlayerData] Level Up! New Level: {Level}");
Save();
}
public void SetLevel(int newLevel, bool resetXp = true)
{
Level = Mathf.Max(1, newLevel);
if (resetXp) Xp = 0;
Save();
}
public void AdvanceTutorial(int step = 1)
{
TutorialStep = Mathf.Max(TutorialStep + step, 0);
Save();
}
public void SetFlag(string flagId)
{
if (!CompletedFlags.Contains(flagId))
{
CompletedFlags.Add(flagId);
Save();
}
}
public bool HasFlag(string flagId)
{
return CompletedFlags.Contains(flagId);
}
}
}