Move archivist's eyeglass code inside null check, fixes NPE when generating loot
This commit is contained in:
@@ -152,21 +152,25 @@ public class RandomSpell extends LootFunction {
|
|||||||
possibleSpells.removeIf(s -> s.getElement() != element);
|
possibleSpells.removeIf(s -> s.getElement() != element);
|
||||||
if(possibleSpells.isEmpty()) return Spells.none; // If it fails anywhere, it'll most likely be here
|
if(possibleSpells.isEmpty()) return Spells.none; // If it fails anywhere, it'll most likely be here
|
||||||
|
|
||||||
float bias = undiscoveredBias;
|
if(player != null){
|
||||||
// Archivist's eyeglass increases undiscovered bias by 0.4 up to a maximum of 0.9
|
|
||||||
if(ItemArtefact.isArtefactActive(player, WizardryItems.charm_spell_discovery)) bias = Math.min(bias + 0.4f, 0.9f);
|
|
||||||
|
|
||||||
// Remove either the undiscovered spells or the discovered ones, depending on the bias
|
float bias = undiscoveredBias;
|
||||||
if(bias > 0 && player != null){
|
// Archivist's eyeglass increases undiscovered bias by 0.4 up to a maximum of 0.9
|
||||||
|
if(ItemArtefact.isArtefactActive(player, WizardryItems.charm_spell_discovery))
|
||||||
|
bias = Math.min(bias + 0.4f, 0.9f);
|
||||||
|
|
||||||
WizardData data = WizardData.get(player);
|
// Remove either the undiscovered spells or the discovered ones, depending on the bias
|
||||||
|
if(bias > 0){
|
||||||
|
|
||||||
int discoveredCount = (int)possibleSpells.stream().filter(data::hasSpellBeenDiscovered).count();
|
WizardData data = WizardData.get(player);
|
||||||
// If none have been discovered or they've all been discovered, don't bother!
|
|
||||||
if(discoveredCount > 0 && discoveredCount < possibleSpells.size()){
|
int discoveredCount = (int)possibleSpells.stream().filter(data::hasSpellBeenDiscovered).count();
|
||||||
// Kinda unintuitive but it's very neat!
|
// If none have been discovered or they've all been discovered, don't bother!
|
||||||
boolean keepDiscovered = random.nextFloat() > 0.5f + 0.5f * bias;
|
if(discoveredCount > 0 && discoveredCount < possibleSpells.size()){
|
||||||
possibleSpells.removeIf(s -> keepDiscovered != data.hasSpellBeenDiscovered(s));
|
// Kinda unintuitive but it's very neat!
|
||||||
|
boolean keepDiscovered = random.nextFloat() > 0.5f + 0.5f * bias;
|
||||||
|
possibleSpells.removeIf(s -> keepDiscovered != data.hasSpellBeenDiscovered(s));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user