2 * @brief アイテムに影響のある魔法の処理
7 #include "spell/spells-object.h"
8 #include "core/player-redraw-types.h"
9 #include "core/player-update-types.h"
10 #include "core/window-redrawer.h"
11 #include "flavor/flavor-describer.h"
12 #include "flavor/object-flavor-types.h"
13 #include "floor/floor-object.h"
14 #include "game-option/disturbance-options.h"
15 #include "inventory/inventory-slot-types.h"
16 #include "monster-race/monster-race.h"
17 #include "monster-race/race-flags1.h"
18 #include "object-enchant/apply-magic.h"
19 #include "object-enchant/item-apply-magic.h"
20 #include "object-enchant/item-feeling.h"
21 #include "object-enchant/object-boost.h"
22 #include "object-enchant/object-ego.h"
23 #include "object-enchant/special-object-flags.h"
24 #include "object-enchant/trc-types.h"
25 #include "object-enchant/trg-types.h"
26 #include "object-hook/hook-armor.h"
27 #include "object-hook/hook-checker.h"
28 #include "object-hook/hook-enchant.h"
29 #include "object-hook/hook-weapon.h"
30 #include "object/item-tester-hooker.h"
31 #include "object/item-use-flags.h"
32 #include "object/object-generator.h"
33 #include "object/object-kind-hook.h"
34 #include "object/object-kind.h"
35 #include "perception/object-perception.h"
36 #include "player-info/avatar.h"
37 #include "player/player-class.h"
38 #include "player/player-damage.h"
39 #include "racial/racial-android.h"
40 #include "spell-kind/spells-perception.h"
41 #include "status/bad-status-setter.h"
42 #include "sv-definition/sv-other-types.h"
43 #include "sv-definition/sv-scroll-types.h"
44 #include "sv-definition/sv-weapon-types.h"
45 #include "system/artifact-type-definition.h"
46 #include "system/floor-type-definition.h"
47 #include "system/monster-race-definition.h"
48 #include "system/object-type-definition.h"
49 #include "system/player-type-definition.h"
50 #include "term/screen-processor.h"
51 #include "util/bit-flags-calculator.h"
52 #include "view/display-messages.h"
56 OBJECT_SUBTYPE_VALUE sval;
62 * @brief 装備強化処理の失敗率定数(千分率) /
63 * Used by the "enchant" function (chance of failure)
64 * (modified for Zangband, we need better stuff there...) -- TY
66 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
69 * Scatter some "amusing" objects near the player
72 #define AMS_NOTHING 0x00 /* No restriction */
73 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
74 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
75 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
76 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
78 static amuse_type amuse_info[]
79 = { { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING }, { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE }, { TV_SPIKE, SV_ANY, 10, AMS_PILE }, { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
80 { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
81 { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
82 { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
83 { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
85 { TV_NONE, 0, 0, 0 } };
89 * @param creature_ptr プレーヤーへの参照ポインタ
90 * @param y1 配置したいフロアのY座標
91 * @param x1 配置したいフロアのX座標
93 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
95 void amusement(player_type *creature_ptr, POSITION y1, POSITION x1, int num, bool known)
98 for (int n = 0; amuse_info[n].tval != 0; n++) {
99 t += amuse_info[n].prob;
104 object_type object_type_body;
107 KIND_OBJECT_IDX k_idx;
108 ARTIFACT_IDX a_idx = 0;
110 bool insta_art, fixed_art;
113 r -= amuse_info[i].prob;
117 i_ptr = &object_type_body;
119 k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
121 /* Paranoia - reroll if nothing */
125 /* Search an artifact index if need */
126 insta_art = k_info[k_idx].gen_flags.has(TRG::INSTA_ART);
127 fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
129 if (insta_art || fixed_art) {
130 for (a_idx = 1; a_idx < max_a_idx; a_idx++) {
131 if (insta_art && !a_info[a_idx].gen_flags.has(TRG::INSTA_ART))
133 if (a_info[a_idx].tval != k_info[k_idx].tval)
135 if (a_info[a_idx].sval != k_info[k_idx].sval)
137 if (a_info[a_idx].cur_num > 0)
142 if (a_idx >= max_a_idx)
146 /* Make an object (if possible) */
147 object_prep(creature_ptr, i_ptr, k_idx);
149 i_ptr->name1 = a_idx;
150 apply_magic_to_object(creature_ptr, i_ptr, 1, AM_NO_FIXED_ART);
152 if (amuse_info[i].flag & AMS_NO_UNIQUE) {
153 if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE)
157 if (amuse_info[i].flag & AMS_MULTIPLE)
158 i_ptr->number = randint1(3);
159 if (amuse_info[i].flag & AMS_PILE)
160 i_ptr->number = randint1(99);
163 object_aware(creature_ptr, i_ptr);
167 /* Paranoia - reroll if nothing */
171 (void)drop_near(creature_ptr, i_ptr, -1, y1, x1);
179 * Scatter some "great" objects near the player
180 * @param caster_ptr プレーヤーへの参照ポインタ
181 * @param y1 配置したいフロアのY座標
182 * @param x1 配置したいフロアのX座標
184 * @param great TRUEならば必ず高級品以上を落とす
185 * @param special TRUEならば必ず特別品を落とす
186 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
188 void acquirement(player_type *caster_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
191 object_type object_type_body;
192 BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : AM_NONE) | (special ? AM_SPECIAL : AM_NONE);
196 i_ptr = &object_type_body;
199 /* Make a good (or great) object (if possible) */
200 if (!make_object(caster_ptr, i_ptr, mode))
204 object_aware(caster_ptr, i_ptr);
208 (void)drop_near(caster_ptr, i_ptr, -1, y1, x1);
214 * Curse the players armor
215 * @return 何も持っていない場合を除き、常にTRUEを返す
216 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
218 bool curse_armor(player_type *owner_ptr)
220 /* Curse the body armor */
222 o_ptr = &owner_ptr->inventory_list[INVEN_BODY];
227 GAME_TEXT o_name[MAX_NLEN];
228 describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
230 /* Attempt a saving throw for artifacts */
231 if (object_is_artifact(o_ptr) && (randint0(100) < 50)) {
234 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
236 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
241 /* not artifact or failed save... */
242 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
243 chg_virtue(owner_ptr, V_ENCHANT, -5);
245 /* Blast the armor */
247 o_ptr->name2 = EGO_BLASTED;
248 o_ptr->to_a = 0 - randint1(5) - randint1(5);
255 for (int i = 0; i < TR_FLAG_SIZE; i++)
256 o_ptr->art_flags[i] = 0;
259 o_ptr->curse_flags = TRC_CURSED;
262 o_ptr->ident |= (IDENT_BROKEN);
263 owner_ptr->update |= (PU_BONUS | PU_MANA);
264 owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
270 * Curse the players weapon
271 * @param owner_ptr 所持者の参照ポインタ
272 * @param force 無条件に呪縛を行うならばTRUE
273 * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
274 * @return 何も持っていない場合を除き、常にTRUEを返す
275 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
277 bool curse_weapon_object(player_type *owner_ptr, bool force, object_type *o_ptr)
282 GAME_TEXT o_name[MAX_NLEN];
283 describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
285 /* Attempt a saving throw */
286 if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force) {
288 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
290 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
295 /* not artifact or failed save... */
297 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
298 chg_virtue(owner_ptr, V_ENCHANT, -5);
300 /* Shatter the weapon */
302 o_ptr->name2 = EGO_SHATTERED;
303 o_ptr->to_h = 0 - randint1(5) - randint1(5);
304 o_ptr->to_d = 0 - randint1(5) - randint1(5);
310 for (int i = 0; i < TR_FLAG_SIZE; i++)
311 o_ptr->art_flags[i] = 0;
314 o_ptr->curse_flags = TRC_CURSED;
317 o_ptr->ident |= (IDENT_BROKEN);
318 owner_ptr->update |= (PU_BONUS | PU_MANA);
319 owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
324 * @brief ボルトのエゴ化処理(火炎エゴのみ) /
326 * @param caster_ptr プレーヤーへの参照ポインタ
328 void brand_bolts(player_type *caster_ptr)
330 /* Use the first acceptable bolts */
331 for (int i = 0; i < INVEN_PACK; i++) {
332 object_type *o_ptr = &caster_ptr->inventory_list[i];
335 if (o_ptr->tval != TV_BOLT)
338 /* Skip artifacts and ego-items */
339 if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
342 /* Skip cursed/broken items */
343 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
347 if (randint0(100) < 75)
350 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
353 o_ptr->name2 = EGO_FLAME;
354 enchant_equipment(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
360 msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
364 * @brief 知識の石の発動を実行する / Do activation of the stone of lore.
365 * @param user_ptr プレイヤー情報への参照ポインタ
366 * @return 実行したらTRUE、しなかったらFALSE
368 * 鑑定を実行した後HPを消費する。1/5で混乱し、1/20で追加ダメージ。
369 * MPがある場合はさらにMPを20消費する。不足する場合は麻痺及び混乱。
371 bool perilous_secrets(player_type *user_ptr)
373 if (!ident_spell(user_ptr, FALSE, TV_NONE))
376 if (user_ptr->msp > 0) {
377 if (20 <= user_ptr->csp)
380 int oops = 20 - user_ptr->csp;
383 user_ptr->csp_frac = 0;
385 msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
387 (void)set_paralyzed(user_ptr, user_ptr->paralyzed + randint1(5 * oops + 1));
388 (void)set_confused(user_ptr, user_ptr->confused + randint1(5 * oops + 1));
391 user_ptr->redraw |= (PR_MANA);
394 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"));
397 (void)set_confused(user_ptr, user_ptr->confused + randint1(10));
400 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"));
407 * Break the curse of an item
408 * @param o_ptr 呪い装備情報の参照ポインタ
410 static void break_curse(object_type *o_ptr)
412 BIT_FLAGS is_curse_broken
413 = object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25);
414 if (!is_curse_broken) {
418 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
420 o_ptr->curse_flags = 0L;
421 o_ptr->ident |= (IDENT_SENSE);
422 o_ptr->feeling = FEEL_NONE;
427 * Enchants a plus onto an item. -RAK-
428 * @param caster_ptr プレーヤーへの参照ポインタ
429 * @param o_ptr 強化するアイテムの参照ポインタ
431 * @param eflag 強化オプション(命中/ダメージ/AC)
432 * @return 強化に成功した場合TRUEを返す
435 * Revamped! Now takes item pointer, number of times to try enchanting,
436 * and a flag of what to try enchanting. Artifacts resist enchantment
437 * some of the time, and successful enchantment to at least +0 might
438 * break a curse on the item. -CFT-
440 * Note that an item can technically be enchanted all the way to +15 if
441 * you wait a very, very, long time. Going from +9 to +10 only works
442 * about 5% of the time, and from +10 to +11 only about 1% of the time.
444 * Note that this function can now be used on "piles" of items, and
445 * the larger the pile, the lower the chance of success.
448 bool enchant_equipment(player_type *caster_ptr, object_type *o_ptr, int n, int eflag)
450 /* Large piles resist enchantment */
451 int prob = o_ptr->number * 100;
453 /* Missiles are easy to enchant */
454 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
461 bool a = object_is_artifact(o_ptr);
462 bool force = (eflag & ENCH_FORCE);
463 for (int i = 0; i < n; i++) {
464 /* Hack -- Roll for pile resistance */
465 if (!force && randint0(prob) >= 100)
469 if (eflag & ENCH_TOHIT) {
472 else if (o_ptr->to_h > 15)
475 chance = enchant_table[o_ptr->to_h];
477 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
481 /* only when you get it above -1 -CFT */
482 if (o_ptr->to_h >= 0)
487 /* Enchant to damage */
488 if (eflag & ENCH_TODAM) {
491 else if (o_ptr->to_d > 15)
494 chance = enchant_table[o_ptr->to_d];
496 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
500 /* only when you get it above -1 -CFT */
501 if (o_ptr->to_d >= 0)
506 /* Enchant to armor class */
507 if (!(eflag & ENCH_TOAC)) {
513 else if (o_ptr->to_a > 15)
516 chance = enchant_table[o_ptr->to_a];
518 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
522 /* only when you get it above -1 -CFT */
523 if (o_ptr->to_a >= 0)
531 set_bits(caster_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
532 set_bits(caster_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
534 calc_android_exp(caster_ptr);
541 * @brief 装備修正強化処理のメインルーチン /
542 * Enchant an item (in the inventory or on the floor)
543 * @param caster_ptr プレーヤーへの参照ポインタ
544 * @param num_hit 命中修正量
545 * @param num_dam ダメージ修正量
546 * @param num_ac AC修正量
547 * @return 強化に成功した場合TRUEを返す
549 * Note that "num_ac" requires armour, else weapon
550 * Returns TRUE if attempted, FALSE if cancelled
552 bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
554 /* Assume enchant weapon */
555 item_tester_hook = object_allow_enchant_weapon;
557 /* Enchant armor if requested */
559 item_tester_hook = object_is_armour;
561 concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
562 concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
566 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_NONE);
570 GAME_TEXT o_name[MAX_NLEN];
571 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
573 msg_format("%s は明るく輝いた!", o_name);
575 msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
579 bool is_enchant_successful = FALSE;
580 if (enchant_equipment(caster_ptr, o_ptr, num_hit, ENCH_TOHIT))
581 is_enchant_successful = TRUE;
582 if (enchant_equipment(caster_ptr, o_ptr, num_dam, ENCH_TODAM))
583 is_enchant_successful = TRUE;
584 if (enchant_equipment(caster_ptr, o_ptr, num_ac, ENCH_TOAC))
585 is_enchant_successful = TRUE;
587 if (!is_enchant_successful) {
590 msg_print(_("強化に失敗した。", "The enchantment failed."));
592 chg_virtue(caster_ptr, V_ENCHANT, -1);
594 chg_virtue(caster_ptr, V_ENCHANT, 1);
596 calc_android_exp(caster_ptr);
598 /* Something happened */
603 * @brief 武器へのエゴ付加処理 /
604 * Brand the current weapon
605 * @param caster_ptr プレーヤーへの参照ポインタ
606 * @param brand_type エゴ化ID(e_info.txtとは連動していない)
608 void brand_weapon(player_type *caster_ptr, int brand_type)
610 /* Assume enchant weapon */
611 item_tester_hook = object_allow_enchant_melee_weapon;
613 concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
614 concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
618 o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | IGNORE_BOTHHAND_SLOT, TV_NONE);
622 bool is_special_item = o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) && !object_is_cursed(o_ptr)
623 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
624 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
625 if (!is_special_item) {
629 msg_print(_("属性付加に失敗した。", "The branding failed."));
630 chg_virtue(caster_ptr, V_ENCHANT, -2);
631 calc_android_exp(caster_ptr);
635 GAME_TEXT o_name[MAX_NLEN];
636 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
639 switch (brand_type) {
641 if (o_ptr->tval == TV_SWORD) {
642 act = _("は鋭さを増した!", "becomes very sharp!");
644 o_ptr->name2 = EGO_SHARPNESS;
645 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, caster_ptr->current_floor_ptr->dun_level) + 1;
647 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
650 act = _("は破壊力を増した!", "seems very powerful.");
651 o_ptr->name2 = EGO_EARTHQUAKES;
652 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, caster_ptr->current_floor_ptr->dun_level);
657 act = _("は人間の血を求めている!", "seems to be looking for humans!");
658 o_ptr->name2 = EGO_KILL_HUMAN;
661 act = _("は電撃に覆われた!", "covered with lightning!");
662 o_ptr->name2 = EGO_BRAND_ELEC;
665 act = _("は酸に覆われた!", "coated with acid!");
666 o_ptr->name2 = EGO_BRAND_ACID;
669 act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
670 o_ptr->name2 = EGO_KILL_EVIL;
673 act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
674 o_ptr->name2 = EGO_KILL_DEMON;
677 act = _("は屍を求めている!", "seems to be looking for undead!");
678 o_ptr->name2 = EGO_KILL_UNDEAD;
681 act = _("は動物の血を求めている!", "seems to be looking for animals!");
682 o_ptr->name2 = EGO_KILL_ANIMAL;
685 act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
686 o_ptr->name2 = EGO_KILL_DRAGON;
689 act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
690 o_ptr->name2 = EGO_KILL_TROLL;
693 act = _("はオークの血を求めている!", "seems to be looking for orcs!");
694 o_ptr->name2 = EGO_KILL_ORC;
697 act = _("は巨人の血を求めている!", "seems to be looking for giants!");
698 o_ptr->name2 = EGO_KILL_GIANT;
701 act = _("は非常に不安定になったようだ。", "seems very unstable now.");
702 o_ptr->name2 = EGO_TRUMP;
703 o_ptr->pval = randint1(2);
706 act = _("は血を求めている!", "thirsts for blood!");
707 o_ptr->name2 = EGO_VAMPIRIC;
710 act = _("は毒に覆われた。", "is coated with poison.");
711 o_ptr->name2 = EGO_BRAND_POIS;
714 act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
715 o_ptr->name2 = EGO_CHAOTIC;
718 act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
719 o_ptr->name2 = EGO_BRAND_FIRE;
722 act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
723 o_ptr->name2 = EGO_BRAND_COLD;
727 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
728 enchant_equipment(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
729 o_ptr->discount = 99;
730 chg_virtue(caster_ptr, V_ENCHANT, 2);
731 calc_android_exp(caster_ptr);