}
const auto flags = o_ptr->get_flags();
- std::vector<std::pair<AttributeType, std::string>> breaths;
- for (const auto &dragon_breath : dragonbreath_info) {
- if (flags.has(dragon_breath.flag)) {
- breaths.push_back({ dragon_breath.type, dragon_breath.name });
- }
- }
-
+ const auto breaths = DragonBreaths::get_breaths(flags);
if (breaths.empty()) {
return false;
}
(void)SpellHex(player_ptr).stop_all_spells();
}
- const auto t = randint0(breaths.size());
- msg_format(_("あなたは%sのブレスを吐いた。", "You breathe %s."), breaths[t].second.data());
- fire_breath(player_ptr, breaths[t].first, dir, 250, 4);
+ const auto &breath = rand_choice(breaths);
+ msg_format(_("あなたは%sのブレスを吐いた。", "You breathe %s."), breath.second.data());
+ fire_breath(player_ptr, breath.first, dir, 250, 4);
return true;
}
#include "effect/attribute-types.h"
#include "locale/language-switcher.h"
#include "object-enchant/tr-types.h"
+#include <sstream>
/*!
* @brief 装備耐性に準じたブレス効果の選択テーブル /
* Define flags, effect type, name for dragon breath activation
*/
-const std::vector<dragonbreath_type> dragonbreath_info = {
+namespace {
+const std::vector<DragonBreathType> dragon_breaths_info = {
{ TR_RES_ACID, AttributeType::ACID, _("酸", "acid") },
{ TR_RES_ELEC, AttributeType::ELEC, _("電撃", "lightning") },
{ TR_RES_FIRE, AttributeType::FIRE, _("火炎", "fire") },
{ TR_RES_CHAOS, AttributeType::CHAOS, _("カオス", "chaos") },
{ TR_RES_DISEN, AttributeType::DISENCHANT, _("劣化", "disenchantment") },
};
+}
+
+std::vector<std::pair<AttributeType, std::string>> DragonBreaths::get_breaths(const TrFlags &flags)
+{
+ std::vector<std::pair<AttributeType, std::string>> breaths;
+ for (const auto &dragon_breath : dragon_breaths_info) {
+ if (flags.has(dragon_breath.flag)) {
+ breaths.push_back({ dragon_breath.type, dragon_breath.name });
+ }
+ }
+
+ return breaths;
+}
+
+std::string DragonBreaths::build_description(const TrFlags &flags)
+{
+ std::stringstream ss;
+ ss << _("", "breathe ");
+ auto has_multi_breaths = false;
+ for (const auto &dragon_breath : dragon_breaths_info) {
+ if (flags.has_not(dragon_breath.flag)) {
+ continue;
+ }
+
+ if (has_multi_breaths) {
+ ss << _("、", ", ");
+ }
+
+ ss << dragon_breath.name;
+ has_multi_breaths = true;
+ }
+
+ ss << _("のブレス(250)", " (250)");
+ return ss.str();
+}
#pragma once
+#include "object-enchant/tr-flags.h"
+#include <string>
+#include <utility>
#include <vector>
enum tr_type : int;
enum class AttributeType;
-struct dragonbreath_type {
+class DragonBreathType {
+public:
tr_type flag;
AttributeType type;
std::string name;
};
-extern const std::vector<dragonbreath_type> dragonbreath_info;
+class DragonBreaths {
+public:
+ static std::vector<std::pair<AttributeType, std::string>> get_breaths(const TrFlags &flags);
+ static std::string build_description(const TrFlags &flags);
+};
std::string ItemEntity::build_activation_description_dragon_breath() const
{
const auto flags = this->get_flags();
- std::stringstream ss;
- ss << _("", "breathe ");
- auto has_multi_breaths = false;
- for (const auto &dragon_breath : dragonbreath_info) {
- if (flags.has_not(dragon_breath.flag)) {
- continue;
- }
-
- if (has_multi_breaths) {
- ss << _("、", ", ");
- }
-
- ss << dragon_breath.name;
- has_multi_breaths = true;
- }
-
- ss << _("のブレス(250)", " (250)");
- return ss.str();
+ return DragonBreaths::build_description(flags);
}