OSDN Git Service

[Refactor] #2523 PlayerType::blind をPlayerBlindnessの呼び出しに差し替えた
[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-result.h"
13 #include "mspell/mspell-util.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 "timed-effect/player-blindness.h"
22 #include "timed-effect/timed-effects.h"
23 #include "view/display-messages.h"
24 #include "world/world.h"
25 #ifdef JP
26 #else
27 #include "monster/monster-description-types.h"
28 #endif
29
30 #define RF4_SPELL_SIZE 32
31 #define RF5_SPELL_SIZE 32
32 #define RF6_SPELL_SIZE 32
33
34 static bool try_melee_spell(PlayerType *player_ptr, melee_spell_type *ms_ptr)
35 {
36     if (spell_is_inate(ms_ptr->thrown_spell) || (!ms_ptr->in_no_magic_dungeon && (!monster_stunned_remaining(ms_ptr->m_ptr) || one_in_(2)))) {
37         return false;
38     }
39
40     disturb(player_ptr, true, true);
41     if (ms_ptr->see_m) {
42         msg_format(_("%^sは呪文を唱えようとしたが失敗した。", "%^s tries to cast a spell, but fails."), ms_ptr->m_name);
43     }
44
45     return true;
46 }
47
48 static bool disturb_melee_spell(PlayerType *player_ptr, melee_spell_type *ms_ptr)
49 {
50     if (spell_is_inate(ms_ptr->thrown_spell) || !SpellHex(player_ptr).check_hex_barrier(ms_ptr->m_idx, HEX_ANTI_MAGIC)) {
51         return false;
52     }
53
54     if (ms_ptr->see_m) {
55         msg_format(_("反魔法バリアが%^sの呪文をかき消した。", "Anti magic barrier cancels the spell which %^s casts."), ms_ptr->m_name);
56     }
57
58     return true;
59 }
60
61 static void process_special_melee_spell(PlayerType *player_ptr, melee_spell_type *ms_ptr)
62 {
63     PlayerClass pc(player_ptr);
64     bool is_special_magic = ms_ptr->m_ptr->ml;
65     is_special_magic &= ms_ptr->maneable;
66     is_special_magic &= w_ptr->timewalk_m_idx == 0;
67     is_special_magic &= !player_ptr->effects()->blindness()->is_blind();
68     is_special_magic &= pc.equals(PlayerClassType::IMITATOR);
69     is_special_magic &= ms_ptr->thrown_spell != MonsterAbilityType::SPECIAL;
70     if (!is_special_magic) {
71         return;
72     }
73
74     auto mane_data = pc.get_specific_data<mane_data_type>();
75
76     if (mane_data->mane_list.size() == MAX_MANE) {
77         mane_data->mane_list.pop_front();
78     }
79
80     mane_data->mane_list.push_back({ ms_ptr->thrown_spell, ms_ptr->dam });
81     mane_data->new_mane = true;
82
83     player_ptr->redraw |= PR_IMITATION;
84 }
85
86 static void process_rememberance(melee_spell_type *ms_ptr)
87 {
88     if (!ms_ptr->can_remember) {
89         return;
90     }
91
92     ms_ptr->r_ptr->r_ability_flags.set(ms_ptr->thrown_spell);
93
94     if (ms_ptr->r_ptr->r_cast_spell < MAX_UCHAR) {
95         ms_ptr->r_ptr->r_cast_spell++;
96     }
97 }
98
99 static void describe_melee_spell(PlayerType *player_ptr, melee_spell_type *ms_ptr)
100 {
101     /* Get the monster name (or "it") */
102     monster_desc(player_ptr, ms_ptr->m_name, ms_ptr->m_ptr, 0x00);
103 #ifdef JP
104 #else
105     /* Get the monster possessive ("his"/"her"/"its") */
106     monster_desc(player_ptr, ms_ptr->m_poss, ms_ptr->m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE);
107 #endif
108
109     /* Get the target's name (or "it") */
110     GAME_TEXT t_name[160];
111     monster_desc(player_ptr, t_name, ms_ptr->t_ptr, 0x00);
112 }
113
114 /*!
115  * @brief モンスターが敵モンスターに特殊能力を使う処理のメインルーチン /
116  * Monster tries to 'cast a spell' (or breath, etc) at another monster.
117  * @param player_ptr プレイヤーへの参照ポインタ
118  * @param m_idx 術者のモンスターID
119  * @return 実際に特殊能力を使った場合TRUEを返す
120  * @details
121  * The player is only disturbed if able to be affected by the spell.
122  */
123 bool monst_spell_monst(PlayerType *player_ptr, MONSTER_IDX m_idx)
124 {
125     melee_spell_type tmp_ms;
126     melee_spell_type *ms_ptr = initialize_melee_spell_type(player_ptr, &tmp_ms, m_idx);
127     if (!check_melee_spell_set(player_ptr, ms_ptr)) {
128         return false;
129     }
130
131     describe_melee_spell(player_ptr, ms_ptr);
132     ms_ptr->thrown_spell = ms_ptr->spells[randint0(ms_ptr->spells.size())];
133     if (player_ptr->riding && (m_idx == player_ptr->riding)) {
134         disturb(player_ptr, true, true);
135     }
136
137     if (try_melee_spell(player_ptr, ms_ptr) || disturb_melee_spell(player_ptr, ms_ptr)) {
138         return true;
139     }
140
141     ms_ptr->can_remember = is_original_ap_and_seen(player_ptr, ms_ptr->m_ptr);
142     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);
143     if (!res.valid) {
144         return false;
145     }
146
147     ms_ptr->dam = res.dam;
148     process_special_melee_spell(player_ptr, ms_ptr);
149     process_rememberance(ms_ptr);
150     if (player_ptr->is_dead && (ms_ptr->r_ptr->r_deaths < MAX_SHORT) && !player_ptr->current_floor_ptr->inside_arena) {
151         ms_ptr->r_ptr->r_deaths++;
152     }
153
154     return true;
155 }