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-checker.h"
29 #include "object-hook/hook-enchant.h"
30 #include "object-hook/hook-weapon.h"
31 #include "object/item-tester-hooker.h"
32 #include "object/item-use-flags.h"
33 #include "object/object-kind-hook.h"
34 #include "object/object-kind.h"
35 #include "perception/object-perception.h"
36 #include "player/player-class.h"
37 #include "player/player-damage.h"
38 #include "racial/racial-android.h"
39 #include "spell-kind/spells-perception.h"
40 #include "status/bad-status-setter.h"
41 #include "sv-definition/sv-other-types.h"
42 #include "sv-definition/sv-scroll-types.h"
43 #include "sv-definition/sv-weapon-types.h"
44 #include "system/artifact-type-definition.h"
45 #include "system/floor-type-definition.h"
46 #include "system/monster-race-definition.h"
47 #include "system/object-type-definition.h"
48 #include "system/player-type-definition.h"
49 #include "term/screen-processor.h"
50 #include "util/bit-flags-calculator.h"
51 #include "view/display-messages.h"
55 OBJECT_SUBTYPE_VALUE sval;
61 * @brief 装備強化処理の失敗率定数(千分率) /
62 * Used by the "enchant" function (chance of failure)
63 * (modified for Zangband, we need better stuff there...) -- TY
65 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
68 * Scatter some "amusing" objects near the player
71 #define AMS_NOTHING 0x00 /* No restriction */
72 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
73 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
74 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
75 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
77 static amuse_type amuse_info[]
78 = { { 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 },
79 { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
80 { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
81 { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
82 { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
84 { TV_NONE, 0, 0, 0 } };
88 * @param creature_ptr プレーヤーへの参照ポインタ
89 * @param y1 配置したいフロアのY座標
90 * @param x1 配置したいフロアのX座標
92 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
94 void amusement(player_type *creature_ptr, POSITION y1, POSITION x1, int num, bool known)
97 for (int n = 0; amuse_info[n].tval != 0; n++) {
98 t += amuse_info[n].prob;
103 object_type object_type_body;
106 KIND_OBJECT_IDX k_idx;
107 ARTIFACT_IDX a_idx = 0;
109 bool insta_art, fixed_art;
112 r -= amuse_info[i].prob;
116 i_ptr = &object_type_body;
118 k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
120 /* Paranoia - reroll if nothing */
124 /* Search an artifact index if need */
125 insta_art = k_info[k_idx].gen_flags.has(TRG::INSTA_ART);
126 fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
128 if (insta_art || fixed_art) {
129 for (a_idx = 1; a_idx < max_a_idx; a_idx++) {
130 if (insta_art && !a_info[a_idx].gen_flags.has(TRG::INSTA_ART))
132 if (a_info[a_idx].tval != k_info[k_idx].tval)
134 if (a_info[a_idx].sval != k_info[k_idx].sval)
136 if (a_info[a_idx].cur_num > 0)
141 if (a_idx >= max_a_idx)
145 /* Make an object (if possible) */
148 i_ptr->name1 = a_idx;
149 apply_magic_to_object(creature_ptr, i_ptr, 1, AM_NO_FIXED_ART);
151 if (amuse_info[i].flag & AMS_NO_UNIQUE) {
152 if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE)
156 if (amuse_info[i].flag & AMS_MULTIPLE)
157 i_ptr->number = randint1(3);
158 if (amuse_info[i].flag & AMS_PILE)
159 i_ptr->number = randint1(99);
162 object_aware(creature_ptr, i_ptr);
166 /* Paranoia - reroll if nothing */
170 (void)drop_near(creature_ptr, i_ptr, -1, y1, x1);
178 * Scatter some "great" objects near the player
179 * @param caster_ptr プレーヤーへの参照ポインタ
180 * @param y1 配置したいフロアのY座標
181 * @param x1 配置したいフロアのX座標
183 * @param great TRUEならば必ず高級品以上を落とす
184 * @param special TRUEならば必ず特別品を落とす
185 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
187 void acquirement(player_type *caster_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
190 object_type object_type_body;
191 BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : AM_NONE) | (special ? AM_SPECIAL : AM_NONE);
195 i_ptr = &object_type_body;
198 /* Make a good (or great) object (if possible) */
199 if (!make_object(caster_ptr, i_ptr, mode))
203 object_aware(caster_ptr, i_ptr);
207 (void)drop_near(caster_ptr, i_ptr, -1, y1, x1);
213 * Curse the players armor
214 * @return 何も持っていない場合を除き、常にTRUEを返す
215 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
217 bool curse_armor(player_type *owner_ptr)
219 /* Curse the body armor */
221 o_ptr = &owner_ptr->inventory_list[INVEN_BODY];
226 GAME_TEXT o_name[MAX_NLEN];
227 describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
229 /* Attempt a saving throw for artifacts */
230 if (o_ptr->is_artifact() && (randint0(100) < 50)) {
233 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
235 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
240 /* not artifact or failed save... */
241 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
242 chg_virtue(owner_ptr, V_ENCHANT, -5);
244 /* Blast the armor */
246 o_ptr->name2 = EGO_BLASTED;
247 o_ptr->to_a = 0 - randint1(5) - randint1(5);
254 for (int i = 0; i < TR_FLAG_SIZE; i++)
255 o_ptr->art_flags[i] = 0;
258 o_ptr->curse_flags.set(TRC::CURSED);
261 o_ptr->ident |= (IDENT_BROKEN);
262 owner_ptr->update |= (PU_BONUS | PU_MANA);
263 owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
269 * Curse the players weapon
270 * @param owner_ptr 所持者の参照ポインタ
271 * @param force 無条件に呪縛を行うならばTRUE
272 * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
273 * @return 何も持っていない場合を除き、常にTRUEを返す
274 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
276 bool curse_weapon_object(player_type *owner_ptr, bool force, object_type *o_ptr)
281 GAME_TEXT o_name[MAX_NLEN];
282 describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
284 /* Attempt a saving throw */
285 if (o_ptr->is_artifact() && (randint0(100) < 50) && !force) {
287 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
289 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
294 /* not artifact or failed save... */
296 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
297 chg_virtue(owner_ptr, V_ENCHANT, -5);
299 /* Shatter the weapon */
301 o_ptr->name2 = EGO_SHATTERED;
302 o_ptr->to_h = 0 - randint1(5) - randint1(5);
303 o_ptr->to_d = 0 - randint1(5) - randint1(5);
309 for (int i = 0; i < TR_FLAG_SIZE; i++)
310 o_ptr->art_flags[i] = 0;
313 o_ptr->curse_flags.set(TRC::CURSED);
316 o_ptr->ident |= (IDENT_BROKEN);
317 owner_ptr->update |= (PU_BONUS | PU_MANA);
318 owner_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
323 * @brief ボルトのエゴ化処理(火炎エゴのみ) /
325 * @param caster_ptr プレーヤーへの参照ポインタ
327 void brand_bolts(player_type *caster_ptr)
329 /* Use the first acceptable bolts */
330 for (int i = 0; i < INVEN_PACK; i++) {
331 object_type *o_ptr = &caster_ptr->inventory_list[i];
334 if (o_ptr->tval != TV_BOLT)
337 /* Skip artifacts and ego-items */
338 if (o_ptr->is_artifact() || o_ptr->is_ego())
341 /* Skip cursed/broken items */
342 if (o_ptr->is_cursed() || o_ptr->is_broken())
346 if (randint0(100) < 75)
349 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
352 o_ptr->name2 = EGO_FLAME;
353 enchant_equipment(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
359 msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
363 * @brief 知識の石の発動を実行する / Do activation of the stone of lore.
364 * @param user_ptr プレイヤー情報への参照ポインタ
365 * @return 実行したらTRUE、しなかったらFALSE
367 * 鑑定を実行した後HPを消費する。1/5で混乱し、1/20で追加ダメージ。
368 * MPがある場合はさらにMPを20消費する。不足する場合は麻痺及び混乱。
370 bool perilous_secrets(player_type *user_ptr)
372 if (!ident_spell(user_ptr, false))
375 if (user_ptr->msp > 0) {
376 if (20 <= user_ptr->csp)
379 int oops = 20 - user_ptr->csp;
382 user_ptr->csp_frac = 0;
384 msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
386 (void)set_paralyzed(user_ptr, user_ptr->paralyzed + randint1(5 * oops + 1));
387 (void)set_confused(user_ptr, user_ptr->confused + randint1(5 * oops + 1));
390 user_ptr->redraw |= (PR_MANA);
393 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"));
396 (void)set_confused(user_ptr, user_ptr->confused + randint1(10));
399 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"));
406 * Break the curse of an item
407 * @param o_ptr 呪い装備情報の参照ポインタ
409 static void break_curse(object_type *o_ptr)
411 BIT_FLAGS is_curse_broken
412 = 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);
413 if (!is_curse_broken) {
417 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
419 o_ptr->curse_flags.clear();
420 o_ptr->ident |= (IDENT_SENSE);
421 o_ptr->feeling = FEEL_NONE;
426 * Enchants a plus onto an item. -RAK-
427 * @param caster_ptr プレーヤーへの参照ポインタ
428 * @param o_ptr 強化するアイテムの参照ポインタ
430 * @param eflag 強化オプション(命中/ダメージ/AC)
431 * @return 強化に成功した場合TRUEを返す
434 * Revamped! Now takes item pointer, number of times to try enchanting,
435 * and a flag of what to try enchanting. Artifacts resist enchantment
436 * some of the time, and successful enchantment to at least +0 might
437 * break a curse on the item. -CFT-
439 * Note that an item can technically be enchanted all the way to +15 if
440 * you wait a very, very, long time. Going from +9 to +10 only works
441 * about 5% of the time, and from +10 to +11 only about 1% of the time.
443 * Note that this function can now be used on "piles" of items, and
444 * the larger the pile, the lower the chance of success.
447 bool enchant_equipment(player_type *caster_ptr, object_type *o_ptr, int n, int eflag)
449 /* Large piles resist enchantment */
450 int prob = o_ptr->number * 100;
452 /* Missiles are easy to enchant */
453 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
460 bool a = o_ptr->is_artifact();
461 bool force = (eflag & ENCH_FORCE);
462 for (int i = 0; i < n; i++) {
463 /* Hack -- Roll for pile resistance */
464 if (!force && randint0(prob) >= 100)
468 if (eflag & ENCH_TOHIT) {
471 else if (o_ptr->to_h > 15)
474 chance = enchant_table[o_ptr->to_h];
476 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
480 /* only when you get it above -1 -CFT */
481 if (o_ptr->to_h >= 0)
486 /* Enchant to damage */
487 if (eflag & ENCH_TODAM) {
490 else if (o_ptr->to_d > 15)
493 chance = enchant_table[o_ptr->to_d];
495 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
499 /* only when you get it above -1 -CFT */
500 if (o_ptr->to_d >= 0)
505 /* Enchant to armor class */
506 if (!(eflag & ENCH_TOAC)) {
512 else if (o_ptr->to_a > 15)
515 chance = enchant_table[o_ptr->to_a];
517 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
521 /* only when you get it above -1 -CFT */
522 if (o_ptr->to_a >= 0)
530 set_bits(caster_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
531 set_bits(caster_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
538 * @brief 装備修正強化処理のメインルーチン /
539 * Enchant an item (in the inventory or on the floor)
540 * @param caster_ptr プレーヤーへの参照ポインタ
541 * @param num_hit 命中修正量
542 * @param num_dam ダメージ修正量
543 * @param num_ac AC修正量
544 * @return 強化に成功した場合TRUEを返す
546 * Note that "num_ac" requires armour, else weapon
547 * Returns TRUE if attempted, FALSE if cancelled
549 bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
551 /* Assume enchant weapon */
552 FuncItemTester item_tester(&object_type::allow_enchant_weapon);
554 /* Enchant armor if requested */
556 item_tester = FuncItemTester(&object_type::is_armour);
558 concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
559 concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
563 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), item_tester);
567 GAME_TEXT o_name[MAX_NLEN];
568 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
570 msg_format("%s は明るく輝いた!", o_name);
572 msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
576 bool is_enchant_successful = false;
577 if (enchant_equipment(caster_ptr, o_ptr, num_hit, ENCH_TOHIT))
578 is_enchant_successful = true;
579 if (enchant_equipment(caster_ptr, o_ptr, num_dam, ENCH_TODAM))
580 is_enchant_successful = true;
581 if (enchant_equipment(caster_ptr, o_ptr, num_ac, ENCH_TOAC))
582 is_enchant_successful = true;
584 if (!is_enchant_successful) {
587 msg_print(_("強化に失敗した。", "The enchantment failed."));
589 chg_virtue(caster_ptr, V_ENCHANT, -1);
591 chg_virtue(caster_ptr, V_ENCHANT, 1);
593 calc_android_exp(caster_ptr);
595 /* Something happened */
600 * @brief 武器へのエゴ付加処理 /
601 * Brand the current weapon
602 * @param caster_ptr プレーヤーへの参照ポインタ
603 * @param brand_type エゴ化ID(e_info.txtとは連動していない)
605 void brand_weapon(player_type *caster_ptr, int brand_type)
607 concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
608 concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
612 o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | IGNORE_BOTHHAND_SLOT, FuncItemTester(&object_type::allow_enchant_melee_weapon));
616 bool is_special_item = o_ptr->k_idx && !o_ptr->is_artifact() && !o_ptr->is_ego() && !o_ptr->is_cursed()
617 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
618 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
619 if (!is_special_item) {
623 msg_print(_("属性付加に失敗した。", "The branding failed."));
624 chg_virtue(caster_ptr, V_ENCHANT, -2);
625 calc_android_exp(caster_ptr);
629 GAME_TEXT o_name[MAX_NLEN];
630 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
633 switch (brand_type) {
635 if (o_ptr->tval == TV_SWORD) {
636 act = _("は鋭さを増した!", "becomes very sharp!");
638 o_ptr->name2 = EGO_SHARPNESS;
639 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, caster_ptr->current_floor_ptr->dun_level) + 1;
641 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
644 act = _("は破壊力を増した!", "seems very powerful.");
645 o_ptr->name2 = EGO_EARTHQUAKES;
646 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, caster_ptr->current_floor_ptr->dun_level);
651 act = _("は人間の血を求めている!", "seems to be looking for humans!");
652 o_ptr->name2 = EGO_KILL_HUMAN;
655 act = _("は電撃に覆われた!", "covered with lightning!");
656 o_ptr->name2 = EGO_BRAND_ELEC;
659 act = _("は酸に覆われた!", "coated with acid!");
660 o_ptr->name2 = EGO_BRAND_ACID;
663 act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
664 o_ptr->name2 = EGO_KILL_EVIL;
667 act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
668 o_ptr->name2 = EGO_KILL_DEMON;
671 act = _("は屍を求めている!", "seems to be looking for undead!");
672 o_ptr->name2 = EGO_KILL_UNDEAD;
675 act = _("は動物の血を求めている!", "seems to be looking for animals!");
676 o_ptr->name2 = EGO_KILL_ANIMAL;
679 act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
680 o_ptr->name2 = EGO_KILL_DRAGON;
683 act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
684 o_ptr->name2 = EGO_KILL_TROLL;
687 act = _("はオークの血を求めている!", "seems to be looking for orcs!");
688 o_ptr->name2 = EGO_KILL_ORC;
691 act = _("は巨人の血を求めている!", "seems to be looking for giants!");
692 o_ptr->name2 = EGO_KILL_GIANT;
695 act = _("は非常に不安定になったようだ。", "seems very unstable now.");
696 o_ptr->name2 = EGO_TRUMP;
697 o_ptr->pval = randint1(2);
700 act = _("は血を求めている!", "thirsts for blood!");
701 o_ptr->name2 = EGO_VAMPIRIC;
704 act = _("は毒に覆われた。", "is coated with poison.");
705 o_ptr->name2 = EGO_BRAND_POIS;
708 act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
709 o_ptr->name2 = EGO_CHAOTIC;
712 act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
713 o_ptr->name2 = EGO_BRAND_FIRE;
716 act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
717 o_ptr->name2 = EGO_BRAND_COLD;
721 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
722 enchant_equipment(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
723 o_ptr->discount = 99;
724 chg_virtue(caster_ptr, V_ENCHANT, 2);
725 calc_android_exp(caster_ptr);