OSDN Git Service

[Refactor] #1752 PlayerClassTypeをenumからenum classへ変更した
[hengbandforosx/hengbandosx.git] / src / melee / melee-spell.cpp
1 #include "melee/melee-spell.h"
2 #include "core/disturbance.h"
3 #include "core/player-redraw-types.h"
4 #include "melee/melee-spell-flags-checker.h"
5 #include "melee/melee-spell-util.h"
6 #include "monster-race/monster-race.h"
7 #include "monster/monster-describer.h"
8 #include "monster/monster-info.h"
9 #include "monster/monster-status.h"
10 #include "mspell/assign-monster-spell.h"
11 #include "mspell/mspell-checker.h"
12 #include "mspell/mspell-util.h"
13 #include "mspell/mspell.h"
14 #include "player-base/player-class.h"
15 #include "player-info/mane-data-type.h"
16 #include "spell-realm/spells-hex.h"
17 #include "system/floor-type-definition.h"
18 #include "system/monster-race-definition.h"
19 #include "system/monster-type-definition.h"
20 #include "system/player-type-definition.h"
21 #include "view/display-messages.h"
22 #include "world/world.h"
23 #ifdef JP
24 #else
25 #include "monster/monster-description-types.h"
26 #endif
27
28 #define RF4_SPELL_SIZE 32
29 #define RF5_SPELL_SIZE 32
30 #define RF6_SPELL_SIZE 32
31
32 static bool try_melee_spell(player_type *player_ptr, melee_spell_type *ms_ptr)
33 {
34     if (spell_is_inate(ms_ptr->thrown_spell) || (!ms_ptr->in_no_magic_dungeon && (!monster_stunned_remaining(ms_ptr->m_ptr) || one_in_(2))))
35         return false;
36
37     disturb(player_ptr, true, true);
38     if (ms_ptr->see_m)
39         msg_format(_("%^sは呪文を唱えようとしたが失敗した。", "%^s tries to cast a spell, but fails."), ms_ptr->m_name);
40
41     return true;
42 }
43
44 static bool disturb_melee_spell(player_type *player_ptr, melee_spell_type *ms_ptr)
45 {
46     if (spell_is_inate(ms_ptr->thrown_spell) || !SpellHex(player_ptr).check_hex_barrier(ms_ptr->m_idx, HEX_ANTI_MAGIC))
47         return false;
48
49     if (ms_ptr->see_m)
50         msg_format(_("反魔法バリアが%^sの呪文をかき消した。", "Anti magic barrier cancels the spell which %^s casts."), ms_ptr->m_name);
51
52     return true;
53 }
54
55 static void process_special_melee_spell(player_type *player_ptr, melee_spell_type *ms_ptr)
56 {
57     bool is_special_magic = ms_ptr->m_ptr->ml;
58     is_special_magic &= ms_ptr->maneable;
59     is_special_magic &= w_ptr->timewalk_m_idx == 0;
60     is_special_magic &= !player_ptr->blind;
61     is_special_magic &= player_ptr->pclass == PlayerClassType::IMITATOR;
62     is_special_magic &= ms_ptr->thrown_spell != RF_ABILITY::SPECIAL;
63     if (!is_special_magic)
64         return;
65
66     auto mane_data = PlayerClass(player_ptr).get_specific_data<mane_data_type>();
67
68     if (mane_data->mane_list.size() == MAX_MANE) {
69         mane_data->mane_list.pop_front();
70     }
71
72     mane_data->mane_list.push_back({ ms_ptr->thrown_spell, ms_ptr->dam });
73     mane_data->new_mane = true;
74
75     player_ptr->redraw |= PR_IMITATION;
76 }
77
78 static void process_rememberance(melee_spell_type *ms_ptr)
79 {
80     if (!ms_ptr->can_remember)
81         return;
82
83     ms_ptr->r_ptr->r_ability_flags.set(ms_ptr->thrown_spell);
84
85     if (ms_ptr->r_ptr->r_cast_spell < MAX_UCHAR)
86         ms_ptr->r_ptr->r_cast_spell++;
87 }
88
89 static void describe_melee_spell(player_type *player_ptr, melee_spell_type *ms_ptr)
90 {
91     /* Get the monster name (or "it") */
92     monster_desc(player_ptr, ms_ptr->m_name, ms_ptr->m_ptr, 0x00);
93 #ifdef JP
94 #else
95     /* Get the monster possessive ("his"/"her"/"its") */
96     monster_desc(player_ptr, ms_ptr->m_poss, ms_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
97 #endif
98
99     /* Get the target's name (or "it") */
100     GAME_TEXT t_name[160];
101     monster_desc(player_ptr, t_name, ms_ptr->t_ptr, 0x00);
102 }
103
104 /*!
105  * @brief モンスターが敵モンスターに特殊能力を使う処理のメインルーチン /
106  * Monster tries to 'cast a spell' (or breath, etc) at another monster.
107  * @param player_ptr プレイヤーへの参照ポインタ
108  * @param m_idx 術者のモンスターID
109  * @return 実際に特殊能力を使った場合TRUEを返す
110  * @details
111  * The player is only disturbed if able to be affected by the spell.
112  */
113 bool monst_spell_monst(player_type *player_ptr, MONSTER_IDX m_idx)
114 {
115     melee_spell_type tmp_ms;
116     melee_spell_type *ms_ptr = initialize_melee_spell_type(player_ptr, &tmp_ms, m_idx);
117     if (!check_melee_spell_set(player_ptr, ms_ptr))
118         return false;
119
120     describe_melee_spell(player_ptr, ms_ptr);
121     ms_ptr->thrown_spell = ms_ptr->spells[randint0(ms_ptr->spells.size())];
122     if (player_ptr->riding && (m_idx == player_ptr->riding))
123         disturb(player_ptr, true, true);
124
125     if (try_melee_spell(player_ptr, ms_ptr) || disturb_melee_spell(player_ptr, ms_ptr))
126         return true;
127
128     ms_ptr->can_remember = is_original_ap_and_seen(player_ptr, ms_ptr->m_ptr);
129     const auto res = monspell_to_monster(player_ptr, ms_ptr->thrown_spell, ms_ptr->y, ms_ptr->x, m_idx, ms_ptr->target_idx, false);
130     if (!res.valid)
131         return false;
132
133     ms_ptr->dam = res.dam;
134     process_special_melee_spell(player_ptr, ms_ptr);
135     process_rememberance(ms_ptr);
136     if (player_ptr->is_dead && (ms_ptr->r_ptr->r_deaths < MAX_SHORT) && !player_ptr->current_floor_ptr->inside_arena)
137         ms_ptr->r_ptr->r_deaths++;
138
139     return true;
140 }