2 * @brief アイテムに影響のある魔法の処理
7 #include "spell/spells-object.h"
8 #include "avatar/avatar.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/item-apply-magic.h"
19 #include "object-enchant/item-feeling.h"
20 #include "object-enchant/item-magic-applier.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-weapon.h"
28 #include "object/item-tester-hooker.h"
29 #include "object/item-use-flags.h"
30 #include "object/object-kind-hook.h"
31 #include "object/object-kind.h"
32 #include "perception/object-perception.h"
33 #include "player-info/class-info.h"
34 #include "racial/racial-android.h"
35 #include "sv-definition/sv-other-types.h"
36 #include "sv-definition/sv-scroll-types.h"
37 #include "sv-definition/sv-weapon-types.h"
38 #include "system/artifact-type-definition.h"
39 #include "system/floor-type-definition.h"
40 #include "system/monster-race-definition.h"
41 #include "system/object-type-definition.h"
42 #include "system/player-type-definition.h"
43 #include "term/screen-processor.h"
44 #include "util/bit-flags-calculator.h"
45 #include "view/display-messages.h"
49 OBJECT_SUBTYPE_VALUE sval;
55 * @brief 装備強化処理の失敗率定数(千分率) /
56 * Used by the "enchant" function (chance of failure)
57 * (modified for Zangband, we need better stuff there...) -- TY
59 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
62 * Scatter some "amusing" objects near the player
65 #define AMS_NOTHING 0x00 /* No restriction */
66 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
67 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
68 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
69 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
71 static amuse_type amuse_info[] = { { ItemKindType::BOTTLE, SV_ANY, 5, AMS_NOTHING }, { ItemKindType::JUNK, SV_ANY, 3, AMS_MULTIPLE }, { ItemKindType::SPIKE, SV_ANY, 10, AMS_PILE }, { ItemKindType::STATUE, SV_ANY, 15, AMS_NOTHING },
72 { ItemKindType::CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { ItemKindType::SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { ItemKindType::FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
73 { ItemKindType::PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { ItemKindType::POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
74 { ItemKindType::SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
75 { ItemKindType::SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { ItemKindType::SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { ItemKindType::SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
77 { ItemKindType::NONE, 0, 0, 0 } };
81 * @param player_ptr プレイヤーへの参照ポインタ
82 * @param y1 配置したいフロアのY座標
83 * @param x1 配置したいフロアのX座標
85 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
87 void amusement(PlayerType *player_ptr, POSITION y1, POSITION x1, int num, bool known)
90 for (int n = 0; amuse_info[n].tval != ItemKindType::NONE; n++) {
91 t += amuse_info[n].prob;
96 ObjectType ObjectType_body;
99 KIND_OBJECT_IDX k_idx;
100 ARTIFACT_IDX a_idx = 0;
102 bool insta_art, fixed_art;
105 r -= amuse_info[i].prob;
110 i_ptr = &ObjectType_body;
112 k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
114 /* Paranoia - reroll if nothing */
119 /* Search an artifact index if need */
120 insta_art = k_info[k_idx].gen_flags.has(ItemGenerationTraitType::INSTA_ART);
121 fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
123 if (insta_art || fixed_art) {
124 for (const auto &a_ref : a_info) {
125 if (a_ref.idx == 0) {
128 if (insta_art && !a_ref.gen_flags.has(ItemGenerationTraitType::INSTA_ART)) {
131 if (a_ref.tval != k_info[k_idx].tval) {
134 if (a_ref.sval != k_info[k_idx].sval) {
137 if (a_ref.cur_num > 0) {
145 if (a_idx >= static_cast<ARTIFACT_IDX>(a_info.size())) {
150 /* Make an object (if possible) */
153 i_ptr->fixed_artifact_idx = a_idx;
155 ItemMagicApplier(player_ptr, i_ptr, 1, AM_NO_FIXED_ART).execute();
157 if (amuse_info[i].flag & AMS_NO_UNIQUE) {
158 if (r_info[i2enum<MonsterRaceId>(i_ptr->pval)].kind_flags.has(MonsterKindType::UNIQUE)) {
163 if (amuse_info[i].flag & AMS_MULTIPLE) {
164 i_ptr->number = randint1(3);
166 if (amuse_info[i].flag & AMS_PILE) {
167 i_ptr->number = randint1(99);
171 object_aware(player_ptr, i_ptr);
175 /* Paranoia - reroll if nothing */
176 if (!(i_ptr->k_idx)) {
180 (void)drop_near(player_ptr, i_ptr, -1, y1, x1);
188 * Scatter some "great" objects near the player
189 * @param player_ptr プレイヤーへの参照ポインタ
190 * @param y1 配置したいフロアのY座標
191 * @param x1 配置したいフロアのX座標
193 * @param great TRUEならば必ず高級品以上を落とす
194 * @param special TRUEならば必ず特別品を落とす
195 * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
197 void acquirement(PlayerType *player_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
200 ObjectType ObjectType_body;
201 BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : AM_NONE) | (special ? AM_SPECIAL : AM_NONE);
205 i_ptr = &ObjectType_body;
208 /* Make a good (or great) object (if possible) */
209 if (!make_object(player_ptr, i_ptr, mode)) {
214 object_aware(player_ptr, i_ptr);
218 (void)drop_near(player_ptr, i_ptr, -1, y1, x1);
224 * Curse the players armor
225 * @return 何も持っていない場合を除き、常にTRUEを返す
226 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
228 bool curse_armor(PlayerType *player_ptr)
230 /* Curse the body armor */
232 o_ptr = &player_ptr->inventory_list[INVEN_BODY];
238 GAME_TEXT o_name[MAX_NLEN];
239 describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
241 /* Attempt a saving throw for artifacts */
242 if (o_ptr->is_artifact() && (randint0(100) < 50)) {
245 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
247 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
252 /* not artifact or failed save... */
253 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
254 chg_virtue(player_ptr, V_ENCHANT, -5);
256 /* Blast the armor */
257 o_ptr->fixed_artifact_idx = 0;
258 o_ptr->ego_idx = EgoType::BLASTED;
259 o_ptr->to_a = 0 - randint1(5) - randint1(5);
266 o_ptr->art_flags.clear();
269 o_ptr->curse_flags.set(CurseTraitType::CURSED);
272 o_ptr->ident |= (IDENT_BROKEN);
273 player_ptr->update |= (PU_BONUS | PU_MANA);
274 player_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
280 * Curse the players weapon
281 * @param player_ptr 所持者の参照ポインタ
282 * @param force 無条件に呪縛を行うならばTRUE
283 * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
284 * @return 何も持っていない場合を除き、常にTRUEを返す
285 * @todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
287 bool curse_weapon_object(PlayerType *player_ptr, bool force, ObjectType *o_ptr)
293 GAME_TEXT o_name[MAX_NLEN];
294 describe_flavor(player_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
296 /* Attempt a saving throw */
297 if (o_ptr->is_artifact() && (randint0(100) < 50) && !force) {
299 msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
301 msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
306 /* not artifact or failed save... */
308 msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
310 chg_virtue(player_ptr, V_ENCHANT, -5);
312 /* Shatter the weapon */
313 o_ptr->fixed_artifact_idx = 0;
314 o_ptr->ego_idx = EgoType::SHATTERED;
315 o_ptr->to_h = 0 - randint1(5) - randint1(5);
316 o_ptr->to_d = 0 - randint1(5) - randint1(5);
322 o_ptr->art_flags.clear();
325 o_ptr->curse_flags.set(CurseTraitType::CURSED);
328 o_ptr->ident |= (IDENT_BROKEN);
329 player_ptr->update |= (PU_BONUS | PU_MANA);
330 player_ptr->window_flags |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
335 * @brief ボルトのエゴ化処理(火炎エゴのみ) /
337 * @param player_ptr プレイヤーへの参照ポインタ
339 void brand_bolts(PlayerType *player_ptr)
341 /* Use the first acceptable bolts */
342 for (int i = 0; i < INVEN_PACK; i++) {
343 auto *o_ptr = &player_ptr->inventory_list[i];
346 if (o_ptr->tval != ItemKindType::BOLT) {
350 /* Skip artifacts and ego-items */
351 if (o_ptr->is_artifact() || o_ptr->is_ego()) {
355 /* Skip cursed/broken items */
356 if (o_ptr->is_cursed() || o_ptr->is_broken()) {
361 if (randint0(100) < 75) {
365 msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
368 o_ptr->ego_idx = EgoType::FLAME;
369 enchant_equipment(player_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
376 msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
381 * Break the curse of an item
382 * @param o_ptr 呪い装備情報の参照ポインタ
384 static void break_curse(ObjectType *o_ptr)
386 BIT_FLAGS is_curse_broken = o_ptr->is_cursed() && o_ptr->curse_flags.has_not(CurseTraitType::PERMA_CURSE) && o_ptr->curse_flags.has_not(CurseTraitType::HEAVY_CURSE) && (randint0(100) < 25);
387 if (!is_curse_broken) {
391 msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
393 o_ptr->curse_flags.clear();
394 o_ptr->ident |= (IDENT_SENSE);
395 o_ptr->feeling = FEEL_NONE;
400 * Enchants a plus onto an item. -RAK-
401 * @param player_ptr プレイヤーへの参照ポインタ
402 * @param o_ptr 強化するアイテムの参照ポインタ
404 * @param eflag 強化オプション(命中/ダメージ/AC)
405 * @return 強化に成功した場合TRUEを返す
408 * Revamped! Now takes item pointer, number of times to try enchanting,
409 * and a flag of what to try enchanting. Artifacts resist enchantment
410 * some of the time, and successful enchantment to at least +0 might
411 * break a curse on the item. -CFT-
413 * Note that an item can technically be enchanted all the way to +15 if
414 * you wait a very, very, long time. Going from +9 to +10 only works
415 * about 5% of the time, and from +10 to +11 only about 1% of the time.
417 * Note that this function can now be used on "piles" of items, and
418 * the larger the pile, the lower the chance of success.
421 bool enchant_equipment(PlayerType *player_ptr, ObjectType *o_ptr, int n, int eflag)
423 /* Large piles resist enchantment */
424 int prob = o_ptr->number * 100;
426 /* Missiles are easy to enchant */
427 if ((o_ptr->tval == ItemKindType::BOLT) || (o_ptr->tval == ItemKindType::ARROW) || (o_ptr->tval == ItemKindType::SHOT)) {
434 bool a = o_ptr->is_artifact();
435 bool force = (eflag & ENCH_FORCE);
436 for (int i = 0; i < n; i++) {
437 /* Hack -- Roll for pile resistance */
438 if (!force && randint0(prob) >= 100) {
443 if (eflag & ENCH_TOHIT) {
444 if (o_ptr->to_h < 0) {
446 } else if (o_ptr->to_h > 15) {
449 chance = enchant_table[o_ptr->to_h];
452 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
456 /* only when you get it above -1 -CFT */
457 if (o_ptr->to_h >= 0) {
463 /* Enchant to damage */
464 if (eflag & ENCH_TODAM) {
465 if (o_ptr->to_d < 0) {
467 } else if (o_ptr->to_d > 15) {
470 chance = enchant_table[o_ptr->to_d];
473 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
477 /* only when you get it above -1 -CFT */
478 if (o_ptr->to_d >= 0) {
484 /* Enchant to armor class */
485 if (!(eflag & ENCH_TOAC)) {
489 if (o_ptr->to_a < 0) {
491 } else if (o_ptr->to_a > 15) {
494 chance = enchant_table[o_ptr->to_a];
497 if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
501 /* only when you get it above -1 -CFT */
502 if (o_ptr->to_a >= 0) {
512 set_bits(player_ptr->update, PU_BONUS | PU_COMBINE | PU_REORDER);
513 set_bits(player_ptr->window_flags, PW_INVEN | PW_EQUIP | PW_PLAYER | PW_FLOOR_ITEM_LIST);
520 * @brief 装備修正強化処理のメインルーチン /
521 * Enchant an item (in the inventory or on the floor)
522 * @param player_ptr プレイヤーへの参照ポインタ
523 * @param num_hit 命中修正量
524 * @param num_dam ダメージ修正量
525 * @param num_ac AC修正量
526 * @return 強化に成功した場合TRUEを返す
528 * Note that "num_ac" requires armour, else weapon
529 * Returns TRUE if attempted, FALSE if cancelled
531 bool enchant_spell(PlayerType *player_ptr, HIT_PROB num_hit, int num_dam, ARMOUR_CLASS num_ac)
533 /* Assume enchant weapon */
534 FuncItemTester item_tester(&ObjectType::allow_enchant_weapon);
536 /* Enchant armor if requested */
538 item_tester = FuncItemTester(&ObjectType::is_armour);
541 concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
542 concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
546 o_ptr = choose_object(player_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), item_tester);
551 GAME_TEXT o_name[MAX_NLEN];
552 describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
554 msg_format("%s は明るく輝いた!", o_name);
556 msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
560 bool is_enchant_successful = false;
561 if (enchant_equipment(player_ptr, o_ptr, num_hit, ENCH_TOHIT)) {
562 is_enchant_successful = true;
564 if (enchant_equipment(player_ptr, o_ptr, num_dam, ENCH_TODAM)) {
565 is_enchant_successful = true;
567 if (enchant_equipment(player_ptr, o_ptr, num_ac, ENCH_TOAC)) {
568 is_enchant_successful = true;
571 if (!is_enchant_successful) {
575 msg_print(_("強化に失敗した。", "The enchantment failed."));
577 chg_virtue(player_ptr, V_ENCHANT, -1);
580 chg_virtue(player_ptr, V_ENCHANT, 1);
583 calc_android_exp(player_ptr);
585 /* Something happened */
590 * @brief 武器へのエゴ付加処理 /
591 * Brand the current weapon
592 * @param player_ptr プレイヤーへの参照ポインタ
593 * @param brand_type エゴ化ID(e_info.txtとは連動していない)
595 void brand_weapon(PlayerType *player_ptr, int brand_type)
597 concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
598 concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
602 o_ptr = choose_object(player_ptr, &item, q, s, USE_EQUIP | IGNORE_BOTHHAND_SLOT, FuncItemTester(&ObjectType::allow_enchant_melee_weapon));
607 bool is_special_item = o_ptr->k_idx && !o_ptr->is_artifact() && !o_ptr->is_ego() && !o_ptr->is_cursed() && !((o_ptr->tval == ItemKindType::SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == ItemKindType::POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE)) && !((o_ptr->tval == ItemKindType::SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
608 if (!is_special_item) {
613 msg_print(_("属性付加に失敗した。", "The branding failed."));
614 chg_virtue(player_ptr, V_ENCHANT, -2);
615 calc_android_exp(player_ptr);
619 GAME_TEXT o_name[MAX_NLEN];
620 describe_flavor(player_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
622 concptr act = nullptr;
623 switch (brand_type) {
625 if (o_ptr->tval == ItemKindType::SWORD) {
626 act = _("は鋭さを増した!", "becomes very sharp!");
628 o_ptr->ego_idx = EgoType::SHARPNESS;
629 o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, player_ptr->current_floor_ptr->dun_level) + 1;
631 if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2)) {
635 act = _("は破壊力を増した!", "seems very powerful.");
636 o_ptr->ego_idx = EgoType::EARTHQUAKES;
637 o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, player_ptr->current_floor_ptr->dun_level);
642 act = _("は人間の血を求めている!", "seems to be looking for humans!");
643 o_ptr->ego_idx = EgoType::KILL_HUMAN;
646 act = _("は電撃に覆われた!", "covered with lightning!");
647 o_ptr->ego_idx = EgoType::BRAND_ELEC;
650 act = _("は酸に覆われた!", "coated with acid!");
651 o_ptr->ego_idx = EgoType::BRAND_ACID;
654 act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
655 o_ptr->ego_idx = EgoType::KILL_EVIL;
658 act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
659 o_ptr->ego_idx = EgoType::KILL_DEMON;
662 act = _("は屍を求めている!", "seems to be looking for undead!");
663 o_ptr->ego_idx = EgoType::KILL_UNDEAD;
666 act = _("は動物の血を求めている!", "seems to be looking for animals!");
667 o_ptr->ego_idx = EgoType::KILL_ANIMAL;
670 act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
671 o_ptr->ego_idx = EgoType::KILL_DRAGON;
674 act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
675 o_ptr->ego_idx = EgoType::KILL_TROLL;
678 act = _("はオークの血を求めている!", "seems to be looking for orcs!");
679 o_ptr->ego_idx = EgoType::KILL_ORC;
682 act = _("は巨人の血を求めている!", "seems to be looking for giants!");
683 o_ptr->ego_idx = EgoType::KILL_GIANT;
686 act = _("は非常に不安定になったようだ。", "seems very unstable now.");
687 o_ptr->ego_idx = EgoType::TRUMP;
688 o_ptr->pval = randint1(2);
691 act = _("は血を求めている!", "thirsts for blood!");
692 o_ptr->ego_idx = EgoType::VAMPIRIC;
695 act = _("は毒に覆われた。", "is coated with poison.");
696 o_ptr->ego_idx = EgoType::BRAND_POIS;
699 act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
700 o_ptr->ego_idx = EgoType::CHAOTIC;
703 act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
704 o_ptr->ego_idx = EgoType::BRAND_FIRE;
707 act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
708 o_ptr->ego_idx = EgoType::BRAND_COLD;
712 msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
713 enchant_equipment(player_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
714 o_ptr->discount = 99;
715 chg_virtue(player_ptr, V_ENCHANT, 2);
716 calc_android_exp(player_ptr);