OSDN Git Service

Merge pull request #1510 from habu1010/feature/refactor-smith-info-class
[hengbandforosx/hengbandosx.git] / src / spell / spells-object.cpp
1 /*!
2  * @brief アイテムに影響のある魔法の処理
3  * @date 2019/01/22
4  * @author deskull
5  */
6
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-info/class-info.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"
50
51 typedef struct {
52     tval_type tval;
53     OBJECT_SUBTYPE_VALUE sval;
54     PERCENTAGE prob;
55     byte flag;
56 } amuse_type;
57
58 /*!
59  * @brief 装備強化処理の失敗率定数(千分率) /
60  * Used by the "enchant" function (chance of failure)
61  * (modified for Zangband, we need better stuff there...) -- TY
62  */
63 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
64
65 /*
66  * Scatter some "amusing" objects near the player
67  */
68
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 */
74
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 },
81
82           { TV_NONE, 0, 0, 0 } };
83
84 /*!
85  * @brief 誰得ドロップを行う。
86  * @param player_ptr プレーヤーへの参照ポインタ
87  * @param y1 配置したいフロアのY座標
88  * @param x1 配置したいフロアのX座標
89  * @param num 誰得の処理回数
90  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
91  */
92 void amusement(player_type *player_ptr, POSITION y1, POSITION x1, int num, bool known)
93 {
94     int t = 0;
95     for (int n = 0; amuse_info[n].tval != 0; n++) {
96         t += amuse_info[n].prob;
97     }
98
99     /* Acquirement */
100     object_type *i_ptr;
101     object_type object_type_body;
102     while (num) {
103         int i;
104         KIND_OBJECT_IDX k_idx;
105         ARTIFACT_IDX a_idx = 0;
106         int r = randint0(t);
107         bool insta_art, fixed_art;
108
109         for (i = 0;; i++) {
110             r -= amuse_info[i].prob;
111             if (r <= 0)
112                 break;
113         }
114         i_ptr = &object_type_body;
115         i_ptr->wipe();
116         k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
117
118         /* Paranoia - reroll if nothing */
119         if (!k_idx)
120             continue;
121
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);
125
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))
129                     continue;
130                 if (a_info[a_idx].tval != k_info[k_idx].tval)
131                     continue;
132                 if (a_info[a_idx].sval != k_info[k_idx].sval)
133                     continue;
134                 if (a_info[a_idx].cur_num > 0)
135                     continue;
136                 break;
137             }
138
139             if (a_idx >= max_a_idx)
140                 continue;
141         }
142
143         /* Make an object (if possible) */
144         i_ptr->prep(k_idx);
145         if (a_idx)
146             i_ptr->name1 = a_idx;
147         apply_magic_to_object(player_ptr, i_ptr, 1, AM_NO_FIXED_ART);
148
149         if (amuse_info[i].flag & AMS_NO_UNIQUE) {
150             if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE)
151                 continue;
152         }
153
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);
158
159         if (known) {
160             object_aware(player_ptr, i_ptr);
161             object_known(i_ptr);
162         }
163
164         /* Paranoia - reroll if nothing */
165         if (!(i_ptr->k_idx))
166             continue;
167
168         (void)drop_near(player_ptr, i_ptr, -1, y1, x1);
169
170         num--;
171     }
172 }
173
174 /*!
175  * @brief 獲得ドロップを行う。
176  * Scatter some "great" objects near the player
177  * @param player_ptr プレーヤーへの参照ポインタ
178  * @param y1 配置したいフロアのY座標
179  * @param x1 配置したいフロアのX座標
180  * @param num 獲得の処理回数
181  * @param great TRUEならば必ず高級品以上を落とす
182  * @param special TRUEならば必ず特別品を落とす
183  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
184  */
185 void acquirement(player_type *player_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
186 {
187     object_type *i_ptr;
188     object_type object_type_body;
189     BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : AM_NONE) | (special ? AM_SPECIAL : AM_NONE);
190
191     /* Acquirement */
192     while (num--) {
193         i_ptr = &object_type_body;
194         i_ptr->wipe();
195
196         /* Make a good (or great) object (if possible) */
197         if (!make_object(player_ptr, i_ptr, mode))
198             continue;
199
200         if (known) {
201             object_aware(player_ptr, i_ptr);
202             object_known(i_ptr);
203         }
204
205         (void)drop_near(player_ptr, i_ptr, -1, y1, x1);
206     }
207 }
208
209 /*!
210  * @brief 防具呪縛処理 /
211  * Curse the players armor
212  * @return 何も持っていない場合を除き、常にTRUEを返す
213  * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
214  */
215 bool curse_armor(player_type *player_ptr)
216 {
217     /* Curse the body armor */
218     object_type *o_ptr;
219     o_ptr = &player_ptr->inventory_list[INVEN_BODY];
220
221     if (!o_ptr->k_idx)
222         return false;
223
224     GAME_TEXT o_name[MAX_NLEN];
225     describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
226
227     /* Attempt a saving throw for artifacts */
228     if (o_ptr->is_artifact() && (randint0(100) < 50)) {
229         /* Cool */
230 #ifdef JP
231         msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
232 #else
233         msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
234 #endif
235         return true;
236     }
237
238     /* not artifact or failed save... */
239     msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
240     chg_virtue(player_ptr, V_ENCHANT, -5);
241
242     /* Blast the armor */
243     o_ptr->name1 = 0;
244     o_ptr->name2 = EGO_BLASTED;
245     o_ptr->to_a = 0 - randint1(5) - randint1(5);
246     o_ptr->to_h = 0;
247     o_ptr->to_d = 0;
248     o_ptr->ac = 0;
249     o_ptr->dd = 0;
250     o_ptr->ds = 0;
251
252     o_ptr->art_flags.clear();
253
254     /* Curse it */
255     o_ptr->curse_flags.set(TRC::CURSED);
256
257     /* Break it */
258     o_ptr->ident |= (IDENT_BROKEN);
259     player_ptr->update |= (PU_BONUS | PU_MANA);
260     player_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
261     return true;
262 }
263
264 /*!
265  * @brief 武器呪縛処理 /
266  * Curse the players weapon
267  * @param player_ptr 所持者の参照ポインタ
268  * @param force 無条件に呪縛を行うならばTRUE
269  * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
270  * @return 何も持っていない場合を除き、常にTRUEを返す
271  * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
272  */
273 bool curse_weapon_object(player_type *player_ptr, bool force, object_type *o_ptr)
274 {
275     if (!o_ptr->k_idx)
276         return false;
277
278     GAME_TEXT o_name[MAX_NLEN];
279     describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
280
281     /* Attempt a saving throw */
282     if (o_ptr->is_artifact() && (randint0(100) < 50) && !force) {
283 #ifdef JP
284         msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
285 #else
286         msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
287 #endif
288         return true;
289     }
290
291     /* not artifact or failed save... */
292     if (!force)
293         msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
294     chg_virtue(player_ptr, V_ENCHANT, -5);
295
296     /* Shatter the weapon */
297     o_ptr->name1 = 0;
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);
301     o_ptr->to_a = 0;
302     o_ptr->ac = 0;
303     o_ptr->dd = 0;
304     o_ptr->ds = 0;
305
306     o_ptr->art_flags.clear();
307
308     /* Curse it */
309     o_ptr->curse_flags.set(TRC::CURSED);
310
311     /* Break it */
312     o_ptr->ident |= (IDENT_BROKEN);
313     player_ptr->update |= (PU_BONUS | PU_MANA);
314     player_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
315     return true;
316 }
317
318 /*!
319  * @brief ボルトのエゴ化処理(火炎エゴのみ) /
320  * Enchant some bolts
321  * @param player_ptr プレーヤーへの参照ポインタ
322  */
323 void brand_bolts(player_type *player_ptr)
324 {
325     /* Use the first acceptable bolts */
326     for (int i = 0; i < INVEN_PACK; i++) {
327         object_type *o_ptr = &player_ptr->inventory_list[i];
328
329         /* Skip non-bolts */
330         if (o_ptr->tval != TV_BOLT)
331             continue;
332
333         /* Skip artifacts and ego-items */
334         if (o_ptr->is_artifact() || o_ptr->is_ego())
335             continue;
336
337         /* Skip cursed/broken items */
338         if (o_ptr->is_cursed() || o_ptr->is_broken())
339             continue;
340
341         /* Randomize */
342         if (randint0(100) < 75)
343             continue;
344
345         msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
346
347         /* Ego-item */
348         o_ptr->name2 = EGO_FLAME;
349         enchant_equipment(player_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
350         return;
351     }
352
353     if (flush_failure)
354         flush();
355     msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
356 }
357
358 /*!
359  * @brief 知識の石の発動を実行する / Do activation of the stone of lore.
360  * @param player_ptr プレイヤー情報への参照ポインタ
361  * @return 実行したらTRUE、しなかったらFALSE
362  * @details
363  * 鑑定を実行した後HPを消費する。1/5で混乱し、1/20で追加ダメージ。
364  * MPがある場合はさらにMPを20消費する。不足する場合は麻痺及び混乱。
365  */
366 bool perilous_secrets(player_type *player_ptr)
367 {
368     if (!ident_spell(player_ptr, false))
369         return false;
370
371     if (player_ptr->msp > 0) {
372         if (20 <= player_ptr->csp)
373             player_ptr->csp -= 20;
374         else {
375             int oops = 20 - player_ptr->csp;
376
377             player_ptr->csp = 0;
378             player_ptr->csp_frac = 0;
379
380             msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
381
382             (void)set_paralyzed(player_ptr, player_ptr->paralyzed + randint1(5 * oops + 1));
383             (void)set_confused(player_ptr, player_ptr->confused + randint1(5 * oops + 1));
384         }
385
386         player_ptr->redraw |= (PR_MANA);
387     }
388
389     take_hit(player_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"));
390
391     if (one_in_(5))
392         (void)set_confused(player_ptr, player_ptr->confused + randint1(10));
393
394     if (one_in_(20))
395         take_hit(player_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"));
396
397     return true;
398 }
399
400 /*!
401  * @brief 呪いの打ち破り処理 /
402  * Break the curse of an item
403  * @param o_ptr 呪い装備情報の参照ポインタ
404  */
405 static void break_curse(object_type *o_ptr)
406 {
407     BIT_FLAGS is_curse_broken
408         = 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);
409     if (!is_curse_broken) {
410         return;
411     }
412
413     msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
414
415     o_ptr->curse_flags.clear();
416     o_ptr->ident |= (IDENT_SENSE);
417     o_ptr->feeling = FEEL_NONE;
418 }
419
420 /*!
421  * @brief 装備修正強化処理 /
422  * Enchants a plus onto an item. -RAK-
423  * @param player_ptr プレーヤーへの参照ポインタ
424  * @param o_ptr 強化するアイテムの参照ポインタ
425  * @param n 強化基本量
426  * @param eflag 強化オプション(命中/ダメージ/AC)
427  * @return 強化に成功した場合TRUEを返す
428  * @details
429  * <pre>
430  * Revamped!  Now takes item pointer, number of times to try enchanting,
431  * and a flag of what to try enchanting.  Artifacts resist enchantment
432  * some of the time, and successful enchantment to at least +0 might
433  * break a curse on the item. -CFT-
434  *
435  * Note that an item can technically be enchanted all the way to +15 if
436  * you wait a very, very, long time.  Going from +9 to +10 only works
437  * about 5% of the time, and from +10 to +11 only about 1% of the time.
438  *
439  * Note that this function can now be used on "piles" of items, and
440  * the larger the pile, the lower the chance of success.
441  * </pre>
442  */
443 bool enchant_equipment(player_type *player_ptr, object_type *o_ptr, int n, int eflag)
444 {
445     /* Large piles resist enchantment */
446     int prob = o_ptr->number * 100;
447
448     /* Missiles are easy to enchant */
449     if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
450         prob = prob / 20;
451     }
452
453     /* Try "n" times */
454     int chance;
455     bool res = false;
456     bool a = o_ptr->is_artifact();
457     bool force = (eflag & ENCH_FORCE);
458     for (int i = 0; i < n; i++) {
459         /* Hack -- Roll for pile resistance */
460         if (!force && randint0(prob) >= 100)
461             continue;
462
463         /* Enchant to hit */
464         if (eflag & ENCH_TOHIT) {
465             if (o_ptr->to_h < 0)
466                 chance = 0;
467             else if (o_ptr->to_h > 15)
468                 chance = 1000;
469             else
470                 chance = enchant_table[o_ptr->to_h];
471
472             if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
473                 o_ptr->to_h++;
474                 res = true;
475
476                 /* only when you get it above -1 -CFT */
477                 if (o_ptr->to_h >= 0)
478                     break_curse(o_ptr);
479             }
480         }
481
482         /* Enchant to damage */
483         if (eflag & ENCH_TODAM) {
484             if (o_ptr->to_d < 0)
485                 chance = 0;
486             else if (o_ptr->to_d > 15)
487                 chance = 1000;
488             else
489                 chance = enchant_table[o_ptr->to_d];
490
491             if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
492                 o_ptr->to_d++;
493                 res = true;
494
495                 /* only when you get it above -1 -CFT */
496                 if (o_ptr->to_d >= 0)
497                     break_curse(o_ptr);
498             }
499         }
500
501         /* Enchant to armor class */
502         if (!(eflag & ENCH_TOAC)) {
503             continue;
504         }
505
506         if (o_ptr->to_a < 0)
507             chance = 0;
508         else if (o_ptr->to_a > 15)
509             chance = 1000;
510         else
511             chance = enchant_table[o_ptr->to_a];
512
513         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
514             o_ptr->to_a++;
515             res = true;
516
517             /* only when you get it above -1 -CFT */
518             if (o_ptr->to_a >= 0)
519                 break_curse(o_ptr);
520         }
521     }
522
523     /* Failure */
524     if (!res)
525         return false;
526     set_bits(player_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
527     set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
528
529     /* Success */
530     return true;
531 }
532
533 /*!
534  * @brief 装備修正強化処理のメインルーチン /
535  * Enchant an item (in the inventory or on the floor)
536  * @param player_ptr プレーヤーへの参照ポインタ
537  * @param num_hit 命中修正量
538  * @param num_dam ダメージ修正量
539  * @param num_ac AC修正量
540  * @return 強化に成功した場合TRUEを返す
541  * @details
542  * Note that "num_ac" requires armour, else weapon
543  * Returns TRUE if attempted, FALSE if cancelled
544  */
545 bool enchant_spell(player_type *player_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
546 {
547     /* Assume enchant weapon */
548     FuncItemTester item_tester(&object_type::allow_enchant_weapon);
549
550     /* Enchant armor if requested */
551     if (num_ac)
552         item_tester = FuncItemTester(&object_type::is_armour);
553
554     concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
555     concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
556
557     OBJECT_IDX item;
558     object_type *o_ptr;
559     o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), item_tester);
560     if (!o_ptr)
561         return false;
562
563     GAME_TEXT o_name[MAX_NLEN];
564     describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
565 #ifdef JP
566     msg_format("%s は明るく輝いた!", o_name);
567 #else
568     msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
569 #endif
570
571     /* Enchant */
572     bool is_enchant_successful = false;
573     if (enchant_equipment(player_ptr, o_ptr, num_hit, ENCH_TOHIT))
574         is_enchant_successful = true;
575     if (enchant_equipment(player_ptr, o_ptr, num_dam, ENCH_TODAM))
576         is_enchant_successful = true;
577     if (enchant_equipment(player_ptr, o_ptr, num_ac, ENCH_TOAC))
578         is_enchant_successful = true;
579
580     if (!is_enchant_successful) {
581         if (flush_failure)
582             flush();
583         msg_print(_("強化に失敗した。", "The enchantment failed."));
584         if (one_in_(3))
585             chg_virtue(player_ptr, V_ENCHANT, -1);
586     } else
587         chg_virtue(player_ptr, V_ENCHANT, 1);
588
589     calc_android_exp(player_ptr);
590
591     /* Something happened */
592     return true;
593 }
594
595 /*!
596  * @brief 武器へのエゴ付加処理 /
597  * Brand the current weapon
598  * @param player_ptr プレーヤーへの参照ポインタ
599  * @param brand_type エゴ化ID(e_info.txtとは連動していない)
600  */
601 void brand_weapon(player_type *player_ptr, int brand_type)
602 {
603     concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
604     concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
605
606     OBJECT_IDX item;
607     object_type *o_ptr;
608     o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | IGNORE_BOTHHAND_SLOT, FuncItemTester(&object_type::allow_enchant_melee_weapon));
609     if (!o_ptr)
610         return;
611
612     bool is_special_item = o_ptr->k_idx && !o_ptr->is_artifact() && !o_ptr->is_ego() && !o_ptr->is_cursed()
613         && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
614         && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
615     if (!is_special_item) {
616         if (flush_failure)
617             flush();
618
619         msg_print(_("属性付加に失敗した。", "The branding failed."));
620         chg_virtue(player_ptr, V_ENCHANT, -2);
621         calc_android_exp(player_ptr);
622         return;
623     }
624
625     GAME_TEXT o_name[MAX_NLEN];
626     describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
627
628     concptr act = nullptr;
629     switch (brand_type) {
630     case 17:
631         if (o_ptr->tval == TV_SWORD) {
632             act = _("は鋭さを増した!", "becomes very sharp!");
633
634             o_ptr->name2 = EGO_SHARPNESS;
635             o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, player_ptr->current_floor_ptr->dun_level) + 1;
636
637             if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
638                 o_ptr->pval = 2;
639         } else {
640             act = _("は破壊力を増した!", "seems very powerful.");
641             o_ptr->name2 = EGO_EARTHQUAKES;
642             o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, player_ptr->current_floor_ptr->dun_level);
643         }
644
645         break;
646     case 16:
647         act = _("は人間の血を求めている!", "seems to be looking for humans!");
648         o_ptr->name2 = EGO_KILL_HUMAN;
649         break;
650     case 15:
651         act = _("は電撃に覆われた!", "covered with lightning!");
652         o_ptr->name2 = EGO_BRAND_ELEC;
653         break;
654     case 14:
655         act = _("は酸に覆われた!", "coated with acid!");
656         o_ptr->name2 = EGO_BRAND_ACID;
657         break;
658     case 13:
659         act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
660         o_ptr->name2 = EGO_KILL_EVIL;
661         break;
662     case 12:
663         act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
664         o_ptr->name2 = EGO_KILL_DEMON;
665         break;
666     case 11:
667         act = _("は屍を求めている!", "seems to be looking for undead!");
668         o_ptr->name2 = EGO_KILL_UNDEAD;
669         break;
670     case 10:
671         act = _("は動物の血を求めている!", "seems to be looking for animals!");
672         o_ptr->name2 = EGO_KILL_ANIMAL;
673         break;
674     case 9:
675         act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
676         o_ptr->name2 = EGO_KILL_DRAGON;
677         break;
678     case 8:
679         act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
680         o_ptr->name2 = EGO_KILL_TROLL;
681         break;
682     case 7:
683         act = _("はオークの血を求めている!", "seems to be looking for orcs!");
684         o_ptr->name2 = EGO_KILL_ORC;
685         break;
686     case 6:
687         act = _("は巨人の血を求めている!", "seems to be looking for giants!");
688         o_ptr->name2 = EGO_KILL_GIANT;
689         break;
690     case 5:
691         act = _("は非常に不安定になったようだ。", "seems very unstable now.");
692         o_ptr->name2 = EGO_TRUMP;
693         o_ptr->pval = randint1(2);
694         break;
695     case 4:
696         act = _("は血を求めている!", "thirsts for blood!");
697         o_ptr->name2 = EGO_VAMPIRIC;
698         break;
699     case 3:
700         act = _("は毒に覆われた。", "is coated with poison.");
701         o_ptr->name2 = EGO_BRAND_POIS;
702         break;
703     case 2:
704         act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
705         o_ptr->name2 = EGO_CHAOTIC;
706         break;
707     case 1:
708         act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
709         o_ptr->name2 = EGO_BRAND_FIRE;
710         break;
711     default:
712         act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
713         o_ptr->name2 = EGO_BRAND_COLD;
714         break;
715     }
716
717     msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
718     enchant_equipment(player_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
719     o_ptr->discount = 99;
720     chg_virtue(player_ptr, V_ENCHANT, 2);
721     calc_android_exp(player_ptr);
722 }