From 4a1ad54f9caf1e20f42a3326a32093e095f76659 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Thu, 10 Mar 2022 19:38:49 +0900 Subject: [PATCH] [Refactor] #1642 Separated polymorph() from influence() --- src/object-use/quaff/quaff-effects.cpp | 40 +++++++++++++++++++++------------- src/object-use/quaff/quaff-effects.h | 1 + 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/object-use/quaff/quaff-effects.cpp b/src/object-use/quaff/quaff-effects.cpp index 7589293e4..96d41a1de 100644 --- a/src/object-use/quaff/quaff-effects.cpp +++ b/src/object-use/quaff/quaff-effects.cpp @@ -445,21 +445,7 @@ bool QuaffEffects::influence(const ObjectType &o_ref) ident = true; break; case SV_POTION_POLYMORPH: - if (this->player_ptr->muta.any() && one_in_(23)) { - lose_all_mutations(this->player_ptr); - break; - } - - do { - if (one_in_(2)) { - if (gain_mutation(this->player_ptr, 0)) { - ident = true; - } - } else if (lose_mutation(this->player_ptr, 0)) { - ident = true; - } - } while (!ident || one_in_(2)); - break; + return this->polymorph(); } return ident; @@ -565,3 +551,27 @@ bool QuaffEffects::detonation() (void)bss.mod_cut(5000); return true; } + +/*! + * @brief 自己変容の薬 + * @return 突然変異を得たか失ったらtrue、そのままならfalse + */ +bool QuaffEffects::polymorph() +{ + if (this->player_ptr->muta.any() && one_in_(23)) { + lose_all_mutations(this->player_ptr); + return false; + } + + auto ident = false; + do { + if (one_in_(2)) { + if (gain_mutation(this->player_ptr, 0)) { + ident = true; + } + } else if (lose_mutation(this->player_ptr, 0)) { + ident = true; + } + } while (!ident || one_in_(2)); + return ident; +} diff --git a/src/object-use/quaff/quaff-effects.h b/src/object-use/quaff/quaff-effects.h index a369213bd..0829b5bb8 100644 --- a/src/object-use/quaff/quaff-effects.h +++ b/src/object-use/quaff/quaff-effects.h @@ -15,4 +15,5 @@ private: bool booze(); bool sleep(); bool detonation(); + bool polymorph(); }; -- 2.11.0