Files
Bat/src/main/java/cc/fascinated/bat/leveling/LevelingFeature.java
Lee b3a6284e40
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m42s
cleanup
2024-12-27 13:04:57 +00:00

53 lines
1.6 KiB
Java

package cc.fascinated.bat.leveling;
import cc.fascinated.bat.common.feature.Feature;
import cc.fascinated.bat.common.feature.FeatureProfile;
import cc.fascinated.bat.leveling.command.LevelingCommand;
import cc.fascinated.bat.service.CommandService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class LevelingFeature extends Feature {
/**
* The cache of the required XP for each level.
*/
public static final Map<Integer, Double> xpRequiredCache = new HashMap<>();
@Autowired
public LevelingFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
super("Leveling", FeatureProfile.FeatureState.DISABLED, true);
super.registerCommand(commandService, context.getBean(LevelingCommand.class));
}
/**
* Gets the amount of XP needed to level up.
*
* @param level The level.
* @param currentXp The current XP.
* @return The needed XP.
*/
public static double getNeededXP(int level, double currentXp) {
return xpRequiredCache.computeIfAbsent(level, integer -> getBaseXP(level) - currentXp);
}
/**
* Gets the base XP for a level.
*
* @param level The level.
* @return The base XP.
*/
public static double getBaseXP(int level) {
return 5 * (Math.pow(level, 2)) + (50 * level) + 100;
}
}