You can now specify for resources to ONLY regen outside of combat

This commit is contained in:
ASangarin 2020-10-19 21:22:35 +02:00
parent 3dd170bdc3
commit 7d227c874b
2 changed files with 18 additions and 9 deletions

View File

@ -4,7 +4,7 @@
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<name>MMOCore</name>
<version>1.4.9</version>
<version>1.4.10</version>
<description>Offer your players a brand new RPG experience.</description>
<build>
<resources>
@ -162,6 +162,13 @@
<scope>system</scope>
<systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath>
</dependency>
<dependency>
<groupId>me.vagdedes</groupId>
<artifactId>spartan</artifactId>
<version>Univsersal</version>
<scope>system</scope>
<systemPath>${basedir}/lib/SpartanAPI.jar</systemPath>
</dependency>
</dependencies>
<distributionManagement>
<repository>

View File

@ -38,11 +38,15 @@ public class ResourceHandler {
this.resource = resource;
offCombatOnly = config.getBoolean("off-combat");
Validate.isTrue(config.contains("type"), "Could not find resource regen scaling type");
type = HandlerType.valueOf(config.getString("type").toUpperCase());
if(config.contains("type")) {
Validate.isTrue(config.contains("type"), "Could not find resource regen scaling type");
type = HandlerType.valueOf(config.getString("type").toUpperCase());
} else type = null;
Validate.notNull(config.getConfigurationSection("value"), "Could not find resource regen value config section");
scalar = new LinearValue(config.getConfigurationSection("value"));
if(type != null) {
Validate.notNull(config.getConfigurationSection("value"), "Could not find resource regen value config section");
scalar = new LinearValue(config.getConfigurationSection("value"));
} else scalar = null;
}
public ResourceHandler(PlayerResource resource, HandlerType type, LinearValue scalar, boolean offCombatOnly) {
@ -56,22 +60,20 @@ public class ResourceHandler {
* REGENERATION FORMULAS HERE.
*/
public double getRegen(PlayerData player) {
double d = 0;
// base resource regeneration = value of the corresponding regen stat
if (!player.isInCombat() || !player.getProfess().hasOption(resource.getOffCombatRegen()))
d += player.getStats().getStat(resource.getRegenStat());
// extra resource regeneration based on CLASS, scales on LEVEL
if (type != null && (!player.isInCombat() || !offCombatOnly))
d = this.scalar.calculate(player.getLevel()) / 100 * type.getScaling(player, resource);
return d;
}
public enum HandlerType {
/*
* resource regeneration scales on max resource
*/