aboutsummaryrefslogtreecommitdiffstats
path: root/Malmstone/Utils/MalmstoneXPCalculator.cs
blob: 4834defe74cc064b03f4f0ef415536931937bd9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;

namespace Malmstone.Utils
{
    public static class MalmstoneXPCalculator
    {
        private static readonly int[] PvpLevels = {
            0, 2000, 2000, 2000, 2000, 3000, 3000, 3000, 3000, 3000, 4000, 4000, 4000, 4000, 4000, 5500, 5500, 5500, 5500, 5500,
            7500, 7500, 7500, 7500, 7500, 10000, 10000, 10000, 10000, 10000, 20000, 20000
        };

        private const int InfinityLevelExp = 20000;
        private const int FrontlineWinExp = 1500;
        private const int FrontlineLose2Exp = 1250;
        private const int FrontlineLoseExp = 1000;
        private const int FrontlineDailyWinExp = 3000;
        private const int FrontlineDailyLose2Exp = 2750;
        private const int FrontlineDailyLoseExp = 2500;
        private const int CrystallineWinExp = 900;
        private const int CrystallineLoseExp = 700;
        private const int RivalWingsWinExp = 1250;
        private const int RivalWingsLoseExp = 750;

        public class XpCalculationResult
        {
            public int RemainingXp { get; set; }
            public int TargetLevel { get; set; }
            public Dictionary<string, int> ActivityCounts { get; set; } = new();
        }

        public static XpCalculationResult CalculateXp(int currentLevel, int goalLevel, int currentProgress)
        {
            if (currentLevel < 1 || goalLevel < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(currentLevel), "Levels must be greater than 0.");
            }

            int remainingXp = 0;

            if (currentLevel <= PvpLevels.Length && goalLevel <= PvpLevels.Length)
            {
                remainingXp = CalculateRemainingXp(currentLevel, goalLevel, currentProgress);
            }
            else
            {
                remainingXp = CalculateRemainingXpBeyondChart(currentLevel, goalLevel, currentProgress);
            }

            if (remainingXp <= 0)
            {
                return new XpCalculationResult { RemainingXp = 0, TargetLevel = goalLevel };
            }

            var result = new XpCalculationResult
            {
                RemainingXp = remainingXp,
                TargetLevel = goalLevel,
            };

            result.ActivityCounts["Crystalline Conflict Win"] = CalculateActivityCount(remainingXp, CrystallineWinExp);
            result.ActivityCounts["Crystalline Conflict Lose"] = CalculateActivityCount(remainingXp, CrystallineLoseExp);
            result.ActivityCounts["Frontline Win"] = CalculateActivityCount(remainingXp, FrontlineWinExp);
            result.ActivityCounts["Frontline Lose 2nd"] = CalculateActivityCount(remainingXp, FrontlineLose2Exp);
            result.ActivityCounts["Frontline Lose 3rd"] = CalculateActivityCount(remainingXp, FrontlineLoseExp);
            result.ActivityCounts["Frontline Daily Win"] = CalculateActivityCount(remainingXp, FrontlineDailyWinExp);
            result.ActivityCounts["Frontline Daily Lose 2nd"] = CalculateActivityCount(remainingXp, FrontlineDailyLose2Exp);
            result.ActivityCounts["Frontline Daily Lose 3rd"] = CalculateActivityCount(remainingXp, FrontlineDailyLoseExp);
            result.ActivityCounts["Rival Wings Win"] = CalculateActivityCount(remainingXp, RivalWingsWinExp);
            result.ActivityCounts["Rival Wings Lose"] = CalculateActivityCount(remainingXp, RivalWingsLoseExp);

            return result;
        }

        private static int CalculateRemainingXp(int currentLevel, int goalLevel, int currentProgress)
        {
            int remainingXp = 0;

            for (int level = currentLevel; level < goalLevel; level++)
            {
                remainingXp += PvpLevels[level];
            }

            return remainingXp - currentProgress;
        }

        private static int CalculateRemainingXpBeyondChart(int currentLevel, int goalLevel, int currentProgress)
        {
            int remainingXp = 0;

            if (currentLevel <= PvpLevels.Length)
            {
                remainingXp = CalculateRemainingXp(currentLevel, PvpLevels.Length, currentProgress);
                currentLevel = PvpLevels.Length;
            }

            remainingXp += (goalLevel - currentLevel) * InfinityLevelExp;

            return remainingXp;
        }

        private static int CalculateActivityCount(int remainingXp, int activityXp)
        {
            return (int)Math.Ceiling((double)remainingXp / activityXp);
        }
    }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage