👔 New leveling algorithm
This commit is contained in:
@@ -101,24 +101,48 @@ public class Account : ModelBase
|
|||||||
|
|
||||||
public abstract class Leveling
|
public abstract class Leveling
|
||||||
{
|
{
|
||||||
public static readonly List<int> ExperiencePerLevel =
|
private const int MaxLevel = 120;
|
||||||
[
|
private const double BaseExp = 100.0;
|
||||||
0, // Level 0
|
private const double K = 3.52; // tweak this for balance
|
||||||
100, // Level 1
|
|
||||||
250, // Level 2
|
// Single level XP requirement (from L → L+1)
|
||||||
500, // Level 3
|
public static double ExpForLevel(int level)
|
||||||
1000, // Level 4
|
{
|
||||||
2000, // Level 5
|
if (level < 1) return 0;
|
||||||
4000, // Level 6
|
return BaseExp + K * Math.Pow(level - 1, 2);
|
||||||
8000, // Level 7
|
}
|
||||||
16000, // Level 8
|
|
||||||
32000, // Level 9
|
// Total cumulative XP required to reach level L
|
||||||
64000, // Level 10
|
public static double TotalExpForLevel(int level)
|
||||||
128000, // Level 11
|
{
|
||||||
256000, // Level 12
|
if (level < 1) return 0;
|
||||||
512000, // Level 13
|
return BaseExp * level + K * ((level - 1) * level * (2 * level - 1)) / 6.0;
|
||||||
1024000 // Level 14
|
}
|
||||||
];
|
|
||||||
|
// Get level from experience
|
||||||
|
public static int GetLevelFromExp(int xp)
|
||||||
|
{
|
||||||
|
if (xp < 0) return 0;
|
||||||
|
|
||||||
|
int level = 0;
|
||||||
|
while (level < MaxLevel && TotalExpForLevel(level + 1) <= xp)
|
||||||
|
{
|
||||||
|
level++;
|
||||||
|
}
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Progress to next level (0.0 ~ 1.0)
|
||||||
|
public static double GetProgressToNextLevel(int xp)
|
||||||
|
{
|
||||||
|
int currentLevel = GetLevelFromExp(xp);
|
||||||
|
if (currentLevel >= MaxLevel) return 1.0;
|
||||||
|
|
||||||
|
double prevTotal = TotalExpForLevel(currentLevel);
|
||||||
|
double nextTotal = TotalExpForLevel(currentLevel + 1);
|
||||||
|
|
||||||
|
return (xp - prevTotal) / (nextTotal - prevTotal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AccountProfile : ModelBase, IIdentifiedResource
|
public class AccountProfile : ModelBase, IIdentifiedResource
|
||||||
@@ -140,7 +164,11 @@ public class AccountProfile : ModelBase, IIdentifiedResource
|
|||||||
[Column(TypeName = "jsonb")] public BadgeReferenceObject? ActiveBadge { get; set; }
|
[Column(TypeName = "jsonb")] public BadgeReferenceObject? ActiveBadge { get; set; }
|
||||||
|
|
||||||
public int Experience { get; set; }
|
public int Experience { get; set; }
|
||||||
[NotMapped] public int Level => Leveling.ExperiencePerLevel.Count(xp => Experience >= xp) - 1;
|
|
||||||
|
[NotMapped]
|
||||||
|
public int Level => Leveling.GetLevelFromExp(Experience);
|
||||||
|
[NotMapped]
|
||||||
|
public double LevelingProgress => Leveling.GetProgressToNextLevel(Experience);
|
||||||
|
|
||||||
public double SocialCredits { get; set; } = 100;
|
public double SocialCredits { get; set; } = 100;
|
||||||
|
|
||||||
@@ -153,12 +181,6 @@ public class AccountProfile : ModelBase, IIdentifiedResource
|
|||||||
_ => 2
|
_ => 2
|
||||||
};
|
};
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
public double LevelingProgress => Level >= Leveling.ExperiencePerLevel.Count - 1
|
|
||||||
? 100
|
|
||||||
: (Experience - Leveling.ExperiencePerLevel[Level]) * 100.0 /
|
|
||||||
(Leveling.ExperiencePerLevel[Level + 1] - Leveling.ExperiencePerLevel[Level]);
|
|
||||||
|
|
||||||
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Picture { get; set; }
|
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Picture { get; set; }
|
||||||
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Background { get; set; }
|
[Column(TypeName = "jsonb")] public CloudFileReferenceObject? Background { get; set; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user