Gather all enchantment info into a single place

This also resolves several TODO notes about duplicate code and makes cPresetItem::ability an eEnchant
This commit is contained in:
2024-08-28 23:41:36 -04:00
committed by Celtic Minstrel
parent 71a9d11cd0
commit 6965b822dc
22 changed files with 216 additions and 83 deletions

View File

@@ -348,57 +348,25 @@ cItem::cItem(eAlchemy recipe) : cItem(ITEM_POTION) {
magic_use_type = info.magic_use_type;
}
void cItem::enchant_weapon(eEnchant enchant_type,short new_val) {
void cItem::enchant_weapon(eEnchant enchant_type) {
if(magic || ability != eItemAbil::NONE)
return;
if(variety != eItemType::ONE_HANDED && variety != eItemType::TWO_HANDED)
return;
magic = true;
enchanted = true;
std::string store_name = full_name;
switch(enchant_type) {
case eEnchant::PLUS_ONE:
store_name += " (+1)";
bonus++;
value = new_val;
break;
case eEnchant::PLUS_TWO:
store_name += " (+2)";
bonus += 2;
value = new_val;
break;
case eEnchant::PLUS_THREE:
store_name += " (+3)";
bonus += 3;
value = new_val;
break;
case eEnchant::SHOOT_FLAME:
store_name += " (F)";
ability = eItemAbil::CAST_SPELL;
abil_strength = 5;
abil_data.spell = eSpell::FLAME;
charges = 8;
break;
case eEnchant::FLAMING:
store_name += " (F!)";
value = new_val;
ability = eItemAbil::DAMAGING_WEAPON;
abil_strength = 5;
abil_data.damage = eDamageType::FIRE;
break;
case eEnchant::PLUS_FIVE:
store_name += " (+5)";
value = new_val;
bonus += 5;
break;
case eEnchant::BLESSED:
store_name += " (B)";
bonus++;
ability = eItemAbil::AFFECT_STATUS;
abil_strength = 5;
abil_data.status = eStatus::BLESS_CURSE;
charges = 8;
break;
const cEnchant& info = *enchant_type;
std::string store_name = full_name + " (";
store_name += info.suffix + ")";
bonus += info.add_bonus;
value = info.adjust_value(value);
if(info.add_ability != eItemAbil::NONE) {
ability = info.add_ability;
abil_strength = info.abil_strength;
abil_data = info.abil_data;
}
if(info.charges > 0) {
charges = info.charges;
}
if(value > 15000)
value = 15000;

View File

@@ -17,6 +17,7 @@
#include "item_variety.hpp"
#include "skills_traits.hpp"
#include "alchemy.hpp"
#include "enchant.hpp"
namespace legacy { struct item_record_type; };
@@ -69,7 +70,7 @@ public:
std::string interesting_string() const;
std::string getAbilName() const;
void enchant_weapon(eEnchant enchant_type, short new_val);
void enchant_weapon(eEnchant enchant_type);
bool abil_harms() const;
bool abil_group() const;
bool can_use() const;

View File

@@ -59,8 +59,6 @@ const item_variety_t& operator*(eItemType type);
enum class eItemUse {HELP_ONE, HARM_ONE, HELP_ALL, HARM_ALL};
enum class eEnchant {PLUS_ONE, PLUS_TWO, PLUS_THREE, SHOOT_FLAME, FLAMING, PLUS_FIVE, BLESSED};
std::ostream& operator << (std::ostream& out, eItemUse e);
std::istream& operator >> (std::istream& in, eItemUse& e);
std::ostream& operator << (std::ostream& out, eItemType e);

View File

@@ -226,7 +226,7 @@ short cTown::light_obscurity(short x,short y) const {
cTown::cItem::cItem() {
loc = {80,80};
code = -1;
ability = -1;
ability = eEnchant::NONE;
charges = 0;
always_there = false;
property = false;

View File

@@ -55,7 +55,8 @@ public:
class cItem { // formerly preset_item_type
public:
location loc;
short code,ability;
short code;
eEnchant ability;
int charges = -1;
bool always_there = false, property = false, contained = false;