Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/tfminecraft/magic/blood/BloodConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public static boolean load(File source, Logger log) {
RoomTemplate.load(config.getConfigurationSection("placement.room.template"), log);
huntPointsRequired = Math.max(1, config.getInt("hunt.points_required", 7));
WhisperConfig.load(config.getConfigurationSection("whispers"), config.getConfigurationSection("voices"), log);
OccultistHints.load(config.getConfigurationSection("hints"), log);
AnimalConfig.load(config.getConfigurationSection("animal"), log);
CorruptionConfig.load(config.getConfigurationSection("corruption"), log);
ChoiceConfig.load(config.getConfigurationSection("choice"), config.getConfigurationSection("classes"),
Expand Down Expand Up @@ -204,6 +205,7 @@ public static void reset() {
purifyCheckMinutes = 10;
huntPointsRequired = 7;
WhisperConfig.reset();
OccultistHints.reset();
AnimalConfig.reset();
CorruptionConfig.reset();
ChoiceConfig.reset();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/tfminecraft/magic/blood/BloodListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ public void onCharacterDeath(CharacterDeathEvent event) {
Player online = Bukkit.getPlayer(killer.ownerId());
Player current = online != null && character.equalsIgnoreCase(AltarService.currentCharacter(online))
? online : null;
WhisperService.addTo(character, killer.ownerId().toString(), WhisperConfig.characterKill(), current);
WhisperService.addTo(character, killer.ownerId().toString(), WhisperConfig.characterKill(), current,
OccultistHints.Deed.CHARACTER_KILL);
}

/** HIGHEST: after other damage plugins, so the ritual knife's stroke stays lethal on a bound animal. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ static void onPlay(Player player, boolean sessionStarted) {
if (character == null) {
return;
}
WhisperService.addTo(character, player.getUniqueId().toString(), WhisperConfig.robbery(), player);
WhisperService.addTo(character, player.getUniqueId().toString(), WhisperConfig.robbery(), player,
OccultistHints.Deed.ROBBERY);
}
}
180 changes: 180 additions & 0 deletions src/main/java/net/tfminecraft/magic/blood/OccultistHints.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package net.tfminecraft.magic.blood;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;

import net.tfminecraft.magic.util.MagicText;

/**
* Faint hints for characters with a fast trait (Occultist) whose voices have not woken yet: a short
* line when a deed feeds their whisper meter, and now and then a riddle when they are alone. Both are
* the character's own thoughts in the pale colours; they never name the rules or the god.
* From the hints: section of the wildmagic/bloodmagic config.
*/
public final class OccultistHints {

/** What fed the meter. Each has its own hint lines (hints.deeds.<name in lower case>). */
public enum Deed {
STOLEN_ANIMAL,
OWN_ANIMAL,
CHARACTER_KILL,
ROBBERY,
CORRUPTION
}

private static final long MINUTE = 60_000L;
/** When each online player may next hear a riddle (by player). */
private static final Map<UUID, Long> NEXT_RIDDLE = new HashMap<>();
/** When each online player may next hear a hint for each deed (by player). */
private static final Map<UUID, Map<Deed, Long>> NEXT_DEED = new HashMap<>();

private static boolean enabled = true;
private static String style = "";
private static List<String> colours = List.of();
private static String sound = "";
private static float pitch = 1f;
private static float volume = 0.4f;
private static long deedCooldown = 60 * MINUTE;
private static final Map<Deed, List<String>> DEEDS = new EnumMap<>(Deed.class);
private static List<String> riddles = List.of();
private static int[] firstRiddle = {30, 90};
private static int[] riddleInterval = {120, 240};

private OccultistHints() {}

static void reset() {
enabled = true;
style = "";
colours = List.of();
sound = "";
pitch = 1f;
volume = 0.4f;
deedCooldown = 60 * MINUTE;
DEEDS.clear();
riddles = List.of();
firstRiddle = new int[] {30, 90};
riddleInterval = new int[] {120, 240};
}

static void load(ConfigurationSection section, Logger log) {
reset();
if (section == null) {
return;
}
enabled = section.getBoolean("enabled", true);
style = section.getString("style", "");
List<String> stops = new ArrayList<>();
for (String raw : section.getStringList("colors")) {
if (VoiceColours.valid(raw)) {
stops.add(raw.trim());
} else {
log.warning("[Magic] blood magic config hints.colors: '" + raw + "' is not a #rrggbb colour");
}
}
colours = List.copyOf(stops);
sound = section.getString("sound", "");
pitch = (float) section.getDouble("pitch", 1.0);
volume = (float) Math.max(0, section.getDouble("volume", 0.4));
deedCooldown = Math.max(0, section.getInt("deed_cooldown_minutes", 60)) * MINUTE;
for (Deed deed : Deed.values()) {
List<String> lines = section.getStringList("deeds." + deed.name().toLowerCase(Locale.ROOT));
if (!lines.isEmpty()) {
DEEDS.put(deed, List.copyOf(lines));
}
}
riddles = List.copyOf(section.getStringList("riddles"));
firstRiddle = range(section.getIntegerList("first_riddle_minutes"), firstRiddle);
riddleInterval = range(section.getIntegerList("riddle_interval_minutes"), riddleInterval);
}

private static int[] range(List<Integer> raw, int[] fallback) {
if (raw.size() != 2) {
return fallback;
}
int min = Math.max(1, Math.min(raw.get(0), raw.get(1)));
return new int[] {min, Math.max(min, Math.max(raw.get(0), raw.get(1)))};
}

/**
* A deed just fed a fast-trait character's meter (the voices are not awake yet): one line about it,
* at most once per deed_cooldown_minutes for each kind of deed.
*/
static void deed(Player player, Deed deed) {
List<String> lines = DEEDS.getOrDefault(deed, List.of());
if (!enabled || lines.isEmpty()) {
return;
}
long now = WhisperService.clock.getAsLong();
Map<Deed, Long> due = NEXT_DEED.computeIfAbsent(player.getUniqueId(), id -> new EnumMap<>(Deed.class));
if (now < due.getOrDefault(deed, 0L)) {
return;
}
due.put(deed, now + deedCooldown);
say(player, lines.get(WhisperService.random.nextInt(lines.size())));
}

/**
* Once a minute for each online player with a character. A riddle falls due a while after they
* join and then every riddle_interval_minutes; it waits until they are alone, and only a fast-trait
* character whose voices have not woken hears it.
*/
static void tick(Player player, String character, BloodRecord record) {
UUID id = player.getUniqueId();
if (!enabled || riddles.isEmpty() || record != null && record.getStage() != BloodStage.NONE) {
NEXT_RIDDLE.remove(id);
return;
}
long now = WhisperService.clock.getAsLong();
Long due = NEXT_RIDDLE.get(id);
if (due == null) {
NEXT_RIDDLE.put(id, now + minutes(firstRiddle) * MINUTE);
return;
}
if (now < due || !WhisperService.alone(player)) {
return;
}
// The trait is only looked up when a riddle falls due; without it the next check is an interval away.
if (WhisperService.fastTraitOf.test(character)) {
say(player, riddles.get(WhisperService.random.nextInt(riddles.size())));
}
NEXT_RIDDLE.put(id, now + minutes(riddleInterval) * MINUTE);
}

private static int minutes(int[] range) {
return range[0] + WhisperService.random.nextInt(range[1] - range[0] + 1);
}

/** One line to this player alone, in the hints' colours and sound. */
static void say(Player player, String line) {
String prefix = MagicText.format(style);
player.sendMessage(colours.isEmpty() ? prefix + MagicText.format(line)
: VoiceColours.gradient(line, colours, prefix));
if (!sound.isBlank()) {
player.playSound(player.getLocation(), sound, volume, pitch);
}
}

/** Forget the player's timers, e.g. after a quit or a character switch. */
static void forget(UUID player) {
NEXT_RIDDLE.remove(player);
NEXT_DEED.remove(player);
}

static Long nextRiddle(UUID player) {
return NEXT_RIDDLE.get(player);
}

static void clear() {
NEXT_RIDDLE.clear();
NEXT_DEED.clear();
}
}
35 changes: 29 additions & 6 deletions src/main/java/net/tfminecraft/magic/blood/WhisperService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,37 @@ public static void add(Player player, double amount) {
* before the voices start. Returns true when this woke them.
*/
public static boolean addTo(String character, String owner, double amount, Player online) {
return addTo(character, owner, amount, online, true);
return addTo(character, owner, amount, online, true, null);
}

private static boolean addTo(String character, String owner, double amount, Player online, boolean multiply) {
/**
* As {@link #addTo(String, String, double, Player)}, for a deed: a fast-trait character online
* whose voices it did not wake gets a faint hint about it.
*/
public static boolean addTo(String character, String owner, double amount, Player online, OccultistHints.Deed deed) {
return addTo(character, owner, amount, online, true, deed);
}

private static boolean addTo(String character, String owner, double amount, Player online, boolean multiply,
OccultistHints.Deed deed) {
if (!BloodConfig.isEnabled() || amount <= 0) {
return false;
}
BloodRecord record = BloodRecords.getOrCreate(character, owner);
if (record.getStage() != BloodStage.NONE) {
return false;
}
double gain = amount * (multiply && fastTraitOf.test(character) ? WhisperConfig.fastMultiplier() : 1);
boolean fast = fastTraitOf.test(character);
double gain = amount * (multiply && fast ? WhisperConfig.fastMultiplier() : 1);
record.setWhisper(record.getWhisper() + gain);
boolean woke = record.getWhisper() >= WhisperConfig.threshold();
if (woke) {
awaken(record, online);
}
BloodRecords.save(record);
if (!woke && fast && deed != null && online != null) {
OccultistHints.deed(online, deed);
}
return woke;
}

Expand Down Expand Up @@ -121,7 +134,13 @@ public static void animalKill(Player killer, Entity animal) {
return;
}
switch (keeper(killer, animal)) {
case OTHERS -> add(killer, WhisperConfig.animalOthers());
case OTHERS -> {
String character = AltarService.currentCharacter(killer);
if (character != null) {
addTo(character, killer.getUniqueId().toString(), WhisperConfig.animalOthers(), killer,
OccultistHints.Deed.STOLEN_ANIMAL);
}
}
case OWN -> ownAnimal(killer);
default -> { }
}
Expand Down Expand Up @@ -184,7 +203,7 @@ static void ownAnimal(Player killer) {
return;
}
record.addOwnAnimalWhisper(day, gain);
addTo(character, owner, gain, killer, false);
addTo(character, owner, gain, killer, false, OccultistHints.Deed.OWN_ANIMAL);
}

static boolean blade(ItemStack item) {
Expand Down Expand Up @@ -224,13 +243,15 @@ static void tick(MagicTickContext context) {
if (record != null && record.getStage() != BloodStage.NONE) {
voiceIfDue(player, record);
}
OccultistHints.tick(player, character, record);
}
}

private static void tenMinutes(Player player, String character) {
double eq = equilibrium.applyAsDouble(player);
if (!Double.isNaN(eq) && eq <= WhisperConfig.corruptionBelow()) {
addTo(character, player.getUniqueId().toString(), WhisperConfig.corruption(), player);
addTo(character, player.getUniqueId().toString(), WhisperConfig.corruption(), player,
OccultistHints.Deed.CORRUPTION);
}
BloodRecord record = BloodRecords.get(character);
if (record == null) {
Expand Down Expand Up @@ -427,6 +448,7 @@ static void give(Player player, ItemStack item) {
/** Forget the player's voice timer, e.g. after a quit or a character switch. */
public static void forget(UUID player) {
NEXT_VOICE.remove(player);
OccultistHints.forget(player);
}

/** Lets the next minute tick speak to the player straight away. */
Expand All @@ -441,6 +463,7 @@ static Long nextVoice(UUID player) {
public static void clear() {
NEXT_VOICE.clear();
KEEPERS_AT_DEATH.clear();
OccultistHints.clear();
}

private static double sessionEquilibrium(Player player) {
Expand Down
44 changes: 44 additions & 0 deletions src/main/resources/wildmagic/bloodmagic/voices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,47 @@ voices:
- "They would call me evil. They'd be right. And far too late."
- "Quiet. So quiet. No god, no father. I did it all myself."
- "...and in the quiet, something old and patient is smiling. It sounds like me."

# Faint hints for fast-trait characters (Occultist) whose voices haven't woken yet. They are the
# character's own thoughts, in the own voice's first pale colours, and never name the rules or the god.
# deeds: one line when a deed feeds the meter (and doesn't wake the voices), at most once per
# deed_cooldown_minutes per kind of deed. riddles: one at random, the first a while after joining
# (first_riddle_minutes), then every riddle_interval_minutes, each waiting until nobody else is within
# voices.alone_radius. Minutes count while online; both stop once the voices wake.
hints:
enabled: true
style: "§o"
colors: ["#d8d2e0", "#bdb6c9"]
sound: tfmc_blood:heart
pitch: 1.2
volume: 0.4
deed_cooldown_minutes: 60
first_riddle_minutes: [30, 90]
riddle_interval_minutes: [120, 240]
deeds:
# Killed with a blade an animal another player keeps.
stolen_animal:
- "It wasn't mine, and somehow that made it better. For a moment something far away leaned closer."
- "Someone will find their pen one short tomorrow. Why do I feel so warm?"
# Killed with a blade an animal they keep themselves.
own_animal:
- "Only one of my own. Something far away looked up, and then lost interest."
- "My own beast. It felt like a small gift. Too small."
# A character they killed died for good.
character_kill:
- "They won't get up again. In the stillness afterwards, something very old drew a long breath."
- "A death that stays. The quiet around me listened, and seemed pleased."
# Started robbing, pickpocketing, lockpicking or looting a grave.
robbery:
- "A lock gives, a purse goes light, and something far away smiles at me. I can't explain it."
- "Taking what isn't mine shouldn't feel like being noticed. It does."
# Their magic's equilibrium sank deep.
corruption:
- "My magic has soured, and the sourness feels like company."
riddles:
- "I dreamt of a stone under the earth again. It was dry, and it was waiting. I woke up thirsty."
- "A beast from someone else's pen, taken while its keeper sleeps. Why does the thought warm me?"
- "Most who fall in a fight get up again. It's the ones who never do that I keep thinking about."
- "Locks, purses, graves. Every time I take what isn't mine, the quiet seems to lean closer."
- "The scholars write that a True Vampire named Alaric Thorme taught blood magic once. Who taught him?"
- "Some nights the quiet feels like it's listening for blood that hasn't been spilled yet."
Loading