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 "status/action-setter.h"
48 #include "system/floor-type-definition.h"
49 #include "system/grid-type-definition.h"
50 #include "system/monster-race-definition.h"
51 #include "system/monster-type-definition.h"
52 #include "system/object-type-definition.h"
53 #include "system/player-type-definition.h"
54 #include "timed-effect/player-stun.h"
55 #include "timed-effect/timed-effects.h"
56 #include "util/bit-flags-calculator.h"
57 #include "view/display-messages.h"
58 #include "wizard/wizard-messages.h"
61 * @brief プレイヤーの変異要素による打撃処理
62 * @param player_ptr プレイヤーへの参照ポインタ
63 * @param m_idx 攻撃目標となったモンスターの参照ID
64 * @param attack 変異要素による攻撃要素の種類
65 * @param fear 攻撃を受けたモンスターが恐慌状態に陥ったかを返す参照ポインタ
66 * @param mdeath 攻撃を受けたモンスターが死亡したかを返す参照ポインタ
68 static void natural_attack(PlayerType *player_ptr, MONSTER_IDX m_idx, PlayerMutationType attack, bool *fear, bool *mdeath)
71 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
72 auto *r_ptr = &r_info[m_ptr->r_idx];
74 int dice_num, dice_side;
77 case PlayerMutationType::SCOR_TAIL:
81 atk_desc = _("尻尾", "tail");
83 case PlayerMutationType::HORNS:
87 atk_desc = _("角", "horns");
89 case PlayerMutationType::BEAK:
93 atk_desc = _("クチバシ", "beak");
95 case PlayerMutationType::TRUNK:
99 atk_desc = _("象の鼻", "trunk");
101 case PlayerMutationType::TENTACLES:
105 atk_desc = _("触手", "tentacles");
108 dice_num = dice_side = n_weight = 1;
109 atk_desc = _("未定義の部位", "undefined body part");
112 GAME_TEXT m_name[MAX_NLEN];
113 monster_desc(player_ptr, m_name, m_ptr, 0);
115 int bonus = player_ptr->to_h_m + (player_ptr->lev * 6 / 5);
116 int chance = (player_ptr->skill_thn + (bonus * BTH_PLUS_ADJ));
118 bool is_hit = (r_ptr->kind_flags.has_not(MonsterKindType::QUANTUM)) || !randint0(2);
119 is_hit &= test_hit_norm(player_ptr, chance, r_ptr->ac, m_ptr->ml);
122 msg_format(_("ミス! %sにかわされた。", "You miss %s."), m_name);
127 msg_format(_("%sを%sで攻撃した。", "You hit %s with your %s."), m_name, atk_desc);
129 int k = damroll(dice_num, dice_side);
130 k = critical_norm(player_ptr, n_weight, bonus, k, (int16_t)bonus, HISSATSU_NONE);
131 k += player_ptr->to_d_m;
135 k = mon_damage_mod(player_ptr, m_ptr, k, false);
136 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,
137 m_ptr->maxhp, m_ptr->max_maxhp);
139 anger_monster(player_ptr, m_ptr);
142 case PlayerMutationType::SCOR_TAIL:
143 project(player_ptr, 0, 0, m_ptr->fy, m_ptr->fx, k, AttributeType::POIS, PROJECT_KILL);
144 *mdeath = (m_ptr->r_idx == 0);
146 case PlayerMutationType::HORNS:
147 case PlayerMutationType::BEAK:
148 case PlayerMutationType::TRUNK:
149 case PlayerMutationType::TENTACLES:
151 MonsterDamageProcessor mdp(player_ptr, m_idx, k, fear, AttributeType::ATTACK);
152 *mdeath = mdp.mon_take_hit(nullptr);
157 touch_zap_player(m_ptr, player_ptr);
161 * @brief プレイヤーの打撃処理メインルーチン
164 * @param mode 発動中の剣術ID
165 * @return 実際に攻撃処理が行われた場合TRUEを返す。
167 * If no "weapon" is available, then "punch" the monster one time.
169 bool do_cmd_attack(PlayerType *player_ptr, POSITION y, POSITION x, combat_options mode)
171 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
172 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[g_ptr->m_idx];
173 auto *r_ptr = &r_info[m_ptr->r_idx];
174 GAME_TEXT m_name[MAX_NLEN];
176 const std::initializer_list<PlayerMutationType> mutation_attack_methods = { PlayerMutationType::HORNS, PlayerMutationType::BEAK, PlayerMutationType::SCOR_TAIL, PlayerMutationType::TRUNK, PlayerMutationType::TENTACLES };
178 disturb(player_ptr, false, true);
180 PlayerEnergy(player_ptr).set_player_turn_energy(100);
182 if (!can_attack_with_main_hand(player_ptr) && !can_attack_with_sub_hand(player_ptr) && player_ptr->muta.has_none_of(mutation_attack_methods)) {
183 msg_format(_("%s攻撃できない。", "You cannot attack."), (empty_hands(player_ptr, false) == EMPTY_HAND_NONE) ? _("両手がふさがって", "") : "");
187 monster_desc(player_ptr, m_name, m_ptr, 0);
190 if (!player_ptr->hallucinated)
191 monster_race_track(player_ptr, m_ptr->ap_r_idx);
193 health_track(player_ptr, g_ptr->m_idx);
196 auto effects = player_ptr->effects();
197 auto is_stunned = effects->stun()->is_stunned();
198 if (any_bits(r_ptr->flags1, RF1_FEMALE) && !(is_stunned || player_ptr->confused || player_ptr->hallucinated || !m_ptr->ml)) {
199 if ((player_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_ZANTETSU) || (player_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_ZANTETSU)) {
200 msg_print(_("拙者、おなごは斬れぬ!", "I can not attack women!"));
205 if (d_info[player_ptr->dungeon_idx].flags.has(DungeonFeatureType::NO_MELEE)) {
206 msg_print(_("なぜか攻撃することができない。", "Something prevents you from attacking."));
210 bool stormbringer = false;
211 if (!is_hostile(m_ptr) && !(is_stunned || player_ptr->confused || player_ptr->hallucinated || is_shero(player_ptr) || !m_ptr->ml)) {
212 if (player_ptr->inventory_list[INVEN_MAIN_HAND].name1 == ART_STORMBRINGER)
214 if (player_ptr->inventory_list[INVEN_SUB_HAND].name1 == ART_STORMBRINGER)
217 msg_format(_("黒い刃は強欲に%sを攻撃した!", "Your black blade greedily attacks %s!"), m_name);
218 chg_virtue(player_ptr, V_INDIVIDUALISM, 1);
219 chg_virtue(player_ptr, V_HONOUR, -1);
220 chg_virtue(player_ptr, V_JUSTICE, -1);
221 chg_virtue(player_ptr, V_COMPASSION, -1);
222 } else if (!PlayerClass(player_ptr).equals(PlayerClassType::BERSERKER)) {
223 if (get_check(_("本当に攻撃しますか?", "Really hit it? "))) {
224 chg_virtue(player_ptr, V_INDIVIDUALISM, 1);
225 chg_virtue(player_ptr, V_HONOUR, -1);
226 chg_virtue(player_ptr, V_JUSTICE, -1);
227 chg_virtue(player_ptr, V_COMPASSION, -1);
229 msg_format(_("%sを攻撃するのを止めた。", "You stop to avoid hitting %s."), m_name);
235 if (player_ptr->afraid) {
237 msg_format(_("恐くて%sを攻撃できない!", "You are too afraid to attack %s!"), m_name);
239 msg_format(_("そっちには何か恐いものがいる!", "There is something scary in your way!"));
241 (void)set_monster_csleep(player_ptr, g_ptr->m_idx, 0);
245 if (monster_csleep_remaining(m_ptr)) {
246 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5))
247 chg_virtue(player_ptr, V_COMPASSION, -1);
248 if (r_ptr->kind_flags.has_not(MonsterKindType::EVIL) || one_in_(5))
249 chg_virtue(player_ptr, V_HONOUR, -1);
252 if (can_attack_with_main_hand(player_ptr) && can_attack_with_sub_hand(player_ptr)) {
253 if (((player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON] - 1000) / 200) < r_ptr->level) {
254 PlayerSkill(player_ptr).gain_two_weapon_skill_exp();
258 if (player_ptr->riding) {
259 PlayerSkill(player_ptr).gain_riding_skill_exp_on_melee_attack(r_ptr);
262 player_ptr->riding_t_m_idx = g_ptr->m_idx;
265 if (can_attack_with_main_hand(player_ptr))
266 exe_player_attack_to_monster(player_ptr, y, x, &fear, &mdeath, 0, mode);
267 if (can_attack_with_sub_hand(player_ptr) && !mdeath)
268 exe_player_attack_to_monster(player_ptr, y, x, &fear, &mdeath, 1, mode);
271 for (auto m : mutation_attack_methods) {
272 if (player_ptr->muta.has(m) && !mdeath) {
273 natural_attack(player_ptr, g_ptr->m_idx, m, &fear, &mdeath);
278 if (fear && m_ptr->ml && !mdeath) {
280 msg_format(_("%^sは恐怖して逃げ出した!", "%^s flees in terror!"), m_name);
283 if (PlayerClass(player_ptr).samurai_stance_is(SamuraiStanceType::IAI) && ((mode != HISSATSU_IAI) || mdeath)) {
284 set_action(player_ptr, ACTION_NONE);