fix
This commit is contained in:
parent
89dc9eb00d
commit
957ab4a5a2
149 changed files with 5379 additions and 3263 deletions
|
|
@ -5,20 +5,56 @@ import org.bukkit.inventory.ItemStack;
|
|||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Генератор случайного лута для сундуков.
|
||||
* Может выдать: Медкит (разное количество зарядов), Набор для срезания.
|
||||
*/
|
||||
public class ChestLoot {
|
||||
|
||||
private final Random random;
|
||||
|
||||
public ChestLoot() {
|
||||
// Веса для разных типов лута (из конфига game.yml: loot.*)
|
||||
private final int medkitWeight;
|
||||
private final int medkitMinCharges;
|
||||
private final int medkitMaxCharges;
|
||||
private final int hookCutterWeight;
|
||||
|
||||
/** Config-aware constructor. */
|
||||
public ChestLoot(dev.loki.config.GameConfig config) {
|
||||
this.random = ThreadLocalRandom.current();
|
||||
var cfg = config.getConfig();
|
||||
this.medkitWeight = cfg.getInt("loot.medkit.weight", 60);
|
||||
this.medkitMinCharges = cfg.getInt("loot.medkit.min-charges", 12);
|
||||
this.medkitMaxCharges = cfg.getInt("loot.medkit.max-charges", 16);
|
||||
this.hookCutterWeight = cfg.getInt("loot.hook-cutter.weight", 40);
|
||||
}
|
||||
|
||||
/** 55% медкит, 45% фонарик. Заряды чуть рандомные. */
|
||||
/** Fallback — hardcoded defaults. */
|
||||
public ChestLoot() {
|
||||
this.random = ThreadLocalRandom.current();
|
||||
this.medkitWeight = 60;
|
||||
this.medkitMinCharges = 12;
|
||||
this.medkitMaxCharges = 16;
|
||||
this.hookCutterWeight = 40;
|
||||
}
|
||||
|
||||
/**
|
||||
* Бросает кубик и возвращает случайный предмет.
|
||||
* Никогда не возвращает null.
|
||||
*/
|
||||
public ItemStack rollLoot() {
|
||||
if (random.nextInt(100) < 55) {
|
||||
return DBDItems.medkit(12 + random.nextInt(5));
|
||||
int total = medkitWeight + hookCutterWeight;
|
||||
if (total <= 0) {
|
||||
return DBDItems.medkit(12);
|
||||
}
|
||||
|
||||
int roll = random.nextInt(total);
|
||||
|
||||
if (roll < medkitWeight) {
|
||||
int charges = medkitMinCharges + random.nextInt(Math.max(1, medkitMaxCharges - medkitMinCharges + 1));
|
||||
return DBDItems.medkit(charges);
|
||||
} else {
|
||||
return DBDItems.flashlight(6 + random.nextInt(3));
|
||||
return DBDItems.hookCutter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue