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 "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
64 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
67 * Scatter some "amusing" objects near the player
70 #define AMS_NOTHING 0x00 /* No restriction */
71 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
72 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
73 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
74 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
76 static amuse_type amuse_info[]
77 = { { 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 },
78 { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
79 { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
80 { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
81 { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
83 { TV_NONE, 0, 0, 0 } };
87 * @param creature_ptr プレーヤーへの参照ポインタ
88 * @param y1 配置したいフロアのY座標
89 * @param x1 配置したいフロアのX座標
91 * @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) */
146 object_prep(creature_ptr, i_ptr, k_idx);
148 i_ptr->name1 = a_idx;
149 apply_magic(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ならばオブジェクトが必ず*鑑定*済になる
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 プレーヤーへの参照ポインタ
329 void brand_bolts(player_type *caster_ptr)
331 /* Use the first acceptable bolts */
332 for (int i = 0; i < INVEN_PACK; i++) {
333 object_type *o_ptr = &caster_ptr->inventory_list[i];
336 if (o_ptr->tval != TV_BOLT)
339 /* Skip artifacts and ego-items */
340 if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
343 /* Skip cursed/broken items */
344 if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
348 if (randint0(100) < 75)
351 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
354 o_ptr->name2 = EGO_FLAME;
355 enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
361 msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
365 * @brief 知識の石の発動を実行する / Do activation of the stone of lore.
366 * @param user_ptr プレイヤー情報への参照ポインタ
367 * @return 実行したらTRUE、しなかったらFALSE
369 * 鑑定を実行した後HPを消費する。1/5で混乱し、1/20で追加ダメージ。
370 * MPがある場合はさらにMPを20消費する。不足する場合は麻痺及び混乱。
372 bool perilous_secrets(player_type *user_ptr)
374 if (!ident_spell(user_ptr, FALSE, TV_NONE))
377 if (user_ptr->msp > 0) {
378 if (20 <= user_ptr->csp)
381 int oops = 20 - user_ptr->csp;
384 user_ptr->csp_frac = 0;
386 msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
388 (void)set_paralyzed(user_ptr, user_ptr->paralyzed + randint1(5 * oops + 1));
389 (void)set_confused(user_ptr, user_ptr->confused + randint1(5 * oops + 1));
392 user_ptr->redraw |= (PR_MANA);
395 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"), -1);
398 (void)set_confused(user_ptr, user_ptr->confused + randint1(10));
401 take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"), -1);
408 * Break the curse of an item
409 * @param o_ptr 呪い装備情報の参照ポインタ
412 static void break_curse(object_type *o_ptr)
414 BIT_FLAGS is_curse_broken
415 = object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25);
416 if (!is_curse_broken) {
420 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
422 o_ptr->curse_flags = 0L;
423 o_ptr->ident |= (IDENT_SENSE);
424 o_ptr->feeling = FEEL_NONE;
429 * Enchants a plus onto an item. -RAK-
430 * @param caster_ptr プレーヤーへの参照ポインタ
431 * @param o_ptr 強化するアイテムの参照ポインタ
433 * @param eflag 強化オプション(命中/ダメージ/AC)
434 * @return 強化に成功した場合TRUEを返す
437 * Revamped! Now takes item pointer, number of times to try enchanting,
438 * and a flag of what to try enchanting. Artifacts resist enchantment
439 * some of the time, and successful enchantment to at least +0 might
440 * break a curse on the item. -CFT-
442 * Note that an item can technically be enchanted all the way to +15 if
443 * you wait a very, very, long time. Going from +9 to +10 only works
444 * about 5% of the time, and from +10 to +11 only about 1% of the time.
446 * Note that this function can now be used on "piles" of items, and
447 * the larger the pile, the lower the chance of success.
450 bool enchant(player_type *caster_ptr, object_type *o_ptr, int n, int eflag)
452 /* Large piles resist enchantment */
453 int prob = o_ptr->number * 100;
455 /* Missiles are easy to enchant */
456 if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
463 bool a = object_is_artifact(o_ptr);
464 bool force = (eflag & ENCH_FORCE);
465 for (int i = 0; i < n; i++) {
466 /* Hack -- Roll for pile resistance */
467 if (!force && randint0(prob) >= 100)
471 if (eflag & ENCH_TOHIT) {
474 else if (o_ptr->to_h > 15)
477 chance = enchant_table[o_ptr->to_h];
479 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
483 /* only when you get it above -1 -CFT */
484 if (o_ptr->to_h >= 0)
489 /* Enchant to damage */
490 if (eflag & ENCH_TODAM) {
493 else if (o_ptr->to_d > 15)
496 chance = enchant_table[o_ptr->to_d];
498 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
502 /* only when you get it above -1 -CFT */
503 if (o_ptr->to_d >= 0)
508 /* Enchant to armor class */
509 if (!(eflag & ENCH_TOAC)) {
515 else if (o_ptr->to_a > 15)
518 chance = enchant_table[o_ptr->to_a];
520 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
524 /* only when you get it above -1 -CFT */
525 if (o_ptr->to_a >= 0)
533 set_bits(caster_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
534 set_bits(caster_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
536 calc_android_exp(caster_ptr);
543 * @brief 装備修正強化処理のメインルーチン /
544 * Enchant an item (in the inventory or on the floor)
545 * @param caster_ptr プレーヤーへの参照ポインタ
546 * @param num_hit 命中修正量
547 * @param num_dam ダメージ修正量
548 * @param num_ac AC修正量
549 * @return 強化に成功した場合TRUEを返す
551 * Note that "num_ac" requires armour, else weapon
552 * Returns TRUE if attempted, FALSE if cancelled
554 bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
556 /* Assume enchant weapon */
557 item_tester_hook = object_allow_enchant_weapon;
559 /* Enchant armor if requested */
561 item_tester_hook = object_is_armour;
563 concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
564 concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
568 o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_NONE);
572 GAME_TEXT o_name[MAX_NLEN];
573 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
575 msg_format("%s は明るく輝いた!", o_name);
577 msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
581 bool is_enchant_successful = FALSE;
582 if (enchant(caster_ptr, o_ptr, num_hit, ENCH_TOHIT))
583 is_enchant_successful = TRUE;
584 if (enchant(caster_ptr, o_ptr, num_dam, ENCH_TODAM))
585 is_enchant_successful = TRUE;
586 if (enchant(caster_ptr, o_ptr, num_ac, ENCH_TOAC))
587 is_enchant_successful = TRUE;
589 if (!is_enchant_successful) {
592 msg_print(_("強化に失敗した。", "The enchantment failed."));
594 chg_virtue(caster_ptr, V_ENCHANT, -1);
596 chg_virtue(caster_ptr, V_ENCHANT, 1);
598 calc_android_exp(caster_ptr);
600 /* Something happened */
605 * @brief 武器へのエゴ付加処理 /
606 * Brand the current weapon
607 * @param caster_ptr プレーヤーへの参照ポインタ
608 * @param brand_type エゴ化ID(e_info.txtとは連動していない)
611 void brand_weapon(player_type *caster_ptr, int brand_type)
613 /* Assume enchant weapon */
614 item_tester_hook = object_allow_enchant_melee_weapon;
616 concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
617 concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
621 o_ptr = choose_object(caster_ptr, &item, q, s, USE_EQUIP | IGNORE_BOTHHAND_SLOT, TV_NONE);
625 bool is_special_item = o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) && !object_is_cursed(o_ptr)
626 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
627 && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
628 if (!is_special_item) {
632 msg_print(_("属性付加に失敗した。", "The branding failed."));
633 chg_virtue(caster_ptr, V_ENCHANT, -2);
634 calc_android_exp(caster_ptr);
638 GAME_TEXT o_name[MAX_NLEN];
639 describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
642 switch (brand_type) {
644 if (o_ptr->tval == TV_SWORD) {
645 act = _("は鋭さを増した!", "becomes very sharp!");
647 o_ptr->name2 = EGO_SHARPNESS;
648 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, caster_ptr->current_floor_ptr->dun_level) + 1;
650 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
653 act = _("は破壊力を増した!", "seems very powerful.");
654 o_ptr->name2 = EGO_EARTHQUAKES;
655 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, caster_ptr->current_floor_ptr->dun_level);
660 act = _("は人間の血を求めている!", "seems to be looking for humans!");
661 o_ptr->name2 = EGO_KILL_HUMAN;
664 act = _("は電撃に覆われた!", "covered with lightning!");
665 o_ptr->name2 = EGO_BRAND_ELEC;
668 act = _("は酸に覆われた!", "coated with acid!");
669 o_ptr->name2 = EGO_BRAND_ACID;
672 act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
673 o_ptr->name2 = EGO_KILL_EVIL;
676 act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
677 o_ptr->name2 = EGO_KILL_DEMON;
680 act = _("は屍を求めている!", "seems to be looking for undead!");
681 o_ptr->name2 = EGO_KILL_UNDEAD;
684 act = _("は動物の血を求めている!", "seems to be looking for animals!");
685 o_ptr->name2 = EGO_KILL_ANIMAL;
688 act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
689 o_ptr->name2 = EGO_KILL_DRAGON;
692 act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
693 o_ptr->name2 = EGO_KILL_TROLL;
696 act = _("はオークの血を求めている!", "seems to be looking for orcs!");
697 o_ptr->name2 = EGO_KILL_ORC;
700 act = _("は巨人の血を求めている!", "seems to be looking for giants!");
701 o_ptr->name2 = EGO_KILL_GIANT;
704 act = _("は非常に不安定になったようだ。", "seems very unstable now.");
705 o_ptr->name2 = EGO_TRUMP;
706 o_ptr->pval = randint1(2);
709 act = _("は血を求めている!", "thirsts for blood!");
710 o_ptr->name2 = EGO_VAMPIRIC;
713 act = _("は毒に覆われた。", "is coated with poison.");
714 o_ptr->name2 = EGO_BRAND_POIS;
717 act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
718 o_ptr->name2 = EGO_CHAOTIC;
721 act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
722 o_ptr->name2 = EGO_BRAND_FIRE;
725 act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
726 o_ptr->name2 = EGO_BRAND_COLD;
730 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
731 enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
732 o_ptr->discount = 99;
733 chg_virtue(caster_ptr, V_ENCHANT, 2);
734 calc_android_exp(caster_ptr);