7 #include "cmd-action/cmd-attack.h"
8 #include "artifact/fixed-art-types.h"
9 #include "avatar/avatar.h"
10 #include "combat/attack-accuracy.h"
11 #include "combat/attack-criticality.h"
12 #include "core/asking-player.h"
13 #include "core/disturbance.h"
14 #include "core/player-update-types.h"
15 #include "core/stuff-handler.h"
16 #include "dungeon/dungeon-flag-types.h"
17 #include "dungeon/dungeon.h"
18 #include "effect/effect-characteristics.h"
19 #include "effect/effect-processor.h"
20 #include "game-option/cheat-types.h"
21 #include "inventory/inventory-slot-types.h"
22 #include "main/sound-definitions-table.h"
23 #include "main/sound-of-music.h"
24 #include "monster-race/monster-race.h"
25 #include "monster-race/race-flags1.h"
26 #include "monster-race/race-flags2.h"
27 #include "monster-race/race-flags3.h"
28 #include "monster/monster-damage.h"
29 #include "monster/monster-describer.h"
30 #include "monster/monster-info.h"
31 #include "monster/monster-status-setter.h"
32 #include "monster/monster-status.h"
33 #include "mutation/mutation-flag-types.h"
34 #include "object/item-use-flags.h"
35 #include "player-attack/player-attack.h"
36 #include "player-base/player-class.h"
37 #include "player-info/equipment-info.h"
38 #include "player-info/samurai-data-type.h"
39 #include "player-status/player-energy.h"
40 #include "player-status/player-hand-types.h"
41 #include "player/attack-defense-types.h"
42 #include "player/player-damage.h"
43 #include "player/player-skill.h"
44 #include "player/player-status-flags.h"
45 #include "player/player-status.h"
46 #include "player/special-defense-types.h"
47 #include "spell/spell-types.h"
48 #include "status/action-setter.h"
49 #include "system/floor-type-definition.h"
50 #include "system/grid-type-definition.h"
51 #include "system/monster-race-definition.h"
52 #include "system/monster-type-definition.h"
53 #include "system/object-type-definition.h"
54 #include "system/player-type-definition.h"
55 #include "timed-effect/player-stun.h"
56 #include "timed-effect/timed-effects.h"
57 #include "util/bit-flags-calculator.h"
58 #include "view/display-messages.h"
59 #include "wizard/wizard-messages.h"
62 * @brief プレイヤーの変異要素による打撃処理
63 * @param player_ptr プレイヤーへの参照ポインタ
64 * @param m_idx 攻撃目標となったモンスターの参照ID
65 * @param attack 変異要素による攻撃要素の種類
66 * @param fear 攻撃を受けたモンスターが恐慌状態に陥ったかを返す参照ポインタ
67 * @param mdeath 攻撃を受けたモンスターが死亡したかを返す参照ポインタ
69 static void natural_attack(player_type *player_ptr, MONSTER_IDX m_idx, MUTA attack, bool *fear, bool *mdeath)
72 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
73 monster_race *r_ptr = &r_info[m_ptr->r_idx];
75 int dice_num, dice_side;
82 atk_desc = _("尻尾", "tail");
88 atk_desc = _("角", "horns");
94 atk_desc = _("クチバシ", "beak");
100 atk_desc = _("象の鼻", "trunk");
102 case MUTA::TENTACLES:
106 atk_desc = _("触手", "tentacles");
109 dice_num = dice_side = n_weight = 1;
110 atk_desc = _("未定義の部位", "undefined body part");
113 GAME_TEXT m_name[MAX_NLEN];
114 monster_desc(player_ptr, m_name, m_ptr, 0);
116 int bonus = player_ptr->to_h_m + (player_ptr->lev * 6 / 5);
117 int chance = (player_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));
119 bool is_hit = ((r_ptr->flags2 & RF2_QUANTUM) == 0) || !randint0(2);
120 is_hit &= test_hit_norm(player_ptr, chance, r_ptr->ac, m_ptr->ml);
123 msg_format(_("ミス! %sにかわされた。", "You miss %s."), m_name);
128 msg_format(_("%sを%sで攻撃した。", "You hit %s with your %s."), m_name, atk_desc);
130 HIT_POINT k = damroll(dice_num, dice_side);
131 k = critical_norm(player_ptr, n_weight, bonus, k, (int16_t)bonus, HISSATSU_NONE);
132 k += player_ptr->to_d_m;
136 k = mon_damage_mod(player_ptr, m_ptr, k, false);
137 msg_format_wizard(player_ptr, CHEAT_MONSTER, _("%dのダメージを与えた。(残りHP %d/%d(%d))", "You do %d damage. (left HP %d/%d(%d))"), k, m_ptr->hp - k,
138 m_ptr->maxhp, m_ptr->max_maxhp);
140 anger_monster(player_ptr, m_ptr);
143 case MUTA::SCOR_TAIL:
144 project(player_ptr, 0, 0, m_ptr->fy, m_ptr->fx, k, GF_POIS, PROJECT_KILL);
145 *mdeath = (m_ptr->r_idx == 0);
150 case MUTA::TENTACLES:
152 MonsterDamageProcessor mdp(player_ptr, m_idx, k, fear);
153 *mdeath = mdp.mon_take_hit(nullptr);
158 touch_zap_player(m_ptr, player_ptr);
162 * @brief プレイヤーの打撃処理メインルーチン
165 * @param mode 発動中の剣術ID
166 * @return 実際に攻撃処理が行われた場合TRUEを返す。
168 * If no "weapon" is available, then "punch" the monster one time.
170 bool do_cmd_attack(player_type *player_ptr, POSITION y, POSITION x, combat_options mode)
172 grid_type *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
173 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
174 monster_race *r_ptr = &r_info[m_ptr->r_idx];
175 GAME_TEXT m_name[MAX_NLEN];
177 const std::initializer_list<MUTA> mutation_attack_methods = { MUTA::HORNS, MUTA::BEAK, MUTA::SCOR_TAIL, MUTA::TRUNK, MUTA::TENTACLES };
179 disturb(player_ptr, false, true);
181 PlayerEnergy(player_ptr).set_player_turn_energy(100);
183 if (!can_attack_with_main_hand(player_ptr) && !can_attack_with_sub_hand(player_ptr) && player_ptr->muta.has_none_of(mutation_attack_methods)) {
184 msg_format(_("%s攻撃できない。", "You cannot attack."), (empty_hands(player_ptr, false) == EMPTY_HAND_NONE) ? _("両手がふさがって", "") : "");
188 monster_desc(player_ptr, m_name, m_ptr, 0);
191 if (!player_ptr->hallucinated)
192 monster_race_track(player_ptr, m_ptr->ap_r_idx);
194 health_track(player_ptr, g_ptr->m_idx);
197 auto effects = player_ptr->effects();
198 auto is_stunned = effects->stun()->is_stunned();
199 if (any_bits(r_ptr->flags1, RF1_FEMALE) && !(is_stunned || player_ptr->confused || player_ptr->hallucinated || !m_ptr->ml)) {
200 if ((player_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_ZANTETSU) || (player_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_ZANTETSU)) {
201 msg_print(_("拙者、おなごは斬れぬ!", "I can not attack women!"));
206 if (d_info[player_ptr->dungeon_idx].flags.has(DF::NO_MELEE)) {
207 msg_print(_("なぜか攻撃することができない。", "Something prevents you from attacking."));
211 bool stormbringer = false;
212 if (!is_hostile(m_ptr) && !(is_stunned || player_ptr->confused || player_ptr->hallucinated || is_shero(player_ptr) || !m_ptr->ml)) {
213 if (player_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_STORMBRINGER)
215 if (player_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_STORMBRINGER)
218 msg_format(_("黒い刃は強欲に%sを攻撃した!", "Your black blade greedily attacks %s!"), m_name);
219 chg_virtue(player_ptr, V_INDIVIDUALISM, 1);
220 chg_virtue(player_ptr, V_HONOUR, -1);
221 chg_virtue(player_ptr, V_JUSTICE, -1);
222 chg_virtue(player_ptr, V_COMPASSION, -1);
223 } else if (player_ptr->pclass != PlayerClassType::BERSERKER) {
224 if (get_check(_("本当に攻撃しますか?", "Really hit it? "))) {
225 chg_virtue(player_ptr, V_INDIVIDUALISM, 1);
226 chg_virtue(player_ptr, V_HONOUR, -1);
227 chg_virtue(player_ptr, V_JUSTICE, -1);
228 chg_virtue(player_ptr, V_COMPASSION, -1);
230 msg_format(_("%sを攻撃するのを止めた。", "You stop to avoid hitting %s."), m_name);
236 if (player_ptr->afraid) {
238 msg_format(_("恐くて%sを攻撃できない!", "You are too afraid to attack %s!"), m_name);
240 msg_format(_("そっちには何か恐いものがいる!", "There is something scary in your way!"));
242 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);
246 if (monster_csleep_remaining(m_ptr)) {
247 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5))
248 chg_virtue(player_ptr, V_COMPASSION, -1);
249 if (!(r_ptr->flags3 & RF3_EVIL) || one_in_(5))
250 chg_virtue(player_ptr, V_HONOUR, -1);
253 if (can_attack_with_main_hand(player_ptr) && can_attack_with_sub_hand(player_ptr)) {
254 if (((player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON] - 1000) / 200) < r_ptr->level) {
255 PlayerSkill(player_ptr).gain_two_weapon_skill_exp();
259 if (player_ptr->riding) {
260 PlayerSkill(player_ptr).gain_riding_skill_exp_on_melee_attack(r_ptr);
263 player_ptr->riding_t_m_idx = g_ptr->m_idx;
266 if (can_attack_with_main_hand(player_ptr))
267 exe_player_attack_to_monster(player_ptr, y, x, &fear, &mdeath, 0, mode);
268 if (can_attack_with_sub_hand(player_ptr) && !mdeath)
269 exe_player_attack_to_monster(player_ptr, y, x, &fear, &mdeath, 1, mode);
272 for (auto m : mutation_attack_methods) {
273 if (player_ptr->muta.has(m) && !mdeath) {
274 natural_attack(player_ptr, g_ptr->m_idx, m, &fear, &mdeath);
279 if (fear && m_ptr->ml && !mdeath) {
281 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
284 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStance::IAI) && ((mode != HISSATSU_IAI) || mdeath)) {
285 set_action(player_ptr, ACTION_NONE);