/
HumanRV
/
rpg_proto
Обзор
Документация
Войти
/
HumanRV
/
rpg_proto
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Scripts/Player/PlayerStats.cs
46 строк
1 KB
Leolan Magnus
attempt 1 skill system
03 май 2025, 21:57
03 май 2025, 21:57
9c0fcc2
Код
Авторство
О чём код?
using Godot; using System; using System.Collections.Generic; [System.Serializable] public partial class PlayerStats { public int Level {get; set;} = 1; public int CurrentXP {get; set;} = 0; public int XPToNextLevel {get; set;} = 1200; public int SkillPoints {get; set;} = 0; public List<int> UnlockedSkills {get; set;} = []; //currentXP, XPToNextLevel public event Action<int,int> OnXPUpdated; // level public event Action<int> OnLevelUpdated; private int CalculateXPToNextLevel() { return Level * 1200; } public void AddXP(int amount) { CurrentXP += amount; CheckLevelUp(); OnXPUpdated.Invoke(CurrentXP, XPToNextLevel); } private void CheckLevelUp() { if (CurrentXP >= XPToNextLevel){ LevelUp(); } } private void LevelUp() { CurrentXP -= XPToNextLevel; Level++; SkillPoints++; XPToNextLevel = CalculateXPToNextLevel(); OnXPUpdated.Invoke(CurrentXP, XPToNextLevel); OnLevelUpdated.Invoke(Level); GD.Print($"Gratz u got a new {Level} level!! {XPToNextLevel}xp to next!"); } }