2 * @brief アイテムに影響のある魔法の処理
7 #include "spell/spells-object.h"
8 #include "avatar/avatar.h"
9 #include "core/player-redraw-types.h"
10 #include "core/player-update-types.h"
11 #include "core/window-redrawer.h"
12 #include "flavor/flavor-describer.h"
13 #include "flavor/object-flavor-types.h"
14 #include "floor/floor-object.h"
15 #include "game-option/disturbance-options.h"
16 #include "inventory/inventory-slot-types.h"
17 #include "monster-race/monster-race.h"
18 #include "monster-race/race-flags1.h"
19 #include "object-enchant/apply-magic.h"
20 #include "object-enchant/item-apply-magic.h"
21 #include "object-enchant/item-feeling.h"
22 #include "object-enchant/object-boost.h"
23 #include "object-enchant/object-ego.h"
24 #include "object-enchant/special-object-flags.h"
25 #include "object-enchant/trc-types.h"
26 #include "object-enchant/trg-types.h"
27 #include "object-hook/hook-armor.h"
28 #include "object-hook/hook-weapon.h"
29 #include "object/item-tester-hooker.h"
30 #include "object/item-use-flags.h"
31 #include "object/object-kind-hook.h"
32 #include "object/object-kind.h"
33 #include "perception/object-perception.h"
34 #include "player/player-class.h"
35 #include "player/player-damage.h"
36 #include "racial/racial-android.h"
37 #include "spell-kind/spells-perception.h"
38 #include "status/bad-status-setter.h"
39 #include "sv-definition/sv-other-types.h"
40 #include "sv-definition/sv-scroll-types.h"
41 #include "sv-definition/sv-weapon-types.h"
42 #include "system/artifact-type-definition.h"
43 #include "system/floor-type-definition.h"
44 #include "system/monster-race-definition.h"
45 #include "system/object-type-definition.h"
46 #include "system/player-type-definition.h"
47 #include "term/screen-processor.h"
48 #include "util/bit-flags-calculator.h"
49 #include "view/display-messages.h"
53 OBJECT_SUBTYPE_VALUE sval;
59 * @brief 装備強化処理の失敗率定数(千分率) /
60 * Used by the "enchant" function (chance of failure)
61 * (modified for Zangband, we need better stuff there...) -- TY
63 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
66 * Scatter some "amusing" objects near the player
69 #define AMS_NOTHING 0x00 /* No restriction */
70 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
71 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
72 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
73 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
75 static amuse_type amuse_info[]
76 = { { 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 },
77 { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
78 { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
79 { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
80 { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
82 { TV_NONE, 0, 0, 0 } };
86 * @param creature_ptr プレーヤーへの参照ポインタ
87 * @param y1 配置したいフロアのY座標
88 * @param x1 配置したいフロアのX座標
90 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
92 void amusement(player_type *creature_ptr, POSITION y1, POSITION x1, int num, bool known)
95 for (int n = 0; amuse_info[n].tval != 0; n++) {
96 t += amuse_info[n].prob;
101 object_type object_type_body;
104 KIND_OBJECT_IDX k_idx;
105 ARTIFACT_IDX a_idx = 0;
107 bool insta_art, fixed_art;
110 r -= amuse_info[i].prob;
114 i_ptr = &object_type_body;
116 k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
118 /* Paranoia - reroll if nothing */
122 /* Search an artifact index if need */
123 insta_art = k_info[k_idx].gen_flags.has(TRG::INSTA_ART);
124 fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
126 if (insta_art || fixed_art) {
127 for (a_idx = 1; a_idx < max_a_idx; a_idx++) {
128 if (insta_art && !a_info[a_idx].gen_flags.has(TRG::INSTA_ART))
130 if (a_info[a_idx].tval != k_info[k_idx].tval)
132 if (a_info[a_idx].sval != k_info[k_idx].sval)
134 if (a_info[a_idx].cur_num > 0)
139 if (a_idx >= max_a_idx)
143 /* Make an object (if possible) */
146 i_ptr->name1 = a_idx;
147 apply_magic_to_object(creature_ptr, i_ptr, 1, AM_NO_FIXED_ART);
149 if (amuse_info[i].flag & AMS_NO_UNIQUE) {
150 if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE)
154 if (amuse_info[i].flag & AMS_MULTIPLE)
155 i_ptr->number = randint1(3);
156 if (amuse_info[i].flag & AMS_PILE)
157 i_ptr->number = randint1(99);
160 object_aware(creature_ptr, i_ptr);
164 /* Paranoia - reroll if nothing */
168 (void)drop_near(creature_ptr, i_ptr, -1, y1, x1);
176 * Scatter some "great" objects near the player
177 * @param caster_ptr プレーヤーへの参照ポインタ
178 * @param y1 配置したいフロアのY座標
179 * @param x1 配置したいフロアのX座標
181 * @param great TRUEならば必ず高級品以上を落とす
182 * @param special TRUEならば必ず特別品を落とす
183 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
185 void acquirement(player_type *caster_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
188 object_type object_type_body;
189 BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : AM_NONE) | (special ? AM_SPECIAL : AM_NONE);
193 i_ptr = &object_type_body;
196 /* Make a good (or great) object (if possible) */
197 if (!make_object(caster_ptr, i_ptr, mode))
201 object_aware(caster_ptr, i_ptr);
205 (void)drop_near(caster_ptr, i_ptr, -1, y1, x1);
211 * Curse the players armor
212 * @return 何も持っていない場合を除き、常にTRUEを返す
213 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
215 bool curse_armor(player_type *owner_ptr)
217 /* Curse the body armor */
219 o_ptr = &owner_ptr->inventory_list[INVEN_BODY];
224 GAME_TEXT o_name[MAX_NLEN];
225 describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
227 /* Attempt a saving throw for artifacts */
228 if (o_ptr->is_artifact() && (randint0(100) < 50)) {
231 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
233 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
238 /* not artifact or failed save... */
239 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
240 chg_virtue(owner_ptr, V_ENCHANT, -5);
242 /* Blast the armor */
244 o_ptr->name2 = EGO_BLASTED;
245 o_ptr->to_a = 0 - randint1(5) - randint1(5);
252 o_ptr->art_flags.fill(0U);
255 o_ptr->curse_flags.set(TRC::CURSED);
258 o_ptr->ident |= (IDENT_BROKEN);
259 owner_ptr->update |= (PU_BONUS | PU_MANA);
260 owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
266 * Curse the players weapon
267 * @param owner_ptr 所持者の参照ポインタ
268 * @param force 無条件に呪縛を行うならばTRUE
269 * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
270 * @return 何も持っていない場合を除き、常にTRUEを返す
271 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
273 bool curse_weapon_object(player_type *owner_ptr, bool force, object_type *o_ptr)
278 GAME_TEXT o_name[MAX_NLEN];
279 describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
281 /* Attempt a saving throw */
282 if (o_ptr->is_artifact() && (randint0(100) < 50) && !force) {
284 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
286 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
291 /* not artifact or failed save... */
293 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
294 chg_virtue(owner_ptr, V_ENCHANT, -5);
296 /* Shatter the weapon */
298 o_ptr->name2 = EGO_SHATTERED;
299 o_ptr->to_h = 0 - randint1(5) - randint1(5);
300 o_ptr->to_d = 0 - randint1(5) - randint1(5);
306 for (int i = 0; i < TR_FLAG_SIZE; i++)
307 o_ptr->art_flags[i] = 0;
310 o_ptr->curse_flags.set(TRC::CURSED);
313 o_ptr->ident |= (IDENT_BROKEN);
314 owner_ptr->update |= (PU_BONUS | PU_MANA);
315 owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
320 * @brief ボルトのエゴ化処理(火炎エゴのみ) /
322 * @param caster_ptr プレーヤーへの参照ポインタ
324 void brand_bolts(player_type *caster_ptr)
326 /* Use the first acceptable bolts */
327 for (int i = 0; i < INVEN_PACK; i++) {
328 object_type *o_ptr = &caster_ptr->inventory_list[i];
331 if (o_ptr->tval != TV_BOLT)
334 /* Skip artifacts and ego-items */
335 if (o_ptr->is_artifact() || o_ptr->is_ego())
338 /* Skip cursed/broken items */
339 if (o_ptr->is_cursed() || o_ptr->is_broken())
343 if (randint0(100) < 75)
346 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
349 o_ptr->name2 = EGO_FLAME;
350 enchant_equipment(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
356 msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
360 * @brief 知識の石の発動を実行する / Do activation of the stone of lore.
361 * @param user_ptr プレイヤー情報への参照ポインタ
362 * @return 実行したらTRUE、しなかったらFALSE
364 * 鑑定を実行した後HPを消費する。1/5で混乱し、1/20で追加ダメージ。
365 * MPがある場合はさらにMPを20消費する。不足する場合は麻痺及び混乱。
367 bool perilous_secrets(player_type *user_ptr)
369 if (!ident_spell(user_ptr, false))
372 if (user_ptr->msp > 0) {
373 if (20 <= user_ptr->csp)
376 int oops = 20 - user_ptr->csp;
379 user_ptr->csp_frac = 0;
381 msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
383 (void)set_paralyzed(user_ptr, user_ptr->paralyzed + randint1(5 * oops + 1));
384 (void)set_confused(user_ptr, user_ptr->confused + randint1(5 * oops + 1));
387 user_ptr->redraw |= (PR_MANA);
390 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"));
393 (void)set_confused(user_ptr, user_ptr->confused + randint1(10));
396 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"));
403 * Break the curse of an item
404 * @param o_ptr 呪い装備情報の参照ポインタ
406 static void break_curse(object_type *o_ptr)
408 BIT_FLAGS is_curse_broken
409 = o_ptr->is_cursed() && o_ptr->curse_flags.has_not(TRC::PERMA_CURSE) && o_ptr->curse_flags.has_not(TRC::HEAVY_CURSE) && (randint0(100) < 25);
410 if (!is_curse_broken) {
414 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
416 o_ptr->curse_flags.clear();
417 o_ptr->ident |= (IDENT_SENSE);
418 o_ptr->feeling = FEEL_NONE;
423 * Enchants a plus onto an item. -RAK-
424 * @param caster_ptr プレーヤーへの参照ポインタ
425 * @param o_ptr 強化するアイテムの参照ポインタ
427 * @param eflag 強化オプション(命中/ダメージ/AC)
428 * @return 強化に成功した場合TRUEを返す
431 * Revamped! Now takes item pointer, number of times to try enchanting,
432 * and a flag of what to try enchanting. Artifacts resist enchantment
433 * some of the time, and successful enchantment to at least +0 might
434 * break a curse on the item. -CFT-
436 * Note that an item can technically be enchanted all the way to +15 if
437 * you wait a very, very, long time. Going from +9 to +10 only works
438 * about 5% of the time, and from +10 to +11 only about 1% of the time.
440 * Note that this function can now be used on "piles" of items, and
441 * the larger the pile, the lower the chance of success.
444 bool enchant_equipment(player_type *caster_ptr, object_type *o_ptr, int n, int eflag)
446 /* Large piles resist enchantment */
447 int prob = o_ptr->number * 100;
449 /* Missiles are easy to enchant */
450 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
457 bool a = o_ptr->is_artifact();
458 bool force = (eflag & ENCH_FORCE);
459 for (int i = 0; i < n; i++) {
460 /* Hack -- Roll for pile resistance */
461 if (!force && randint0(prob) >= 100)
465 if (eflag & ENCH_TOHIT) {
468 else if (o_ptr->to_h > 15)
471 chance = enchant_table[o_ptr->to_h];
473 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
477 /* only when you get it above -1 -CFT */
478 if (o_ptr->to_h >= 0)
483 /* Enchant to damage */
484 if (eflag & ENCH_TODAM) {
487 else if (o_ptr->to_d > 15)
490 chance = enchant_table[o_ptr->to_d];
492 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
496 /* only when you get it above -1 -CFT */
497 if (o_ptr->to_d >= 0)
502 /* Enchant to armor class */
503 if (!(eflag & ENCH_TOAC)) {
509 else if (o_ptr->to_a > 15)
512 chance = enchant_table[o_ptr->to_a];
514 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
518 /* only when you get it above -1 -CFT */
519 if (o_ptr->to_a >= 0)
527 set_bits(caster_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
528 set_bits(caster_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
535 * @brief 装備修正強化処理のメインルーチン /
536 * Enchant an item (in the inventory or on the floor)
537 * @param caster_ptr プレーヤーへの参照ポインタ
538 * @param num_hit 命中修正量
539 * @param num_dam ダメージ修正量
540 * @param num_ac AC修正量
541 * @return 強化に成功した場合TRUEを返す
543 * Note that "num_ac" requires armour, else weapon
544 * Returns TRUE if attempted, FALSE if cancelled
546 bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
548 /* Assume enchant weapon */
549 FuncItemTester item_tester(&object_type::allow_enchant_weapon);
551 /* Enchant armor if requested */
553 item_tester = FuncItemTester(&object_type::is_armour);
555 concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
556 concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
560 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), item_tester);
564 GAME_TEXT o_name[MAX_NLEN];
565 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
567 msg_format("%s は明るく輝いた!", o_name);
569 msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
573 bool is_enchant_successful = false;
574 if (enchant_equipment(caster_ptr, o_ptr, num_hit, ENCH_TOHIT))
575 is_enchant_successful = true;
576 if (enchant_equipment(caster_ptr, o_ptr, num_dam, ENCH_TODAM))
577 is_enchant_successful = true;
578 if (enchant_equipment(caster_ptr, o_ptr, num_ac, ENCH_TOAC))
579 is_enchant_successful = true;
581 if (!is_enchant_successful) {
584 msg_print(_("強化に失敗した。", "The enchantment failed."));
586 chg_virtue(caster_ptr, V_ENCHANT, -1);
588 chg_virtue(caster_ptr, V_ENCHANT, 1);
590 calc_android_exp(caster_ptr);
592 /* Something happened */
597 * @brief 武器へのエゴ付加処理 /
598 * Brand the current weapon
599 * @param caster_ptr プレーヤーへの参照ポインタ
600 * @param brand_type エゴ化ID(e_info.txtとは連動していない)
602 void brand_weapon(player_type *caster_ptr, int brand_type)
604 concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
605 concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
609 o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | IGNORE_BOTHHAND_SLOT, FuncItemTester(&object_type::allow_enchant_melee_weapon));
613 bool is_special_item = o_ptr->k_idx && !o_ptr->is_artifact() && !o_ptr->is_ego() && !o_ptr->is_cursed()
614 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
615 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
616 if (!is_special_item) {
620 msg_print(_("属性付加に失敗した。", "The branding failed."));
621 chg_virtue(caster_ptr, V_ENCHANT, -2);
622 calc_android_exp(caster_ptr);
626 GAME_TEXT o_name[MAX_NLEN];
627 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
629 concptr act = nullptr;
630 switch (brand_type) {
632 if (o_ptr->tval == TV_SWORD) {
633 act = _("は鋭さを増した!", "becomes very sharp!");
635 o_ptr->name2 = EGO_SHARPNESS;
636 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, caster_ptr->current_floor_ptr->dun_level) + 1;
638 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
641 act = _("は破壊力を増した!", "seems very powerful.");
642 o_ptr->name2 = EGO_EARTHQUAKES;
643 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, caster_ptr->current_floor_ptr->dun_level);
648 act = _("は人間の血を求めている!", "seems to be looking for humans!");
649 o_ptr->name2 = EGO_KILL_HUMAN;
652 act = _("は電撃に覆われた!", "covered with lightning!");
653 o_ptr->name2 = EGO_BRAND_ELEC;
656 act = _("は酸に覆われた!", "coated with acid!");
657 o_ptr->name2 = EGO_BRAND_ACID;
660 act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
661 o_ptr->name2 = EGO_KILL_EVIL;
664 act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
665 o_ptr->name2 = EGO_KILL_DEMON;
668 act = _("は屍を求めている!", "seems to be looking for undead!");
669 o_ptr->name2 = EGO_KILL_UNDEAD;
672 act = _("は動物の血を求めている!", "seems to be looking for animals!");
673 o_ptr->name2 = EGO_KILL_ANIMAL;
676 act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
677 o_ptr->name2 = EGO_KILL_DRAGON;
680 act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
681 o_ptr->name2 = EGO_KILL_TROLL;
684 act = _("はオークの血を求めている!", "seems to be looking for orcs!");
685 o_ptr->name2 = EGO_KILL_ORC;
688 act = _("は巨人の血を求めている!", "seems to be looking for giants!");
689 o_ptr->name2 = EGO_KILL_GIANT;
692 act = _("は非常に不安定になったようだ。", "seems very unstable now.");
693 o_ptr->name2 = EGO_TRUMP;
694 o_ptr->pval = randint1(2);
697 act = _("は血を求めている!", "thirsts for blood!");
698 o_ptr->name2 = EGO_VAMPIRIC;
701 act = _("は毒に覆われた。", "is coated with poison.");
702 o_ptr->name2 = EGO_BRAND_POIS;
705 act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
706 o_ptr->name2 = EGO_CHAOTIC;
709 act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
710 o_ptr->name2 = EGO_BRAND_FIRE;
713 act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
714 o_ptr->name2 = EGO_BRAND_COLD;
718 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
719 enchant_equipment(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
720 o_ptr->discount = 99;
721 chg_virtue(caster_ptr, V_ENCHANT, 2);
722 calc_android_exp(caster_ptr);