OSDN Git Service

[Refactor] struct player_type を class PlayerType に置換。
[hengbandforosx/hengbandosx.git] / src / blue-magic / blue-magic-checker.cpp
index 0b8aed8..e848794 100644 (file)
 #include "core/player-redraw-types.h"
 #include "main/sound-definitions-table.h"
 #include "main/sound-of-music.h"
-#include "mind/mind-blue-mage.h"
 #include "monster-race/race-ability-mask.h"
 #include "mspell/monster-power-table.h"
+#include "player-base/player-class.h"
+#include "player-info/bluemage-data-type.h"
 #include "player/attack-defense-types.h"
 #include "status/experience.h"
+#include "system/angband.h"
+#include "system/player-type-definition.h"
+#include "timed-effect/player-stun.h"
+#include "timed-effect/timed-effects.h"
 #include "view/display-messages.h"
 
 /*!
  * @brief 青魔法のラーニング判定と成功した場合のラーニング処理
  * @param monspell ラーニングを試みるモンスター攻撃のID
- * @return なし
  */
-void learn_spell(player_type *learner_ptr, int monspell)
+void learn_spell(PlayerType *player_ptr, MonsterAbilityType monspell)
 {
-    if (learner_ptr->action != ACTION_LEARN)
+    if (player_ptr->action != ACTION_LEARN)
         return;
-    if (monspell < 0)
+    auto bluemage_data = PlayerClass(player_ptr).get_specific_data<bluemage_data_type>();
+    if (!bluemage_data || bluemage_data->learnt_blue_magics.has(monspell))
         return;
-    if (learner_ptr->magic_num2[monspell])
-        return;
-    if (learner_ptr->confused || learner_ptr->blind || learner_ptr->image || learner_ptr->stun || learner_ptr->paralyzed)
+
+    auto effects = player_ptr->effects();
+    auto is_stunned = effects->stun()->is_stunned();
+    if (player_ptr->confused || player_ptr->blind || player_ptr->hallucinated || is_stunned || player_ptr->paralyzed)
         return;
-    if (randint1(learner_ptr->lev + 70) > monster_powers[monspell].level + 40) {
-        learner_ptr->magic_num2[monspell] = 1;
-        msg_format(_("%sを学習した!", "You have learned %s!"), monster_powers[monspell].name);
-        gain_exp(learner_ptr, monster_powers[monspell].level * monster_powers[monspell].smana);
+    const auto &monster_power = monster_powers.at(monspell);
+    if (randint1(player_ptr->lev + 70) > monster_power.level + 40) {
+        bluemage_data->learnt_blue_magics.set(monspell);
+        msg_format(_("%sを学習した!", "You have learned %s!"), monster_power.name);
+        gain_exp(player_ptr, monster_power.level * monster_power.smana);
         sound(SOUND_STUDY);
-        learner_ptr->new_mane = TRUE;
-        learner_ptr->redraw |= PR_STATE;
+        bluemage_data->new_magic_learned = true;
+        player_ptr->redraw |= PR_STATE;
     }
 }
 
 /*!
- * @brief モンスター特殊能力のフラグ配列から特定条件の魔法だけを抜き出す処理
+ * @brief モンスター特殊能力のフラグ配列から特定のタイプの能力だけを抜き出す処理
  * Extract monster spells mask for the given mode
- * @param f4 モンスター特殊能力の4番目のフラグ配列
- * @param f5 モンスター特殊能力の5番目のフラグ配列
- * @param f6 モンスター特殊能力の6番目のフラグ配列
- * @param mode 抜き出したい条件
- * @return なし
- * @todo f4, f5, f6を構造体にまとめ直す
+ * @param ability_flags モンスター特殊能力のフラグ集合
+ * @param type 抜き出したいタイプ
  */
-void set_rf_masks(EnumClassFlagGroup<RF_ABILITY> &ability_flags, blue_magic_type mode)
+void set_rf_masks(EnumClassFlagGroup<MonsterAbilityType> &ability_flags, BlueMagicType type)
 {
     ability_flags.clear();
 
-    switch (mode) {
-    case MONSPELL_TYPE_BOLT:
-        ability_flags.set(RF_ABILITY_BOLT_MASK | RF_ABILITY_BEAM_MASK).reset(RF_ABILITY::ROCKET);
+    switch (type) {
+    case BlueMagicType::BOLT:
+        ability_flags.set(RF_ABILITY_BOLT_MASK | RF_ABILITY_BEAM_MASK).reset(MonsterAbilityType::ROCKET);
         break;
 
-    case MONSPELL_TYPE_BALL:
+    case BlueMagicType::BALL:
         ability_flags.set(RF_ABILITY_BALL_MASK).reset(RF_ABILITY_BREATH_MASK);
         break;
 
-    case MONSPELL_TYPE_BREATH:
+    case BlueMagicType::BREATH:
         ability_flags.set(RF_ABILITY_BREATH_MASK);
         break;
 
-    case MONSPELL_TYPE_SUMMON:
+    case BlueMagicType::SUMMON:
         ability_flags.set(RF_ABILITY_SUMMON_MASK);
         break;
 
-    case MONSPELL_TYPE_OTHER:
+    case BlueMagicType::OTHER:
         ability_flags.set(RF_ABILITY_ATTACK_MASK);
         ability_flags.reset(RF_ABILITY_BOLT_MASK | RF_ABILITY_BEAM_MASK | RF_ABILITY_BALL_MASK | RF_ABILITY_INDIRECT_MASK);
         break;