2 * @brief スピード等のステータスに影響のある魔法の処理
7 #include "spell/spells-status.h"
8 #include "avatar/avatar.h"
9 #include "cmd-action/cmd-spell.h"
10 #include "cmd-item/cmd-magiceat.h"
11 #include "core/player-redraw-types.h"
12 #include "core/player-update-types.h"
13 #include "core/stuff-handler.h"
14 #include "core/window-redrawer.h"
15 #include "effect/attribute-types.h"
16 #include "effect/effect-characteristics.h"
17 #include "flavor/flavor-describer.h"
18 #include "flavor/object-flavor-types.h"
19 #include "floor/cave.h"
20 #include "floor/floor-object.h"
21 #include "floor/geometry.h"
22 #include "grid/feature-flag-types.h"
23 #include "hpmp/hp-mp-processor.h"
24 #include "inventory/inventory-object.h"
25 #include "inventory/inventory-slot-types.h"
26 #include "main/sound-definitions-table.h"
27 #include "main/sound-of-music.h"
28 #include "mind/mind-force-trainer.h"
29 #include "monster/monster-describer.h"
30 #include "object/object-kind-hook.h"
31 #include "player-base/player-class.h"
32 #include "player-info/class-info.h"
33 #include "player-info/magic-eater-data-type.h"
34 #include "player-status/player-energy.h"
35 #include "player/attack-defense-types.h"
36 #include "spell-kind/spells-launcher.h"
37 #include "spell-kind/spells-teleport.h"
38 #include "spell-kind/spells-world.h"
39 #include "status/action-setter.h"
40 #include "status/bad-status-setter.h"
41 #include "status/base-status.h"
42 #include "status/body-improvement.h"
43 #include "status/buff-setter.h"
44 #include "status/experience.h"
45 #include "status/shape-changer.h"
46 #include "status/sight-setter.h"
47 #include "system/baseitem-info.h"
48 #include "system/floor-type-definition.h"
49 #include "system/grid-type-definition.h"
50 #include "system/item-entity.h"
51 #include "system/monster-entity.h"
52 #include "system/player-type-definition.h"
53 #include "target/target-getter.h"
54 #include "timed-effect/player-acceleration.h"
55 #include "timed-effect/player-cut.h"
56 #include "timed-effect/timed-effects.h"
57 #include "util/bit-flags-calculator.h"
58 #include "view/display-messages.h"
62 * @param player_ptr プレイヤーへの参照ポインタ
63 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
65 * @return 作用が実際にあった場合TRUEを返す
67 bool heal_monster(PlayerType *player_ptr, DIRECTION dir, int dam)
69 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
70 return project_hook(player_ptr, AttributeType::OLD_HEAL, dir, dam, flg);
75 * @param player_ptr プレイヤーへの参照ポインタ
76 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
78 * @return 作用が実際にあった場合TRUEを返す
80 bool speed_monster(PlayerType *player_ptr, DIRECTION dir, int power)
82 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
83 return project_hook(player_ptr, AttributeType::OLD_SPEED, dir, power, flg);
88 * @param player_ptr プレイヤーへの参照ポインタ
89 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
91 * @return 作用が実際にあった場合TRUEを返す
93 bool slow_monster(PlayerType *player_ptr, DIRECTION dir, int power)
95 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
96 return project_hook(player_ptr, AttributeType::OLD_SLOW, dir, power, flg);
101 * @param player_ptr プレイヤーへの参照ポインタ
102 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
104 * @return 作用が実際にあった場合TRUEを返す
106 bool sleep_monster(PlayerType *player_ptr, DIRECTION dir, int power)
108 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
109 return project_hook(player_ptr, AttributeType::OLD_SLEEP, dir, power, flg);
113 * @brief モンスター拘束(STASIS)処理
114 * @param player_ptr プレイヤーへの参照ポインタ
115 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
116 * @return 作用が実際にあった場合TRUEを返す
117 * @details 威力はプレイヤーレベル*2に固定
119 bool stasis_monster(PlayerType *player_ptr, DIRECTION dir)
121 return fire_ball_hide(player_ptr, AttributeType::STASIS, dir, player_ptr->lev * 2, 0);
125 * @brief 邪悪なモンスター拘束(STASIS)処理
126 * @param player_ptr プレイヤーへの参照ポインタ
127 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
128 * @return 作用が実際にあった場合TRUEを返す
129 * @details 威力はプレイヤーレベル*2に固定
131 bool stasis_evil(PlayerType *player_ptr, DIRECTION dir)
133 return fire_ball_hide(player_ptr, AttributeType::STASIS_EVIL, dir, player_ptr->lev * 2, 0);
138 * @param player_ptr プレイヤーへの参照ポインタ
139 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
140 * @param plev プレイヤーレベル(=効力)
141 * @return 作用が実際にあった場合TRUEを返す
143 bool confuse_monster(PlayerType *player_ptr, DIRECTION dir, PLAYER_LEVEL plev)
145 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
146 return project_hook(player_ptr, AttributeType::OLD_CONF, dir, plev, flg);
151 * @param player_ptr プレイヤーへの参照ポインタ
152 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
153 * @param plev プレイヤーレベル(=効力)
154 * @return 作用が実際にあった場合TRUEを返す
156 bool stun_monster(PlayerType *player_ptr, DIRECTION dir, PLAYER_LEVEL plev)
158 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
159 return project_hook(player_ptr, AttributeType::STUN, dir, plev, flg);
164 * @param player_ptr プレイヤーへの参照ポインタ
165 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
167 * @return 作用が実際にあった場合TRUEを返す
169 bool poly_monster(PlayerType *player_ptr, DIRECTION dir, int power)
171 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
172 bool tester = (project_hook(player_ptr, AttributeType::OLD_POLY, dir, power, flg));
174 chg_virtue(player_ptr, Virtue::CHANCE, 1);
181 * @param player_ptr プレイヤーへの参照ポインタ
182 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
183 * @return 作用が実際にあった場合TRUEを返す
185 bool clone_monster(PlayerType *player_ptr, DIRECTION dir)
187 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
188 return project_hook(player_ptr, AttributeType::OLD_CLONE, dir, 0, flg);
193 * @param player_ptr プレイヤーへの参照ポインタ
194 * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
195 * @param plev プレイヤーレベル(=効力)
196 * @return 作用が実際にあった場合TRUEを返す
198 bool fear_monster(PlayerType *player_ptr, DIRECTION dir, PLAYER_LEVEL plev)
200 BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
201 return project_hook(player_ptr, AttributeType::TURN_ALL, dir, plev, flg);
204 bool time_walk(PlayerType *player_ptr)
206 if (player_ptr->timewalk) {
207 msg_print(_("既に時は止まっている。", "Time is already stopped."));
211 player_ptr->timewalk = true;
212 msg_print(_("「時よ!」", "You yell 'Time!'"));
213 // msg_print(_("「『ザ・ワールド』!時は止まった!」", "You yell 'The World! Time has stopped!'"));
216 player_ptr->energy_need -= 1000 + (100 + player_ptr->csp - 50) * TURNS_PER_TICK / 10;
217 player_ptr->redraw |= (PR_MAP);
218 player_ptr->update |= (PU_MONSTER_STATUSES);
219 player_ptr->window_flags |= (PW_OVERHEAD | PW_DUNGEON);
220 handle_stuff(player_ptr);
225 * @brief プレイヤーのヒットダイスを振る / Role Hitpoints
226 * @param player_ptr プレイヤーへの参照ポインタ
227 * @param options スペル共通オプション
229 void roll_hitdice(PlayerType *player_ptr, spell_operation options)
231 int min_value = player_ptr->hitdie + ((PY_MAX_LEVEL + 2) * (player_ptr->hitdie + 1)) * 3 / 8;
232 int max_value = player_ptr->hitdie + ((PY_MAX_LEVEL + 2) * (player_ptr->hitdie + 1)) * 5 / 8;
236 /* Pre-calculate level 1 hitdice */
237 player_ptr->player_hp[0] = (int)player_ptr->hitdie;
239 for (int i = 1; i < 4; i++) {
240 player_ptr->player_hp[0] += randint1(player_ptr->hitdie);
243 /* Roll the hitpoint values */
244 for (int i = 1; i < PY_MAX_LEVEL; i++) {
245 player_ptr->player_hp[i] = player_ptr->player_hp[i - 1] + randint1(player_ptr->hitdie);
248 /* Require "valid" hitpoints at highest level */
249 if ((player_ptr->player_hp[PY_MAX_LEVEL - 1] >= min_value) && (player_ptr->player_hp[PY_MAX_LEVEL - 1] <= max_value)) {
254 player_ptr->knowledge &= ~(KNOW_HPRATE);
256 auto percent = (player_ptr->player_hp[PY_MAX_LEVEL - 1] * 200) / (2 * player_ptr->hitdie + ((PY_MAX_LEVEL - 1 + 3) * (player_ptr->hitdie + 1)));
258 /* Update and redraw hitpoints */
259 player_ptr->update |= (PU_HP);
260 player_ptr->redraw |= (PR_HP);
261 player_ptr->window_flags |= (PW_PLAYER);
263 if (!(options & SPOP_NO_UPDATE)) {
264 handle_stuff(player_ptr);
267 if (!(options & SPOP_DISPLAY_MES)) {
271 if (options & SPOP_DEBUG) {
272 msg_format(_("現在の体力ランクは %d/100 です。", "Your life rate is %d/100 now."), percent);
273 player_ptr->knowledge |= KNOW_HPRATE;
277 msg_print(_("体力ランクが変わった。", "Life rate has changed."));
280 bool life_stream(PlayerType *player_ptr, bool message, bool virtue_change)
283 chg_virtue(player_ptr, Virtue::VITALITY, 1);
284 chg_virtue(player_ptr, Virtue::UNLIFE, -5);
288 msg_print(_("体中に生命力が満ちあふれてきた!", "You feel life flow through your body!"));
291 restore_level(player_ptr);
292 BadStatusSetter bss(player_ptr);
293 (void)bss.set_poison(0);
294 (void)bss.set_blindness(0);
295 (void)bss.set_confusion(0);
296 (void)bss.hallucination(0);
297 (void)bss.set_stun(0);
298 (void)bss.set_cut(0);
299 (void)bss.set_paralysis(0);
300 (void)restore_all_status(player_ptr);
301 (void)set_shero(player_ptr, 0, true);
302 handle_stuff(player_ptr);
303 hp_player(player_ptr, 5000);
308 bool heroism(PlayerType *player_ptr, int base)
311 if (BadStatusSetter(player_ptr).set_fear(0)) {
315 if (set_hero(player_ptr, player_ptr->hero + randint1(base) + base, false)) {
319 if (hp_player(player_ptr, 10)) {
326 bool berserk(PlayerType *player_ptr, int base)
329 if (BadStatusSetter(player_ptr).set_fear(0)) {
333 if (set_shero(player_ptr, player_ptr->shero + randint1(base) + base, false)) {
337 if (hp_player(player_ptr, 30)) {
344 bool cure_light_wounds(PlayerType *player_ptr, DICE_NUMBER dice, DICE_SID sides)
347 if (hp_player(player_ptr, damroll(dice, sides))) {
351 BadStatusSetter bss(player_ptr);
352 if (bss.set_blindness(0)) {
356 if (bss.mod_cut(-10)) {
360 if (set_shero(player_ptr, 0, true)) {
367 bool cure_serious_wounds(PlayerType *player_ptr, DICE_NUMBER dice, DICE_SID sides)
370 if (hp_player(player_ptr, damroll(dice, sides))) {
374 BadStatusSetter bss(player_ptr);
375 if (bss.set_blindness(0)) {
379 if (bss.set_confusion(0)) {
383 if (bss.set_cut((player_ptr->effects()->cut()->current() / 2) - 50)) {
387 if (set_shero(player_ptr, 0, true)) {
394 bool cure_critical_wounds(PlayerType *player_ptr, int pow)
397 if (hp_player(player_ptr, pow)) {
401 BadStatusSetter bss(player_ptr);
402 if (bss.set_blindness(0)) {
406 if (bss.set_confusion(0)) {
410 if (bss.set_poison(0)) {
414 if (bss.set_stun(0)) {
418 if (bss.set_cut(0)) {
422 if (set_shero(player_ptr, 0, true)) {
429 bool true_healing(PlayerType *player_ptr, int pow)
432 if (hp_player(player_ptr, pow)) {
436 BadStatusSetter bss(player_ptr);
437 if (bss.set_blindness(0)) {
441 if (bss.set_confusion(0)) {
445 if (bss.set_poison(0)) {
449 if (bss.set_stun(0)) {
453 if (bss.set_cut(0)) {
457 if (bss.hallucination(0)) {
464 bool restore_mana(PlayerType *player_ptr, bool magic_eater)
466 if (PlayerClass(player_ptr).equals(PlayerClassType::MAGIC_EATER) && magic_eater) {
467 // 魔力復活による、魔道具術師の取り込んだ魔法の回復量
468 // 取り込み数が10回未満: 3 回分回復
469 // 取り込み数が10回以上: 取り込み回数/3 回分回復
470 auto magic_eater_data = PlayerClass(player_ptr).get_specific_data<magic_eater_data_type>();
471 for (auto tval : { ItemKindType::STAFF, ItemKindType::WAND }) {
472 for (auto &item : magic_eater_data->get_item_group(tval)) {
473 item.charge += (item.count < 10) ? EATER_CHARGE * 3 : item.count * EATER_CHARGE / 3;
474 item.charge = std::min(item.charge, item.count * EATER_CHARGE);
479 for (auto &item : magic_eater_data->get_item_group(ItemKindType::ROD)) {
480 const auto bi_id = lookup_baseitem_id({ ItemKindType::ROD, sval });
481 item.charge -= ((item.count < 10) ? EATER_ROD_CHARGE * 3 : item.count * EATER_ROD_CHARGE / 3) * baseitems_info[bi_id].pval;
482 item.charge = std::max(item.charge, 0);
486 msg_print(_("頭がハッキリとした。", "You feel your head clear."));
487 player_ptr->window_flags |= (PW_PLAYER);
491 if (player_ptr->csp >= player_ptr->msp) {
495 player_ptr->csp = player_ptr->msp;
496 player_ptr->csp_frac = 0;
497 msg_print(_("頭がハッキリとした。", "You feel your head clear."));
498 player_ptr->redraw |= (PR_MP);
499 player_ptr->window_flags |= (PW_PLAYER);
500 player_ptr->window_flags |= (PW_SPELL);
504 bool restore_all_status(PlayerType *player_ptr)
507 if (do_res_stat(player_ptr, A_STR)) {
510 if (do_res_stat(player_ptr, A_INT)) {
513 if (do_res_stat(player_ptr, A_WIS)) {
516 if (do_res_stat(player_ptr, A_DEX)) {
519 if (do_res_stat(player_ptr, A_CON)) {
522 if (do_res_stat(player_ptr, A_CHR)) {
528 bool fishing(PlayerType *player_ptr)
531 if (!get_direction(player_ptr, &dir, false, false)) {
534 POSITION y = player_ptr->y + ddy[dir];
535 POSITION x = player_ptr->x + ddx[dir];
536 player_ptr->fishing_dir = dir;
537 auto *floor_ptr = player_ptr->current_floor_ptr;
538 if (!cave_has_flag_bold(floor_ptr, y, x, TerrainCharacteristics::WATER)) {
539 msg_print(_("そこは水辺ではない。", "You can't fish here."));
543 if (floor_ptr->grid_array[y][x].m_idx) {
544 const auto m_name = monster_desc(player_ptr, &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx], 0);
545 msg_format(_("%sが邪魔だ!", "%s^ is standing in your way."), m_name.data());
546 PlayerEnergy(player_ptr).reset_player_turn();
550 set_action(player_ptr, ACTION_FISH);
551 player_ptr->redraw |= (PR_ACTION);
556 * @brief 装備を脱ぎ捨てて小宇宙を燃やす
557 * @param player_ptr プレイヤー情報への参照ポインタ
558 * @param o_ptr_ptr 脱ぐ装備品への参照ポインタのポインタ
559 * @return 脱いだらTRUE、脱がなかったらFALSE
561 * 脱いで落とした装備にtimeoutを設定するために装備品のアドレスを返す。
563 bool cosmic_cast_off(PlayerType *player_ptr, ItemEntity **o_ptr_ptr)
565 auto *o_ptr = (*o_ptr_ptr);
567 /* Cast off activated item */
569 for (slot = INVEN_MAIN_HAND; slot <= INVEN_FEET; slot++) {
570 if (o_ptr == &player_ptr->inventory_list[slot]) {
575 if (slot > INVEN_FEET) {
580 (&forge)->copy_from(o_ptr);
581 inven_item_increase(player_ptr, slot, (0 - o_ptr->number));
582 inven_item_optimize(player_ptr, slot);
584 OBJECT_IDX old_o_idx = drop_near(player_ptr, &forge, 0, player_ptr->y, player_ptr->x);
585 *o_ptr_ptr = &player_ptr->current_floor_ptr->o_list[old_o_idx];
587 const auto item_name = describe_flavor(player_ptr, &forge, OD_NAME_ONLY);
588 msg_format(_("%sを脱ぎ捨てた。", "You cast off %s."), item_name.data());
589 sound(SOUND_TAKE_OFF);
592 msg_print(_("「燃え上がれ俺の小宇宙!」", "You say, 'Burn up my cosmo!"));
593 TIME_EFFECT t = 20 + randint1(20);
594 BadStatusSetter bss(player_ptr);
595 (void)bss.mod_blindness(t);
596 (void)bss.set_fear(0);
597 (void)set_tim_esp(player_ptr, player_ptr->tim_esp + t, false);
598 (void)set_tim_regen(player_ptr, player_ptr->tim_regen + t, false);
599 (void)set_hero(player_ptr, player_ptr->hero + t, false);
600 (void)set_blessed(player_ptr, player_ptr->blessed + t, false);
601 (void)mod_acceleration(player_ptr, t, false);
602 (void)set_shero(player_ptr, player_ptr->shero + t, false);
603 if (PlayerClass(player_ptr).equals(PlayerClassType::FORCETRAINER)) {
604 set_current_ki(player_ptr, true, player_ptr->lev * 5 + 190);
605 msg_print(_("気が爆発寸前になった。", "Your force absorbs the explosion."));
612 * @brief プレイヤーの因果混乱処理 / Apply Nexus
613 * @param m_ptr 因果混乱をプレイヤーに与えたモンスターの情報参照ポインタ
615 void apply_nexus(MonsterEntity *m_ptr, PlayerType *player_ptr)
617 switch (randint1(7)) {
621 teleport_player(player_ptr, 200, TELEPORT_PASSIVE);
627 teleport_player_to(player_ptr, m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
632 if (randint0(100) < player_ptr->skill_sav) {
633 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
637 teleport_level(player_ptr, 0);
642 if (randint0(100) < player_ptr->skill_sav) {
643 msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
647 msg_print(_("体がねじれ始めた...", "Your body starts to scramble..."));
648 status_shuffle(player_ptr);
655 * @brief プレイヤーのステータスシャッフル処理
656 * @param player_ptr プレイヤーへの参照ポインタ
658 void status_shuffle(PlayerType *player_ptr)
660 /* Pick a pair of stats */
661 int i = randint0(A_MAX);
664 //!< @todo ここのループは一体何をしている?
665 for (j = i; j == i; j = randint0(A_MAX)) { /* loop */
669 const auto max1 = player_ptr->stat_max[i];
670 const auto cur1 = player_ptr->stat_cur[i];
671 const auto max2 = player_ptr->stat_max[j];
672 const auto cur2 = player_ptr->stat_cur[j];
674 player_ptr->stat_max[i] = max2;
675 player_ptr->stat_cur[i] = cur2;
676 player_ptr->stat_max[j] = max1;
677 player_ptr->stat_cur[j] = cur1;
679 for (int k = 0; k < A_MAX; k++) {
680 if (player_ptr->stat_max[k] > player_ptr->stat_max_max[k]) {
681 player_ptr->stat_max[k] = player_ptr->stat_max_max[k];
683 if (player_ptr->stat_cur[k] > player_ptr->stat_max_max[k]) {
684 player_ptr->stat_cur[k] = player_ptr->stat_max_max[k];
688 player_ptr->update |= PU_BONUS;