OSDN Git Service

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