pyoe2_craftpath/api/
currency.rs

1use std::hash::{Hash, Hasher};
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    api::{
7        provider::item_info::ItemInfoProvider,
8        types::{BaseGroupId, BaseItemId, EssenceId, THashSet},
9    },
10    utils::hash_utils::hash_set_unordered,
11};
12
13#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
14#[cfg_attr(
15    feature = "python",
16    pyo3_stub_gen::derive::gen_stub_pyclass_complex_enum
17)]
18#[cfg_attr(feature = "python", pyo3::prelude::pyclass)]
19#[cfg_attr(
20    feature = "python",
21    pyo3(eq, weakref, from_py_object, frozen, hash, get_all, str)
22)]
23pub enum CraftCurrencyEnum {
24    // CURRENCIES
25    OrbOfTransmutationNormal(), // cauz of complex enum type () is needed for python rep
26    OrbOfTransmutationGreater(),
27    OrbOfTransmutationPerfect(),
28    OrbOfAugmentationNormal(),
29    OrbOfAugmentationGreater(),
30    OrbOfAugmentationPerfect(),
31    RegalOrbNormal(),
32    RegalOrbGreater(),
33    RegalOrbPerfect(),
34    ExaltedOrbNormal(),
35    ExaltedOrbGreater(),
36    ExaltedOrbPerfect(),
37    OrbOfAnnulment(),
38    ChaosOrbNormal(),
39    ChaosOrbGreater(),
40    ChaosOrbPerfect(),
41    ArtificersOrb(),
42    VaalOrb(),
43    OmenOfCorruption(),
44
45    FracturingOrb(),
46
47    // DESECRATION
48    Desecrator(BaseItemId, BaseGroupId),
49    // CAN REROLL ONCE
50    AbyssalEchoes(),
51    // KURGAL MOD
52    TheBlackblooded(),
53    // ULAMAN MOD
54    TheSovereign(),
55    // AMANAMU MOD
56    TheLiege(),
57    // FORCE SUFFIX
58    DextralNecromancy(),
59    // FORCE PREFIX
60    SinistralNecromancy(),
61
62    // OMENS
63    // REGAL ORB, EX ORB
64    HomogenisingCoronation(),
65    HomogenisingExaltation(),
66    // EX ORB ONLY SUFFIX
67    DextralExaltation(),
68    // EX ORB ONLY PREFIX
69    SinistralExaltation(),
70
71    // Annuli ONLY SUFFIX
72    DextralAnnulment(),
73    // Annuli ONLY PREFIX
74    SinistralAnnulment(),
75
76    // CHAOS SUFFIX REMOVE
77    DextralErasure(),
78    // CHAOS PREFIX REMOVE
79    SinistralErasure(),
80    // CHAOS REMOVE LOWEST ILVL AFFIX
81    Whittling(),
82
83    Essence(EssenceId),
84    DextralCrystallisation(),
85    SinistralCrystallisation(),
86}
87
88#[cfg(feature = "python")]
89#[cfg_attr(feature = "python", pyo3_stub_gen::derive::gen_stub_pymethods)]
90#[cfg_attr(feature = "python", pyo3::pymethods)]
91impl CraftCurrencyEnum {
92    #[pyo3(name = "get_item_name")]
93    fn get_item_name_py<'a>(&self, item_info: &'a ItemInfoProvider) -> String {
94        self.get_item_name(&item_info).to_string()
95    }
96}
97
98impl CraftCurrencyEnum {
99    pub fn get_item_name<'a>(&self, item_info: &'a ItemInfoProvider) -> &'a str {
100        match self {
101            CraftCurrencyEnum::FracturingOrb() => "Fracturing Orb",
102            CraftCurrencyEnum::ArtificersOrb() => "Artificer's Orb",
103            CraftCurrencyEnum::VaalOrb() => "Vaal Orb",
104            CraftCurrencyEnum::OmenOfCorruption() => "Omen of Corruption",
105            CraftCurrencyEnum::AbyssalEchoes() => "Omen of Abyssal Echoes",
106            CraftCurrencyEnum::ChaosOrbGreater() => "Greater Chaos Orb",
107            CraftCurrencyEnum::ChaosOrbNormal() => "Chaos Orb",
108            CraftCurrencyEnum::ChaosOrbPerfect() => "Perfect Chaos Orb",
109            CraftCurrencyEnum::DextralAnnulment() => "Omen of Dextral Annulment",
110            CraftCurrencyEnum::DextralCrystallisation() => "Omen of Dextral Crystallisation",
111            CraftCurrencyEnum::DextralErasure() => "Omen of Dextral Erasure",
112            CraftCurrencyEnum::DextralExaltation() => "Omen of Dextral Exaltation",
113            CraftCurrencyEnum::DextralNecromancy() => "Omen of Dextral Necromancy",
114            CraftCurrencyEnum::ExaltedOrbGreater() => "Greater Exalted Orb",
115            CraftCurrencyEnum::ExaltedOrbNormal() => "Exalted Orb",
116            CraftCurrencyEnum::ExaltedOrbPerfect() => "Perfect Exalted Orb",
117            CraftCurrencyEnum::HomogenisingCoronation() => "Omen of Homogenising Coronation",
118            CraftCurrencyEnum::HomogenisingExaltation() => "Omen of Homogenising Exaltation",
119            CraftCurrencyEnum::OrbOfAnnulment() => "Orb of Annulment",
120            CraftCurrencyEnum::OrbOfAugmentationGreater() => "Greater Orb of Augmentation",
121            CraftCurrencyEnum::OrbOfAugmentationNormal() => "Orb of Augmentation",
122            CraftCurrencyEnum::OrbOfAugmentationPerfect() => "Perfect Orb of Augmentation",
123            CraftCurrencyEnum::OrbOfTransmutationGreater() => "Greater Orb of Transmutation",
124            CraftCurrencyEnum::OrbOfTransmutationNormal() => "Orb of Transmutation",
125            CraftCurrencyEnum::OrbOfTransmutationPerfect() => "Perfect Orb of Transmutation",
126            CraftCurrencyEnum::RegalOrbGreater() => "Greater Regal Orb",
127            CraftCurrencyEnum::RegalOrbNormal() => "Regal Orb",
128            CraftCurrencyEnum::RegalOrbPerfect() => "Perfect Regal Orb",
129            CraftCurrencyEnum::SinistralAnnulment() => "Omen of Sinistral Annulment",
130            CraftCurrencyEnum::SinistralCrystallisation() => "Omen of Sinistral Crystallisation",
131            CraftCurrencyEnum::SinistralErasure() => "Omen of Sinistral Erasure",
132            CraftCurrencyEnum::SinistralExaltation() => "Omen of Sinistral Exaltation",
133            CraftCurrencyEnum::SinistralNecromancy() => "Omen of Sinistral Necromancy",
134            CraftCurrencyEnum::TheBlackblooded() => "Omen of the Blackblooded",
135            CraftCurrencyEnum::TheLiege() => "Omen of the Liege",
136            CraftCurrencyEnum::TheSovereign() => "Omen of the Sovereign",
137            CraftCurrencyEnum::Whittling() => "Omen of Whittling",
138            CraftCurrencyEnum::Desecrator(base_item_id, base_group_id) => {
139                // Thanks for the info in https://www.craftofexile.com/js/poe2.js !
140                // My alg. doesnt handle loose propagation, so Ancient Bones are not needed for now
141                match base_item_id.get_raw_value() {
142                    // Jawbones
143                    4 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 216
144                    | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 => {
145                        "Preserved Jawbone"
146                    }
147
148                    // Ribs
149                    5 | 6 | 8 | 9 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44
150                    | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 229
151                    | 230 | 231 | 232 => "Preserved Rib",
152
153                    // Fallback for base items that are not jawbones or ribs
154                    _ => match base_group_id.get_raw_value() {
155                        1 => "Preserved Collarbone",
156                        9 => "Preserved Cranium",
157                        11 => "Preserved Spine",
158                        _ => todo!("Unhandled bone type"),
159                    },
160                }
161            }
162
163            CraftCurrencyEnum::Essence(bid) => item_info
164                .cache_essence_def
165                .get(bid)
166                .unwrap()
167                .name_essence
168                .as_str(),
169        }
170    }
171}
172
173#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
174#[cfg_attr(feature = "python", pyo3_stub_gen::derive::gen_stub_pyclass)]
175#[cfg_attr(feature = "python", pyo3::prelude::pyclass)]
176#[cfg_attr(
177    feature = "python",
178    pyo3(weakref, frozen, eq, hash, from_py_object, get_all, str)
179)]
180pub struct CraftCurrencyList {
181    pub list: THashSet<CraftCurrencyEnum>,
182}
183
184impl Hash for CraftCurrencyList {
185    fn hash<H: Hasher>(&self, state: &mut H) {
186        let currency_list_hash = hash_set_unordered(&self.list);
187        currency_list_hash.hash(state);
188    }
189}
190
191#[cfg(feature = "python")]
192crate::derive_DebugDisplay!(CraftCurrencyList, CraftCurrencyEnum);