OSDN Git Service

[Refactor] #38862 Moved spells-* to spell/
[hengband/hengband.git] / src / spell / spells-status.c
1 #include "system/angband.h"
2 #include "core/stuff-handler.h"
3 #include "util.h"
4
5 #include "cmd-magiceat.h"
6 #include "avatar.h"
7 #include "effect/effect-characteristics.h"
8 #include "object/object-flavor.h"
9 #include "player/player-status.h"
10 #include "player/player-class.h"
11 #include "spell/spells-status.h"
12 #include "spell/spells-type.h"
13 #include "monster/monster.h"
14 #include "cmd-spell.h"
15 #include "player/player-effects.h"
16 #include "object/object-kind.h"
17 #include "targeting.h"
18 #include "realm/realm-song.h"
19 #include "view/display-main-window.h"
20 #include "spell/spells2.h"
21 #include "spell/spells3.h"
22
23 /*!
24  * @brief モンスター回復処理
25  * @param caster_ptr プレーヤーへの参照ポインタ
26  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
27  * @param dam 威力
28  * @return 作用が実際にあった場合TRUEを返す
29  */
30 bool heal_monster(player_type *caster_ptr, DIRECTION dir, HIT_POINT dam)
31 {
32         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
33         return (project_hook(caster_ptr, GF_OLD_HEAL, dir, dam, flg));
34 }
35
36
37 /*!
38  * @brief モンスター加速処理
39  * @param caster_ptr プレーヤーへの参照ポインタ
40  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
41  * @param power 効力
42  * @return 作用が実際にあった場合TRUEを返す
43  */
44 bool speed_monster(player_type *caster_ptr, DIRECTION dir, int power)
45 {
46         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
47         return (project_hook(caster_ptr, GF_OLD_SPEED, dir, power, flg));
48 }
49
50
51 /*!
52  * @brief モンスター減速処理
53  * @param caster_ptr プレーヤーへの参照ポインタ
54  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
55  * @param power 効力
56  * @return 作用が実際にあった場合TRUEを返す
57  */
58 bool slow_monster(player_type *caster_ptr, DIRECTION dir, int power)
59 {
60         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
61         return (project_hook(caster_ptr, GF_OLD_SLOW, dir, power, flg));
62 }
63
64
65 /*!
66  * @brief モンスター催眠処理
67  * @param caster_ptr プレーヤーへの参照ポインタ
68  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
69  * @param power 効力
70  * @return 作用が実際にあった場合TRUEを返す
71  */
72 bool sleep_monster(player_type *caster_ptr, DIRECTION dir, int power)
73 {
74         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
75         return (project_hook(caster_ptr, GF_OLD_SLEEP, dir, power, flg));
76 }
77
78
79 /*!
80  * @brief モンスター拘束(STASIS)処理
81  * @param caster_ptr プレーヤーへの参照ポインタ
82  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
83  * @return 作用が実際にあった場合TRUEを返す
84  * @details 威力はプレイヤーレベル*2に固定
85  */
86 bool stasis_monster(player_type *caster_ptr, DIRECTION dir)
87 {
88         return (fire_ball_hide(caster_ptr, GF_STASIS, dir, caster_ptr->lev * 2, 0));
89 }
90
91
92 /*!
93  * @brief 邪悪なモンスター拘束(STASIS)処理
94  * @param caster_ptr プレーヤーへの参照ポインタ
95  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
96  * @return 作用が実際にあった場合TRUEを返す
97  * @details 威力はプレイヤーレベル*2に固定
98  */
99 bool stasis_evil(player_type *caster_ptr, DIRECTION dir)
100 {
101         return (fire_ball_hide(caster_ptr, GF_STASIS_EVIL, dir, caster_ptr->lev * 2, 0));
102 }
103
104
105 /*!
106  * @brief モンスター混乱処理
107  * @param caster_ptr プレーヤーへの参照ポインタ
108  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
109  * @param plev プレイヤーレベル(=効力)
110  * @return 作用が実際にあった場合TRUEを返す
111  */
112 bool confuse_monster(player_type *caster_ptr, DIRECTION dir, PLAYER_LEVEL plev)
113 {
114         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
115         return (project_hook(caster_ptr, GF_OLD_CONF, dir, plev, flg));
116 }
117
118
119 /*!
120  * @brief モンスター朦朧処理
121  * @param caster_ptr プレーヤーへの参照ポインタ
122  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
123  * @param plev プレイヤーレベル(=効力)
124  * @return 作用が実際にあった場合TRUEを返す
125  */
126 bool stun_monster(player_type *caster_ptr, DIRECTION dir, PLAYER_LEVEL plev)
127 {
128         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
129         return (project_hook(caster_ptr, GF_STUN, dir, plev, flg));
130 }
131
132
133 /*!
134  * @brief チェンジモンスター処理
135  * @param caster_ptr プレーヤーへの参照ポインタ
136  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
137  * @param power 効力
138  * @return 作用が実際にあった場合TRUEを返す
139  */
140 bool poly_monster(player_type *caster_ptr, DIRECTION dir, int power)
141 {
142         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
143         bool tester = (project_hook(caster_ptr, GF_OLD_POLY, dir, power, flg));
144         if (tester)
145                 chg_virtue(caster_ptr, V_CHANCE, 1);
146         return(tester);
147 }
148
149
150 /*!
151  * @brief クローンモンスター処理
152  * @param caster_ptr プレーヤーへの参照ポインタ
153  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
154  * @return 作用が実際にあった場合TRUEを返す
155  */
156 bool clone_monster(player_type *caster_ptr, DIRECTION dir)
157 {
158         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
159         return (project_hook(caster_ptr, GF_OLD_CLONE, dir, 0, flg));
160 }
161
162
163 /*!
164  * @brief モンスター恐慌処理
165  * @param caster_ptr プレーヤーへの参照ポインタ
166  * @param dir 方向(5ならばグローバル変数 target_col/target_row の座標を目標にする)
167  * @param plev プレイヤーレベル(=効力)
168  * @return 作用が実際にあった場合TRUEを返す
169  */
170 bool fear_monster(player_type *caster_ptr, DIRECTION dir, PLAYER_LEVEL plev)
171 {
172         BIT_FLAGS flg = PROJECT_STOP | PROJECT_KILL | PROJECT_REFLECTABLE;
173         return (project_hook(caster_ptr, GF_TURN_ALL, dir, plev, flg));
174 }
175
176
177 bool time_walk(player_type *creature_ptr)
178 {
179         if (creature_ptr->timewalk)
180         {
181                 msg_print(_("既に時は止まっている。", "Time is already stopped."));
182                 return FALSE;
183         }
184
185         creature_ptr->timewalk = TRUE;
186         msg_print(_("「時よ!」", "You yell 'Time!'"));
187 //      msg_print(_("「『ザ・ワールド』!時は止まった!」", "You yell 'The World! Time has stopped!'"));
188         msg_print(NULL);
189
190         creature_ptr->energy_need -= 1000 + (100 + creature_ptr->csp - 50)*TURNS_PER_TICK / 10;
191         creature_ptr->redraw |= (PR_MAP);
192         creature_ptr->update |= (PU_MONSTERS);
193         creature_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
194         handle_stuff(creature_ptr);
195         return TRUE;
196 }
197
198
199 /*!
200  * @brief プレイヤーのヒットダイスを振る / Role Hitpoints
201  * @param creature_ptr プレーヤーへの参照ポインタ
202  * @param options スペル共通オプション
203  * @return なし
204  */
205 void roll_hitdice(player_type *creature_ptr, spell_operation options)
206 {
207         HIT_POINT min_value = creature_ptr->hitdie + ((PY_MAX_LEVEL + 2) * (creature_ptr->hitdie + 1)) * 3 / 8;
208         HIT_POINT max_value = creature_ptr->hitdie + ((PY_MAX_LEVEL + 2) * (creature_ptr->hitdie + 1)) * 5 / 8;
209
210         /* Rerate */
211         while (TRUE)
212         {
213                 /* Pre-calculate level 1 hitdice */
214                 creature_ptr->player_hp[0] = (HIT_POINT)creature_ptr->hitdie;
215
216                 for (int i = 1; i < 4; i++)
217                 {
218                         creature_ptr->player_hp[0] += randint1(creature_ptr->hitdie);
219                 }
220
221                 /* Roll the hitpoint values */
222                 for (int i = 1; i < PY_MAX_LEVEL; i++)
223                 {
224                         creature_ptr->player_hp[i] = creature_ptr->player_hp[i - 1] + randint1(creature_ptr->hitdie);
225                 }
226
227                 /* Require "valid" hitpoints at highest level */
228                 if ((creature_ptr->player_hp[PY_MAX_LEVEL - 1] >= min_value) &&
229                         (creature_ptr->player_hp[PY_MAX_LEVEL - 1] <= max_value)) break;
230         }
231
232         PERCENTAGE percent = (int)(((long)creature_ptr->player_hp[PY_MAX_LEVEL - 1] * 200L) /
233                 (2 * creature_ptr->hitdie + ((PY_MAX_LEVEL - 1 + 3) * (creature_ptr->hitdie + 1))));
234
235         /* Update and redraw hitpoints */
236         creature_ptr->update |= (PU_HP);
237         creature_ptr->redraw |= (PR_HP);
238         creature_ptr->window |= (PW_PLAYER);
239
240         if (!(options & SPOP_NO_UPDATE)) handle_stuff(creature_ptr);
241
242         if (!(options & SPOP_DISPLAY_MES)) return;
243
244         if (options & SPOP_DEBUG)
245         {
246                 msg_format(_("現在の体力ランクは %d/100 です。", "Your life rate is %d/100 now."), percent);
247                 creature_ptr->knowledge |= KNOW_HPRATE;
248                 return;
249         }
250
251         msg_print(_("体力ランクが変わった。", "Life rate is changed."));
252         creature_ptr->knowledge &= ~(KNOW_HPRATE);
253 }
254
255
256 bool life_stream(player_type *creature_ptr, bool message, bool virtue_change)
257 {
258         if (virtue_change)
259         {
260                 chg_virtue(creature_ptr, V_VITALITY, 1);
261                 chg_virtue(creature_ptr, V_UNLIFE, -5);
262         }
263
264         if (message)
265         {
266                 msg_print(_("体中に生命力が満ちあふれてきた!", "You feel life flow through your body!"));
267         }
268
269         restore_level(creature_ptr);
270         (void)set_poisoned(creature_ptr, 0);
271         (void)set_blind(creature_ptr, 0);
272         (void)set_confused(creature_ptr, 0);
273         (void)set_image(creature_ptr, 0);
274         (void)set_stun(creature_ptr, 0);
275         (void)set_cut(creature_ptr,0);
276         (void)restore_all_status(creature_ptr);
277         (void)set_shero(creature_ptr, 0, TRUE);
278         handle_stuff(creature_ptr);
279         hp_player(creature_ptr, 5000);
280
281         return TRUE;
282 }
283
284
285 bool heroism(player_type *creature_ptr, int base)
286 {
287         bool ident = FALSE;
288         if (set_afraid(creature_ptr, 0)) ident = TRUE;
289         if (set_hero(creature_ptr, creature_ptr->hero + randint1(base) + base, FALSE)) ident = TRUE;
290         if (hp_player(creature_ptr, 10)) ident = TRUE;
291         return ident;
292 }
293
294
295 bool berserk(player_type *creature_ptr, int base)
296 {
297         bool ident = FALSE;
298         if (set_afraid(creature_ptr, 0)) ident = TRUE;
299         if (set_shero(creature_ptr, creature_ptr->shero + randint1(base) + base, FALSE)) ident = TRUE;
300         if (hp_player(creature_ptr, 30)) ident = TRUE;
301         return ident;
302 }
303
304
305 bool cure_light_wounds(player_type *creature_ptr, DICE_NUMBER dice, DICE_SID sides)
306 {
307         bool ident = FALSE;
308         if (hp_player(creature_ptr, damroll(dice, sides))) ident = TRUE;
309         if (set_blind(creature_ptr, 0)) ident = TRUE;
310         if (set_cut(creature_ptr,creature_ptr->cut - 10)) ident = TRUE;
311         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
312         return ident;
313 }
314
315
316 bool cure_serious_wounds(player_type *creature_ptr, DICE_NUMBER dice, DICE_SID sides)
317 {
318         bool ident = FALSE;
319         if (hp_player(creature_ptr, damroll(dice, sides))) ident = TRUE;
320         if (set_blind(creature_ptr, 0)) ident = TRUE;
321         if (set_confused(creature_ptr, 0)) ident = TRUE;
322         if (set_cut(creature_ptr,(creature_ptr->cut / 2) - 50)) ident = TRUE;
323         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
324         return ident;
325 }
326
327
328 bool cure_critical_wounds(player_type *creature_ptr, HIT_POINT pow)
329 {
330         bool ident = FALSE;
331         if (hp_player(creature_ptr, pow)) ident = TRUE;
332         if (set_blind(creature_ptr, 0)) ident = TRUE;
333         if (set_confused(creature_ptr, 0)) ident = TRUE;
334         if (set_poisoned(creature_ptr, 0)) ident = TRUE;
335         if (set_stun(creature_ptr, 0)) ident = TRUE;
336         if (set_cut(creature_ptr,0)) ident = TRUE;
337         if (set_shero(creature_ptr, 0, TRUE)) ident = TRUE;
338         return ident;
339 }
340
341
342 bool true_healing(player_type *creature_ptr, HIT_POINT pow)
343 {
344         bool ident = FALSE;
345         if (hp_player(creature_ptr, pow)) ident = TRUE;
346         if (set_blind(creature_ptr, 0)) ident = TRUE;
347         if (set_confused(creature_ptr, 0)) ident = TRUE;
348         if (set_poisoned(creature_ptr, 0)) ident = TRUE;
349         if (set_stun(creature_ptr, 0)) ident = TRUE;
350         if (set_cut(creature_ptr,0)) ident = TRUE;
351         if (set_image(creature_ptr, 0)) ident = TRUE;
352         return ident;
353 }
354
355
356 bool restore_mana(player_type *creature_ptr, bool magic_eater)
357 {
358         if (creature_ptr->pclass == CLASS_MAGIC_EATER && magic_eater)
359         {
360                 int i;
361                 for (i = 0; i < EATER_EXT * 2; i++)
362                 {
363                         creature_ptr->magic_num1[i] += (creature_ptr->magic_num2[i] < 10) ? EATER_CHARGE * 3 : creature_ptr->magic_num2[i] * EATER_CHARGE / 3;
364                         if (creature_ptr->magic_num1[i] > creature_ptr->magic_num2[i] * EATER_CHARGE) creature_ptr->magic_num1[i] = creature_ptr->magic_num2[i] * EATER_CHARGE;
365                 }
366
367                 for (; i < EATER_EXT * 3; i++)
368                 {
369                         KIND_OBJECT_IDX k_idx = lookup_kind(TV_ROD, i - EATER_EXT * 2);
370                         creature_ptr->magic_num1[i] -= ((creature_ptr->magic_num2[i] < 10) ? EATER_ROD_CHARGE * 3 : creature_ptr->magic_num2[i] * EATER_ROD_CHARGE / 3)*k_info[k_idx].pval;
371                         if (creature_ptr->magic_num1[i] < 0) creature_ptr->magic_num1[i] = 0;
372                 }
373
374                 msg_print(_("頭がハッキリとした。", "You feel your head clear."));
375                 creature_ptr->window |= (PW_PLAYER);
376                 return TRUE;
377         }
378         
379         if (creature_ptr->csp >= creature_ptr->msp) return FALSE;
380
381         creature_ptr->csp = creature_ptr->msp;
382         creature_ptr->csp_frac = 0;
383         msg_print(_("頭がハッキリとした。", "You feel your head clear."));
384         creature_ptr->redraw |= (PR_MANA);
385         creature_ptr->window |= (PW_PLAYER);
386         creature_ptr->window |= (PW_SPELL);
387         return TRUE;
388 }
389
390
391 bool restore_all_status(player_type *creature_ptr)
392 {
393         bool ident = FALSE;
394         if (do_res_stat(creature_ptr, A_STR)) ident = TRUE;
395         if (do_res_stat(creature_ptr, A_INT)) ident = TRUE;
396         if (do_res_stat(creature_ptr, A_WIS)) ident = TRUE;
397         if (do_res_stat(creature_ptr, A_DEX)) ident = TRUE;
398         if (do_res_stat(creature_ptr, A_CON)) ident = TRUE;
399         if (do_res_stat(creature_ptr, A_CHR)) ident = TRUE;
400         return ident;
401 }
402
403
404 bool fishing(player_type *creature_ptr)
405 {
406         DIRECTION dir;
407         if (!get_direction(creature_ptr, &dir, FALSE, FALSE)) return FALSE;
408         POSITION y = creature_ptr->y + ddy[dir];
409         POSITION x = creature_ptr->x + ddx[dir];
410         creature_ptr->fishing_dir = dir;
411         if (!cave_have_flag_bold(creature_ptr->current_floor_ptr, y, x, FF_WATER))
412         {
413                 msg_print(_("そこは水辺ではない。", "There is no fishing place."));
414                 return FALSE;
415         }
416         
417         if (creature_ptr->current_floor_ptr->grid_array[y][x].m_idx)
418         {
419                 GAME_TEXT m_name[MAX_NLEN];
420                 monster_desc(creature_ptr, m_name, &creature_ptr->current_floor_ptr->m_list[creature_ptr->current_floor_ptr->grid_array[y][x].m_idx], 0);
421                 msg_format(_("%sが邪魔だ!", "%^s is standing in your way."), m_name);
422                 free_turn(creature_ptr);
423                 return FALSE;
424         }
425
426         set_action(creature_ptr, ACTION_FISH);
427         creature_ptr->redraw |= (PR_STATE);
428         return TRUE;
429 }
430
431
432 bool cosmic_cast_off(player_type *creature_ptr, object_type *o_ptr)
433 {
434         /* Cast off activated item */
435         INVENTORY_IDX inv;
436         for (inv = INVEN_RARM; inv <= INVEN_FEET; inv++)
437         {
438                 if (o_ptr == &creature_ptr->inventory_list[inv]) break;
439         }
440
441         if (inv > INVEN_FEET) return FALSE;
442
443         object_type forge;
444         object_copy(&forge, o_ptr);
445         inven_item_increase(creature_ptr, inv, (0 - o_ptr->number));
446         inven_item_optimize(creature_ptr, inv);
447         OBJECT_IDX o_idx = drop_near(creature_ptr, &forge, 0, creature_ptr->y, creature_ptr->x);
448         o_ptr = &creature_ptr->current_floor_ptr->o_list[o_idx];
449
450         GAME_TEXT o_name[MAX_NLEN];
451         object_desc(creature_ptr, o_name, o_ptr, OD_NAME_ONLY);
452         msg_format(_("%sを脱ぎ捨てた。", "You cast off %s."), o_name);
453
454         /* Get effects */
455         msg_print(_("「燃え上がれ俺の小宇宙!」", "You say, 'Burn up my cosmo!"));
456         int t = 20 + randint1(20);
457         (void)set_blind(creature_ptr, creature_ptr->blind + t);
458         (void)set_afraid(creature_ptr, 0);
459         (void)set_tim_esp(creature_ptr, creature_ptr->tim_esp + t, FALSE);
460         (void)set_tim_regen(creature_ptr, creature_ptr->tim_regen + t, FALSE);
461         (void)set_hero(creature_ptr, creature_ptr->hero + t, FALSE);
462         (void)set_blessed(creature_ptr, creature_ptr->blessed + t, FALSE);
463         (void)set_fast(creature_ptr, creature_ptr->fast + t, FALSE);
464         (void)set_shero(creature_ptr, creature_ptr->shero + t, FALSE);
465         if (creature_ptr->pclass == CLASS_FORCETRAINER)
466         {
467                 P_PTR_KI = creature_ptr->lev * 5 + 190;
468                 msg_print(_("気が爆発寸前になった。", "Your force absorbs the explosion."));
469         }
470
471         return TRUE;
472 }
473
474
475 /*!
476  * @brief プレイヤーの因果混乱処理 / Apply Nexus
477  * @param m_ptr 因果混乱をプレイヤーに与えたモンスターの情報参照ポインタ
478  * @return なし
479  */
480 void apply_nexus(monster_type *m_ptr, player_type *target_ptr)
481 {
482         switch (randint1(7))
483         {
484         case 1: case 2: case 3:
485         {
486                 teleport_player(target_ptr, 200, TELEPORT_PASSIVE);
487                 break;
488         }
489
490         case 4: case 5:
491         {
492                 teleport_player_to(target_ptr, m_ptr->fy, m_ptr->fx, TELEPORT_PASSIVE);
493                 break;
494         }
495
496         case 6:
497         {
498                 if (randint0(100) < target_ptr->skill_sav)
499                 {
500                         msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
501                         break;
502                 }
503
504                 teleport_level(target_ptr, 0);
505                 break;
506         }
507
508         case 7:
509         {
510                 if (randint0(100) < target_ptr->skill_sav)
511                 {
512                         msg_print(_("しかし効力を跳ね返した!", "You resist the effects!"));
513                         break;
514                 }
515
516                 msg_print(_("体がねじれ始めた...", "Your body starts to scramble..."));
517                 status_shuffle(target_ptr);
518                 break;
519         }
520         }
521 }
522
523
524 /*!
525  * @brief プレイヤーのステータスシャッフル処理
526  * @param creature_ptr プレーヤーへの参照ポインタ
527  * @return なし
528  */
529 void status_shuffle(player_type *creature_ptr)
530 {
531         /* Pick a pair of stats */
532         int i = randint0(A_MAX);
533         int j;
534
535         // todo ここのループは一体何をしている?
536         for (j = i; j == i; j = randint0(A_MAX)) /* loop */;
537
538         BASE_STATUS max1 = creature_ptr->stat_max[i];
539         BASE_STATUS cur1 = creature_ptr->stat_cur[i];
540         BASE_STATUS max2 = creature_ptr->stat_max[j];
541         BASE_STATUS cur2 = creature_ptr->stat_cur[j];
542
543         creature_ptr->stat_max[i] = max2;
544         creature_ptr->stat_cur[i] = cur2;
545         creature_ptr->stat_max[j] = max1;
546         creature_ptr->stat_cur[j] = cur1;
547
548         for (int k = 0; k < A_MAX; k++)
549         {
550                 if (creature_ptr->stat_max[k] > creature_ptr->stat_max_max[k]) creature_ptr->stat_max[k] = creature_ptr->stat_max_max[k];
551                 if (creature_ptr->stat_cur[k] > creature_ptr->stat_max_max[k]) creature_ptr->stat_cur[k] = creature_ptr->stat_max_max[k];
552         }
553
554         creature_ptr->update |= PU_BONUS;
555 }