Fixed period of 0 for exp items

This commit is contained in:
Indyuce 2022-07-24 21:25:26 +02:00
parent 8d53cbfcc7
commit a659468775

View File

@ -55,9 +55,7 @@ public class ExperienceItem {
Validate.isTrue(config.contains("triggers")); Validate.isTrue(config.contains("triggers"));
id = config.getName(); id = config.getName();
final int periodOption = config.getInt("period", 1); period = config.getInt("period", 1);
// A period of 0 means the item will only trigger once
period = periodOption == 0 ? Integer.MAX_VALUE : periodOption;
firstTrigger = config.getInt("first-trigger", period); firstTrigger = config.getInt("first-trigger", period);
lastTrigger = config.getInt("last-trigger", Integer.MAX_VALUE); lastTrigger = config.getInt("last-trigger", Integer.MAX_VALUE);
claimChance = config.getDouble("chance", 100) / 100; claimChance = config.getDouble("chance", 100) / 100;
@ -79,10 +77,17 @@ public class ExperienceItem {
* account the randomness factor from the 'chance' parameter * account the randomness factor from the 'chance' parameter
*/ */
public boolean roll(int professionLevel, int timesCollected) { public boolean roll(int professionLevel, int timesCollected) {
// Check for the last triggering level
if (professionLevel > lastTrigger) if (professionLevel > lastTrigger)
return false; return false;
int claimsRequired = (professionLevel + 1 - (firstTrigger + timesCollected * period)); // A period of 0 means the item only triggers once
if (period == 0 && timesCollected > 0)
return false;
// Basic formula
final int claimsRequired = (professionLevel + 1 - (firstTrigger + timesCollected * period));
if (claimsRequired < 1) if (claimsRequired < 1)
return false; return false;