OSDN Git Service

[Refactor] #3566 object_flags() をItemEntity のオブジェクトメソッドにコピペした (差し替えは次のメソッドで)
authorHourier <66951241+Hourier@users.noreply.github.com>
Thu, 27 Jul 2023 14:39:03 +0000 (23:39 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sun, 8 Oct 2023 05:24:44 +0000 (14:24 +0900)
src/system/item-entity.cpp
src/system/item-entity.h

index ac2cd0a..97f61c1 100644 (file)
@@ -820,3 +820,103 @@ ArtifactType &ItemEntity::get_fixed_artifact() const
 {
     return ArtifactsInfo::get_instance().get_artifact(this->fixed_artifact_idx);
 }
+
+TrFlags ItemEntity::get_flags() const
+{
+    const auto &baseitem = this->get_baseitem();
+    auto flags = baseitem.flags;
+
+    if (this->is_fixed_artifact()) {
+        flags = this->get_fixed_artifact().flags;
+    }
+
+    if (this->is_ego()) {
+        const auto &ego = this->get_ego();
+        flags.set(ego.flags);
+        this->modify_ego_lite_flags(flags);
+    }
+
+    flags.set(this->art_flags);
+    if (auto effect = Smith::object_effect(this); effect.has_value()) {
+        auto tr_flags = Smith::get_effect_tr_flags(effect.value());
+        flags.set(tr_flags);
+    }
+
+    if (Smith::object_activation(this).has_value()) {
+        flags.set(TR_ACTIVATE);
+    }
+
+    return flags;
+}
+
+TrFlags ItemEntity::get_flags_known() const
+{
+    TrFlags flags{};
+    if (!this->is_aware()) {
+        return flags;
+    }
+
+    const auto &baseitem = this->get_baseitem();
+    flags = baseitem.flags;
+    if (!this->is_known()) {
+        return flags;
+    }
+
+    if (this->is_ego()) {
+        const auto &ego = this->get_ego();
+        flags.set(ego.flags);
+        this->modify_ego_lite_flags(flags);
+    }
+
+    if (this->is_fully_known()) {
+        if (this->is_fixed_artifact()) {
+            flags = this->get_fixed_artifact().flags;
+        }
+
+        flags.set(this->art_flags);
+    }
+
+    if (auto effect = Smith::object_effect(this); effect.has_value()) {
+        auto tr_flags = Smith::get_effect_tr_flags(effect.value());
+        flags.set(tr_flags);
+    }
+
+    if (Smith::object_activation(this).has_value()) {
+        flags.set(TR_ACTIVATE);
+    }
+
+    return flags;
+}
+
+/*!
+ * @brief エゴ光源のフラグを修正する
+ *
+ * 寿命のある光源で寿命が0ターンの時、光源エゴアイテムに起因するフラグは
+ * 灼熱エゴの火炎耐性を除き付与されないようにする。
+ *
+ * @param flags フラグ情報を受け取る配列
+ */
+void ItemEntity::modify_ego_lite_flags(TrFlags &flags) const
+{
+    if (this->bi_key.tval() != ItemKindType::LITE) {
+        return;
+    }
+
+    if (!this->is_lite_requiring_fuel() || this->fuel != 0) {
+        return;
+    }
+
+    switch (this->ego_idx) {
+    case EgoType::LITE_AURA_FIRE:
+        flags.reset(TR_SH_FIRE);
+        return;
+    case EgoType::LITE_INFRA:
+        flags.reset(TR_INFRA);
+        return;
+    case EgoType::LITE_EYE:
+        flags.reset({ TR_RES_BLIND, TR_SEE_INVIS });
+        return;
+    default:
+        return;
+    }
+}
index f20a7fd..ad5bdd9 100644 (file)
@@ -140,9 +140,12 @@ public:
     BaseitemInfo &get_baseitem() const;
     EgoItemDefinition &get_ego() const;
     ArtifactType &get_fixed_artifact() const;
+    TrFlags get_flags() const;
+    TrFlags get_flags_known() const;
 
 private:
     int get_baseitem_price() const;
     int calc_figurine_value() const;
     int calc_capture_value() const;
+    void modify_ego_lite_flags(TrFlags &flags) const;
 };