2 * @brief 武器でも防具でもアクセサリでもない、その他のアイテム群を生成・強化する処理
5 * @details 他との兼ね合いでEnchanterとなっているが、油つぼ・人形・死体・像は生成のみで強化はしない
8 #include "object-enchant/others/apply-magic-others.h"
9 #include "artifact/random-art-generator.h"
10 #include "game-option/cheat-options.h"
11 #include "inventory/inventory-slot-types.h"
12 #include "monster-floor/place-monster-types.h"
13 #include "monster-race/monster-race-hook.h"
14 #include "monster-race/monster-race.h"
15 #include "monster-race/race-indice-types.h"
16 #include "monster/monster-list.h"
17 #include "monster/monster-util.h"
18 #include "object-enchant/object-ego.h"
19 #include "object-enchant/tr-types.h"
20 #include "object-enchant/trc-types.h"
21 #include "object/tval-types.h"
22 #include "perception/object-perception.h"
23 #include "sv-definition/sv-lite-types.h"
24 #include "sv-definition/sv-other-types.h"
25 #include "system/baseitem-info.h"
26 #include "system/floor-type-definition.h"
27 #include "system/item-entity.h"
28 #include "system/monster-race-info.h"
29 #include "system/player-type-definition.h"
30 #include "util/bit-flags-calculator.h"
31 #include "view/display-messages.h"
32 #include <unordered_map>
36 * @param player_ptr プレイヤーへの参照ポインタ
37 * @param o_ptr 強化を与えたい/生成したいオブジェクトの構造体参照ポインタ
39 * @details power > 2はデバッグ専用.
41 OtherItemsEnchanter::OtherItemsEnchanter(PlayerType *player_ptr, ItemEntity *o_ptr)
42 : player_ptr(player_ptr)
48 * @brief その他雑多のオブジェクトに生成ランクごとの強化を与える
49 * @details power > 2はデバッグ専用.
51 void OtherItemsEnchanter::apply_magic()
53 const auto tval = this->o_ptr->bi_key.tval();
55 case ItemKindType::FLASK:
56 this->o_ptr->fuel = this->o_ptr->pval;
57 this->o_ptr->pval = 0;
59 case ItemKindType::WAND:
60 case ItemKindType::STAFF:
61 this->enchant_wand_staff();
63 case ItemKindType::ROD:
64 this->o_ptr->pval = this->o_ptr->get_baseitem().pval;
66 case ItemKindType::CAPTURE:
67 this->o_ptr->pval = 0;
68 object_aware(this->player_ptr, this->o_ptr);
69 this->o_ptr->mark_as_known();
71 case ItemKindType::FIGURINE:
72 this->generate_figurine();
74 case ItemKindType::CORPSE:
75 this->generate_corpse();
77 case ItemKindType::STATUE:
78 this->generate_statue();
80 case ItemKindType::CHEST:
81 this->generate_chest();
90 * The wand or staff gets a number of initial charges equal
91 * to between 1/2 (+1) and the full object kind's pval.
93 void OtherItemsEnchanter::enchant_wand_staff()
95 const auto &baseitem = this->o_ptr->get_baseitem();
96 this->o_ptr->pval = baseitem.pval / 2 + randint1((baseitem.pval + 1) / 2);
100 * @brief ランダムに選択したモンスター種族IDからその人形を作る
103 * レアリティが1~100のものだけ生成対象になる
107 void OtherItemsEnchanter::generate_figurine()
109 auto *floor_ptr = this->player_ptr->current_floor_ptr;
112 r_idx = MonsterRace::pick_one_at_random();
113 if (!item_monster_okay(this->player_ptr, r_idx) || (r_idx == MonsterRaceId::TSUCHINOKO)) {
117 auto *r_ptr = &monraces_info[r_idx];
118 auto check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
119 if ((r_ptr->rarity == 0) || (r_ptr->rarity > 100) || (randint0(check) > 0)) {
126 this->o_ptr->pval = enum2i(r_idx);
128 this->o_ptr->curse_flags.set(CurseTraitType::CURSED);
133 * @brief ランダムに選択したモンスター種族IDからその死体/骨を作る
135 * そもそも死体も骨も落とさないモンスターは対象外
136 * ユニークやあやしい影等、そこらに落ちている死体としてふさわしくないものは弾く
137 * レアリティが1~100のものだけ生成対象になる (はず)
138 * レベルの高い死体/骨ほど生成されにくい
140 void OtherItemsEnchanter::generate_corpse()
142 const std::unordered_map<int, MonsterDropType> match = {
143 { SV_SKELETON, MonsterDropType::DROP_SKELETON },
144 { SV_CORPSE, MonsterDropType::DROP_CORPSE },
147 get_mon_num_prep(this->player_ptr, item_monster_okay, nullptr);
148 auto *floor_ptr = this->player_ptr->current_floor_ptr;
151 r_idx = get_mon_num(this->player_ptr, 0, floor_ptr->dun_level, PM_NONE);
152 auto &r_ref = monraces_info[r_idx];
153 auto check = (floor_ptr->dun_level < r_ref.level) ? (r_ref.level - floor_ptr->dun_level) : 0;
154 const auto sval = this->o_ptr->bi_key.sval();
155 if (!sval.has_value()) {
159 if ((r_ref.rarity == 0) || (match.find(sval.value()) != match.end() && r_ref.drop_flags.has_not(match.at(sval.value()))) || (randint0(check) > 0)) {
166 this->o_ptr->pval = enum2i(r_idx);
167 object_aware(this->player_ptr, this->o_ptr);
168 this->o_ptr->mark_as_known();
172 * @brief ランダムに選択したモンスター種族IDからその像を作る
173 * @details レアリティが1以上のものだけ生成対象になる
175 void OtherItemsEnchanter::generate_statue()
177 auto pick_r_idx_for_statue = [] {
179 auto r_idx = MonsterRace::pick_one_at_random();
180 if (monraces_info[r_idx].rarity > 0) {
185 auto r_idx = pick_r_idx_for_statue();
186 auto *r_ptr = &monraces_info[r_idx];
188 this->o_ptr->pval = enum2i(r_idx);
190 msg_format(_("%sの像", "Statue of %s"), r_ptr->name.data());
193 object_aware(this->player_ptr, this->o_ptr);
194 this->o_ptr->mark_as_known();
199 * @details 箱にはレベルがあり、箱の召喚トラップが発動すると箱レベルと同等のモンスターが召喚される
201 void OtherItemsEnchanter::generate_chest()
203 auto obj_level = this->o_ptr->get_baseitem().level;
204 if (obj_level <= 0) {
208 this->o_ptr->pval = randint1(obj_level);
209 if (this->o_ptr->bi_key.sval() == SV_CHEST_KANDUME) {
210 this->o_ptr->pval = 6;
213 this->o_ptr->chest_level = this->player_ptr->current_floor_ptr->dun_level + 5;
214 if (this->o_ptr->pval > 55) {
215 this->o_ptr->pval = 55 + randint0(5);