From a41488ca179375771f17e2ed457759a43a7e4817 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:51:58 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#3772=20DragonBreaths=20=E3=82=AF?= =?utf8?q?=E3=83=A9=E3=82=B9=E3=82=92=E5=AE=9A=E7=BE=A9=E3=81=97=E3=81=A6d?= =?utf8?q?ragonbreath=5Finfo=20=E6=94=B9=E3=82=81=20dragon=5Fbreaths=5Finf?= =?utf8?q?o=20=E3=81=B8=E3=81=AE=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9?= =?utf8?q?=E3=82=92=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=86=85=E3=81=AB?= =?utf8?q?=E9=99=90=E5=AE=9A=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/object-activation/activation-breath.cpp | 14 +++-------- src/object-enchant/dragon-breaths-table.cpp | 39 ++++++++++++++++++++++++++++- src/object-enchant/dragon-breaths-table.h | 12 +++++++-- src/system/item-entity.cpp | 19 +------------- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/object-activation/activation-breath.cpp b/src/object-activation/activation-breath.cpp index b3bd7509e..d6b06b40e 100644 --- a/src/object-activation/activation-breath.cpp +++ b/src/object-activation/activation-breath.cpp @@ -31,13 +31,7 @@ bool activate_dragon_breath(PlayerType *player_ptr, ItemEntity *o_ptr) } const auto flags = o_ptr->get_flags(); - std::vector> 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; } @@ -50,9 +44,9 @@ bool activate_dragon_breath(PlayerType *player_ptr, ItemEntity *o_ptr) (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; } diff --git a/src/object-enchant/dragon-breaths-table.cpp b/src/object-enchant/dragon-breaths-table.cpp index 2b47584ea..9b4f8090e 100644 --- a/src/object-enchant/dragon-breaths-table.cpp +++ b/src/object-enchant/dragon-breaths-table.cpp @@ -2,12 +2,14 @@ #include "effect/attribute-types.h" #include "locale/language-switcher.h" #include "object-enchant/tr-types.h" +#include /*! * @brief 装備耐性に準じたブレス効果の選択テーブル / * Define flags, effect type, name for dragon breath activation */ -const std::vector dragonbreath_info = { +namespace { +const std::vector dragon_breaths_info = { { TR_RES_ACID, AttributeType::ACID, _("酸", "acid") }, { TR_RES_ELEC, AttributeType::ELEC, _("電撃", "lightning") }, { TR_RES_FIRE, AttributeType::FIRE, _("火炎", "fire") }, @@ -23,3 +25,38 @@ const std::vector dragonbreath_info = { { TR_RES_CHAOS, AttributeType::CHAOS, _("カオス", "chaos") }, { TR_RES_DISEN, AttributeType::DISENCHANT, _("劣化", "disenchantment") }, }; +} + +std::vector> DragonBreaths::get_breaths(const TrFlags &flags) +{ + std::vector> 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(); +} diff --git a/src/object-enchant/dragon-breaths-table.h b/src/object-enchant/dragon-breaths-table.h index c13e3ee5e..5b07bdbf5 100644 --- a/src/object-enchant/dragon-breaths-table.h +++ b/src/object-enchant/dragon-breaths-table.h @@ -1,13 +1,21 @@ #pragma once +#include "object-enchant/tr-flags.h" +#include +#include #include 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_info; +class DragonBreaths { +public: + static std::vector> get_breaths(const TrFlags &flags); + static std::string build_description(const TrFlags &flags); +}; diff --git a/src/system/item-entity.cpp b/src/system/item-entity.cpp index e8e684a5f..9311dc300 100644 --- a/src/system/item-entity.cpp +++ b/src/system/item-entity.cpp @@ -1067,22 +1067,5 @@ std::string ItemEntity::build_activation_description(const ActivationType &act) 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); } -- 2.11.0