152 lines
4.7 KiB
Plaintext
152 lines
4.7 KiB
Plaintext
// Quest system
|
|
#include "src/quests/bat_invasion_game.nvgt"
|
|
#include "src/quests/enchanted_melody_game.nvgt"
|
|
#include "src/quests/escape_from_hel_game.nvgt"
|
|
|
|
const int QUEST_BAT_INVASION = 0;
|
|
const int QUEST_ENCHANTED_MELODY = 1;
|
|
const int QUEST_ESCAPE_FROM_HEL = 2;
|
|
const int QUEST_TYPE_COUNT = 3;
|
|
|
|
int[] quest_queue;
|
|
bool quest_roll_done_today = false;
|
|
|
|
string get_quest_name(int quest_type) {
|
|
if (quest_type == QUEST_BAT_INVASION) return "Bat Invasion";
|
|
if (quest_type == QUEST_ENCHANTED_MELODY) return "Enchanted Melody";
|
|
if (quest_type == QUEST_ESCAPE_FROM_HEL) return "Escape from Hel";
|
|
return "Unknown Quest";
|
|
}
|
|
|
|
string get_quest_description(int quest_type) {
|
|
if (quest_type == QUEST_BAT_INVASION) {
|
|
return "Bat Invasion. Giant killer bats are attacking. Press space to throw when the bat is centered.";
|
|
}
|
|
if (quest_type == QUEST_ENCHANTED_MELODY) {
|
|
return "Enchanted Melody. Repeat the pattern using E R D F or U I J K. Lowest to highest pitch.";
|
|
}
|
|
if (quest_type == QUEST_ESCAPE_FROM_HEL) {
|
|
return "Escape from Hel. Press space to jump over open graves. The pace quickens.";
|
|
}
|
|
return "Unknown quest.";
|
|
}
|
|
|
|
int get_quest_chance_from_favor() {
|
|
int chance = int(favor * QUEST_CHANCE_PER_FAVOR);
|
|
if (chance < QUEST_MIN_CHANCE && favor > 1.0) chance = QUEST_MIN_CHANCE;
|
|
if (chance > 100) chance = 100;
|
|
return chance;
|
|
}
|
|
|
|
void add_quest(int quest_type) {
|
|
if (quest_queue.length() >= QUEST_MAX_ACTIVE) return;
|
|
quest_queue.insert_last(quest_type);
|
|
notify("A new quest is available: " + get_quest_name(quest_type) + ".");
|
|
}
|
|
|
|
void attempt_daily_quest() {
|
|
if (quest_roll_done_today) return;
|
|
if (favor <= 1.0) return;
|
|
if (world_altars.length() == 0) return;
|
|
if (quest_queue.length() >= QUEST_MAX_ACTIVE) return;
|
|
|
|
quest_roll_done_today = true;
|
|
int chance = get_quest_chance_from_favor();
|
|
int roll = random(1, 100);
|
|
if (roll > chance) return;
|
|
|
|
int quest_type = random(0, QUEST_TYPE_COUNT - 1);
|
|
add_quest(quest_type);
|
|
}
|
|
|
|
void check_quest_menu() {
|
|
if (key_pressed(KEY_Q)) {
|
|
if (x > BASE_END) {
|
|
speak_with_history("You are not in the base.", true);
|
|
return;
|
|
}
|
|
if (quest_queue.length() == 0) {
|
|
speak_with_history("No quests available.", true);
|
|
return;
|
|
}
|
|
run_quest_menu();
|
|
}
|
|
}
|
|
|
|
void apply_quest_reward(int score) {
|
|
if (score <= 0) {
|
|
speak_with_history("No reward earned.", true);
|
|
return;
|
|
}
|
|
|
|
double favor_gain = score * QUEST_FAVOR_PER_POINT;
|
|
favor += favor_gain;
|
|
|
|
int stones_gain = (score >= QUEST_STONE_SCORE) ? 1 : 0;
|
|
int logs_gain = (score >= QUEST_LOG_SCORE) ? 1 : 0;
|
|
int skins_gain = (score >= QUEST_SKIN_SCORE) ? 1 : 0;
|
|
|
|
int stones_added = add_to_stack(inv_stones, stones_gain);
|
|
inv_stones += stones_added;
|
|
int logs_added = add_to_stack(inv_logs, logs_gain);
|
|
inv_logs += logs_added;
|
|
int skins_added = add_to_stack(inv_skins, skins_gain);
|
|
inv_skins += skins_added;
|
|
|
|
string message = "Quest reward: favor +" + format_favor(favor_gain) + ".";
|
|
if (stones_gain > 0) message += " Stones +" + stones_added + ".";
|
|
if (logs_gain > 0) message += " Logs +" + logs_added + ".";
|
|
if (skins_gain > 0) message += " Skins +" + skins_added + ".";
|
|
speak_with_history(message, true);
|
|
}
|
|
|
|
void run_quest(int quest_type) {
|
|
speak_with_history(get_quest_description(quest_type), true);
|
|
wait(800);
|
|
p.pause_all();
|
|
int score = 0;
|
|
if (quest_type == QUEST_BAT_INVASION) score = run_bat_invasion();
|
|
else if (quest_type == QUEST_ENCHANTED_MELODY) score = run_enchanted_melody();
|
|
else if (quest_type == QUEST_ESCAPE_FROM_HEL) score = run_escape_from_hel();
|
|
apply_quest_reward(score);
|
|
p.resume_all();
|
|
}
|
|
|
|
void run_quest_menu() {
|
|
speak_with_history("Quest menu.", true);
|
|
|
|
int selection = 0;
|
|
string[] options;
|
|
for (uint i = 0; i < quest_queue.length(); i++) {
|
|
options.insert_last(get_quest_name(quest_queue[i]));
|
|
}
|
|
|
|
while(true) {
|
|
wait(5);
|
|
menu_background_tick();
|
|
if (key_pressed(KEY_ESCAPE)) {
|
|
speak_with_history("Closed.", true);
|
|
break;
|
|
}
|
|
|
|
if (key_pressed(KEY_DOWN)) {
|
|
selection++;
|
|
if (selection >= options.length()) selection = 0;
|
|
speak_with_history(options[selection], true);
|
|
}
|
|
|
|
if (key_pressed(KEY_UP)) {
|
|
selection--;
|
|
if (selection < 0) selection = options.length() - 1;
|
|
speak_with_history(options[selection], true);
|
|
}
|
|
|
|
if (key_pressed(KEY_RETURN)) {
|
|
int quest_type = quest_queue[selection];
|
|
quest_queue.remove_at(selection);
|
|
run_quest(quest_type);
|
|
break;
|
|
}
|
|
}
|
|
}
|