Files
draugnorak/src/inventory_items.nvgt

349 lines
13 KiB
Plaintext

// Inventory items and equipment
// Item storage is now handled by item_registry.nvgt
// Equipment type constants
const int EQUIP_NONE = -1;
const int EQUIP_SPEAR = 0;
const int EQUIP_AXE = 1;
const int EQUIP_SLING = 2;
const int EQUIP_HAT = 3;
const int EQUIP_GLOVES = 4;
const int EQUIP_PANTS = 5;
const int EQUIP_TUNIC = 6;
const int EQUIP_MOCCASINS = 7;
const int EQUIP_POUCH = 8;
const int EQUIP_BOW = 9;
const int EQUIP_BACKPACK = 10;
const int EQUIP_FISHING_POLE = 11;
// Health bonuses from equipment
const int HAT_MAX_HEALTH_BONUS = 1;
const int GLOVES_MAX_HEALTH_BONUS = 1;
const int PANTS_MAX_HEALTH_BONUS = 3;
const int TUNIC_MAX_HEALTH_BONUS = 4;
const int MOCCASINS_MAX_HEALTH_BONUS = 2;
// Equipment state
bool spear_equipped = false;
bool axe_equipped = false;
bool sling_equipped = false;
bool bow_equipped = false;
bool fishing_pole_equipped = false;
int equipped_head = EQUIP_NONE;
int equipped_torso = EQUIP_NONE;
int equipped_arms = EQUIP_NONE;
int equipped_hands = EQUIP_NONE;
int equipped_legs = EQUIP_NONE;
int equipped_feet = EQUIP_NONE;
// Quick slots
int[] quick_slots;
void reset_quick_slots() {
quick_slots.resize(10);
for (uint i = 0; i < quick_slots.length(); i++) {
quick_slots[i] = -1;
}
}
int get_personal_stack_limit() {
int limit = MAX_ITEM_STACK;
if (equipped_arms == EQUIP_POUCH) {
limit += POUCH_STACK_BONUS;
} else if (equipped_arms == EQUIP_BACKPACK) {
limit += 9;
}
return limit;
}
int get_arrow_limit() {
// Quiver required to hold arrows
// Each quiver holds 12 arrows
int quivers = get_personal_count(ITEM_QUIVERS);
if (quivers == 0) return 0;
return quivers * ARROW_CAPACITY_PER_QUIVER;
}
void clamp_arrows_to_quiver_limit() {
int maxArrows = get_arrow_limit();
int currentArrows = get_personal_count(ITEM_ARROWS);
if (currentArrows <= maxArrows) return;
set_personal_count(ITEM_ARROWS, maxArrows);
if (maxArrows == 0) {
speak_with_history("You need a quiver to carry arrows.", true);
} else {
speak_with_history("You can only carry " + maxArrows + " arrows with your current quivers.", true);
}
}
string get_equipment_name(int equip_type) {
if (equip_type == EQUIP_SPEAR) return "Spear";
if (equip_type == EQUIP_AXE) return "Stone Axe";
if (equip_type == EQUIP_SLING) return "Sling";
if (equip_type == EQUIP_BOW) return "Bow";
if (equip_type == EQUIP_HAT) return "Skin Hat";
if (equip_type == EQUIP_GLOVES) return "Skin Gloves";
if (equip_type == EQUIP_PANTS) return "Skin Pants";
if (equip_type == EQUIP_TUNIC) return "Skin Tunic";
if (equip_type == EQUIP_MOCCASINS) return "Moccasins";
if (equip_type == EQUIP_POUCH) return "Skin Pouch";
if (equip_type == EQUIP_BACKPACK) return "Backpack";
if (equip_type == EQUIP_FISHING_POLE) return "Fishing Pole";
return "Unknown";
}
bool equipment_available(int equip_type) {
// Check unruned items first, then runed versions
if (equip_type == EQUIP_SPEAR) return get_personal_count(ITEM_SPEARS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_AXE) return get_personal_count(ITEM_AXES) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_SLING) return get_personal_count(ITEM_SLINGS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_BOW) return get_personal_count(ITEM_BOWS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_HAT) return get_personal_count(ITEM_SKIN_HATS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_GLOVES) return get_personal_count(ITEM_SKIN_GLOVES) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_PANTS) return get_personal_count(ITEM_SKIN_PANTS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_TUNIC) return get_personal_count(ITEM_SKIN_TUNICS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_MOCCASINS) return get_personal_count(ITEM_MOCCASINS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_POUCH) return get_personal_count(ITEM_SKIN_POUCHES) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_BACKPACK) return get_personal_count(ITEM_BACKPACKS) > 0 || has_any_runed_version(equip_type);
if (equip_type == EQUIP_FISHING_POLE) return get_personal_count(ITEM_FISHING_POLES) > 0;
return false;
}
void equip_equipment_type(int equip_type) {
if (equip_type == EQUIP_SPEAR || equip_type == EQUIP_AXE || equip_type == EQUIP_SLING || equip_type == EQUIP_BOW || equip_type == EQUIP_FISHING_POLE) {
spear_equipped = (equip_type == EQUIP_SPEAR);
axe_equipped = (equip_type == EQUIP_AXE);
sling_equipped = (equip_type == EQUIP_SLING);
bow_equipped = (equip_type == EQUIP_BOW);
fishing_pole_equipped = (equip_type == EQUIP_FISHING_POLE);
return;
}
if (equip_type == EQUIP_HAT) equipped_head = EQUIP_HAT;
else if (equip_type == EQUIP_TUNIC) equipped_torso = EQUIP_TUNIC;
else if (equip_type == EQUIP_GLOVES) equipped_hands = EQUIP_GLOVES;
else if (equip_type == EQUIP_PANTS) equipped_legs = EQUIP_PANTS;
else if (equip_type == EQUIP_MOCCASINS) equipped_feet = EQUIP_MOCCASINS;
else if (equip_type == EQUIP_POUCH) equipped_arms = EQUIP_POUCH;
else if (equip_type == EQUIP_BACKPACK) equipped_arms = EQUIP_BACKPACK;
}
bool equipment_is_equipped(int equip_type) {
if (equip_type == EQUIP_SPEAR) return spear_equipped;
if (equip_type == EQUIP_AXE) return axe_equipped;
if (equip_type == EQUIP_SLING) return sling_equipped;
if (equip_type == EQUIP_BOW) return bow_equipped;
if (equip_type == EQUIP_FISHING_POLE) return fishing_pole_equipped;
if (equip_type == EQUIP_HAT) return equipped_head == EQUIP_HAT;
if (equip_type == EQUIP_TUNIC) return equipped_torso == EQUIP_TUNIC;
if (equip_type == EQUIP_GLOVES) return equipped_hands == EQUIP_GLOVES;
if (equip_type == EQUIP_PANTS) return equipped_legs == EQUIP_PANTS;
if (equip_type == EQUIP_MOCCASINS) return equipped_feet == EQUIP_MOCCASINS;
if (equip_type == EQUIP_POUCH) return equipped_arms == EQUIP_POUCH;
if (equip_type == EQUIP_BACKPACK) return equipped_arms == EQUIP_BACKPACK;
return false;
}
void unequip_equipment_type(int equip_type) {
if (equip_type == EQUIP_SPEAR) {
spear_equipped = false;
} else if (equip_type == EQUIP_AXE) {
axe_equipped = false;
} else if (equip_type == EQUIP_SLING) {
sling_equipped = false;
} else if (equip_type == EQUIP_BOW) {
bow_equipped = false;
} else if (equip_type == EQUIP_FISHING_POLE) {
fishing_pole_equipped = false;
} else if (equip_type == EQUIP_HAT && equipped_head == EQUIP_HAT) {
equipped_head = EQUIP_NONE;
} else if (equip_type == EQUIP_TUNIC && equipped_torso == EQUIP_TUNIC) {
equipped_torso = EQUIP_NONE;
} else if (equip_type == EQUIP_GLOVES && equipped_hands == EQUIP_GLOVES) {
equipped_hands = EQUIP_NONE;
} else if (equip_type == EQUIP_PANTS && equipped_legs == EQUIP_PANTS) {
equipped_legs = EQUIP_NONE;
} else if (equip_type == EQUIP_MOCCASINS && equipped_feet == EQUIP_MOCCASINS) {
equipped_feet = EQUIP_NONE;
} else if (equip_type == EQUIP_POUCH && equipped_arms == EQUIP_POUCH) {
equipped_arms = EQUIP_NONE;
} else if (equip_type == EQUIP_BACKPACK && equipped_arms == EQUIP_BACKPACK) {
equipped_arms = EQUIP_NONE;
}
}
void update_max_health_from_equipment() {
int bonus = 0;
if (equipped_head == EQUIP_HAT) bonus += HAT_MAX_HEALTH_BONUS;
if (equipped_hands == EQUIP_GLOVES) bonus += GLOVES_MAX_HEALTH_BONUS;
if (equipped_legs == EQUIP_PANTS) bonus += PANTS_MAX_HEALTH_BONUS;
if (equipped_torso == EQUIP_TUNIC) bonus += TUNIC_MAX_HEALTH_BONUS;
if (equipped_feet == EQUIP_MOCCASINS) bonus += MOCCASINS_MAX_HEALTH_BONUS;
max_health = base_max_health + bonus;
if (player_health > max_health) {
player_health = max_health;
}
// Calculate walk speed with all bonuses
int base_speed = (equipped_feet == EQUIP_MOCCASINS) ? MOCCASINS_WALK_SPEED : BASE_WALK_SPEED;
// Apply rune speed bonuses (stacks with moccasins)
int rune_bonus = get_total_rune_walk_speed_bonus();
walk_speed = base_speed - rune_bonus;
// Apply blessing bonus on top of existing speed
if (blessing_speed_active) {
int blessing_bonus = BASE_WALK_SPEED - BLESSING_WALK_SPEED;
if (blessing_bonus < 0) blessing_bonus = 0;
walk_speed -= blessing_bonus;
}
// Ensure minimum walk speed
if (walk_speed < 200) walk_speed = 200;
}
int get_quick_slot_key() {
if (key_pressed(KEY_1)) return 1;
if (key_pressed(KEY_2)) return 2;
if (key_pressed(KEY_3)) return 3;
if (key_pressed(KEY_4)) return 4;
if (key_pressed(KEY_5)) return 5;
if (key_pressed(KEY_6)) return 6;
if (key_pressed(KEY_7)) return 7;
if (key_pressed(KEY_8)) return 8;
if (key_pressed(KEY_9)) return 9;
if (key_pressed(KEY_0)) return 0;
return -1;
}
bool try_consume_heal_scroll() {
if (player_health > 0) return false;
if (get_personal_count(ITEM_HEAL_SCROLL) <= 0) return false;
add_personal_count(ITEM_HEAL_SCROLL, -1);
player_health = max_health / 2;
if (player_health < 1) player_health = 1;
p.play_stationary("sounds/actions/heal_scroll.ogg", false);
return true;
}
void activate_quick_slot(int slot_index) {
if (slot_index < 0 || slot_index >= int(quick_slots.length())) {
return;
}
int equip_type = quick_slots[slot_index];
if (equip_type < 0) {
speak_with_history("No item bound to slot " + slot_index + ".", true);
return;
}
if (equipment_is_equipped(equip_type)) {
unequip_equipment_type(equip_type);
clear_equipped_rune_for_slot(equip_type);
update_max_health_from_equipment();
speak_with_history(get_equipment_name(equip_type) + " unequipped.", true);
return;
}
if (!equipment_available(equip_type)) {
speak_with_history("Item not available.", true);
return;
}
equip_equipment_type(equip_type);
update_max_health_from_equipment();
speak_with_history(get_equipment_name(equip_type) + " equipped.", true);
}
void check_quick_slot_keys() {
int slot_index = get_quick_slot_key();
if (slot_index != -1) {
activate_quick_slot(slot_index);
}
}
int add_to_stack(int current, int amount) {
if (amount <= 0) return 0;
int space = get_personal_stack_limit() - current;
if (space <= 0) return 0;
if (amount > space) return space;
return amount;
}
string format_favor(double value) {
if (value < 0) value = 0;
return "" + int(value);
}
string get_equipped_weapon_name() {
if (spear_equipped) return "Spear";
if (axe_equipped) return "Stone Axe";
if (sling_equipped) return "Sling";
if (bow_equipped) return "Bow";
if (fishing_pole_equipped) return "Fishing Pole";
return "None";
}
string get_speed_status() {
string status = "";
int rune_bonus = get_total_rune_walk_speed_bonus();
if (blessing_speed_active) {
status = "blessed";
} else if (equipped_feet == EQUIP_MOCCASINS && rune_bonus > 0) {
status = "boosted by moccasins and runes";
} else if (equipped_feet == EQUIP_MOCCASINS) {
status = "boosted by moccasins";
} else if (rune_bonus > 0) {
status = "boosted by runes";
} else {
status = "normal";
}
return status;
}
void cleanup_equipment_after_inventory_change() {
if (!equipment_available(EQUIP_SPEAR)) spear_equipped = false;
if (!equipment_available(EQUIP_AXE)) axe_equipped = false;
if (!equipment_available(EQUIP_SLING)) sling_equipped = false;
if (!equipment_available(EQUIP_BOW)) bow_equipped = false;
if (!equipment_available(EQUIP_FISHING_POLE)) fishing_pole_equipped = false;
bool any_weapon_equipped = spear_equipped || axe_equipped || sling_equipped || bow_equipped || fishing_pole_equipped;
if (!any_weapon_equipped) equipped_weapon_rune = RUNE_NONE;
if (!equipment_available(EQUIP_HAT)) {
equipped_head = EQUIP_NONE;
equipped_head_rune = RUNE_NONE;
}
if (!equipment_available(EQUIP_GLOVES)) {
equipped_hands = EQUIP_NONE;
equipped_hands_rune = RUNE_NONE;
}
if (!equipment_available(EQUIP_PANTS)) {
equipped_legs = EQUIP_NONE;
equipped_legs_rune = RUNE_NONE;
}
if (!equipment_available(EQUIP_TUNIC)) {
equipped_torso = EQUIP_NONE;
equipped_torso_rune = RUNE_NONE;
}
if (!equipment_available(EQUIP_MOCCASINS)) {
equipped_feet = EQUIP_NONE;
equipped_feet_rune = RUNE_NONE;
}
if (equipped_arms == EQUIP_POUCH && !equipment_available(EQUIP_POUCH)) {
equipped_arms = EQUIP_NONE;
equipped_arms_rune = RUNE_NONE;
}
if (equipped_arms == EQUIP_BACKPACK && !equipment_available(EQUIP_BACKPACK)) {
equipped_arms = EQUIP_NONE;
equipped_arms_rune = RUNE_NONE;
}
clamp_arrows_to_quiver_limit();
update_max_health_from_equipment();
}