From 70db53644ec502cc2e365c65dd87724ec25fd604 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Mon, 8 Mar 2021 22:51:42 -0300 Subject: [PATCH] :triangular_flag_on_post: Add ini toggle for auto-equipping armor. Disabled by default. --- Source/diablo.cpp | 2 ++ Source/diablo.h | 3 +++ Source/inv.cpp | 4 ++++ Source/items.h | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 8df8385c5..94aa9cb39 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -433,6 +433,7 @@ static void SaveOptions() setIniInt("Game", "Auto Gold Pickup", sgOptions.bAutoGoldPickup); setIniInt("Game", "Adria Refills Mana", sgOptions.bAdriaRefillsMana); setIniInt("Game", "Auto Equip Weapons on Pickup", sgOptions.bAutoEquipWeapons); + setIniInt("Game", "Auto Equip Armor on Pickup", sgOptions.bAutoEquipArmor); setIniValue("Network", "Bind Address", sgOptions.szBindAddress); } @@ -480,6 +481,7 @@ static void LoadOptions() sgOptions.bAutoGoldPickup = getIniBool("Game", "Auto Gold Pickup", false); sgOptions.bAdriaRefillsMana = getIniBool("Game", "Adria Refills Mana", false); sgOptions.bAutoEquipWeapons = getIniBool("Game", "Auto Equip Weapons on Pickup", true); + sgOptions.bAutoEquipArmor = getIniBool("Game", "Auto Equip Armor on Pickup", false); getIniValue("Network", "Bind Address", sgOptions.szBindAddress, sizeof(sgOptions.szBindAddress), "0.0.0.0"); } diff --git a/Source/diablo.h b/Source/diablo.h index 8ebd95e1e..fe13a4cdc 100644 --- a/Source/diablo.h +++ b/Source/diablo.h @@ -101,6 +101,9 @@ typedef struct Options { /** @brief Automatically attempt to equip weapon-type items when picking them up. */ bool bAutoEquipWeapons; + /** @brief Automatically attempt to equip armor-type items when picking them up. */ + bool bAutoEquipArmor; + /** @brief Optionally bind to a specific network interface. */ char szBindAddress[129]; } Options; diff --git a/Source/inv.cpp b/Source/inv.cpp index b32b64c29..e5b2abfc4 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -812,6 +812,10 @@ bool AutoEquipEnabled(const ItemStruct &item) return sgOptions.bAutoEquipWeapons; } + if (item.isArmor()) { + return sgOptions.bAutoEquipArmor; + } + return true; } diff --git a/Source/items.h b/Source/items.h index bfbd4e032..17467d0e5 100644 --- a/Source/items.h +++ b/Source/items.h @@ -179,6 +179,27 @@ typedef struct ItemStruct { } } + /** + * @brief Checks whether this item is an armor. + * @return 'True' in case the item is an armor and 'False' otherwise. + */ + bool isArmor() const + { + if (this->isEmpty()) { + return false; + } + + switch (this->_itype) { + case ITYPE_HARMOR: + case ITYPE_LARMOR: + case ITYPE_MARMOR: + return true; + + default: + return false; + } + } + } ItemStruct; typedef struct ItemGetRecordStruct {