OSDN Git Service

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